From a3fbeb1f07a4415b672ce6fcf2960eef43416064 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:23:12 +0100 Subject: [PATCH 1/4] Explain how to resolve terminal required-check failures Architecture-Review: unchanged; Only refusal rendering changes, with the recorded readiness reasons left intact. Co-Authored-By: Codex --- src/loopzero/cli.py | 17 ++++++++++++++--- tests/test_cli.py | 18 +++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 48a64159..e7ee2dc6 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -1207,7 +1207,7 @@ def cmd_ready(args: argparse.Namespace) -> int: return 3 pr, readiness, kicked = waited assert readiness is not None - for reason in readiness.reasons: + for reason in _readiness_messages(pr, readiness): print(f"not ready: {reason}") if not readiness.ready: if args.wait is None and _pending_checks(config, pr, readiness): @@ -1248,6 +1248,17 @@ def _pending_checks( return reasons if reasons and all(r in waitable for r in reasons) else () +def _readiness_messages(pr: github.PR, readiness: github.Readiness) -> Iterator[str]: + for reason in readiness.reasons: + check, separator, conclusion = reason.rpartition("' is ") + if (separator and check.startswith("required check '") and conclusion not in {"pending", "skipped"} + and reason not in readiness.waitable_failures): + yield (f"{reason}. Inspect {pr.url}/checks. Fix reproducible failures before retrying. " + "Rerun the failed job only for a transient failure. Once green, run `loopzero ready --wait`.") + else: + yield reason + + def _merge_check_hint(config: Config, pr: github.PR, readiness: github.Readiness) -> str: if _pending_checks(config, pr, readiness): return "; next: loopzero merge --wait" @@ -1531,7 +1542,7 @@ def _merge_with_mergify( """Request Mergify after readiness verifies the source gates and queue configuration.""" if not readiness.ready: hint = _merge_check_hint(config, pr, readiness) - raise CliError("not ready to request Mergify: " + "; ".join(readiness.reasons) + hint) + raise CliError("not ready to request Mergify: " + "; ".join(_readiness_messages(pr, readiness)) + hint) queue = config.mergify_queue assert queue is not None requested, confirmed_marker = mergify.markers( @@ -1612,7 +1623,7 @@ def cmd_merge(args: argparse.Namespace) -> int: else: if not readiness.ready: hint = _merge_check_hint(config, pr, readiness) - raise CliError("not ready to merge: " + "; ".join(readiness.reasons) + hint) + raise CliError("not ready to merge: " + "; ".join(_readiness_messages(pr, readiness)) + hint) if admit_by is not None and time.monotonic() > admit_by: print(f"timed out before merging PR #{pr.number}") return 3 diff --git a/tests/test_cli.py b/tests/test_cli.py index c09d043c..de4bf011 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -49,6 +49,7 @@ REPO = "acme/widgets" URL = f"https://github.com/{REPO}/pull/7" +FAILED_CHECK_HINT = f". Inspect {URL}/checks. Fix reproducible failures before retrying. Rerun the failed job only for a transient failure. Once green, run `loopzero ready --wait`." MERGIFY_QUEUE_FIXTURE = json.loads((Path(__file__).with_name("fixtures") / "mergify-queue.json").read_text()) BRANCH_READ = branch_head_key().split() PR_LIST_READ = pr_list_key().split() @@ -2345,7 +2346,7 @@ def test_ready_not_ready_lists_reasons(wt: Path, gh: FakeGh, capsys, head) -> No assert code == 1 assert without_accepted_receipt(out).splitlines() == [ "not ready: no review recorded for the current head", - "not ready: required check 'checks' is failure", + f"not ready: required check 'checks' is failure{FAILED_CHECK_HINT}", ] assert all(c["argv"][:2] != ["pr", "ready"] for c in gh.calls) assert not any("actions/runs" in " ".join(c["argv"]) for c in gh.calls) @@ -2369,9 +2370,8 @@ def test_ready_uses_base_required_ci_when_worktree_empties_it( code, out, err = run(capsys, "ready") - out = without_accepted_receipt(out) assert (code, err) == (1, "") - assert out == "not ready: required check 'checks' is failure\n" + assert without_accepted_receipt(out) == f"not ready: required check 'checks' is failure{FAILED_CHECK_HINT}\n" def test_pending_required_check_names_the_wait(wt: Path, gh: FakeGh, capsys, head) -> None: @@ -2687,7 +2687,7 @@ def sleep(seconds): assert (code, err) == (expected, "") assert out.endswith({ - 0: f"ready: {URL}\n", 1: "not ready: required check 'checks' is failure\n", + 0: f"ready: {URL}\n", 1: f"not ready: required check 'checks' is failure{FAILED_CHECK_HINT}\n", 3: f"timed out waiting for required checks on {head[:12]}\n", }[expected]) @@ -2724,7 +2724,7 @@ def sleep(seconds: float) -> None: assert "timed out waiting for required checks" in out else: assert out.endswith(f"ready: {URL}\n" if expected == 0 else - "not ready: required check 'checks' is failure\n") + f"not ready: required check 'checks' is failure{FAILED_CHECK_HINT}\n") @pytest.mark.usefixtures("replay_gh") @@ -2772,7 +2772,7 @@ def advance(seconds): assert sleeps == ([30.0, 5.0, 5.0] if replacement == "pending" else [30.0, 5.0] if initial_pending else [30.0]) assert out.endswith(f"ready: {URL}\n" if expected == 0 else - "not ready: required check 'checks' is failure\n" if expected == 1 else + f"not ready: required check 'checks' is failure{FAILED_CHECK_HINT}\n" if expected == 1 else f"timed out waiting for required checks on {head[:12]}\n") assert sum(c["argv"][:2] == ["pr", "ready"] for c in gh.calls) == 1 @@ -2971,7 +2971,7 @@ def advance(seconds): ) assert (code, err, bool(sleeps)) == (expected, "", waited) assert out.endswith(f"ready: {URL}\n" if expected == 0 else - f"not ready: required check '{name}' is failure\n") + f"not ready: required check '{name}' is failure{FAILED_CHECK_HINT}\n") assert (f"waiting: required check '{name}' is failure" in out) == waited assert out.count("predates the review; awaiting refresh") == int( waited and (age < 0 or age >= 120) and not pending @@ -3256,14 +3256,14 @@ def test_ready_respects_latest_review_state(wt: Path, gh: FakeGh, capsys, state, def test_merge_refuses_when_not_ready(wt: Path, gh: FakeGh, capsys, head) -> None: arm_pr(gh, head, isDraft=False) gh.respond(reviews_key(), [rev(head, "primary")]) - arm_readiness(gh, head, wt, threads=( + arm_readiness(gh, head, wt, conclusion="failure", threads=( {"isResolved": False, "isOutdated": False, "path": "feature.py", "line": 1, "comments": {"nodes": [{"body": f"" "\n**critical: Bad**"}]}},)) code, out, err = run(capsys, "merge") out = without_accepted_receipt(out) assert code == 1 and out == "" - assert "not ready to merge: open critical finding at feature.py:1: Bad" in err + assert f"not ready to merge: open critical finding at feature.py:1: Bad; required check 'checks' is failure{FAILED_CHECK_HINT}" in err assert wt.exists() From 677c87b4c5592104dccf841e97124c3eccc5ebe1 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:25:09 +0100 Subject: [PATCH 2/4] Keep multi-blocker assertions compatible with the review-budget change Co-Authored-By: Codex --- tests/test_cli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index afb1192c..a9e2c09d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2320,10 +2320,11 @@ def test_ready_not_ready_lists_reasons(wt: Path, gh: FakeGh, capsys, head) -> No "name": "checks", "status": "completed", "conclusion": "failure", "check_suite": {"id": 10}}]) code, out, _ = run(capsys, "ready") + out = out.replace(FAILED_CHECK_HINT, "") assert code == 1 assert without_accepted_receipt(out).splitlines() == [ "not ready: no review recorded for the current head", - f"not ready: required check 'checks' is failure{FAILED_CHECK_HINT}", + "not ready: required check 'checks' is failure", ] assert all(c["argv"][:2] != ["pr", "ready"] for c in gh.calls) assert not any("actions/runs" in " ".join(c["argv"]) for c in gh.calls) @@ -2342,8 +2343,7 @@ def test_ready_explains_trusted_policy_blocker(wt, gh, capsys, head, retargeted, code, out, err = run(capsys, "ready") - assert (code, err) == (1, "") - assert without_accepted_receipt(out) == f"not ready: {reason}\n" + assert (code, err, without_accepted_receipt(out)) == (1, "", f"not ready: {reason}\n") def test_pending_required_check_names_the_wait(wt: Path, gh: FakeGh, capsys, head) -> None: From a29a2761ae947003283ce94694ede13f09b8c967 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:38:02 +0100 Subject: [PATCH 3/4] Seed the candidate attestation Git graph once per worker Co-Authored-By: Codex --- tests/test_candidate.py | 58 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/test_candidate.py b/tests/test_candidate.py index 28dfdc6e..1b228c55 100644 --- a/tests/test_candidate.py +++ b/tests/test_candidate.py @@ -11,15 +11,18 @@ import base64 import subprocess from copy import deepcopy +from functools import partial from importlib import import_module from itertools import cycle from os import environ +from shutil import copytree import pytest from loopzero import candidate from loopzero.candidate import CandidateError, CandidateRaceError, attest_candidate from loopzero.types import LoopZeroError +from tests.conftest import commit_file, git as isolated_git @pytest.fixture(autouse=True) @@ -205,38 +208,36 @@ def block(number: int, _source: dict) -> None: run_attestation(github_payloads=values, source_policy=block) +@pytest.fixture(scope="session") +def candidate_seed(tmp_path_factory): + remote = tmp_path_factory.mktemp("candidate-seed") + git = partial(isolated_git, remote) + git("init", "-b", "main") + commit_file(remote, "base", "base\n", "base") + for branch, content in (("parent", "H1\n"), ("source", "reviewed\n")): + git("checkout", "-b", branch, "main") + commit_file(remote, branch, content, branch) + git("checkout", "-b", "candidate", "main") + git("merge", "--no-ff", "parent", "-m", "parent integration") + git("merge", "--no-ff", "source", "-m", "source integration") + git("checkout", "main") + git("merge", "--squash", "parent") + git("commit", "-m", "squashed parent") + return remote, *git("rev-parse", "source^", "parent", "source", "candidate", "main").split() + + @pytest.fixture -def tree_candidate(tmp_path, monkeypatch): - remote = tmp_path / "remote" - remote.mkdir() +def tree_candidate(candidate_seed, tmp_path, monkeypatch): + seed, base, parent, source, candidate_sha, main = candidate_seed + remote = copytree(seed, tmp_path / "remote") def git(*args): - return subprocess.run(["git", *args], cwd=remote, check=True, capture_output=True, - text=True).stdout.strip() - - git("init", "-b", "main") - git("config", "user.name", "Test") - git("config", "user.email", "test@example.org") + return isolated_git(remote, *args).strip() def commit(name, content): - (remote / name).write_text(content) - git("add", ".") - git("commit", "-m", name) + commit_file(remote, name, content, name) return git("rev-parse", "HEAD") - base = commit("base", "base\n") - git("checkout", "-b", "parent") - parent = commit("parent", "H1\n") - git("checkout", "-b", "source", base) - source = commit("source", "reviewed\n") - git("checkout", "-b", "candidate", base) - git("merge", "--no-ff", parent, "-m", "parent integration") - git("merge", "--no-ff", source, "-m", "source integration") - candidate_sha = git("rev-parse", "HEAD") - git("checkout", "main") - git("merge", "--squash", parent) - git("commit", "-m", "squashed parent") - main = git("rev-parse", "HEAD") popen = subprocess.Popen def isolated_fetch(argv, **kwargs): @@ -281,10 +282,9 @@ def attest( reads = cycle([main_head, main_after or main_head]) def get(path): - if path.endswith("/git/ref/heads/main"): - sha = next(reads) - return {"object": {"sha": sha}} if sha else {} - return deepcopy(values[path]) + if not path.endswith("/git/ref/heads/main"): + return deepcopy(values[path]) + return {"object": {"sha": sha}} if (sha := next(reads)) else {} return run(candidate_event, github_get=get, mergify_status=lambda *_: deepcopy(queue), source_policy=policy) From 6c1060dcd248dbc2971614f3f0883511f3c3c18d Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:39:45 +0100 Subject: [PATCH 4/4] Exercise each stage runner response once across base paths Co-Authored-By: Codex --- tests/test_stage_runner.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/test_stage_runner.py b/tests/test_stage_runner.py index 17491193..6fe18983 100644 --- a/tests/test_stage_runner.py +++ b/tests/test_stage_runner.py @@ -12,16 +12,15 @@ from .test_sandbox import bwrap_log, make_config # noqa: F401 -@pytest.mark.parametrize('base_ref', ['stale', 'missing', 'recorded']) -@pytest.mark.parametrize('body,verdict,tails', [ - ('print(json.dumps(r))', True, ['ok', 'ok']), - ('r["exit_code"]=7;print(json.dumps(r))', False, ['ok']), - ('print("x" * 3000 + "worker socket unavailable", file=sys.stderr);sys.exit(42)', False, None), - ('r["exit_code"]=7;r["tail"]="Ω"*10000+" newest";print(json.dumps(r))', False, +@pytest.mark.parametrize('base_ref,body,verdict,tails', [ + *[(base_ref, 'print(json.dumps(r))', True, ['ok', 'ok']) for base_ref in ('stale', 'missing', 'recorded')], + ('stale', 'r["exit_code"]=7;print(json.dumps(r))', False, ['ok']), + ('stale', 'print("x" * 3000 + "worker socket unavailable", file=sys.stderr);sys.exit(42)', False, None), + ('stale', 'r["exit_code"]=7;r["tail"]="Ω"*10000+" newest";print(json.dumps(r))', False, ['Ω' * 8188 + ' newest']), - ('subprocess.run(["git","-C",repo,"-c","user.name=test","-c","user.email=t@e","commit","--allow-empty","-m","drift"],stdout=sys.stderr,check=True);print(json.dumps(r))', False, None), - ('r.update(not_started=True,duration_s=0,tail="");print(json.dumps(r))', True, ['one', 'two']), - *[(body, False, None) for body in [ + ('stale', 'subprocess.run(["git","-C",repo,"-c","user.name=test","-c","user.email=t@e","commit","--allow-empty","-m","drift"],stdout=sys.stderr,check=True);print(json.dumps(r))', False, None), + ('stale', 'r.update(not_started=True,duration_s=0,tail="");print(json.dumps(r))', True, ['one', 'two']), + *[('stale', body, False, None) for body in [ '', '''print('{"x":' * 100000 + "0" + "}" * 100000)''', 'print("{")', 'print(json.dumps(r));print(json.dumps(r))', 'del r["exit_code"];print(json.dumps(r))', 'del r["worktree"];print(json.dumps(r))', 'r["duration_s"]=float("nan");print(json.dumps(r))', @@ -66,17 +65,15 @@ def test_runner(git_repo, tmp_path, bwrap_log, body, verdict, tails, base_ref): if tails is not None: assert [r.tail for r in report.results] == tails if not verdict: + assert calls == ['echo one'] assert sum(r.tail == 'ok' for r in report.results) <= 1 if '* 100000' in body: assert 'Stage runner failed' in report.results[0].tail assert any(word in report.results[0].tail.lower() for word in ('recursion', 'stack overflow')) - if 'drift' in body: - assert report.dirty and calls == ['echo one'] - assert 'Worktree changed after stage' in report.results[0].tail - elif not verdict: - assert calls == ['echo one'] current_head = _save_report(git_repo, report) if 'drift' in body: + assert report.dirty + assert 'Worktree changed after stage' in report.results[0].tail assert current_head == git(git_repo, 'rev-parse', 'HEAD').strip() and current_head != report.head assert _load_report(git_repo) != report return