From 0d2df39339ca788bf75f492683079ccccf940000 Mon Sep 17 00:00:00 2001 From: Paul Bakaus Date: Fri, 28 Aug 2026 15:32:22 -0700 Subject: [PATCH] Root-relative stylesheet hrefs resolve against the project, not the drive root Bugbot on #599: path.resolve treated /assets/hero.css as filesystem-absolute. Both the working directory and the artifact's directory are tried; unreadable candidates skip. AI-assisted (Claude Code). --- skill/scripts/build-phase.mjs | 7 ++++++- tests/build-phase.test.mjs | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/skill/scripts/build-phase.mjs b/skill/scripts/build-phase.mjs index 73b367e8a..47639d9b4 100644 --- a/skill/scripts/build-phase.mjs +++ b/skill/scripts/build-phase.mjs @@ -355,7 +355,12 @@ export function unreferencedPlates(spec, artifact = null) { const href = m[1]; if (/^(https?:|data:|\/\/)/i.test(href)) continue; if (!/rel=["']?stylesheet/i.test(m[0]) && !/\.css(\?|$)/i.test(href)) continue; - linked.push(path.resolve(path.dirname(artifact), href.split('?')[0])); + const clean = href.split('?')[0]; + // a root-relative href serves from the project root, not the drive + // root: try the working directory and the artifact's own directory + // (unreadable candidates are skipped by the corpus loop) + if (clean.startsWith('/')) { linked.push(path.join(process.cwd(), clean), path.join(path.dirname(artifact), clean)); } + else linked.push(path.resolve(path.dirname(artifact), clean)); } } catch { /* the artifact still counts */ } } diff --git a/tests/build-phase.test.mjs b/tests/build-phase.test.mjs index cdcfa7162..68407d303 100644 --- a/tests/build-phase.test.mjs +++ b/tests/build-phase.test.mjs @@ -485,6 +485,9 @@ describe('unreferencedPlates', () => { fs.writeFileSync(path.join(d, 'index.html'), `
`); fs.writeFileSync(path.join(d, 'assets', 'hero.css'), '.hero { background: red; }'); assert.deepEqual(unreferencedPlates(spec, path.join(d, 'index.html')), [], 'a stylesheet linked by the artifact counts wherever it lives'); + // a root-relative href resolves against the project, not the drive root + fs.writeFileSync(path.join(d, 'index.html'), `
`); + assert.deepEqual(unreferencedPlates(spec, path.join(d, 'index.html')), [], 'a root-relative stylesheet href counts'); fs.writeFileSync(path.join(deep, 'deep.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');