diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index fe52870f3..3fd04b1fd 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -4,8 +4,9 @@ - **Tested** -- hardware (GPU + driver, CPU), Rust version, debug / release: -- `cargo test --workspace -- --test-threads=4`: N passed, N failed, N ignored (SKIPPED GPU tests: …) + +- **Regression run** +- diff --git a/scripts/pr_check.py b/scripts/pr_check.py index b834254cd..29998dd88 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,21 @@ def smoke_blocks(body): return out +def filled(body, section): + """Whether `body` has a `**section**` heading, on a line of its own, with something written + 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(): + 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 +70,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..787fc304e --- /dev/null +++ b/scripts/pr_check.tests.py @@ -0,0 +1,111 @@ +"""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_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_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", "