import test from 'node:test' import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import path from 'node:path' import { fileURLToPath } from 'node:url' const testDirectory = path.dirname(fileURLToPath(import.meta.url)) const workspace = path.resolve(testDirectory, '..', '..') const manifestPath = path.join(workspace, 'design-pipeline', 'manifests', 'g01-background-candidates.json') const wrapperPath = path.join(workspace, 'design-pipeline', 'scripts', 'build-g01-backgrounds.mjs') test('G01 background candidate manifest preserves four portable masters and selects the approved long background', async () => { const manifest = JSON.parse(await readFile(manifestPath, 'utf8')) assert.equal(manifest.schemaVersion, 1) assert.equal(manifest.page, 'G01') assert.equal(manifest.status, 'long-flagship-selected-for-genealogy-module') assert.equal(manifest.selectedCandidateId, 'g01-list-background-long-flagship') assert.equal(manifest.runtimeOutput, 'static/assets/modules/genealogy/opaque/genealogy-page-background-long.png') assert.equal(manifest.candidates.length, 4) const ids = new Set() for (const candidate of manifest.candidates) { assert.ok(!ids.has(candidate.id), `duplicate candidate id: ${candidate.id}`) ids.add(candidate.id) assert.match(candidate.prompt, /\d+x\d+/) assert.ok(candidate.sourcePixels.width > 0 && candidate.sourcePixels.height > 0) assert.ok(['chroma-key', 'opaque-paper', 'opaque-paper-resize'].includes(candidate.processingMode)) for (const key of ['master', 'generatedOutput']) { const absolute = path.resolve(workspace, candidate[key]) const relative = path.relative(workspace, absolute) assert.ok(!relative.startsWith('..') && !path.isAbsolute(relative), `${key} escapes workspace`) } } const selected = manifest.candidates.find(({ id }) => id === manifest.selectedCandidateId) assert.deepEqual(selected.sourcePixels, { width: 1536, height: 3840 }) assert.deepEqual(selected.outputPixels, { width: 1440, height: 3600 }) assert.equal(selected.processingMode, 'opaque-paper-resize') }) test('G01 Node wrapper delegates pixel decoding to locked Pillow without Sharp', async () => { const wrapper = await readFile(wrapperPath, 'utf8') assert.doesNotMatch(wrapper, /from ['"]sharp['"]/) assert.match(wrapper, /build_g01_backgrounds\.py/) assert.match(wrapper, /candidates\?\.length !== 4/) })