Skip to content
Merged
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 @@ -628,6 +628,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:

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: Recovery wording duplicates the receipt predicate's message

The new branch checks report.settings_sha256 is None, which is the same test as the receipt predicate in _check_report_problem (cli.py:326). That keeps check and ready consistent: a passing report with no fingerprint is now rejected by both. The problem is that the rerun instructions now live in two places with different wording: here, and the recovery string at cli.py:324. If one is edited later, operators could get conflicting advice. Smallest fix: move the instruction into a shared constant, or build this message from _check_report_problem's output. The branch also fires when the fingerprint was already None before any stage ran (the runner executable couldn't be read at start). The message covers that case because it says "stable, readable", so this is not a bug.

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 @@ -3058,6 +3058,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):
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