From 2c5dac354eb0f5b7c3812803e5d4798f54973c34 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 26 Oct 2026 06:11:01 +0100 Subject: [PATCH] parity-main: name a merge only when HEAD fails again and the base passes The bisect ended on the newest merge when the failed harnesses pass everywhere now (a flake, or a runner that was missing the sounds), and on the oldest when they fail everywhere (the runner), and commented on that pull request either way. It now reruns them at HEAD and at the base first and names nobody unless HEAD fails and the base passes. Co-Authored-By: Claude Opus 5.5 --- tests/test_parity_main.py | 29 +++++++++++++++++++++++++++++ tools/parity_main.py | 17 ++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/test_parity_main.py b/tests/test_parity_main.py index 7a72ecae5..aa58375a6 100644 --- a/tests/test_parity_main.py +++ b/tests/test_parity_main.py @@ -33,6 +33,35 @@ class ParityMainTests(unittest.TestCase): self.assertEqual(parity_main.base(runs=[]), parent, "no green run yet: the last merge") self.assertEqual(parity_main.base(runs=[head]), head) + def test_bisect_names_a_merge_only_when_head_fails_and_the_base_passes(self): + with tempfile.TemporaryDirectory() as tmp, mock.patch.object(parity_main, "ROOT", Path(tmp)): + git = lambda *arguments: parity_main.git(*arguments).stdout.strip() + git("init", "-q") + for n in range(4): + git("-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "--allow-empty", + "-m", f"Merge pull request #{n} from x/y") + commits = git("rev-list", "--reverse", "HEAD").split() + last_run = Path(tmp) / ".local/parity-runner/last-run.json" + last_run.parent.mkdir(parents=True) + last_run.write_text('{"failed": ["music"]}') + real_run = parity_main.subprocess.run + for broken_from, blamed in ((None, None), (0, None), (2, "2")): + comments = [] + # git runs for real in the scratch repo; a `gh pr comment` is only recorded, never sent. + fake_run = lambda command, **kwargs: (comments.append(command) if command[0] == "gh" + else real_run(command, **kwargs)) + with mock.patch.object(parity_main, "LAST_RUN", last_run), \ + mock.patch.object(parity_main, "run_harnesses", lambda names, timeout: broken_from is not None + and commits.index(git("rev-parse", "HEAD")) >= broken_from), \ + mock.patch.object(parity_main.subprocess, "run", fake_run), \ + mock.patch("builtins.print") as printed: + parity_main.bisect(commits[0], 60, comment=True) + if blamed: + self.assertEqual([command[3] for command in comments], [blamed]) + else: + self.assertEqual(comments, [], printed.call_args_list[-1]) + self.assertEqual(git("rev-parse", "HEAD"), commits[-1], "HEAD checked out again") + def test_a_harness_a_commit_does_not_have_cannot_fail_there(self): with mock.patch.object(parity_main.subprocess, "run") as run: self.assertFalse(parity_main.run_harnesses(["not_a_harness_yet"], 60)) diff --git a/tools/parity_main.py b/tools/parity_main.py index ff319aed0..76fa49070 100644 --- a/tools/parity_main.py +++ b/tools/parity_main.py @@ -8,7 +8,7 @@ so a run tests every merge since the last green one (`tools/parity.py --changed `), however many landed while the previous run went on. `bisect` reads the harnesses that failed (.local/parity-runner/last-run.json), checks out the first-parent merges between BASE and HEAD by halves and runs only those harnesses, then names the first merge they -fail on (written to $GITHUB_STEP_SUMMARY and, with --comment, on its pull request). HEAD is checked out again at the end. +fail on, once they fail again at HEAD and pass at BASE (written to $GITHUB_STEP_SUMMARY and, with --comment, on its pull request). HEAD is checked out again at the end. """ import argparse @@ -90,7 +90,22 @@ def bisect(since, timeout, comment): git("checkout", "-q", "--detach", commit) return run_harnesses(failed, timeout) + def blame_nobody(why): + line = f"parity-main: {', '.join(failed)} {why}: no merge is named." + print(line) + if os.environ.get("GITHUB_STEP_SUMMARY"): + with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as summary: + summary.write(f"### {line}\n") + return 0 + + # A merge is named only when the harnesses fail again at HEAD and pass at the base: otherwise the search would + # end on the newest merge (a flake, or a runner missing files, passes everywhere now) or the oldest one (the + # runner fails at every commit) and blame it for nothing. try: + if not fails(head): + return blame_nobody(f"pass when run again at {head[:9]}: a flake or the runner") + if fails(since): + return blame_nobody(f"fail at the base {since[:9]} too: the runner or a flake") culprit = first_bad(commits, fails) if len(commits) > 1 else commits[0] finally: git("checkout", "-q", "--detach", head)