Skip to content

tests: reject identical fenced blocks that are back to back in docs/ - #5394

Open
milas6669 wants to merge 2 commits into
ItsNotRexed:mainfrom
milas6669:docs/character-models-adjacent-fence
Open

milas6669 wants to merge 2 commits into
ItsNotRexed:mainfrom
milas6669:docs/character-models-adjacent-fence

Conversation

@milas6669

@milas6669 milas6669 commented Nov 23, 2026 •

Copy link
Copy Markdown

What this is now

Rebased onto 561b65a8 after the Round 44 merge. docs/character_models.md no longer carries the repeated block on main — its Reproduce section was rewritten during that merge, and no done: for the item exists in the coordination thread — so the docs half of this PR is moot and was dropped in the rebase. What remains is the guard: tests/test_docs_adjacent_fenced_blocks.py.

If the maintainers would rather not carry a guard for a defect that is no longer in the tree, closing this is the right call; the test's cases are small enough to lift into an existing docs test instead.

The test

Fails when two identical fenced blocks appear back to back in any docs/*.md:

  • identical means the same info string and the same body: a Python and a Ruby snippet that read the same are two examples, not a duplicate (from @shdann's review, fixed in this branch's second commit);
  • the fence parser tracks the opening character and its length, so a shorter fence inside a longer one does not end the block early, and tilde fences work;
  • prose between the blocks, a one-line difference, and empty blocks are not reported;
  • synthetic cases cover the hit and each near-miss, so a parser that silently stops finding repeats fails the test instead of passing it.

As the tree stands, the scan finds no pair in 61 pages. The guard is aimed at the merge-leftover class the coordination issue tracks (repeated merges of the same PR leaving duplicated text), not at a live defect.

Tests run

python -I tests/test_docs_adjacent_fenced_blocks.py  -> Ran 3 tests, OK
python -I tests/test_docs_*.py                       -> 12 of 12 pass
python -I tests/test_semantic_translator_use.py      -> OK
git diff --check                                     -> clean

Review notes: @Kam471's LGTM was on e434ca04, before the info-string fix and this rebase; @shdann's report is fixed at 9f99b0189.

No GPU used, no game data. AI-assisted.

Depends on: none.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

The duplicate check flags two examples with different language tags as identical. On head e434ca04, the input below reports lines 1 and 5. The Python and Ruby examples have the same source text but different results: Python 3 evaluates the expression to 0.5 and Ruby evaluates it to 0.

Run this from the repository root with py -3.14 -I:

import sys
sys.path.insert(0, "tests")
from test_docs_adjacent_fenced_blocks import adjacent_repeats

page = "~~~python\n1 / 2\n~~~\n\n~~~ruby\n1 / 2\n~~~\n"
print(adjacent_repeats(page))                           # actual [(1, 5)], expected []
print(adjacent_repeats(page.replace("ruby", "python")))  # actual and expected [(1, 5)]

Keep the opening fence's info string with the body when comparing blocks. The original duplicate in character_models.md still needs to match: the detector reports (312, 322) on merge base 3faac557 and no pair on this head. All 33 tests in test_docs_*.py pass on Windows.

AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed head e434ca04e9.

Commands:

  • python tests/test_docs_adjacent_fenced_blocks.py -> Ran 3 tests, OK (0.6 s), 61 docs pages scanned
  • Negative control: main's docs/character_models.md + this test -> FAIL "the block at line 312 is repeated at line 322"
  • git diff --check main...HEAD -> clean

The detector reports only byte-identical blocks separated by blank lines, handles longer/shorter fences and tildes, and has synthetic tests for both the positive and the near-miss (one-line difference, prose between blocks, empty blocks). Removing the second copy is correct; the surrounding text still refers to the single manifest.

Verdict: LGTM.

@milas6669

Copy link
Copy Markdown
Author

You are right, and the fix is in 12bb7fb2 on this branch.

The detector now keeps the opening fence's info string with the body and compares both, so two languages with the same text are two examples, not a duplicate:

>>> adjacent_repeats("~~~python\n1 / 2\n~~~\n\n~~~ruby\n1 / 2\n~~~\n")
[]
>>> adjacent_repeats("~~~python\n1 / 2\n~~~\n\n~~~python\n1 / 2\n~~~\n")
[(1, 5)]
  • The info string is stripped and lower-cased before the comparison, so ``` Python and ```python are the same tag; the fence character and its length still do not matter.
  • The original pair is still caught: the detector reports (312, 322) against main's character_models.md and nothing against this head.
  • A synthetic case for exactly your Python/Ruby pair is in test_detector_finds_only_identical_adjacent_blocks, so this cannot quietly regress.
  • All 11 tests/test_docs_*.py pass here, and git diff --check is clean.

Thanks for the precise repro — it was the whole report.

AI-assisted.

@milas6669
milas6669 force-pushed the docs/character-models-adjacent-fence branch from 12bb7fb to 9f99b01 Compare November 23, 2026 11:41
@milas6669 milas6669 changed the title docs: drop the repeated manifest block in character_models, and test for adjacent fenced blocks tests: reject identical fenced blocks that are back to back in docs/ Nov 23, 2026
@milas6669

Copy link
Copy Markdown
Author

Rebased onto 561b65a8 and retitled.

The Round 44 merge rewrote docs/character_models.md's Reproduce section, so the repeated block this PR removed is no longer on main and that half of the diff is gone; the branch now carries only the guard test, with the info-string fix from @shdann's report.

On head 9f99b0189: the new test 3/3, test_docs_*.py 12/12, test_semantic_translator_use.py OK, git diff --check clean, and the PR is mergeable again. @Kam471's LGTM covered e434ca04, before both changes.

If a guard for a defect that is no longer in the tree is not worth carrying, say so and I will close it — the cases are small enough to fold into an existing docs test instead.

AI-assisted.

@memorypressure

Copy link
Copy Markdown

Two things after today's round-44 merge batch (main 561b65a): your guard is valuable and green — I ran it against current main and it now reports nothing, because the character_models.md duplication it targets was fixed on main independently — but that means git merge-tree now conflicts in character_models.md where your docs deletion overlaps the landed fix. The resolution is trivial: rebase, take main's side in that file, keep the guard file (it registers cleanly). The guard itself is well-scoped: identical-plus-blank-lines-only adjacency, fences and nesting handled by synthetic self-tests, and I confirmed the whole-docs scan is not vacuous (it flagged the exact repeat at 312/322 on pre-round-44 main). Coordination note: open PR #4490 adds a sibling repeated-LINES guard; the two are conflict-free and overlap in intent, so consider folding them into one checker eventually. Checks queued. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@milas6669

Copy link
Copy Markdown
Author

Thanks — and that conflict is already gone: the rebase landed at 11:40 UTC, before your comment. Head 9f99b018 takes main's side of docs/character_models.md (my deletion is dropped, main's round-44 text kept) and keeps the guard file, so git merge-tree is clean and the PR shows mergeable again. On that head: the guard 3/3, test_docs_*.py 12/12, test_semantic_translator_use.py OK, git diff --check clean.

On #4490: agreed they overlap in intent, and the two checks are complementary — repeated lines anywhere versus repeated fenced blocks adjacent to each other. I would keep them separate until one lands, then fold both scans into a single docs checker in a follow-up, rather than have two PRs edit the same test file at once. If the maintainers would rather have the fold-up front instead, say so and I will close this one and put the block scan into #4490's file as a suggestion to its author.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 9f99b01 merged with main 561b65a on Linux (WSL2, Python 3.12.16, -I): pass

  • tests/test_docs_adjacent_fenced_blocks.py: 3 run, 3 passed, 0 failed. The scan reads 40+ pages under docs/ and finds no adjacent repeat on current main.
  • Negative control: added a scratch docs/zz_tmp_dup.md with two identical back-to-back sh blocks; the page test fails with docs/zz_tmp_dup.md: the block at line 3 is repeated at line 7; file removed afterwards.
  • Edge case I did not exercise: fences nested in a list item with 4+ spaces of indent are not recognised (FENCE allows 0-3), so a repeat there would not be flagged. Only top-level docs/*.md is scanned (not docs/i18n/).

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.

5 participants