Skip to content

build(docs): fail docs:check on dead internal links, dead #anchors, missing required anchors and broken Options rows (#322, #649, #319) - #876

Merged
nc9 merged 3 commits into
mainfrom
docs/link-anchor-check
Oct 16, 2026
Merged

nc9 merged 3 commits into
mainfrom
docs/link-anchor-check

Conversation

@nc9

@nc9 nc9 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

make validate and bun run docs:check used to pass with dead internal links and dead #anchors in the docs. tangly check --strict (0.5.0, and 0.5.2) does not check either: a probe docs tree with a dead page link, a dead /rules/performance/... link and a dead #anchor passed it, and tangly has no flag or config for it. This PR adds the check.

Closes #322, closes #649. Closes #319 (its last open criterion, AC2).

What it does

docs/scripts/check-links.ts runs after tangly check --strict in docs:check (the CI "Docs check and build" job runs it, no workflow change) and in make validate. It fails, printing file:line: message, on:

  • A dead internal link. Inline links and images, reference definitions and JSX href, whether absolute, relative or same-page, are resolved the way a browser resolves them from the page URL. The target must be a page (<route>.mdx, .md or <route>/index.mdx; /x/index and /x.md count as /x), a redirect source in docs.json or _redirects, or a file. External links, code (fenced blocks and code spans) and MDX comments are skipped.
  • A dead anchor. The #id must be one the target page renders. The checker computes ids the way the site does: tangly's renderer takes a {#id} marker at the end of a heading (written \{#id\} in MDX), and otherwise rehype-slug runs github-slugger over the rendered heading text, after Astro's smartypants has turned -- into a dash. It also counts id="..." attributes and <a name>. Checked against the live site, the computed ids match on all 435 pages.
  • A missing required anchor. docs/scripts/required-anchors.json lists the guides/failed-audits and cloud/firewall sections the cloud's failure explanations link to (run page, email, bell, MCP). Removing or renaming one fails CI. Renaming a heading's text is fine as long as its {#id} stays.
  • A broken Options row (docs(rules): auto-generated Options tables print every type as unknown and every default as undefined on 25 pages #319). A rule page's ## Options table row printing unknown or `undefined` fails, so the generator defect cannot come back.

It found three dead anchors on main, fixed here: two links to /configuration/storage#content-store-max-bytes (the id is content_store_max_bytes) and one to /configuration/crawler#max-pages (max_pages).

docs/.tanglyignore gains /scripts/ (top level only): tangly build copies every file in the docs root into the site, so without it the script would have been published.

CONTRIBUTING.md says what docs:check now checks, and to keep a heading's {#id} when renaming it.

Known limits

The checker reads the source line by line, not through the MDX parser. An inline link whose (target) spans lines is not checked, and a letter written as a named HTML entity in a heading (&eacute;) would slug wrong. The docs have neither, and both are written down in the script.

Checks

  • bun test docs/scripts/check-links.test.ts: 18 pass. Fixtures in a temp dir: dead absolute and relative links, dead cross-page and same-page anchors, valid explicit and heading-derived ids, repeats, code spans, smartypants dashes, longer fences, MDX comments, reference links, <a name> vs data-id, required anchors, Options rows (Type and Default columns only), a nested scripts section, _redirects patterns (*, :name), and a 50k-bracket line (linear scan). It lands in the CI rest suite (scripts/test-suites.ts).
  • bun docs/scripts/check-links.ts on the docs: passes (it failed on the three dead anchors before the fix).
  • tangly check --strict once at the final sha (rebased on main 8024e29): passes.
  • Type-checked strict with noUncheckedIndexedAccess (docs has no tsconfig of its own). Formatted with the CLI's oxfmt config. docs has no lint step.
  • Codex review: three rounds. Fixed: end-of-heading-only markers, reference links, spaced href, MDX comments, fence lengths, <a name>, data-id, entities, github-slugger's exact repeat order, multi-backtick code spans, and the quadratic link regex. Its CI-wiring point was retracted after planSuites showed docs in rest. The only open point is the named-entity letter case above.

Docs: this is the docs gate. Agent skill: no change needed.

@nc9
nc9 marked this pull request as ready for review October 16, 2026 14:02
@claude

claude Bot commented Oct 16, 2026

Copy link
Copy Markdown

Reviewed the diff. I found no blocking problems. The checker is well scoped, the tests cover the main cases, and the quadratic-backtracking guard on the bracket scan is a nice touch. I did not run the tests or the checker against the real docs tree.

  • (low) docs/scripts/check-links.ts, SKIP_DIRS: scripts is skipped at every depth, not just docs/scripts. A future docs section named scripts/ (for example guides/scripts/) would be silently left unchecked. Skipping only the top-level scripts directory would be safer.
  • (low) check-links.ts, link loop: a target containing { is skipped without a message, so a typo in a JSX expression href is never flagged. That is probably right, but the header comment could say it.
  • (low) redirectSources: _redirects lines with placeholders (:splat, :slug) or a mid-path * are treated as exact sources. A link that only a pattern redirect would catch gets reported as dead. This is a false positive that fails loudly, and no docs link hits it today.
  • (low) required-anchors.json is a hand-maintained list that mirrors cloud links. It will drift if the cloud adds links, so a pointer to where the cloud defines them would help.
  • (nit) Anchors on a heading with an explicit {#id} are not entered in the slug-repeat occurrences map. This matches the described site behaviour. A one-line comment would save the next reader a double-take.
  • (nit) The #content_store_max_bytes and #max_pages link fixes look right, since they match the code-span slug rule the tests cover.

Comment thread docs/scripts/check-links.ts Fixed
@nc9
nc9 force-pushed the docs/link-anchor-check branch from 287205a to ca0ee22 Compare October 16, 2026 14:40
nc9 added a commit that referenced this pull request Oct 16, 2026
… redirect patterns, strips every angle bracket (#322, #649)

Review follow-ups on #876: a docs section named scripts deeper down is checked; _redirects sources with * or :name placeholders match as patterns; heading text drops every < and > after tag removal (also clears the CodeQL incomplete-sanitization alert); comments on JSX-expression targets, explicit ids and where the required anchors come from.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Review triage, fixed in ca0ee22 (rebased on main 8024e29):

  • (low) scripts skipped at every depth: now only the top-level docs/scripts is skipped. A nested section called scripts is checked, and a test covers it.
  • (low) { targets skipped silently: the header comment now says JSX-expression targets are not checked. Flagging them would mean evaluating JSX.
  • (low) _redirects patterns: a source's * and :name placeholders now match as patterns, so a mid-path * or a :slug source counts as a redirect. Test added.
  • (low) where required anchors come from: the $comment in required-anchors.json now names the cloud's failure-explanation anchors it mirrors.
  • (nit) explicit ids and the repeat count: comment added (rehype-slug skips a heading that already has an id).
  • CodeQL "incomplete multi-character sanitization" on the tag strip: the strip now removes tags with <[^<>]*>, and the last step of the heading-text pipeline drops any < or > left (stray, unescaped or decoded from &lt;). The slug drops them anyway. This only computes anchor slugs and never renders HTML. The live-site comparison still matches on every page.

@claude

claude Bot commented Oct 16, 2026

Copy link
Copy Markdown

Reviewed the diff (checker, tests, required-anchors, docs fixes). The design is sound and the tests cover the edge cases well. I didn't run the tests or the checker, so this is from reading only. No blocking issues.

  • (low) docs/scripts/check-links.ts BROKEN_OPTION_CELL: it flags any table cell on a rule page's ## Options section that is exactly unknown or undefined. That includes a legitimate default or enum value written unknown. It matches the cell contents, not the Type or Default column position. It is fine today, but the error message could say which column to check.
  • (low) redirectSources: JSON.parse on docs.json throws a raw stack trace if the file is malformed. Wrapping it so the failure prints docs.json: <message> would be friendlier. tangly check runs first and probably catches this anyway.
  • (low) Redirect targets are only checked as sources. A link to /old#anchor that goes through a redirect passes without the anchor being checked. The header comment documents this, so I'm only noting it.
  • (nit) check-links.test.ts, the 50k-bracket test: the < 1000 ms wall-clock assertion could flake on a loaded CI runner. The regex design already avoids the quadratic case, so a looser bound like 5 s would be safer.
  • (nit) required-anchors.json is a hand-maintained mirror of anchors the cloud app links to, so the two can drift. A pointer to the cloud-side module in the CONTRIBUTING note would help.
  • (nit) .tanglyignore gets scripts/. Please confirm this only matches the top-level docs dir, not a future nested guides/scripts/ section. The tests do check that a nested scripts section is still link-checked, but the ignore pattern itself isn't tested.

Test coverage is good: 17 cases cover dead links, anchors, fences, comments, redirects and the Options rows.

Comment thread docs/scripts/check-links.ts Fixed
nc9 added a commit that referenced this pull request Oct 16, 2026
…Default Options cells; tanglyignore anchors /scripts/ (#322, #649, #319)

Second review round on #876: the heading-text tag strip is a small scanner, which clears the CodeQL incomplete-sanitization alert the regex kept raising; the Options check reads the Type and Default columns by header, so a description mentioning unknown is not flagged; a malformed docs.json reports docs.json: <error>; .tanglyignore uses /scripts/ so a nested docs section named scripts is still published (scripts/ matched at any depth); the bracket-scan time bound is 5 s.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Round-2 triage, fixed in the new head:

  • CodeQL "incomplete multi-character sanitization" (still raised on the <[^<>]*> replace): the tag strip is now a small character scanner with no regex. It drops <...> and keeps \< escaped for the unescape step. The trailing [<>] removal stays.
  • (low) Options cells: the check now reads the Type and Default columns by their header, so a Description that says unknown is not flagged. The message names the columns. Test added. All 41 Options tables in the rule docs use | Option | Type | Default | Description |.
  • (low) malformed docs.json: now reports docs.json: <parse error> instead of a raw stack.
  • (low) anchors through a redirect: unchanged and documented. The redirect target decides them.
  • (nit) 50k-bracket time bound: raised to 5 s.
  • (nit) .tanglyignore: you were right that scripts/ matched at any depth (checked with tangly's ignore package: guides/scripts/index.mdx was ignored). It is now /scripts/, which matches only the top level.
  • (nit) required-anchors pointer: the JSON's $comment names the cloud's failure-explanation anchors it mirrors.

@claude

claude Bot commented Oct 16, 2026

Copy link
Copy Markdown

Reviewed the diff: the new docs/scripts/check-links.ts, its tests, the required-anchors.json list, the Makefile and package.json wiring, and the three anchor fixes in the docs. I didn't run the tests or the check, and gh pr checks wouldn't run here, so I didn't see CI status.

No blocking problems.

  • (low) docs/scripts/check-links.ts, redirected(): it rebuilds a RegExp for every redirect source on every dead-link candidate. It only runs for links that miss, so the cost is negligible today. Compile the patterns once in checkDocs if the redirect list grows.
  • (low) docs/scripts/check-links.ts, redirectSources: a _redirects line with a full URL as its source, or one with a query string, would never match. That is fine for the current docs. A one-line comment saying so would help the next editor.
  • (nit) docs/scripts/check-links.ts, header comment: it says inline links whose (target) spans lines aren't checked. It would be safer to fail on one than to skip it silently, but it's acceptable while the docs have none.
  • (nit) docs/scripts/required-anchors.json: the file is hand-kept in sync with the cloud app, so it can drift. The $comment explains the rule well. Linking the cloud module path would make it easier to find.

Test coverage is strong. Slug edge cases, code fences, MDX comments, redirects, the required-anchor and Options-row checks, and a bracket-run performance guard are all covered. The three corrected anchors (#content_store_max_bytes, #max_pages) follow the new slug rules.

🤖 Generated with Claude Code

nc9 added 3 commits October 17, 2026 02:04
…issing required anchors and broken Options rows (#322, #649, #319)

tangly 0.5 check --strict passes all of these. docs/scripts/check-links.ts runs after it in docs:check and make validate: internal links must reach a page, redirect or file; anchors must be an id the target page renders (github-slugger, explicit {#id}, id=, <a name>), matching the live site on all 435 pages; anchors the cloud links to are listed in required-anchors.json; rule Options rows may not print unknown/undefined. Fixes the three dead anchors it found. scripts/ is tanglyignored so the check is not published.

Signed-off-by: Nik Cubrilovic <[email protected]>
… redirect patterns, strips every angle bracket (#322, #649)

Review follow-ups on #876: a docs section named scripts deeper down is checked; _redirects sources with * or :name placeholders match as patterns; heading text drops every < and > after tag removal (also clears the CodeQL incomplete-sanitization alert); comments on JSX-expression targets, explicit ids and where the required anchors come from.

Signed-off-by: Nik Cubrilovic <[email protected]>
…Default Options cells; tanglyignore anchors /scripts/ (#322, #649, #319)

Second review round on #876: the heading-text tag strip is a small scanner, which clears the CodeQL incomplete-sanitization alert the regex kept raising; the Options check reads the Type and Default columns by header, so a description mentioning unknown is not flagged; a malformed docs.json reports docs.json: <error>; .tanglyignore uses /scripts/ so a nested docs section named scripts is still published (scripts/ matched at any depth); the bracket-scan time bound is 5 s.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the docs/link-anchor-check branch from 02f7cb1 to 87b9566 Compare October 16, 2026 15:04
@nc9

nc9 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Third-round triage. No code change, rebased on main 6b8406b:

  • (low) regex per redirect source: it only runs for links that miss a page, and the docs have 12 redirect sources. Not worth caching yet.
  • (low) full-URL or query-string _redirects sources: none exist in the docs. Such a source would make a link report dead (fails loud), not pass silently.
  • (nit) multi-line (target): the docs have none. Parsing them would mean an MDX parser. It is documented in the header.
  • (nit) cloud module path in required-anchors.json: this is the public repo, and the cloud module is private, so the $comment names what it mirrors rather than a path.

@claude

claude Bot commented Oct 16, 2026

Copy link
Copy Markdown

Review of #876 (docs link/anchor checker). I read the diff and did not run the tests or the script. The CI checks were still pending when I looked.

No blocking issues. The checker logic reads correctly. In particular, the repeat-slug counting matches github-slugger, and explicit {#id} headings are correctly left out of the repeat count.

  • (low) docs/scripts/check-links.ts, redirected(): it rebuilds a RegExp for every redirect source on every dead-link candidate. That is fine at today's scale, but you could compile the patterns once in checkDocs.
  • (low) docs/scripts/check-links.ts, main block: a malformed or missing required-anchors.json throws a raw stack trace. A file: message error like the one docs.json gets would be more consistent.
  • (low) docs/scripts/check-links.ts, walk: it only skips scripts at the top level, which is good. It still follows symlinks through statSync, so a symlink cycle could loop. This is unlikely in the docs tree.
  • (nit) required-anchors.json is a hand-maintained list that mirrors cloud-side constants. Nothing checks it against the cloud, so it can drift. The $comment documents this, which is enough for now.
  • (nit) Known limits are documented: multi-line link targets and named-entity letters in headings. Both are acceptable.

Test coverage is thorough: 18 tests covering the edge cases above, plus the linear-time regression. The three dead-anchor fixes in docs/cli/self.mdx and docs/crawl.mdx look correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants