Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: …)
<!-- 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**
<!-- Required when the PR changes crates/xcl/src outside tests: `scripts/smoke.ps1` on a real title,
Expand All @@ -20,4 +21,5 @@ PR:
-

**AI use**
- none / tool and model, and what it did
<!-- none / tool and model, and what it did -->
-
19 changes: 18 additions & 1 deletion scripts/pr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
111 changes: 111 additions & 0 deletions scripts/pr_check.tests.py
Original file line number Diff line number Diff line change
@@ -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", "<!-- what you could\n not check -->\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**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- 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", "<!-- results to come\n")
self.assertEqual(problems(body), [empty(s) for s in ("Tested", "Not tested", "AI use")])

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.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
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()
Loading