Skip to content

tests(docs_links): track fenced code blocks line by line (#7872) - #7966

Closed
ray3242 wants to merge 3 commits into
ItsNotRexed:mainfrom
ray3242:fix/docs-link-fences
Closed

ray3242 wants to merge 3 commits into
ItsNotRexed:mainfrom
ray3242:fix/docs-link-fences

Conversation

@ray3242

@ray3242 ray3242 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claim: #7804 (comment) (issue #7872).

What and why

tests/test_docs_links.py dropped fenced code blocks with re.compile(r"```.*?```", re.S). Regex-pairing arbitrary backtick runs mis-matches as soon as a page contains a ```python line inside a real code block (a closing fence cannot have an info string), so later fences get paired wrongly and real headings after them disappear from anchors(). On current main the real heading ### A 600-frame headless guest scene in runtime/README.md was absent from anchors() — 15 anchors found instead of 19 — so any correct link to it is reported as anchor not found.

The fix tracks fences line by line: at least three leading backticks open a block, and only a line of backticks alone (no info string) with at least as many closes it. Lines inside a block are skipped; everything else is passed through. No game data or docs content is changed — only the checker.

Tested

Windows 11, CPython 3.12.10, CPU only:

  • python -I -m unittest discover -s tests -p test_docs_links.py → 8/8 OK.
  • New test_fence_with_info_string_inside_a_block_is_not_a_closer uses a synthetic page; verified it fails with the old regex (old_strip_keeps_heading False) and passes here.
  • On runtime/README.md, anchors() now contains a-600-frame-headless-guest-scene (19 anchors, previously 15).
  • python -m compileall -q make_game.py tools tests → exit 0; git diff --check → exit 0.

No GPU used. This machine has an NVIDIA GeForce GTX 1060 6GB / driver 582.78, but no GPU test was needed. No game data, keys or decryption. AI-assisted (OpenCode).

Depends on: none.

@Gevroska

Copy link
Copy Markdown

Reproduced a remaining false negative on 89f1a2b9. A top-level line indented by four spaces is literal code, but lstrip() lets its backticks open a fence that consumes the next heading. CommonMark fence rules

From the PR checkout, run this with python -I.

import sys
sys.path.insert(0, 'tests')
from test_docs_links import strip_fences
sample = '    ```\n    example command\n\n## Real heading\n'
print('## Real heading' in strip_fences(sample))

It prints False. The heading follows an indented code block, so the expected result is True.

@ibressan

Copy link
Copy Markdown

Additional fence cases on Windows (Python 3.13.17, 89f1a2b9). Beyond the four-space case already reported, two examples expose differences in anchors():

samples = [
    '```lang`example\n\n# Visible Heading\n',
    '~~~\n# Hidden Heading\n~~~\n# Visible Heading\n',
]

Both should yield only visible-heading. This head returns an empty set for the first case and both headings for the second. The first case also passes at dde82f2, so it's a regression. The second is a pre-existing gap. For comparison, #7935 at 310c139d returned only visible-heading in both cases. CommonMark fence rules

Synthetic fixtures only. AI-assisted.

@ray3242

ray3242 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@Gevroska — thank you, that was a real defect and your repro was exact. Pushed 9d58d981b: strip_fences() now checks indentation first — four or more leading spaces are an indented code block (not a fence) and are dropped, while zero to three spaces still allow a fence. Added test_four_space_indented_backticks_are_literal_code. Your snippet now prints True; python -I -m unittest discover -s tests -p test_docs_links.py → 9/9 OK and git diff --check clean. AI-assisted (OpenCode).

@molodayamama

Copy link
Copy Markdown

Verified the updated head 9d58d981b61fe4905d21789c676784a789ee4f0e on Windows (9/9 docs-link tests). I tested the closing side of the fix. Within a fenced block I inserted a possible closing fence indented by four spaces, one tab, or one space and a tab, followed by a hidden heading, a real closer and a visible heading. All three versions returned only the visible anchor. The four-space closing case returned only the hidden anchor at the previous head.

AI-assisted verification.

@ray3242

ray3242 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@molodayamama — thank you for covering the closing side with the indentation variants (four spaces, tab, space+tab). That complements @Gevroska's opening-side case and the 9/9 Windows result matches mine. Good to have both fence boundaries pinned. AI-assisted (OpenCode).

@ray3242

ray3242 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate: PR #7935 (BlazeXYZ, opened 17:48:54Z, before this PR) fixes the same #7872 fence bug with the same test file. My PR was opened at 17:52:04Z after the issue was filed; I should have re-checked open PRs before opening. Nothing from mine should land on this item. AI-assisted (OpenCode).

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.

4 participants