Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/loopzero/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,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)
Expand Down
37 changes: 37 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2991,6 +2991,43 @@ 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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Only the mid-run retarget case is tested, not a runner that is missing from the start

The acceptance criteria cover two cases: runner identity that is missing, and runner identity that changes. The new test only covers the change during execution. A runner whose identity can't be resolved at the start also goes through the new branch, because settings_fingerprint returns None when runner_executable is None (sandbox.py:300). I checked by reading the code, not by running it. A small parametrized case where the configured runner can't be resolved from the start, but the stage still reports exit 0, would lock in that behaviour too. This doesn't block the change.

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)
publish_workflow(wt, WORKFLOW.replace("[checks]", f"[checks]\nrunner = {json.dumps([str(runner)])}"))
arm_approved_ready_pr(gh, head, wt, readiness={"local_exit": None}, isDraft=False)

code, out, err = run(capsys, "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, "ready")[0] == 1

code, out, _ = run(capsys, "check")
assert code == 0 and "receipt produced:" in out
assert run(capsys, "ready")[0] == 0


@pytest.mark.parametrize("base_sensitive", [False, True])
def test_wait_snapshot_handles_trusted_base_advance(wt, repo, base_sensitive):
if base_sensitive:
Expand Down
Loading