Skip to content

test_docs_links: pair code fences line by line so real headings keep their anchors (#7872) - #7935

Open
BlazeXYZ wants to merge 1 commit into
ItsNotRexed:mainfrom
BlazeXYZ:fix/docs-links-fence-pairing
Open

BlazeXYZ wants to merge 1 commit into
ItsNotRexed:mainfrom
BlazeXYZ:fix/docs-links-fence-pairing

Conversation

@BlazeXYZ

Copy link
Copy Markdown

Fixes #7872.

strip_fences() used the regex ```.*?```, which pairs any two triple-backtick runs. An inline ```code``` or the inner fence of a four-backtick block knocks every later pair out of step. Text that sits between real code blocks then gets stripped, its headings drop out of anchors(), and valid links show up as anchor not found.

The checker now pairs fences line by line, following CommonMark:

  • A fence opens with a run of 3 or more backticks (with no backtick in the info string) or tildes, indented at most 3 spaces.
  • It closes only on a run of the same character, at least as long, alone on its line.
  • An unclosed fence runs to the end of the page.

Tests

  • test_fences_pair_line_by_line: a synthetic page with a nested 4-backtick fence, inline triple backticks, a tilde fence holding backticks, a fence with an info string and an unclosed fence. Only the three real headings survive. The old regex fails this test.
  • test_heading_after_inline_triple_backticks_keeps_its_anchor: checks the anchors() path end to end.
  • python -I tests/test_docs_links.py on Windows, CPython 3.12: runtime/README.md now yields a-600-frame-headless-guest-scene, and the repository scan reports no anchor not found.

CPU only, no game data, no GPU.

…their anchors (ItsNotRexed#7872)

The regex ```.*?``` paired any two triple-backtick runs, including inline
```code``` and the inner fence of a four-backtick block, so text between
real code blocks was dropped and its headings vanished from anchors().
Pair fences the CommonMark way instead: an opening run of 3+ backticks or
tildes is closed only by a run of the same character at least as long,
alone on its line; an unclosed fence runs to the end of the page.
@alexwlsnr

Copy link
Copy Markdown

Linux CPython 3.14 check: the full python -I tests/test_docs_links.py currently fails only because docs/gpu_test_results.md links to missing gpu-test-results/RX9070GRE.txt in this checkout. I could not complete a clean full-suite verification; the failure appears unrelated to fence parsing. I am not posting a pass.

@elderdragon0

Copy link
Copy Markdown

Tested 310c139 on Windows 11 with Python 3.13. All 8 focused tests passed, and the previously missing a-600-frame-headless-guest-scene anchor now resolves. The repository scan reports only the existing broken GPU-results link tracked in #7532.

One edge case: when strip_fences() receives a string with CRLF line endings directly, it misses the closing fence and drops the real heading after it. The same input with LF works. The current file-reading path normalizes line endings, so normal link checking passed. Matching the fence after line.rstrip("\r\n") would also handle direct CRLF input.

AI-assisted.

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Windows 11 (26100), CPython 3.14.7, CPU only, no game files: pass.

  • Up to date with upstream/main (dde82f27e).
  • Ran python -I tests/test_docs_links.py: new unit tests test_fences_pair_line_by_line and test_heading_after_inline_triple_backticks_keeps_its_anchor pass cleanly.
  • Resolved false-positive failure from unpatched main: ../runtime/README.md#a-600-frame-headless-guest-scene anchor was erroneously reported as anchor not found on main because inline triple backticks knocked fence pairing out of step; with this PR, the anchor resolves correctly. (The only remaining failure in the suite is the pre-existing missing file docs/gpu_test_results.md -> RX9070GRE.txt on main).
  • Verified negative control: the old regex ```.*?``` extracted headings from inside code comments/tilde blocks (# Inside tilde, # Inside a comment, # Never closed), whereas CommonMark line-by-line pairing strictly retains only valid document headings (# Before, ## Between, ### After).
  • python -I -m compileall tests/test_docs_links.py: clean.
  • python -I scripts/check_no_game_data.py tests/test_docs_links.py: clean (exit 0).
  • git diff --check upstream/main...HEAD: clean.

AI-assisted.

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified via Claude Code (Opus 5.5): strip_fences() line-by-line fence pairing according to CommonMark rules correctly handles nested 4-backtick blocks, tilde blocks, inline backticks, and unclosed trailing fences. Note: The failure in test_every_relative_link_resolves reproduces on main due to an existing broken link in docs/gpu_test_results.md (gpu-test-results/RX9070GRE.txt from #6720). Constructive note: Adding \r? before $ in FENCE_CLOSE ensures direct invocations of strip_fences with raw CRLF strings cleanly match fence closures.

@azterixx

Copy link
Copy Markdown

checked: #7935 | with: python -I -m unittest discover -s tests -p test_docs_links.py | on: Debian 13, Intel i7-8700, CPython 3.13.5, head 310c139, CPU only | result: the new tests pass; test_every_relative_link_resolves still fails on one link that is also broken on main@dde82f27e (docs/gpu_test_results.md -> gpu-test-results/RX9070GRE.txt, missing file); the dev-tools.md anchor failure from main is gone

@flaqueeee

Copy link
Copy Markdown

I tested this on Windows with Python 3.13.0 using python -I tests/test_docs_links.py. On main (dde82f2), the suite reported both a missing a-600-frame-headless-guest-scene anchor and a broken RX9070GRE.txt link. With the patch from 310c139 applied, 8 of 9 tests passed and the anchor error was gone. The only remaining failure was the pre-existing link issue covered by #7532.

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.

test_docs_links: strip_fences() mis-pairs code fences and hides real heading anchors

7 participants