From 9e24a5e1e18e622eb045b301dac92af03b7f315a Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 18 Sep 2026 00:34:49 +0000 Subject: [PATCH] Add controller asset integrity tests --- tests/assets.test.mjs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/assets.test.mjs diff --git a/tests/assets.test.mjs b/tests/assets.test.mjs new file mode 100644 index 0000000..a93e274 --- /dev/null +++ b/tests/assets.test.mjs @@ -0,0 +1,42 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; + +import topHud from '../src/assets/controller/top-hud.js'; +import leftStatus from '../src/assets/controller/left-status.js'; +import rightControls from '../src/assets/controller/right-controls.js'; +import cannonRoundel from '../src/assets/controller/cannon-roundel.js'; +import helmFrame from '../src/assets/controller/helm-frame.js'; +import helmKnob from '../src/assets/controller/helm-knob.js'; + +const assets = { + topHud, + leftStatus, + rightControls, + cannonRoundel, + helmFrame, + helmKnob, +}; + +const decodeWebP = (name, dataUrl) => { + const match = /^data:image\/webp;base64,([A-Za-z0-9+/=]+)$/.exec(dataUrl); + assert.ok(match, `${name} must be a WebP data URL`); + + const bytes = Buffer.from(match[1], 'base64'); + assert.equal(bytes.subarray(0, 4).toString('ascii'), 'RIFF', `${name} RIFF header`); + assert.equal(bytes.subarray(8, 12).toString('ascii'), 'WEBP', `${name} WEBP signature`); + + const declaredSize = bytes.readUInt32LE(4) + 8; + assert.equal( + bytes.length, + declaredSize, + `${name} must not be truncated: declared ${declaredSize}, actual ${bytes.length}`, + ); + + assert.ok(bytes.length > 100, `${name} should contain real image data`); +}; + +for (const [name, dataUrl] of Object.entries(assets)) { + test(`${name} WebP payload is structurally complete`, () => { + decodeWebP(name, dataUrl); + }); +}