openclaw/test/scripts/docs-source-anchors.test.ts
Peter Steinberger 0a1e564d34
fix(docs): repair section links and duplicate source anchors (#137879)
Point the computer-use section link at its existing published alias and let headings own the Podman and generated maturity jump targets. Preserve existing IDs and cover resolution and uniqueness through the shared publishing parser.
2026-09-03 22:39:31 -07:00

38 lines
1.6 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { parseDocsDocument, resolveDocsFragment } from "../../scripts/lib/docs-markdown.mjs";
const docsRoot = path.resolve(import.meta.dirname, "../../docs");
function readDocument(file: string) {
return parseDocsDocument(fs.readFileSync(path.join(docsRoot, file), "utf8"));
}
describe("authored docs section links", () => {
it("links Codex Computer Use to the Windows and Linux fulfiller section", () => {
const source = readDocument("plugins/codex-computer-use.md");
const target = readDocument("nodes/computer-use.md");
const links = source.links.filter((href: string) => href.startsWith("/nodes/computer-use#"));
expect(links).toHaveLength(1);
const heading = target.tokens.find(
(token, index) =>
token.type === "heading_open" &&
target.tokens[index + 1]?.content === "Windows and Linux (experimental, direct SDK)",
);
expect(heading).toBeDefined();
const headingIds = [heading?.attrGet("id"), heading?.meta?.anchorAlias].filter(
(id): id is string => typeof id === "string",
);
expect(headingIds).not.toHaveLength(0);
expect(headingIds).toContain(resolveDocsFragment(links[0].split("#")[1], new Set(target.ids)));
});
it("keeps the Podman and Tailscale jump target unique and collision-free", () => {
const document = readDocument("install/podman.md");
expect(document.links).toContain("#podman-and-tailscale");
expect(document.ids.filter((id: string) => id === "podman-and-tailscale")).toHaveLength(1);
expect(document.collisions).toEqual([]);
});
});