chore(gates): check docs internal links and heading anchors

Merged
TH
1mo ago
+439-22

Summary

Adds pnpm check:doc-links and a docs-links gate. They fail when a link on the docs site, or a README link into it, points to a page or heading that rspress didn't render, or when a page renders the same heading ID twice. rspress's production build already fails on links to missing pages, but it builds #fragment links to missing headings without complaint. Pages moving between files (#3397, #3399) and dedup passes like #3295 can break those silently.

Design: check the built site. The gate runs pnpm --dir website build (about 3 s warm), then scripts/check-doc-links.ts, which reads website/doc_build/**/*.html:

  • Heading IDs: taken from the IDs rspress rendered, so there is no copy of its slugger, heading-text extraction, or link rewriting, and no Markdown parser. The PR adds no dependencies, and the lockfile is unchanged.
  • Internal links: each must name a built page, and its fragment must be an ID on that page. External URLs are skipped; there are no network calls.
  • Site base: read from the build (rspress serves its entry script under assetPrefix, which defaults to base). The script also checks the home link, so a misread base fails instead of making every link look external. It doesn't force a base with RSPRESS_BASE, because rspack's build cache ignores that variable and would serve stale output.
  • README: its https://oss.callstack.com/agent-device/docs/... URLs (Markdown links and bare URLs) are checked against the same build.
  • Errors name the built page, the link, and the source file, e.g. docs/quick-start: link "/agent-device/docs/sessions#find-a-session-logs" โ†’ no heading "find-a-session-logs" (website/docs/docs/quick-start.md).

Why not an rspress plugin: a rehype or afterBuild plugin would read the same rendered IDs. But it would have to collect links across pages inside rspress hooks, couple the gate to the website config, and still leave README to a separate script. Scanning the HTML after the build checks the same output with less coupling.

Wiring: registered in check-affected (checks.ts/model.ts). Changes to website docs, website/package.json, rspress.config.ts or README.md select it. It's also part of check:tooling, and the docs-links.yml workflow runs it because ci.yml ignores docs paths. website/doc_build/ is added to .gitignore.

Validation

  • pnpm check:affected --run passed on ea62cf206.
  • The checker's tests pass (7/7): fixture builds for a missing page, a missing fragment, a same-page fragment, a duplicate heading ID, external and asset links, and good and bad README URLs.
  • pnpm check:doc-links passes on current main docs, which include #3396โ€“#3399.
  • A planted bad anchor in quick-start.md and one in a README bare URL each failed and were named.
  • Tooling only, so no device runs.

๐Ÿค– Generated with Claude Code