From 5f405589a51671f9a4f019244c6e4090807558f2 Mon Sep 17 00:00:00 2001 From: quality Date: Fri, 16 Oct 2026 03:25:28 -0400 Subject: [PATCH] test: cover sitemap stat fallback and hive release-branch version mapping sitemap.ts getLastModified() swallowed stat errors with a fresh Date but the catch path was never exercised; getVersionFromBranch() was only tested for main/master and unknown branches, never for the v4/v5/v6 release branches or docs/ branches it actually maps. Both files now report 100% in the Vitest coverage gate. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: quality --- src/__tests__/sitemap.test.ts | 29 +++++++++++++++++++++++++++++ src/__tests__/versions.test.ts | 13 +++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/__tests__/sitemap.test.ts b/src/__tests__/sitemap.test.ts index e9938f5..d20f362 100644 --- a/src/__tests__/sitemap.test.ts +++ b/src/__tests__/sitemap.test.ts @@ -100,6 +100,35 @@ describe("sitemap generated from fixture content", () => { expect(byUrl.has(`${SITE_URL}/docs/hive/unlinked/page`)).toBe(false); }); + it("falls back to the current time when a linked file cannot be stat'ed", () => { + fixtureRoot = fs.mkdtempSync(path.join(realCwd, ".sitemap-stat-")); + const archPath = write("docs/content/hive/architecture.md"); + vi.spyOn(process, "cwd").mockReturnValue(fixtureRoot); + const realStat = fs.statSync; + vi.spyOn(fs, "statSync").mockImplementation((( + p: fs.PathLike, + ...rest: unknown[] + ) => { + if (String(p) === archPath) { + throw Object.assign(new Error("EACCES"), { code: "EACCES" }); + } + return (realStat as (...a: unknown[]) => fs.Stats)(p, ...rest); + }) as typeof fs.statSync); + + const before = Date.now(); + const entries = sitemap(); + const after = Date.now(); + const arch = entries.find( + entry => entry.url === `${SITE_URL}/docs/hive/overview/architecture` + ); + + expect(arch).toBeDefined(); + expect(arch?.lastModified).toBeInstanceOf(Date); + const stamp = (arch?.lastModified as Date).getTime(); + expect(stamp).toBeGreaterThanOrEqual(before); + expect(stamp).toBeLessThanOrEqual(after); + }); + it("omits generated routes for missing content while retaining project roots", () => { fixtureRoot = fs.mkdtempSync(path.join(realCwd, ".sitemap-empty-")); vi.spyOn(process, "cwd").mockReturnValue(fixtureRoot); diff --git a/src/__tests__/versions.test.ts b/src/__tests__/versions.test.ts index 414d4d7..6d557db 100644 --- a/src/__tests__/versions.test.ts +++ b/src/__tests__/versions.test.ts @@ -111,6 +111,19 @@ describe("getVersionFromBranch", () => { it("returns null for docs/* branches with no matching version entry", () => { expect(getVersionFromBranch("docs/9.9.9")).toBeNull(); }); + + it("maps hive release branches to their version keys", () => { + // v5 feeds the `stable` channel and is the sync-hive-docs default ref; + // if it stops resolving, the version selector loses its default entry. + expect(getVersionFromBranch("v5")).toBe("latest"); + expect(getVersionFromBranch("v6")).toBe("v6"); + expect(getVersionFromBranch("v4")).toBe("v4"); + }); + + it("maps docs/ branches to the version key", () => { + expect(getVersionFromBranch("docs/v6")).toBe("v6"); + expect(getVersionFromBranch("docs/latest")).toBe("latest"); + }); }); describe("isVersionBranch", () => {