Skip to content

fix(docs): the link check reports in path order, not the filesystem's #943 - #947

Merged
nc9 merged 1 commit into
mainfrom
fix/943-check-links-order
Oct 20, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/943-check-links-order

Conversation

@nc9

@nc9 nc9 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #943.

checkDocs (docs/scripts/check-links.ts) walked the docs tree in readdirSync order, and that order is the filesystem's. A test comparing its problems as an array, "checks a nested section named scripts, and matches redirect patterns", failed on some CI runners: on #942's PR, and once on main at 88b6520. It passed on others.

Fix

  • checkDocs sorts the file list before reading it. This also makes deterministic which page wins when two files name one route (a.mdx and a/index.mdx); before, that depended on the listing order.
  • Problems come back sorted by file, then line. The sort is stable, so two problems on one line keep the order they were found in.
  • An optional listDir parameter (default readdirSync) lets a test feed the walker its own listing order.

Acceptance criteria

  • checkDocs reports problems in a deterministic order, files sorted by path and then by line, whatever order the filesystem lists them in.
  • The test passes regardless of directory listing order. A new test runs the checker over the natural, reversed and 5 shuffled listings of a 5-file tree, including a nested directory and an a.mdx / a/index.mdx pair, and expects the same array each time. The one cross-file assertion in the file now expects path order. Every other multi-problem assertion is within one page, where order follows the page and does not depend on the filesystem.
  • docs:check on the real docs passes, and its output is unchanged apart from ordering. It reports no problems either way: tangly --strict passes and check-links prints "all good".

The updated test fails against the old checker on macOS (APFS lists index.mdx before guides/), the opposite of the runner that failed, which shows the old output depended on the listing order. bun test scripts/check-links.test.ts: 19 pass on bun 1.4.0.

No CHANGELOG entry: this is a docs build-script fix, not a user-visible change.

squirrel skill impact

None.

…943

checkDocs walked the docs tree in readdirSync order, which differs between
machines, so a test comparing its problems as an array failed on one CI
runner and passed on another. It now sorts the files before reading them,
which also makes the winner deterministic when a.mdx and a/index.mdx name
the same route, and returns problems sorted by file, then line. A test runs
the checker over reversed and shuffled directory listings.

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

claude Bot commented Oct 20, 2026

Copy link
Copy Markdown

Reviewed the diff of check-links.ts and its test. I couldn't run the tests here, since the shell is read-only.

  • (nit) check-links.ts: the file list is sorted with the default .sort() and problems with </>. Both compare by UTF-16 code unit, so they agree, and the result is locale-independent. A one-line comment saying that would stop someone swapping in localeCompare later.
  • (nit) The test's shuffle uses a seeded LCG, so it is reproducible. Five shuffles of a 5-file tree is modest coverage, but together with the reversed listing it is enough for this fix.

The fix looks correct. Sorting before the route map is built makes the a.mdx vs a/index.mdx winner deterministic. The stable sort on file then line preserves the order of same-line problems. The new listDir parameter defaults to readdirSync, so existing callers are unaffected. I found no bugs, security concerns or performance concerns.

@nc9

nc9 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Triage: both nits noted. Neither needs a change: the two sorts agree by UTF-16 code unit and are locale-independent, and the reversed listing plus the seeded shuffles cover the order dependence this fixes.

@nc9
nc9 merged commit 886ceef into main Oct 20, 2026
15 checks passed
@nc9
nc9 deleted the fix/943-check-links-order branch October 20, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs check-links: checkDocs reports in readdir order, so its test flakes on some runners

1 participant