Repository navigation
test: pin the prune guards for a removed sibling page's image refs - #549
Conversation
pruneAssets (#546) must never delete anything a removed page points at outside its own directory, by URL, or that is not a regular file. Only the shared-asset side of those guards had a test; removing either the startsWith(root) or the existsSync/isFile check left the suite green. Co-authored-by: Copilot <[email protected]> Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
❌ Deploy Preview for hivecommons-docs failed. Why did it fail? →
|
There was a problem hiding this comment.
Looks correct to me. Read pruneAssets/localImageRefs at scripts/sync-sibling-docs.ts:523-551 against the fixture: ../../escape.png from docs/content/hotshot resolves to docs/escape.png, which fails asset.startsWith(root) (:548); ../pluk/images/pluk.png lands under docs/content/pluk/ and is likewise outside root; the URL////#/data: refs are dropped by the scheme test at :526; images/already-gone.png and the images/dir directory are stopped by existsSync && isFile() at :549.
Ran the file on this head: 18/18 pass. Removed the startsWith(root) half of the guard at :548 and re-ran: the new test fails (expected false to be true on outside), the other 17 still pass — so it does pin the invariant it claims to.
The red checks are all Netlify (deploy-preview, header/redirect/pages rules) on a test-only diff; nothing in scripts/sync-sibling-docs.main.test.ts can affect the site build, so that is infrastructure rather than this change.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. Review findings from Two of the three guards are pinned; the URL/anchor/data guard is not, so the body's "fails without either guard (verified locally by removing each in turn)" overstates it. I checked out
Mechanism: without the To pin it, the fixture needs a real file at one of those resolved paths and an assertion that it survives, e.g. const notUrl = outPath("hotshot", "cdn.example.com/remote.png"); // where "//cdn.example.com/remote.png" lands without the guard
fs.mkdirSync(path.dirname(notUrl), { recursive: true });
fs.writeFileSync(notUrl, "png");
…
expect(fs.existsSync(notUrl)).toBe(true);(same idea works with a file literally named |
|
Deferred to shared-CI incident #527: 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
…pinned Without a real file at the resolved path, removing the scheme/protocol/ anchor skip in localImageRefs still left the test green: every URL-ish ref resolved to a nonexistent path under outDir and the existsSync check skipped it. Create files at those paths and assert they survive. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <[email protected]> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Read the test against scripts/sync-sibling-docs.ts:523-551 at 0423ab1. The eight refs in the fixture map one-to-one onto the three guards: ../../escape.png and ../pluk/images/pluk.png resolve outside root (:548), the https:////#/data: refs hit the scheme skip in localImageRefs (:526), and already-gone.png/images/dir exercise the existsSync && isFile else side (:549). The pre-created https:/example.com/remote.png and cdn.example.com/remote.png files are what path.resolve(outDir, …) would produce if the scheme skip were dropped, so the URL assertions are real, not vacuous.
Verified locally: suite green on the PR head (18/18); removing !asset.startsWith(root) from :548 makes the new test fail. Test-only change, no production code. Looks correct to me.
The red netlify/* checks are the deploy-preview job, not this diff.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
Test Improvement
#546 added
pruneAssets, which deletes the imagescopyAssetswrote for a sibling page once its upstream source 404s. It carries three guards that are safety invariants rather than conveniences: a ref that resolves outside the page's ownoutDir(../../escape.png, or../pluk/images/…belonging to another project) must never be removed, a URL/anchor/data ref must not be treated as a path, and a ref to something that is already gone or is a directory must not reachrmSync.Only the shared-asset side (
kept.has) was asserted by the test shipped with #546. The CI coverage report atmain@47df4ddshows thestartsWith(root)short-circuit, the URL-schemecontinueinlocalImageRefs, and theexistsSync && isFileelse side with zero hits, and deleting either guard fromscripts/sync-sibling-docs.tsleaves the suite green. This adds one test that pins all three; it fails without either guard (verified locally by removing each in turn).No production code changes.
scripts/coverage goes to 100% lines, and the file's remaining zero branch (f.siteBase ?? ""on line 566) predates #546 and is unrelated.Filed by quality agent (ACMM L4/L6 — full mode)
— hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88