From d511a50fe03525471468a304b3bd95b40cacae71 Mon Sep 17 00:00:00 2001 From: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sat, 31 Oct 2026 15:29:28 -0400 Subject: [PATCH 1/2] test: pin the prune guards for a removed sibling page's image refs 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 <223556219+Copilot@users.noreply.github.com> Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- scripts/sync-sibling-docs.main.test.ts | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/scripts/sync-sibling-docs.main.test.ts b/scripts/sync-sibling-docs.main.test.ts index ccede45..813c884 100644 --- a/scripts/sync-sibling-docs.main.test.ts +++ b/scripts/sync-sibling-docs.main.test.ts @@ -254,6 +254,42 @@ describe("sync-sibling-docs main()", () => { expect(fs.existsSync(shared)).toBe(true); }); + it("never prunes paths a removed page references outside its directory, by URL, or that are not files", async () => { + const stale = outPath("hotshot", "linux.md"); + const outside = path.join(caseDir, "docs", "escape.png"); + const sibling = outPath("pluk", "images/pluk.png"); + const dir = outPath("hotshot", "images/dir"); + fs.mkdirSync(path.dirname(stale), { recursive: true }); + fs.mkdirSync(path.dirname(sibling), { recursive: true }); + fs.mkdirSync(dir, { recursive: true }); + fs.writeFileSync(outside, "png"); + fs.writeFileSync(sibling, "png"); + fs.writeFileSync( + stale, + [ + "![up](../../escape.png)", + "![other](../pluk/images/pluk.png)", + "![abs](https://example.com/remote.png)", + "![proto](//cdn.example.com/remote.png)", + "![anchor](#not-an-image)", + "![data](data:image/png;base64,AAAA)", + "![gone](images/already-gone.png)", + "![dir](images/dir)", + "", + ].join("\n") + ); + stubFetch(allReadmes()); + const { warn, err } = await runSync(); + + expect(exitSpy).not.toHaveBeenCalled(); + expect(err).toBe(""); + expect(fs.existsSync(stale)).toBe(false); + expect(warn).toContain("removed stale hotshot/linux.md"); + expect(fs.existsSync(outside)).toBe(true); + expect(fs.existsSync(sibling)).toBe(true); + expect(fs.statSync(dir).isDirectory()).toBe(true); + }); + it.each([429, 500])( "keeps a previously synced optional page when its source answers %i", async status => { From 0423ab10ede9a630232b06bc00e21795bc447dc6 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sat, 31 Oct 2026 15:54:07 -0400 Subject: [PATCH 2/2] test: plant files where URL image refs would resolve so the guard is 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 <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- scripts/sync-sibling-docs.main.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/sync-sibling-docs.main.test.ts b/scripts/sync-sibling-docs.main.test.ts index 813c884..58741bf 100644 --- a/scripts/sync-sibling-docs.main.test.ts +++ b/scripts/sync-sibling-docs.main.test.ts @@ -259,11 +259,19 @@ describe("sync-sibling-docs main()", () => { const outside = path.join(caseDir, "docs", "escape.png"); const sibling = outPath("pluk", "images/pluk.png"); const dir = outPath("hotshot", "images/dir"); + // Where the URL refs below would land if localImageRefs stopped skipping + // them: the scheme/host segments become path components under outDir. + const schemeAsPath = outPath("hotshot", "https:/example.com/remote.png"); + const protoAsPath = outPath("hotshot", "cdn.example.com/remote.png"); fs.mkdirSync(path.dirname(stale), { recursive: true }); fs.mkdirSync(path.dirname(sibling), { recursive: true }); fs.mkdirSync(dir, { recursive: true }); + fs.mkdirSync(path.dirname(schemeAsPath), { recursive: true }); + fs.mkdirSync(path.dirname(protoAsPath), { recursive: true }); fs.writeFileSync(outside, "png"); fs.writeFileSync(sibling, "png"); + fs.writeFileSync(schemeAsPath, "png"); + fs.writeFileSync(protoAsPath, "png"); fs.writeFileSync( stale, [ @@ -287,6 +295,8 @@ describe("sync-sibling-docs main()", () => { expect(warn).toContain("removed stale hotshot/linux.md"); expect(fs.existsSync(outside)).toBe(true); expect(fs.existsSync(sibling)).toBe(true); + expect(fs.existsSync(schemeAsPath)).toBe(true); + expect(fs.existsSync(protoAsPath)).toBe(true); expect(fs.statSync(dir).isDirectory()).toBe(true); });