From 5bdaffa7d4e1c5261ee2ceebaa0b337a7cb20202 Mon Sep 17 00:00:00 2001 From: Rareuncommon <117473426+Rareuncommon@users.noreply.github.com> Date: Tue, 24 Nov 2026 09:49:41 -0500 Subject: [PATCH] PR checks: a section's heading is a line of its own, and comments are removed first Rebuilt on main after #965 / #1037, which took over the empty-section and template-placeholder part of this change. What is left: - A section name in bold at the end of a sentence was taken for the section's heading. When the sentence came before the real section, the real one was never read: a filled description was reported empty. - The heading search could start inside an HTML comment, so a section commented out as a whole passed. - An unclosed |\Z)", "", body, flags=re.S) + names = "|".join(re.escape(h) for h in HEADINGS) + end = r"(?=\n[ \t]*\*\*(?:" + names + r")\*\*[ \t]*(?:\n|\Z)|\Z)" + start = r"(?:^|\n)[ \t]*\*\*" + re.escape(section) + r"\*\*[ \t]*(?=\n)" + return [m.group(1) for m in re.finditer(start + r"(.*?)" + end, body, re.S)] + + def section_has_content(body, section): """True when `**section**` exists and has at least one non-placeholder line.""" - next_heading = "|".join(re.escape(h) for h in HEADINGS) - m = re.search( - r"\*\*" + re.escape(section) + r"\*\*[ \t]*\n(.*?)(?=\n\*\*(?:" + next_heading + r")\*\*|\Z)", - body, - re.S, - ) - if not m: - return False - text = re.sub(r"", "", m.group(1), flags=re.S) - for raw in text.splitlines(): - line = re.sub(r"^\s*[-*•]+\s*", "", raw).strip() - if line and line not in TEMPLATE_PLACEHOLDERS: - return True + for text in section_texts(body, section): + for raw in text.splitlines(): + line = re.sub(r"^\s*[-*•]+\s*", "", raw).strip() + if line and line not in TEMPLATE_PLACEHOLDERS: + return True return False diff --git a/scripts/test_pr_check.py b/scripts/test_pr_check.py index e5de366a54..2ce15217d8 100644 --- a/scripts/test_pr_check.py +++ b/scripts/test_pr_check.py @@ -97,5 +97,62 @@ def test_bare_bullets_and_html_comments_only_fail(self): self.assertEqual(3, len(problems)) +class SectionHeadingTests(unittest.TestCase): + """Where a required section starts and ends, and what counts as its text.""" + + FILLED = ("A change to a script.\n\n**What is in it**\n- `scripts/example.py`: the change\n\n" + "**Tested**\n- `python3 scripts/example.py`: ok\n\n**Not tested**\n- Windows\n\n" + "**AI use**\n- none\n") + + def problems(self, body): + return check(body, HEAD, [changed("scripts/example.py")], lambda _: False) + + @staticmethod + def empty(section): + return f"the **{section}** section is missing or empty" + + def test_filled_description_passes(self): + self.assertEqual([], self.problems(self.FILLED)) + self.assertEqual([], self.problems(self.FILLED.replace("\n", "\r\n"))) + + def test_section_inside_a_comment_is_not_there(self): + # the heading and its only result, both commented out + body = self.FILLED.replace("**Tested**\n- `python3 scripts/example.py`: ok\n", + "\n") + self.assertEqual([self.empty("Tested")], self.problems(body)) + # the heading is there, its only result is commented out across lines + body = self.FILLED.replace("- Windows\n", "\n") + self.assertEqual([self.empty("Not tested")], self.problems(body)) + + def test_unclosed_comment_hides_what_follows(self): + # GitHub shows nothing after an unclosed comment: the sections after it are not there + body = self.FILLED.replace("- `python3 scripts/example.py`: ok\n", "