From f5fbe10c2c22886630b5ffa0bc2323fbebb99cc3 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 25 Sep 2026 12:15:41 -0700 Subject: [PATCH 1/3] Strip a Tilde or Unclosed Fence Before Reading Review Coverage FENCE now accepts either fence character, closes only on a run of the opener's character at least as long as the opener, and runs an unclosed fence to the end of the body, so a coverage marker quoted in a tilde fence or after an unclosed backtick fence is no longer read as stated coverage. Co-Authored-By: Claude Opus 5.5 (1M context) --- scripts/pr_review.py | 6 +++++- scripts/tests/test_pr_review.py | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/scripts/pr_review.py b/scripts/pr_review.py index ae8edf8fe..f72f87b53 100755 --- a/scripts/pr_review.py +++ b/scripts/pr_review.py @@ -399,7 +399,11 @@ # A fenced block is a quotation rather than a statement, and 131 of those bodies carry one. # This change puts both spellings into the source and the runbook, so a review of it quotes them. # A quoted count read as this round's own is a coverage figure nobody stated. -FENCE = re.compile(r"^ {0,3}```.*?^ {0,3}```[^\n]*", re.DOTALL | re.MULTILINE) +FENCE = re.compile( + r"^ {0,3}(?:(`{3,})[^`\n]*|(~{3,})[^\n]*)(?:\n.*?)??" + r"(?:\n {0,3}(?:\1`*|\2~*)[ \t]*\r?(?=\n|\Z)|\Z)", + re.DOTALL | re.MULTILINE, +) # An inline code span is a quotation for the same reason a fenced block is. # A reviewer naming `` in prose was read as opening one. # Bounded to a paragraph, and an escaped tick opens nothing, since either masks a section. diff --git a/scripts/tests/test_pr_review.py b/scripts/tests/test_pr_review.py index 98b9c8356..fb3a4413d 100755 --- a/scripts/tests/test_pr_review.py +++ b/scripts/tests/test_pr_review.py @@ -1952,6 +1952,29 @@ def test_a_quoted_marker_is_not_this_round_stating_its_coverage(self) -> None: pr_review.coverage_statements(f"Prose about the change. {MARKER}"), ) + def test_a_tilde_or_unclosed_fence_quotes_a_marker(self) -> None: + """Markdown fences with tildes as well as backticks, and runs an unclosed fence to the end. + + Stripping only a closed backtick fence read a marker quoted in either of the others as this + round's stated coverage, the failure direction that reports coverage nobody claimed. + """ + for label, body in ( + ("in a tilde fence", f"~~~text\n{MARKER}\n~~~"), + ("in an unclosed backtick fence", f"```text\n{MARKER}"), + ("in an unclosed tilde fence", f"~~~\n{MARKER}\n"), + ("after a closer of the other character", f"```text\nx\n~~~\n{MARKER}"), + ("after a closer shorter than the opener", f"````\n```\n{MARKER}\n````\n"), + ): + with self.subTest(case=label): + self.assertEqual((pr_review.UNSTATED, ""), pr_review.coverage_of({"body": body})) + for label, body in ( + ("after a closed backtick fence", f"```text\nx\n```\n{MARKER}"), + ("after a closed tilde fence", f"~~~\nx\n~~~\n{MARKER}"), + ("after a CRLF fence", f"```\r\nx\r\n```\r\n{MARKER}"), + ): + with self.subTest(case=label): + self.assertEqual(pr_review.FULL, pr_review.coverage_of({"body": body})[0]) + def test_a_marker_indented_into_a_code_block_is_a_quotation(self) -> None: """Four columns of indentation open a Markdown code block, so a marker there is quoted. From 7818daad864671476dfcbc1963e0a36139763d9d Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 25 Sep 2026 12:26:34 -0700 Subject: [PATCH 2/3] Give the Fence Test's Docstring an Unambiguous Verb Co-Authored-By: Claude Opus 5.5 (1M context) --- scripts/tests/test_pr_review.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/test_pr_review.py b/scripts/tests/test_pr_review.py index fb3a4413d..4c723c7ea 100755 --- a/scripts/tests/test_pr_review.py +++ b/scripts/tests/test_pr_review.py @@ -1953,7 +1953,7 @@ def test_a_quoted_marker_is_not_this_round_stating_its_coverage(self) -> None: ) def test_a_tilde_or_unclosed_fence_quotes_a_marker(self) -> None: - """Markdown fences with tildes as well as backticks, and runs an unclosed fence to the end. + """Markdown opens a fence with tildes as well as backticks, and runs an unclosed one to the end. Stripping only a closed backtick fence read a marker quoted in either of the others as this round's stated coverage, the failure direction that reports coverage nobody claimed. From 10af399635bcfac3f11c576d388d8fe51c68e6ee Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 25 Sep 2026 12:31:42 -0700 Subject: [PATCH 3/3] Run an Unclosed Fence to the End Only for the Coverage Reader Masking the rest of the body after an unclosed fence hid a suppressed section from its reader, which reads as clean. Every other reader keeps reading past an unclosed fence as it did before, while the coverage reader, where masking reads as no coverage and so blocks, still runs it to the end. Co-Authored-By: Claude Opus 5.5 (1M context) --- scripts/pr_review.py | 36 ++++++++++++++++++++++++--------- scripts/tests/test_pr_review.py | 9 +++++++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/scripts/pr_review.py b/scripts/pr_review.py index f72f87b53..0322f71a1 100755 --- a/scripts/pr_review.py +++ b/scripts/pr_review.py @@ -217,6 +217,7 @@ import sys import tarfile import time +from collections.abc import Callable from datetime import UTC, datetime from pathlib import Path @@ -401,9 +402,26 @@ # A quoted count read as this round's own is a coverage figure nobody stated. FENCE = re.compile( r"^ {0,3}(?:(`{3,})[^`\n]*|(~{3,})[^\n]*)(?:\n.*?)??" - r"(?:\n {0,3}(?:\1`*|\2~*)[ \t]*\r?(?=\n|\Z)|\Z)", + r"(?:(?P\n {0,3}(?:\1`*|\2~*)[ \t]*\r?(?=\n|\Z))|\Z)", re.DOTALL | re.MULTILINE, ) + + +def strip_fences( + body: str, repl: Callable[[re.Match[str]], str] = lambda m: "", to_end: bool = False +) -> str: + """The body with each fenced block replaced by `repl`, the unclosed one kept unless `to_end`. + + Markdown runs an unclosed fence to the end of the body, so for the coverage reader everything + after one is a quotation, and masking it there reads as no coverage, which blocks. Every other + reader looks for something that blocks, such as a suppressed finding or an unrecognized shape, + and masking the rest of the body there would hide it, so those keep reading it. + """ + return FENCE.sub( + lambda m: repl(m) if to_end or m.group("close") is not None else m.group(), body + ) + + # An inline code span is a quotation for the same reason a fenced block is. # A reviewer naming `` in prose was read as opening one. # Bounded to a paragraph, and an escaped tick opens nothing, since either masks a section. @@ -1173,7 +1191,7 @@ def review_effort(pr: dict) -> tuple[str, str]: newest = newest_of(head_reviews(pr)) if newest is None: return "unknown", "unknown" - plain = FENCE.sub("", newest.get("body") or "") + plain = strip_fences(newest.get("body") or "") for line in plain.splitlines(): match = EFFORT_LINE.fullmatch(line) if match: @@ -1237,7 +1255,7 @@ def coverage_statements(body: str) -> list[str]: the marker comes off before the line is kept, because every reader downstream reads the kept line with its indentation already stripped. """ - plain = CODE_SPAN.sub(" ", FENCE.sub("", body or "")) + plain = CODE_SPAN.sub(" ", strip_fences(body or "", to_end=True)) found = [] quoted = False continues = False @@ -1525,7 +1543,7 @@ def second_format(body: str) -> bool: Quotations are dropped first for the reason a coverage line's are: this change puts the marker into the diff, and a round quoting it is not a round written in that format. """ - return bool(CCR_OVERVIEW.search(CODE_SPAN.sub(" ", FENCE.sub("", body or "")))) + return bool(CCR_OVERVIEW.search(CODE_SPAN.sub(" ", strip_fences(body or "")))) def findings_on(tail: str) -> int | None: @@ -1583,7 +1601,7 @@ def stated_total(body: str) -> int | None: The largest wins where the preamble states more than one, so an ambiguous body overstates the shortfall rather than suppressing it. """ - plain = CODE_SPAN.sub(" ", FENCE.sub("", body or "")) + plain = CODE_SPAN.sub(" ", strip_fences(body or "")) opener = DETAILS_OPEN.search(plain) preamble = plain[: opener.start()] if opener else plain totals = [findings_on(m.group(1)) for m in CCR_FINDINGS.finditer(preamble)] @@ -1678,7 +1696,7 @@ def file_table(body: str) -> list[str]: table later in the body is read as a second table rather than as more of the first. """ paths, reading = [], False - for line in FENCE.sub("", body or "").splitlines(): + for line in strip_fences(body or "").splitlines(): if TABLE_HEADER.match(line): reading = True elif (row := TABLE_ROW.match(line)) is None: @@ -1854,7 +1872,7 @@ def unrecognized_in(body: str) -> list[str]: # What is left of a drifted refusal is a body with no heading, which is the arm below. if refusal_of({"body": body}): return [] - plain = CODE_SPAN.sub(" ", FENCE.sub("", body or "")) + plain = CODE_SPAN.sub(" ", strip_fences(body or "")) headings = [normal(ln) for ln in plain.splitlines() if MARKDOWN_HEADING.match(ln)] labels = [normal(m.group(1)) for m in map(LABEL_LINE.match, plain.splitlines()) if m] found = [f"heading: {h}" for h in dict.fromkeys(headings) if unvetted(h, VETTED_HEADINGS)] @@ -2285,7 +2303,7 @@ def mask_quotations(body: str) -> str: """ return CODE_SPAN.sub( lambda m: QUOTED_CHAR.sub(" ", m.group()), - FENCE.sub(lambda m: QUOTED_CHAR.sub(" ", m.group()), body or ""), + strip_fences(body or "", lambda m: QUOTED_CHAR.sub(" ", m.group())), ) @@ -2450,7 +2468,7 @@ def qodo_open_findings(body: str) -> list[str]: return [] return [ s.strip() - for s in SUMMARY.findall(CODE_SPAN.sub(" ", FENCE.sub("", body))) + for s in SUMMARY.findall(CODE_SPAN.sub(" ", strip_fences(body))) if QODO_FINDING.match(s) and not QODO_BADGE.search(s) ] diff --git a/scripts/tests/test_pr_review.py b/scripts/tests/test_pr_review.py index 4c723c7ea..299e45440 100755 --- a/scripts/tests/test_pr_review.py +++ b/scripts/tests/test_pr_review.py @@ -1975,6 +1975,15 @@ def test_a_tilde_or_unclosed_fence_quotes_a_marker(self) -> None: with self.subTest(case=label): self.assertEqual(pr_review.FULL, pr_review.coverage_of({"body": body})[0]) + def test_an_unclosed_fence_hides_no_suppressed_section(self) -> None: + """Only the coverage reader runs an unclosed fence to the end of the body. + + There masking reads as no coverage, which blocks. Run to the end for the suppressed-section + reader, a stray fence above the section hid the finding it holds, which reads as clean. + """ + body = collapsed().replace("\n\n
", "\n\n```\n\n
") + self.assertEqual(1, len(pr_review.suppressed_blocks(body))) + def test_a_marker_indented_into_a_code_block_is_a_quotation(self) -> None: """Four columns of indentation open a Markdown code block, so a marker there is quoted.