diff --git a/scripts/pr_check.py b/scripts/pr_check.py index 592808f42c..74e8361015 100644 --- a/scripts/pr_check.py +++ b/scripts/pr_check.py @@ -11,6 +11,14 @@ import argparse, os, re, subprocess, sys SECTIONS = ("Tested", "Not tested", "AI use") +HEADINGS = ("What is in it", "Tested", "Regression run", "Not tested", "AI use") +# placeholder lines copied verbatim from .github/pull_request_template.md (#965) +TEMPLATE_PLACEHOLDERS = frozenset({ + "hardware (GPU + driver, CPU), Rust version, debug / release:", + "`cargo test --workspace -- --test-threads=4`: N passed, N failed, N ignored (SKIPPED GPU tests: …)", + "`cargo test --workspace -- --test-threads=4`: N passed, N failed, N ignored (SKIPPED GPU tests: ...)", + "none / tool and model, and what it did", +}) # 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") @@ -48,6 +56,24 @@ def runtime(path): return path.startswith("crates/xcl/src/") and "/tests" not in path and not path.endswith("tests.rs") +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 + return False + + def check(body, head, files, is_main_ancestor, *, test_only=False): """The problems (empty: mergeable as far as this check goes). `files`: (path, status, binary, size) with `size` a function giving the file's bytes; `is_main_ancestor(sha)`: whether the @@ -55,7 +81,7 @@ def check(body, head, files, is_main_ancestor, *, test_only=False): 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 section_has_content(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/test_pr_check.py b/scripts/test_pr_check.py index faa0defef4..ad965a7bf4 100644 --- a/scripts/test_pr_check.py +++ b/scripts/test_pr_check.py @@ -1,3 +1,4 @@ +from pathlib import Path import unittest from pr_check import check, smoke_blocks @@ -51,5 +52,38 @@ def test_blocks_in_separate_fences_stay_separate(self): self.assertEqual(["1111111aaaa", "1234567890"], [b["commit"] for b in smoke_blocks(body)]) +class TemplatePlaceholderTests(unittest.TestCase): + def test_untouched_pr_template_fails_all_required_sections(self): + template = Path(__file__).resolve().parent.parent / ".github" / "pull_request_template.md" + body = template.read_text(encoding="utf-8") + problems = check(body, HEAD, [changed("README.md")], lambda _: True) + self.assertEqual( + [ + "the **Tested** section is missing or empty", + "the **Not tested** section is missing or empty", + "the **AI use** section is missing or empty", + ], + problems, + ) + + def test_filled_template_with_comments_and_real_lines_passes(self): + body = ( + "**Tested**\n" + "\n" + "- hardware (GPU + driver, CPU), Rust version, debug / release: RTX 3070 Ti, Rust 1.88.0\n" + "- `cargo test --workspace -- --test-threads=4`: N passed, N failed, N ignored (SKIPPED GPU tests: …)\n" + "**Not tested**\n" + "- AMD GPUs\n" + "**AI use**\n" + "- none\n" + ) + self.assertEqual([], check(body, HEAD, [changed("README.md")], lambda _: True)) + + def test_bare_bullets_and_html_comments_only_fail(self): + body = "**Tested**\n\n-\n**Not tested**\n*\n**AI use**\n - \n" + problems = check(body, HEAD, [changed("README.md")], lambda _: True) + self.assertEqual(3, len(problems)) + + if __name__ == "__main__": unittest.main()