diff --git a/skill/scripts/build-phase.mjs b/skill/scripts/build-phase.mjs index 5c643b365..d29b51ebf 100644 --- a/skill/scripts/build-phase.mjs +++ b/skill/scripts/build-phase.mjs @@ -341,7 +341,10 @@ function sourceFiles(root = '.', limit = 400) { export function unreferencedPlates(spec, artifact = null) { const plates = (spec?.regions || []).filter((r) => r.medium === 'raster' && r.plate); if (!plates.length) return []; - const files = artifact && fs.existsSync(artifact) ? [artifact] : sourceFiles(); + // The artifact narrows nothing: a plate may be referenced only from a + // stylesheet the artifact links (assets/hero.css), so the source walk runs + // either way and the artifact is simply guaranteed a seat in the corpus. + const files = [...new Set([...(artifact && fs.existsSync(artifact) ? [artifact] : []), ...sourceFiles()])]; let corpus = ''; for (const f of files) { try { corpus += fs.readFileSync(f, 'utf8') + '\n'; } catch { /* skip */ } } const missing = []; diff --git a/tests/build-phase.test.mjs b/tests/build-phase.test.mjs index ac635601d..8bfa65654 100644 --- a/tests/build-phase.test.mjs +++ b/tests/build-phase.test.mjs @@ -475,8 +475,12 @@ describe('unreferencedPlates', () => { fs.writeFileSync(path.join(d, 'assets', 'hero.css'), ".hero { background-image: url('./plates/hero-plate.png'); }"); const spec = { regions: [{ id: 'hero-art', medium: 'raster', plate: 'assets/plates/hero-plate.png' }] }; assert.deepEqual(unreferencedPlates(spec, null), [], 'the stylesheet under assets counts as a reference'); + // an explicit artifact does not bypass the stylesheet walk + fs.writeFileSync(path.join(d, 'index.html'), '
'); + assert.deepEqual(unreferencedPlates(spec, path.join(d, 'index.html')), [], 'the linked stylesheet still counts with --artifact set'); fs.writeFileSync(path.join(d, 'assets', 'hero.css'), '.hero { background: red; }'); assert.equal(unreferencedPlates(spec, null).length, 1, 'an unreferenced plate is still named'); + assert.equal(unreferencedPlates(spec, path.join(d, 'index.html')).length, 1, 'and with the artifact set too'); } finally { process.chdir(prev); fs.rmSync(d, { recursive: true, force: true }); } }); });