From 8d99ad3ac9b4ffff5965b767514583848f42a951 Mon Sep 17 00:00:00 2001 From: lunaeme Date: Wed, 25 Nov 2026 07:09:04 -0300 Subject: [PATCH] PR checks: the PR's smoke block must show how its run ended (#2213) scripts/pr_check.py required only `title`, `seconds` and `frames shown` in an `xcl-smoke` block. The PR's `device removals`, `crashes`, `exit` and `peak commit` lines were read with dict.get(), and a missing or non-numeric value counted as clean. A block that lost its `crashes: 1` line, or that kept smoke.ps1's own `peak commit: n/a MB`, passed. So did `exit: 0xc0000005`, because only an exit starting with "killed" was a problem. The PR's own block now needs all four lines, in the form smoke.ps1 prints them: the two counters as plain integers and `peak commit` as ` MB`. number() reads only leading digits, so `1.5 GB` was 1 and `3,000 MB` was 3. An exit other than 0x0 is a problem (`killed (no exit)` keeps its message). `seconds` must not be 0 in either block, and `frames shown` and `peak commit` must not be 0 in the PR's: the comparisons treat 0 as "no value" and skipped themselves. Main's block is otherwise unchanged, because its run may have crashed (#1506). Fixes #2213 Co-Authored-By: Claude Opus 5.5 --- scripts/pr_check.py | 28 +++++++++++++++++-------- scripts/test_pr_check.py | 44 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/scripts/pr_check.py b/scripts/pr_check.py index cb0ef3ef9e..f15cee4ad0 100644 --- a/scripts/pr_check.py +++ b/scripts/pr_check.py @@ -33,10 +33,13 @@ MAX_BINARY = 1 << 20 FRAMES_KEPT = 0.8 # the PR's frames at least this share of main's COMMIT_GROWTH = 1.25 # the PR's peak commit at most this times main's -# the lines a smoke block needs to be compared with the other (the crash and device-removal -# counts are checked where they are used), and those of them that are numbers +# the lines a smoke block needs to be compared with the other, and those of them that are numbers SMOKE_FIELDS = ("title", "seconds", "frames shown") SMOKE_NUMBERS = ("seconds", "frames shown") +# the lines the PR's own block also needs, to show it ended cleanly (smoke.ps1 always prints +# them; main's run may have crashed, #1506), and the exact form smoke.ps1 prints their values in +PR_SMOKE_FIELDS = ("device removals", "crashes", "exit", "peak commit") +PR_SMOKE_FORMS = {"device removals": r"\d+", "crashes": r"\d+", "peak commit": r"\d+ MB"} def smoke_blocks(body): @@ -58,13 +61,16 @@ def number(s): return int(m.group(1)) if m else None -def field_problems(block, run): - """What `block` (the smoke block of `run`) lacks for the comparison: a missing line or a - number that is not one.""" +def field_problems(block, run, fields=SMOKE_FIELDS, numbers=SMOKE_NUMBERS, forms=None, positive=("seconds",)): + """What is wrong with `block` (the smoke block of `run`): a missing line, a number that is not + one, a value not in the form smoke.ps1 prints it in, or a 0 where a real run has more.""" name = f"{run} regression run (`xcl-smoke` block of commit {(block.get('commit') or '?').split()[0]})" - out = [f"{name} has no `{k}` line" for k in SMOKE_FIELDS if not block.get(k)] - out += [f"{name} has a non-numeric `{k}`: {block[k]}" for k in SMOKE_NUMBERS + out = [f"{name} has no `{k}` line" for k in fields if not block.get(k)] + out += [f"{name} has a non-numeric `{k}`: {block[k]}" for k in numbers if block.get(k) and number(block[k]) is None] + out += [f"{name} has a malformed `{k}`: {block[k]}" for k, form in (forms or {}).items() + if block.get(k) and not re.fullmatch(form, block[k])] + out += [f"{name} shows `{k}: 0`" for k in positive if number(block.get(k)) == 0] return out @@ -141,12 +147,16 @@ def check(body, head, files, is_main_ancestor, *, test_only=False): "with the same title and time as the PR's") if clean: pr = clean[-1] - problems += field_problems(pr, "the PR's") + problems += field_problems(pr, "the PR's", SMOKE_FIELDS + PR_SMOKE_FIELDS, forms=PR_SMOKE_FORMS, + positive=("seconds", "frames shown", "peak commit")) for key in ("device removals", "crashes"): if (number(pr.get(key)) or 0) > 0: problems.append(f"the PR's regression run shows {key}: {pr.get(key)}") - if pr.get("exit", "").startswith("killed"): + code = pr.get("exit", "") + if code.startswith("killed"): problems.append("the PR's regression run did not end by itself (killed)") + elif code and code != "0x0": + problems.append(f"the PR's regression run ended with exit {code}") if main: m = next((b for b in main if b.get("title") == pr.get("title") and b.get("seconds") == pr.get("seconds")), None) for b in [m] if m else main: diff --git a/scripts/test_pr_check.py b/scripts/test_pr_check.py index 8cc45d5d06..246687a8c1 100644 --- a/scripts/test_pr_check.py +++ b/scripts/test_pr_check.py @@ -6,6 +6,9 @@ HEAD = "1234567890abcdef" BODY = "**Tested**\nSynthetic fixtures\n**Not tested**\nRetail titles\n**AI use**\nNone\n" +# the lines scripts/smoke.ps1 prints for a run that ended cleanly +CLEAN_RUN = ("title: G\nseconds: 60\nexit: 0x0\nframes shown: 100 (PresentX 100)\n" + "device removals: 0\ncrashes: 0\npeak commit: 3000 MB\n") def changed(path, binary=False): @@ -71,7 +74,7 @@ def test_frontier_models_and_ordinary_words_pass(self): class SmokeBlockTests(unittest.TestCase): def test_two_blocks_in_one_fence_are_two_blocks(self): - run = "title: G\nseconds: 60\nframes shown: 100\ndevice removals: 0\ncrashes: 0\n" + run = CLEAN_RUN body = ("```\nxcl-smoke v1\ncommit: 1111111aaaa\n" + run + "\n" "xcl-smoke v1\ncommit: 1234567890\n" + run + "```\n") blocks = smoke_blocks(body) @@ -102,6 +105,45 @@ def test_non_numeric_frames_shown_fails(self): self.assertIn("the PR's regression run (`xcl-smoke` block of commit 1234567890) " "has a non-numeric `frames shown`: many", problems) + def test_clean_pr_run_passes(self): + self.assertEqual([], self.smoke_problems(CLEAN_RUN, CLEAN_RUN)) + + def test_pr_run_without_a_safety_line_fails(self): + for field in ("device removals", "crashes", "exit", "peak commit"): + with self.subTest(field=field): + pr_run = "".join(l + "\n" for l in CLEAN_RUN.splitlines() if not l.startswith(field + ":")) + self.assertEqual([f"the PR's regression run (`xcl-smoke` block of commit 1234567890) has no `{field}` line"], + self.smoke_problems(CLEAN_RUN, pr_run)) + + def test_pr_run_with_malformed_counters_fails(self): + for field, value in (("crashes", "none"), ("crashes", "0x0"), ("device removals", "n/a"), ("device removals", "0.0"), + ("peak commit", "n/a MB"), ("peak commit", "1.5 GB"), ("peak commit", "3,000 MB")): + with self.subTest(field=field, value=value): + pr_run = CLEAN_RUN.replace(f"{field}: {'0' if field != 'peak commit' else '3000 MB'}", f"{field}: {value}") + self.assertEqual([f"the PR's regression run (`xcl-smoke` block of commit 1234567890) " + f"has a malformed `{field}`: {value}"], self.smoke_problems(CLEAN_RUN, pr_run)) + + def test_zero_seconds_frames_or_commit_fail(self): + pr = "the PR's regression run (`xcl-smoke` block of commit 1234567890)" + no_memory = self.smoke_problems(CLEAN_RUN, CLEAN_RUN.replace("peak commit: 3000 MB", "peak commit: 0 MB")) + self.assertEqual([f"{pr} shows `peak commit: 0`"], no_memory) + no_frames = self.smoke_problems(CLEAN_RUN, CLEAN_RUN.replace("frames shown: 100 (PresentX 100)", "frames shown: 0")) + self.assertIn(f"{pr} shows `frames shown: 0`", no_frames) + zeros = CLEAN_RUN.replace("seconds: 60", "seconds: 0") + problems = self.smoke_problems(zeros, zeros) + self.assertIn(f"{pr} shows `seconds: 0`", problems) + self.assertIn("the main regression run (`xcl-smoke` block of commit 1111111aaaa) shows `seconds: 0`", problems) + + def test_pr_run_that_did_not_exit_cleanly_fails(self): + crashed = self.smoke_problems(CLEAN_RUN, CLEAN_RUN.replace("exit: 0x0", "exit: 0xc0000005")) + self.assertEqual(["the PR's regression run ended with exit 0xc0000005"], crashed) + killed = self.smoke_problems(CLEAN_RUN, CLEAN_RUN.replace("exit: 0x0", "exit: killed (no exit)")) + self.assertEqual(["the PR's regression run did not end by itself (killed)"], killed) + + def test_main_run_may_lack_the_safety_lines(self): + main_run = "title: G\nseconds: 60\nframes shown: 100\n" + self.assertEqual([], self.smoke_problems(main_run, CLEAN_RUN)) + class TemplatePlaceholderTests(unittest.TestCase): def test_untouched_pr_template_fails_all_required_sections(self):