diff --git a/scripts/pr_check.py b/scripts/pr_check.py index 3a526b4a9d..a282fee9fe 100644 --- a/scripts/pr_check.py +++ b/scripts/pr_check.py @@ -113,9 +113,11 @@ def check(body, head, files, is_main_ancestor, *, test_only=False): if not test_only and any(runtime(p) or builds_runtime(p) for p, *_ in files): blocks = smoke_blocks(body) - mine = [b for b in blocks if len(b.get("commit", "")) >= 7 and head.startswith(b["commit"].split()[0])] + # a block's commit is the first word of its `commit:` line; fewer than 7 digits name no commit + sha = lambda b: (b.get("commit", "").split() or [""])[0] + mine = [b for b in blocks if len(sha(b)) >= 7 and head.startswith(sha(b))] clean = [b for b in mine if "uncommitted" not in b.get("commit", "")] - base = [b for b in blocks if b not in mine and len(b.get("commit", "").split()[0] if b.get("commit") else "") >= 7] + base = [b for b in blocks if b not in mine and len(sha(b)) >= 7] if not clean: problems.append(f"the PR changes the runtime: **Regression run** needs an `xcl-smoke` block made on this PR's " f"head commit {head[:12]} with no uncommitted changes (rerun scripts/smoke.ps1 after every push)") diff --git a/scripts/test_pr_check.py b/scripts/test_pr_check.py index e5de366a54..80247ba68b 100644 --- a/scripts/test_pr_check.py +++ b/scripts/test_pr_check.py @@ -64,6 +64,43 @@ def test_blocks_in_separate_fences_stay_separate(self): self.assertEqual(["1111111aaaa", "1234567890"], [b["commit"] for b in smoke_blocks(body)]) +class SmokeBlockCommitTests(unittest.TestCase): + """Which `xcl-smoke` block counts as the run on the PR's head commit.""" + + HEAD = "1234567890abcdef1234567890abcdef12345678" + MAIN = "feedfacefeedfacefeedfacefeedfacefeedface" + NEEDS_HEAD = "needs an `xcl-smoke` block made on this PR's head commit" + + def problems(self, commit): + block = ("```\nxcl-smoke v1\ncommit: {}\ntitle: t\nseconds: 60\nframes shown: 100\n" + "peak commit: 100 MB\ndevice removals: 0\ncrashes: 0\nexit: ok\n```\n") + body = BODY + "**Regression run**\n" + block.format(self.MAIN) + block.format(commit) + files = [changed("crates/xcl/src/hle/d3d12x/vram.rs")] + return check(body, self.HEAD, files, lambda sha: sha == self.MAIN) + + def test_a_block_on_the_head_commit_is_the_prs_run(self): + for commit in (self.HEAD, self.HEAD[:7], self.HEAD[:12]): + self.assertEqual([], self.problems(commit), commit) + + def test_a_short_first_word_names_no_commit(self): + # The whole value was measured, but only its first word compared: "1 some other" + # passed as a run on any head that starts with 1. + for commit in ("1 some other", "12 not a hash", "123456", "123456 (uncommitted changes)"): + problems = self.problems(commit) + self.assertEqual(1, len(problems), (commit, problems)) + self.assertIn(self.NEEDS_HEAD, problems[0]) + + def test_another_commit_is_not_the_prs_run(self): + problems = self.problems("abcdef0123456") + self.assertEqual(1, len(problems), problems) + self.assertIn(self.NEEDS_HEAD, problems[0]) + + def test_uncommitted_changes_are_refused(self): + problems = self.problems(self.HEAD[:12] + " (uncommitted changes)") + self.assertEqual(1, len(problems), problems) + self.assertIn(self.NEEDS_HEAD, problems[0]) + + 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"