Skip to content

doc-check: symlinks through folders, untouched symlink budgets, fences (#947) - #1020

Merged
scuttletoby merged 4 commits into
mainfrom
fix/947-doc-check-followups
Nov 22, 2026
Merged

scuttletoby merged 4 commits into
mainfrom
fix/947-doc-check-followups

Conversation

@scuttletoby

@scuttletoby scuttletoby commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

The five follow-ups from the #942 reviews, in fork-ci/actions/doc-check/. Each has a test that fails on main's doc_check.py and passes here.

What changed, per item

  1. Removal scan and folder symlinks. The scan now walks each untouched symlink and each link in untouched files name by name, as the file system does. It follows symlinks at every step, folder symlinks included, on both the base tree (git ls-tree) and the checkout. It runs when the change deletes a path or changes a symlink (git diff --raw, mode 120000 on either side). It blames a symlink or link only if it resolved on the base, points to nothing now, and its base path went through something this change removed (this change removed real/A.md) or a symlink it changed (this change changed the symlink docs). This replaces the old spelling match, which only followed the symlink's own text. Newly caught: CLAUDE.md -> docs/A.md with docs -> real when real/A.md is deleted or real is renamed; docs retargeted to nothing or out of the repository, or removed; and the same cases through a doc link. If git fails while reading the base tree, the check exits 2 instead of passing.
  2. Untouched symlink budget in --base. An untouched selected symlink is checked when its target, or a symlink on its way, is part of the change, and it is judged under its own budget, as --all does. Example: CLAUDE.md -> AGENTS.md, where AGENTS.md grows to 61 lines, now fails both modes on CLAUDE.md's 40-line budget. As in --all, anything the target already reports is reported once, at the target. If the untouched symlink now points to nothing, it is left to the scan from item 1, so a symlink that was already dangling on the base is still not blamed.
  3. Inline code mid-run. INLINE_CODE gets (?<!)`, so inline code starts only at a whole run of backticks. An unmatched run such as "close it with ``` and see g" no longer hides the link.
  4. Fence on a list item's own line. - ```sh (also 1. and 10)) opens a fence at the item's content column. Before, its closing line opened a fence that hid the rest of the item.
  5. Indented code: decided to skip it, as main did. A line 4 or more columns past its list item's content column is indented code, and its links are skipped, unless it continues a paragraph (then its links are still checked, tested). This covers the reviewer's case (a ``` block indented 4 past the item). The same rule applies at the margin (column 0), because CommonMark reads both the same way and one rule is simpler than two. Round 1 below makes list items follow CommonMark (lazy lines, several markers on a line), so a paragraph in an item is never read as code.

README and the module docstring now say this.

State question: is a symlink judged the same by --base and --all?

Yes, for every case the change causes. SymlinkParity runs both modes on each case and checks that --base prints the same DOC CLAUDE.md: ... line as --all.

Untouched CLAUDE.md -> X.md -> docs/A.md, docs -> real --all --base
docs retargeted to nothing or out of the repository fails fails (changed the symlink docs)
removed half-way (X.md deleted, so the chain dangles) fails fails (removed X.md)
the change makes a loop (docs -> docs) fails fails (changed the symlink docs)
target grows past the symlink's own budget fails fails (same budget line)
already dangling on the base, a loop on the base too fails passes: not this change's, by design (README "Not covered")

General vs project

  • General (the action, used by any project): all five fixes, the base-tree resolver, and the fail-closed git read. No new config key, no change to defaults.
  • Project (this repo): nothing. There is no .github/doc-check.json here. --all on this repo prints byte-identical output before and after (687 files, 455 problems, the same lines), so the change adds no false failures. --base origin/main reports 0 problems. A throwaway local branch that deleted docs/fork/agent-rules.md ran the full scan in 0.6 s and reported its one remaining link.

Checks run

  • python3 -I -B fork-ci/actions/doc-check/doc_check.test.py: 55 OK (53 before round 1). On main's doc_check.py, 19 of the new checks fail; the "removed half-way" and "already dangling" guards pass there too, as they should.
  • vp run check:changed: format, typecheck and tests pass.
  • Everything relevant ran locally. These tests use no local sockets and no jq.

Round 1 (code review)

Finding Fix or reason dropped Test
Major: the indented-code rule hid links in a list item after a lazy line, or after - - item A lazy line (one that continues the item's paragraph without indent) keeps the item open, and every marker on a line opens an item. Close variants found against commonmark.js and fixed here: a lazy line opens no fence or item; an empty item, or one numbered from 2, cannot interrupt a paragraph; - - - is a thematic break, not three items; indented code needs a blank line only after a paragraph (so a heading, closing fence or closed list followed by an indented line is code, and the line after it is read right). test_a_list_item_stays_open_on_a_lazy_line_and_every_marker_on_a_line_counts: the reviewer's two cases and the variants. 8 cases fail on 5966908.
Minor: GIT_LITERAL_PATHSPECS had no test Test added. test_a_deleted_doc_named_like_a_pathspec_magic_word: deleting :(top)A.md that a.md links to fails the check. It passes (wrongly) without the variable.
Minor: a test name said "deleted_or_renamed" but it only deletes Renamed to ..._deleted. test_the_target_of_an_untouched_symlink_through_a_folder_symlink_deleted
Minor: some indented code is still checked as text Dropped, see Left. The heading and closing-fence cases are now read as code anyway, as a side effect of the major fix. covered by the major's test
Minor: removing resolve()'s guards leaves all tests green Dropped, see Left. none

CommonMark comparison. Same method as the review: link_lines against micromark 4.0.0, and also against commonmark.js 0.31.2 (the reference parser), each pinned in a scratch folder. Two seeds of 6000 random block-only docs (list markers, nested markers, lazy lines, indents, tabs, fences, headings, thematic breaks). The docs come from a different generator than the review's, so the counts don't compare with its numbers.

Docs where the checker... main 5966908 this head
misses a link (commonmark.js, seeds 1 / 2) 9 / 8 144 / 159 0 / 0
checks a link that is in code (commonmark.js) 3611 / 3580 259 / 246 4 / 5
misses a link (micromark) 10 / 14 154 / 160 26 / 38
checks a link that is in code (micromark) 3611 / 3580 274 / 259 37 / 54

Every micromark miss on this head is a doc where micromark and commonmark.js disagree. The case is code followed by 2) foo. micromark reads 2) foo as paragraph text; commonmark.js, like the spec, reads it as a list (the numbered-from-2 rule only applies when the line before is paragraph text). The 4-5 links still checked inside code are fail-closed only: a setext === underline, and tabs inside list items, which are counted as 4 columns rather than to the next tab stop.

Left

  • Indented code that is still checked as text (after a list marker followed by 5 or more spaces, after a setext underline, tabs in list items): dropped. These only add failures (fail closed), main has them too, and doc-check: follow-ups from #942 reviews (symlinks through folders, budgets, fences) #947 did not list them.
  • resolve()'s guards (absolute target, .. past the root, a file used as a folder) have no test: dropped. In every case the review built, the walk ends in "no such path" either way, so no test can tell them apart.

Fixes #947

After the narrow check (4e85c93)

Finding Fix Check
A 2. item right below a > line was read as paragraph text and its indented content as code, so a broken link there passed (narrow check, comment 7085651329) The checker does not model block quotes; a line after a quote's paragraph now opens what it would open outside the quote, and an indented line after a quote stays lazy text test_a_block_quote_line_is_no_paragraph_the_next_line_goes_on: red before the fix (1 failure), 56 OK after; --all output byte-identical before and after on this repo

🤖 Generated with Claude Code

#947)

- The removal scan walks each untouched symlink and link name by name on the
  base tree and the checkout, through folder symlinks, and runs when the
  change removes a path or changes a symlink. It blames only what resolved on
  the base and names the path the change removed or the symlink it changed;
  what already pointed to no file on the base (a loop too) stays unblamed.
- --base also checks an untouched symlink whose target (or a symlink on the
  way) the change touched, under the symlink's own budget, as --all does.
- Inline code starts only at a whole run of backticks.
- A fence on a list item's own line ("- ```sh") opens a fence in the item.
- Indented code (in a list item or at the margin, after a blank line) is
  skipped, as CommonMark reads it.
- Reading the base tree fails closed (exit 2) when git fails.

Fixes #947

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: lens agent · read at: 5966908
covered: #947 (body, no comments yet), the PR body, the full diff of fork-ci/actions/doc-check (doc_check.py, doc_check.test.py, README.md)
checks: ran doc_check.test.py (53 OK); ran the new tests on main's doc_check.py (19 fail, as the body says); undid each fix one at a time (each item's test goes red, except the four noted under minor); built --base repos for a two-link loop, a self-loop through "..", a folder symlink retargeted to "../.." and to an absolute path, each run twice; compared link_lines with a CommonMark parser (micromark) on 6000 random block-only docs: this head misses a link in 18 docs (main: 8) and checks a link CommonMark puts in code in 765 (main: 3238)
state: runs again: same output, byte for byte, in every repo I built; loops (self, two-link, through "..") stop after 40 hops in under a second; links and symlinks that leave the repository are reported, never followed: the walk only uses lstat and readlink inside the repository, and read_doc checks realpath before it opens anything; an empty doc (or a symlink to an empty file) is read and checked, not skipped (the read_doc check is "is not None", not truthiness); a missing --files path is skipped as before; git failing on the base tree exits 2
blocker: none
major: the new indented-code rule hides links that main checks and GitHub renders (doc_check.py:216-229). When a list item wraps onto an unindented (lazy) line, link_lines pops the item, which it already did on main. The item's next paragraph, indented 4 after a blank line, then counts as indented code from the margin, so a broken link in it passes. Two markers on one line (example 2) end the same way. Both examples below exit 0 on this head and exit 1 on main, and CommonMark makes them links. Fix here: on a paragraph continuation line, keep the open items instead of popping them, and push every marker of a line like the one in example 2. Add the two examples to test_a_link_in_indented_code_is_skipped (doc_check.test.py:292).
minor: GIT_LITERAL_PATHSPECS (doc_check.py:64-65) has no test, and it changes the result. Without it, deleting a file named ":(top)A.md" that a.md links to passes; with it, the deletion fails as it should. Small and in scope: add that case to the Removed tests in this PR.
minor: test_the_target_of_an_untouched_symlink_through_a_folder_symlink_deleted_or_renamed (doc_check.test.py:394) only deletes; the rename is the next test. Small and in scope: rename it to ..._deleted in this PR.
minor: some indented code is still checked as if it were text: after a heading, after a closing fence, and after a list marker followed by 5 or more spaces. Drop: these are extra failures only (fail closed), main has them too, and #947 did not list them.
minor: removing resolve()'s guards (absolute target, ".." past the root, a file used as a folder) leaves all tests green. Drop: in every case I built, the walk ends in "no such path" either way, so a test could not see them.

Examples for the major (each line in nope.md is a link in CommonMark):

1. Step one that wraps
onto the next line.

    More about step one, see [g](nope.md).
- - nested item

      more text [x](nope.md)

Untested here: nothing. These tests use no local socket and no jq. fork-ci-result on this head: success.

🤖 Generated with Claude Code

Round 1 of the code review. A line that continues a list item's paragraph
without indent (lazy) no longer ends the item, and in "- - item" each marker
opens an item, so the item's next paragraph is never read as indented code.
A lazy line opens nothing; an empty item or one numbered from 2 cannot
interrupt a paragraph; "- - -" is a thematic break; indented code needs a
blank line only after a paragraph. Tests: the reviewer's two cases and the
variants found against commonmark.js, a deleted doc named ":(top)A.md"
(GIT_LITERAL_PATHSPECS), and a test name that says only what it tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby

Copy link
Copy Markdown
Owner Author

not a lens: narrow check after fix round 1
read at: 6ff6171 · scope: git diff 5966908e 6ff6171 (no main merge in it), fork-ci/actions/doc-check/doc_check.py and doc_check.test.py only

Verdict: NOT SAFE. The reviewer's two cases and the whole lazy-line / nested-marker family are fixed at the root. But the new "can't interrupt a paragraph" guard also applies after a block-quote line, so a broken link that main and 5966908 both catch now passes. The fix is one line plus a test.

Oracle: commonmark.js 0.31.2 (the reference parser), pinned in a scratch folder outside the repo, compared with link_lines on main, 5966908 and this head. I wrote 103 cases by hand for the shapes in the brief, plus random docs: 3 × 6000 block-only docs (no HTML, no quotes) and 3 × 6000 docs with block quotes and HTML blocks.

1. Major fixed at the root? Yes for what the review found, but there is one new miss (block quotes).

  • None of these miss a link on this head: lazy lines (one or several, under nested items, ending in 2) x), - - x, 1. - x, * 1) x, - 1. - x, - - - / * * * / _ _ _ breaks, 2. after a paragraph, indented code after a list, heading, closing fence, blank or ***, tabs (-\tx, \t continuations, - x\nlazy\n\n\t[x]), > - x\nlazy, - > x\nlazy, HTML blocks. On 5966908, 23 of the 103 hand cases miss a link. Block-only random docs: 0 misses in 18000 (main: 4).
  • New miss, caused by this round (doc_check.py:229, :254-255). A > line leaves para set, so on the next line in_para is true and an ordered item numbered from 2 (or an empty item) is read as paragraph text. The item's indented content is then read as indented code from the margin. commonmark.js (and cmark, which works the same way) does not read that line as lazy: the quote does not continue, so the list starts. Check exits 0 on this head and 1 on main and on 5966908:
    1. Install it.
    
    > **Note:** this needs a recent runtime.
    2. Run it.
    
        See [setup](setup.md) for flags.
    
    The same happens with >\n2. x\n\n [a](a.md), > # h, > ---, or a closed fence in a quote followed by 2. x, > - x\n2. y\n\n [c](c.md), and 1. one\n\n> note\n>\n2. two\n\n [a](a.md). A blank line between the quote and 2. avoids it. Across the 18000 random docs with quotes and HTML, this head misses a link main catches in 5 docs, all of this shape (the fix below catches 4 of them).
    Fix I tried (scratch copy): keep quoted = body.startswith('>') from the previous non-blank line, and use in_para = para and kept == len(items) and not quoted. With it, none of the 19 quote cases misses a link (one has a false alarm that main has too), the 103 hand cases still miss nothing, and the block-only fuzz is unchanged. One random doc still misses a link: > then a tab-indented line then 2.. That shape is very rare, so I'd leave it. Add the example above to test_a_list_item_stays_open_on_a_lazy_line_and_every_marker_on_a_line_counts (doc_check.test.py:310).

