40 lines
1.8 KiB
JavaScript
40 lines
1.8 KiB
JavaScript
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 three portable masters', async () => {
|
|
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'))
|
|
assert.equal(manifest.schemaVersion, 1)
|
|
assert.equal(manifest.page, 'G01')
|
|
assert.equal(manifest.status, 'candidates-pending-user-selection')
|
|
assert.equal(manifest.candidates.length, 3)
|
|
|
|
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, /1024x1536/)
|
|
assert.deepEqual(candidate.sourcePixels, { width: 1024, height: 1536 })
|
|
assert.ok(['chroma-key', 'opaque-paper'].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`)
|
|
}
|
|
}
|
|
})
|
|
|
|
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/)
|
|
})
|