From 23a208d2f5f68e6c532f0e188de4f57d084ac4dd Mon Sep 17 00:00:00 2001 From: Rareuncommon <117473426+Rareuncommon@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:01:22 -0500 Subject: [PATCH 1/4] PR checks: a section with nothing under it is refused as empty The check of **Tested** / **Not tested** / **AI use** looked for any non-space character after the heading, so the next section's heading, or the template's lone "-", counted as the section's text: the pull request template pasted unchanged passed as "description ok". Only an empty last section was caught. A section now ends at the next heading of the outline, and comments and list markers with nothing after them are not text. A line in bold that is not one of the outline's headings still belongs to the section. scripts/pr_check.tests.py covers it without GitHub or git (python3 scripts/pr_check.tests.py): 4 of its 8 tests fail on the old check. Assisted-by: Claude Code (Claude Fable 5.2) --- scripts/pr_check.py | 15 +++++++- scripts/pr_check.tests.py | 81 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 scripts/pr_check.tests.py diff --git a/scripts/pr_check.py b/scripts/pr_check.py index b834254cd..d6e73445d 100644 --- a/scripts/pr_check.py +++ b/scripts/pr_check.py @@ -10,6 +10,8 @@ import argparse, os, re, subprocess, sys SECTIONS = ("Tested", "Not tested", "AI use") +# the headings of the description's outline: a section ends where the next one starts +HEADINGS = ("What is in it", "Tested", "Regression run", "Not tested", "AI use") # small / open-weight models are not accepted for code (CONTRIBUTING.md, "AI-assisted contributions") BANNED_MODELS = r"\b(qwen|deepseek|llama|mistral|mixtral|gemma|phi-?\d)" # game data never goes into the repository (CONTRIBUTING.md, "Licence and provenance") @@ -37,6 +39,17 @@ def smoke_blocks(body): return out +def filled(body, section): + """Whether `body` has a `**section**` heading with something written under it, before the + next heading: comments and list markers with nothing after them are not something.""" + end = r"(?=\n[ \t]*\*\*(?:" + "|".join(HEADINGS) + r")\*\*|\Z)" + for m in re.finditer(r"\*\*" + section + r"\*\*[ \t]*(?=\n)(.*?)" + end, body, re.S): + text = re.sub(r"", "", m.group(1), flags=re.S) + if re.sub(r"^[ \t]*[-*+][ \t]*$", "", text, flags=re.M).strip(): + return True + return False + + def number(s): m = re.match(r"\s*(\d+)", s or "") return int(m.group(1)) if m else None @@ -53,7 +66,7 @@ def check(body, head, files, is_main_ancestor): body = body.replace("\r\n", "\n") problems = [] for section in SECTIONS: - if not re.search(r"\*\*" + section + r"\*\*\s*\n\s*\S", body): + if not filled(body, section): problems.append(f"the **{section}** section is missing or empty") ai = re.search(r"\*\*AI use\*\*(.*?)(\n\*\*|\Z)", body, re.S) diff --git a/scripts/pr_check.tests.py b/scripts/pr_check.tests.py new file mode 100644 index 000000000..d610f46e1 --- /dev/null +++ b/scripts/pr_check.tests.py @@ -0,0 +1,81 @@ +"""Tests of scripts/pr_check.py's check of the description's sections. No GitHub, no git: + + python3 scripts/pr_check.tests.py +""" +import os, sys, unittest + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, HERE) +import pr_check + +HEAD = "0123456789abcdef0123456789abcdef01234567" +FILLED = """A change to a script. + +**What is in it** +- `scripts/example.py`: the change + +**Tested** +- `python3 scripts/example.py`: ok + +**Not tested** +- Windows + +**AI use** +- none +""" + + +def problems(body): + # one file that is not runtime: only the description is checked + files = [("scripts/example.py", "modified", False, lambda: 0)] + return pr_check.check(body, HEAD, files, lambda sha: False) + + +def empty(section): + return f"the **{section}** section is missing or empty" + + +class Sections(unittest.TestCase): + def test_filled_description_passes(self): + self.assertEqual(problems(FILLED), []) + self.assertEqual(problems(FILLED.replace("\n", "\r\n")), []) + + def test_missing_section(self): + body = FILLED.replace("**Not tested**\n- Windows\n\n", "") + self.assertEqual(problems(body), [empty("Not tested")]) + + def test_empty_section_before_another_one(self): + # the next section's heading is not this section's text + body = FILLED.replace("- `python3 scripts/example.py`: ok\n", "") + self.assertEqual(problems(body), [empty("Tested")]) + body = FILLED.replace("- Windows\n", "") + self.assertEqual(problems(body), [empty("Not tested")]) + + def test_empty_last_section(self): + self.assertEqual(problems(FILLED.replace("- none\n", "")), [empty("AI use")]) + + def test_list_marker_alone_is_empty(self): + body = FILLED.replace("- Windows\n", "-\n") + self.assertEqual(problems(body), [empty("Not tested")]) + body = FILLED.replace("- Windows\n", "- \n *\n") + self.assertEqual(problems(body), [empty("Not tested")]) + + def test_comment_alone_is_empty(self): + body = FILLED.replace("- Windows\n", "\n") + self.assertEqual(problems(body), [empty("Not tested")]) + + def test_untouched_template_is_refused(self): + path = os.path.join(HERE, "..", ".github", "pull_request_template.md") + with open(path, encoding="utf-8") as f: + self.assertIn(empty("Not tested"), problems(f.read())) + + def test_text_in_bold_is_text(self): + # a line in bold that is not a heading of the outline does not end the section + body = FILLED.replace("- Windows\n", "**AMD**: not run\n") + self.assertEqual(problems(body), []) + body = FILLED.replace("- Windows\n", "\n\n not on AMD\n") + self.assertEqual(problems(body), []) + + +if __name__ == "__main__": + unittest.main() From 92c9282a3fa85a48fffd80da858240e56a447729 Mon Sep 17 00:00:00 2001 From: Rareuncommon <117473426+Rareuncommon@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:32:27 -0500 Subject: [PATCH 2/4] PR checks: a section inside a comment, or named mid-sentence, is not there Review of #527 (shdann): the heading search could start inside an HTML comment, so a description with the whole Tested section commented out passed, and a section name in bold at the end of a sentence was taken for its heading. Comments are removed from the description before the headings are looked for, and a heading has to be a line of its own (leading and trailing spaces allowed). Two tests cover both; they fail on the commit before. Assisted-by: Claude Code (Claude Fable 5.2) --- scripts/pr_check.py | 12 +++++++----- scripts/pr_check.tests.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/scripts/pr_check.py b/scripts/pr_check.py index d6e73445d..bba81ef28 100644 --- a/scripts/pr_check.py +++ b/scripts/pr_check.py @@ -40,12 +40,14 @@ def smoke_blocks(body): def filled(body, section): - """Whether `body` has a `**section**` heading with something written under it, before the - next heading: comments and list markers with nothing after them are not something.""" + """Whether `body` has a `**section**` heading, on a line of its own, with something written + under it before the next heading. Comments are taken out first, so a heading or a result + inside one is not there; list markers with nothing after them are not something.""" + body = re.sub(r"", "", body, flags=re.S) end = r"(?=\n[ \t]*\*\*(?:" + "|".join(HEADINGS) + r")\*\*|\Z)" - for m in re.finditer(r"\*\*" + section + r"\*\*[ \t]*(?=\n)(.*?)" + end, body, re.S): - text = re.sub(r"", "", m.group(1), flags=re.S) - if re.sub(r"^[ \t]*[-*+][ \t]*$", "", text, flags=re.M).strip(): + start = r"(?:^|\n)[ \t]*\*\*" + section + r"\*\*[ \t]*(?=\n)" + for m in re.finditer(start + r"(.*?)" + end, body, re.S): + if re.sub(r"^[ \t]*[-*+][ \t]*$", "", m.group(1), flags=re.M).strip(): return True return False diff --git a/scripts/pr_check.tests.py b/scripts/pr_check.tests.py index d610f46e1..4a92823e5 100644 --- a/scripts/pr_check.tests.py +++ b/scripts/pr_check.tests.py @@ -64,6 +64,24 @@ def test_comment_alone_is_empty(self): body = FILLED.replace("- Windows\n", "\n") self.assertEqual(problems(body), [empty("Not tested")]) + def test_section_inside_a_comment_is_not_there(self): + # the heading and its only result, both commented out + body = FILLED.replace("**Tested**\n- `python3 scripts/example.py`: ok\n", + "\n") + self.assertEqual(problems(body), [empty("Tested")]) + # the heading is there, its only result is commented out across lines + body = FILLED.replace("- Windows\n", "\n") + self.assertEqual(problems(body), [empty("Not tested")]) + + def test_heading_is_a_line_of_its_own(self): + # a section name in bold at the end of a sentence is not the section's heading + body = FILLED.replace("**Tested**\n- `python3 scripts/example.py`: ok\n", + "Nothing here was **Tested**\nas far as I know.\n") + self.assertEqual(problems(body), [empty("Tested")]) + # indented, or with spaces after it, it still is + body = FILLED.replace("**Tested**\n", " **Tested** \n") + self.assertEqual(problems(body), []) + def test_untouched_template_is_refused(self): path = os.path.join(HERE, "..", ".github", "pull_request_template.md") with open(path, encoding="utf-8") as f: From dc6fa59992ce09bf28fcda7cd945d0ac83dbbab7 Mon Sep 17 00:00:00 2001 From: Rareuncommon <117473426+Rareuncommon@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:09:29 -0500 Subject: [PATCH 3/4] PR checks: a section ends only at a heading line; an unclosed comment hides the rest Review of #527 (Kalmarv), points 1 and 2: - The end of a section had no line-of-its-own rule, so a sentence under a section that began with a heading name in bold ended it: a filled Tested section was reported empty. - An unclosed ", "", body, flags=re.S) - end = r"(?=\n[ \t]*\*\*(?:" + "|".join(HEADINGS) + r")\*\*|\Z)" + under it before the next heading, which is a line of its own too. Comments are taken out + first, so a heading or a result inside one is not there; list markers with nothing after + them are not something.""" + # an unclosed comment hides the rest of the description on GitHub, so it takes it here too + body = re.sub(r"|\Z)", "", body, flags=re.S) + end = r"(?=\n[ \t]*\*\*(?:" + "|".join(HEADINGS) + r")\*\*[ \t]*(?:\n|\Z)|\Z)" start = r"(?:^|\n)[ \t]*\*\*" + section + r"\*\*[ \t]*(?=\n)" for m in re.finditer(start + r"(.*?)" + end, body, re.S): if re.sub(r"^[ \t]*[-*+][ \t]*$", "", m.group(1), flags=re.M).strip(): diff --git a/scripts/pr_check.tests.py b/scripts/pr_check.tests.py index 4a92823e5..524862c9d 100644 --- a/scripts/pr_check.tests.py +++ b/scripts/pr_check.tests.py @@ -82,6 +82,17 @@ def test_heading_is_a_line_of_its_own(self): body = FILLED.replace("**Tested**\n", " **Tested** \n") self.assertEqual(problems(body), []) + def test_heading_name_at_the_start_of_a_sentence_is_text(self): + # only a heading on a line of its own ends the section before it + body = FILLED.replace("- `python3 scripts/example.py`: ok\n", + "**AI use** below covers the test too; 3 passed\n") + self.assertEqual(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 = FILLED.replace("- `python3 scripts/example.py`: ok\n", " +- **Regression run** +- diff --git a/scripts/pr_check.tests.py b/scripts/pr_check.tests.py index 524862c9d..787fc304e 100644 --- a/scripts/pr_check.tests.py +++ b/scripts/pr_check.tests.py @@ -95,8 +95,9 @@ def test_unclosed_comment_hides_what_follows(self): def test_untouched_template_is_refused(self): path = os.path.join(HERE, "..", ".github", "pull_request_template.md") + # the hints under each heading are comments: none of them counts as a result with open(path, encoding="utf-8") as f: - self.assertIn(empty("Not tested"), problems(f.read())) + self.assertEqual(problems(f.read()), [empty(s) for s in ("Tested", "Not tested", "AI use")]) def test_text_in_bold_is_text(self): # a line in bold that is not a heading of the outline does not end the section