Merge pull request #2025 from ludovic111/ci/parity-main-bisect-confirm
🤖 Agent: bisect fix; tests/test_parity_main.py passes (4 tests).
This commit is contained in:
@@ -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))
|
||||
|
||||
+16
-1
@@ -8,7 +8,7 @@
|
||||
so a run tests every merge since the last green one (`tools/parity.py --changed <base>`), 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)
|
||||
|
||||
Reference in New Issue
Block a user