2. The opposite error (checking links that are really in code): much less than before, and nothing new that matters. On block-only docs, false alarms drop from about 1960 per 6000 (main) to 135-152. In the hand cases, the 10 that remain all happen on main too: p\n=== setext, an empty -/+ item after a paragraph, -\t\tx tabs, > code, and HTML blocks (which the checker does not model). Head raised a false alarm main didn't in just 2 of 36000 random docs: an empty item followed by a blank line and then a fence, and a - setext underline over a tab-indented line. Both shapes are odd, and both only fail closed. On this repo, head and main read the same links in all 1311 tracked .md and .mdx files: none added, none skipped. Weight: the block-quote miss above is the only real cost. It hides a broken link silently. The remaining false alarms are rare, show up loudly, and could block a PR but cannot let a bad link through.

3. Keeping "indented code needs a blank line only after a paragraph" (doc_check.py:242, :262) instead of dropping minor 3: sound. This is the CommonMark rule (indented code cannot interrupt a paragraph, and nothing else stops it). The oracle agrees: heading, closing fence, ***, - - - and closed-list cases all match. It is also what removes most of the old false alarms in item 2. It makes more lines code, so it can only cause a miss where para is wrongly false. I found none in the block-only fuzz. The one case I found where para is wrong goes the other way: it is wrongly true after >, which is item 1.

