From 84117182e4c8986cbe51dc7696502c66c6cb7931 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:20:49 +0100 Subject: [PATCH] Fail check when a delegated runner leaves an unverified receipt Architecture-Review: unchanged; the coordinator still owns runner fingerprinting and readiness still verifies the receipt. Co-Authored-By: Codex --- src/loopzero/cli.py | 5 +++++ tests/test_cli.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 31c6ad72..52085dfb 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -649,6 +649,11 @@ def cmd_check(args: argparse.Namespace) -> int: print(f"check result discarded: checked HEAD {report.head}, current HEAD {current_head}", file=sys.stderr) return 1 + if report.ok and report.settings_sha256 is None: + print("check stages passed but the receipt is unverified; rerun loopzero check from the task " + "worktree with a stable, readable configured runner before running ready", file=sys.stderr) + _refresh_pr_checks(wt, config) + return 1 if report.ok and not report.dirty: _print_receipt(wt, report, "produced") _refresh_pr_checks(wt, config) diff --git a/tests/test_cli.py b/tests/test_cli.py index 4b779553..99bafa11 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2988,6 +2988,45 @@ def change_policy(_seconds): assert run(capsys, *args, "check")[0] == 1 +def test_check_refuses_unverified_receipt_after_runner_retarget(wt, gh, capsys, head, tmp_path): + runner = tmp_path / "runner" + original = tmp_path / "runner-a" + replacement = tmp_path / "runner-b" + stage = ( + f"#!{sys.executable}\n" + "import json, sys\n" + "frame = json.load(sys.stdin)\n" + "del frame['env']\n" + "frame.update(exit_code=0, duration_s=0, not_started=False, tail='')\n" + ) + for target, extra in ( + (original, f"from pathlib import Path\np = Path({str(runner)!r})\n" + f"p.unlink()\np.symlink_to({str(replacement)!r})\n"), + (replacement, ""), + ): + target.write_text(stage + extra + "print(json.dumps(frame))\n") + target.chmod(0o755) + runner.symlink_to(original) + config_path = tmp_path / "delegated.toml" + config_path.write_text(WORKFLOW.replace("[checks]", f"[checks]\nrunner = {json.dumps([str(runner)])}")) + args = ("--config", str(config_path)) + arm_approved_ready_pr(gh, head, wt, readiness={"local_exit": None}, isDraft=False) + + code, out, err = run(capsys, *args, "check") + assert code == 1 + assert "receipt produced:" not in out and "PASS" not in out + assert "stages passed but the receipt is unverified" in err + assert "rerun loopzero check from the task worktree with a stable, readable configured runner" in err + report = cli._load_report(wt) + assert report.head == head and not report.dirty and report.ok + assert report.settings_sha256 is None + assert run(capsys, *args, "ready")[0] == 1 + + code, out, _ = run(capsys, *args, "check") + assert code == 0 and "receipt produced:" in out + assert run(capsys, *args, "ready")[0] == 0 + + @pytest.mark.parametrize("fixed", [False, True]) def test_ready_matches_effective_inherited_check_environment( wt, gh, capsys, head, tmp_path, monkeypatch, fixed,