Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/__tests__/sitemap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/<version-key> branches to the version key", () => {
expect(getVersionFromBranch("docs/v6")).toBe("v6");
expect(getVersionFromBranch("docs/latest")).toBe("latest");
});
});

describe("isVersionBranch", () => {
Expand Down
Loading