4. Tests. On this head, python3 -I -B fork-ci/actions/doc-check/doc_check.test.py passes (55 OK). Running this head's test file against 5966908's doc_check.py gives 10 failing subtests, all in test_a_list_item_stays_open_... (doc_check.test.py:310-339): 7 link cases and 3 code cases (- - -, # h, closed fence). The body says 8; it is 10. The pathspec test (doc_check.test.py:373) passes on 5966908, as it should, since the variable was already there. With GIT_LITERAL_PATHSPECS removed from a scratch copy of the head, it fails, as the body says. Nothing tests the block-quote case from item 1.

5. --all on this repo: the same. I ran the main and head scripts on both the head tree and the current main tree (d7bb702). All four outputs are byte-identical: 687 files, 455 problems, 1 warning, exit 1.

fork-ci-result on 6ff6171: success (all checks finished, none failed).

🤖 Generated with Claude Code

scuttletoby and others added 2 commits November 22, 2026 20:57
…e it

The checker does not model block quotes, so a ">" line counted as a
paragraph that the next line continues: "2." right below a quote was read
as text and its indented content as code, which hid a broken link. Such a
line goes on with the quote's paragraph only lazily, so it now opens what
it would open outside the quote; an indented line after it stays lazy
text. Found by the narrow check on #1020; commonmark.js 0.31.2 agrees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby
scuttletoby merged commit 6407716 into main Nov 22, 2026
30 checks passed
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.

doc-check: follow-ups from #942 reviews (symlinks through folders, budgets, fences)

1 participant