From 1487c26b0f65d4f4c41ba7c6fefa2ecc0ac9d4f5 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 9 Oct 2026 22:20:55 -0700 Subject: [PATCH 1/2] Harden the Source-Pinning Assertions in test_pr_review.py Co-Authored-By: Claude Sonnet 5.5 --- tests/test_pr_review.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/test_pr_review.py b/tests/test_pr_review.py index 218486c8a..0a8050ddb 100755 --- a/tests/test_pr_review.py +++ b/tests/test_pr_review.py @@ -49,6 +49,15 @@ def flowed_text(text: str) -> str: return " ".join(text.split()) +def comment_flowed_text(text: str) -> str: + """Strip each line's leading `#` marker, then collapse as `flowed_text` does. + + A `#` comment that rewraps gains a marker on its new line as well as a newline, so + collapsing whitespace alone leaves the marker between two words of a pinned phrase. + """ + return flowed_text(" ".join(line.lstrip().removeprefix("#") for line in text.splitlines())) + + HEAD = "a" * 40 OLD = "b" * 40 @@ -4286,7 +4295,7 @@ def test_every_emphasis_tag_the_stripper_names_is_dropped(self) -> None: def test_the_vetted_lists_hold_what_the_comment_beside_them_counts(self) -> None: """The comment states the sizes, and adding an entry without it is how it goes stale.""" - source = Path(pr_review.__file__).read_text(encoding="utf-8") + source = comment_flowed_text(Path(pr_review.__file__).read_text(encoding="utf-8")) stated = re.search( r"the output is regular: (\d+) headings, (\d+) summaries and (\d+) labels", source ) @@ -8378,7 +8387,7 @@ def test_an_archive_that_is_not_a_readable_tarball_is_undecided(self) -> None: def test_a_ref_is_matched_as_bytes_so_an_undecodable_file_is_still_searched(self) -> None: """Skipping a file this cannot decode is how a present ref reads as absent.""" source = (REPO / "scripts" / "pr_review.py").read_text(encoding="utf-8") - self.assertIn("n in blob", source) + self.assertIn("n in blob", flowed_text(source)) def test_an_absent_status_is_absence_and_a_rate_limit_is_not(self) -> None: """Reading a 403 as a missing commit reports a correct description as contradicting itself.""" @@ -8647,9 +8656,10 @@ def test_an_inverted_pair_of_check_thresholds_is_rejected_at_the_flags_too(self) def test_the_backoff_is_bounded_and_non_decreasing(self) -> None: """A wait that sleeps zero seconds is a busy loop, and one that shrinks polls harder later.""" source = (REPO / "scripts" / "pr_review.py").read_text(encoding="utf-8") - delays = [ - int(n) for n in source.split("delays = [")[1].split("]")[0].replace(" ", "").split(",") - ] + assigned = re.search(r"\bdelays\b[^=\n]*=\s*\[([^\]]*)\]", source) + if assigned is None: + self.fail("the backoff delays list assignment is no longer in pr_review.py") + delays = [int(n) for n in assigned.group(1).replace(" ", "").split(",") if n.strip()] self.assertGreaterEqual(len(delays), 3) self.assertTrue(all(d > 0 for d in delays)) self.assertEqual(delays, sorted(delays)) From eca11e1f3bc3217e29e95762e18e3b0649f53dd4 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 9 Oct 2026 22:27:28 -0700 Subject: [PATCH 2/2] Test the Comment Reader on a Phrase Split Across Comment Lines Co-Authored-By: Claude Sonnet 5.5 --- tests/test_pr_review.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_pr_review.py b/tests/test_pr_review.py index 0a8050ddb..882939370 100755 --- a/tests/test_pr_review.py +++ b/tests/test_pr_review.py @@ -4293,6 +4293,16 @@ def test_every_emphasis_tag_the_stripper_names_is_dropped(self) -> None: self.assertEqual("Open (N)", pr_review.normal(f"<{tag}>Open (2)")) self.assertEqual("Open (N)", pr_review.normal("Open (2)")) + def test_a_phrase_rewrapped_across_comment_lines_reads_as_one_sentence(self) -> None: + """Collapsing whitespace alone would leave the second line's marker inside the phrase.""" + wrapped = ( + "x = 1\n # the output is regular: 10 headings, 10\n # summaries and 4 labels.\n" + ) + self.assertIn( + "the output is regular: 10 headings, 10 summaries and 4 labels.", + comment_flowed_text(wrapped), + ) + def test_the_vetted_lists_hold_what_the_comment_beside_them_counts(self) -> None: """The comment states the sizes, and adding an entry without it is how it goes stale.""" source = comment_flowed_text(Path(pr_review.__file__).read_text(encoding="utf-8"))