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
8 changes: 6 additions & 2 deletions src/loopzero/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,10 +1671,14 @@ def cmd_status(args: argparse.Namespace) -> int:
print(f"branch: {branch}")
print(f"head: {head}")
print(f"base: {config.base_branch}")
print(f"dirty: {'yes' if worktree.is_dirty(wt) else 'no'}")
dirty = worktree.is_dirty(wt)
print(f"dirty: {'yes' if dirty else 'no'}")
checked = not dirty and _current_check_report(wt, config, head) is not 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: Receipt is verified twice when a PR exists

cmd_status calls _current_check_report here. When a PR exists, _readiness calls it again at cli.py:286. Each call reloads checks.json and recomputes sandbox.settings_fingerprint, which can resolve the base revision and hash the runner executable. The result is correct, but the cost doubles. Readiness then reports the local half of its decision as a separate run loopzero check at this head reason, so the two outputs can disagree if the file changes between the calls. This is not blocking. A small follow-up is to let _readiness accept an already-verified report, or to accept the duplicate work explicitly.

print(f"local checks: {'passed' if checked else 'no reusable pass'}", flush=True)

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: New status label breaks the column alignment

Every other status field uses a 10-character label column, such as dirty: and pr: . The new local checks: label is wider, so its value starts in a different column from the rest of the block. Either use a short label that fits the column, such as checks: passed, or widen the whole block consistently. The tests match on substrings, so they need an update only if the label text changes.

pr = github.pr_for_branch(config.repo, branch)
if pr is None:
print("pr: none (commit changes and pass `loopzero check` before `loopzero pr`)")
hint = "run `loopzero pr`" if checked else "commit changes and pass `loopzero check` before `loopzero pr`"
print(f"pr: none ({hint})")
return 0
print(f"pr: #{pr.number} {pr.url} ({'draft' if pr.is_draft else 'ready'}, {pr.state})")
reviews = _pr_reviews(config.repo, pr.number)
Expand Down
36 changes: 36 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3663,12 +3663,48 @@ def test_status_full(wt: Path, gh: FakeGh, capsys, git_calls) -> None:
code, out, _ = run(capsys, "status")
assert_git_cost(git_calls, 7, 1)
assert code == 0 and "dirty: yes" in out
assert "local checks: passed" not in out
assert f"pr: #7 {URL} (draft, OPEN)" in out
assert f"review: primary on {head[:12]} (approved)" in out
assert "ready: no" in out and " - required check 'checks' is pending" in out
assert sum(1 for c in gh.calls if c["argv"][:2] == ["api", reviews_key()[4:]]) == 1


@pytest.mark.parametrize("receipt", ["pass", "missing", "partial", "failed", "stale", "fingerprint"])
def test_status_no_pr_reports_receipt_before_lookup(wt, gh, capsys, monkeypatch, head, receipt):
if receipt != "missing":
arm_readiness(gh, head, wt, local_exit=int(receipt == "failed"))
path = wt / ".loopzero" / "checks.json"
report = json.loads(path.read_text())
if receipt == "partial":
report["results"].pop()
elif receipt == "stale":
report["head"] = "0" * 40
elif receipt == "fingerprint":
report["settings_sha256"] = "0" * 64
path.write_text(json.dumps(report))

def lookup(*_):
local = capsys.readouterr().out
assert "local checks:" in local
assert ("local checks: passed" in local) == (receipt == "pass")

monkeypatch.setattr(github, "pr_for_branch", lookup)
code, out, _ = run(capsys, "status")
assert code == 0
hint = "run `loopzero pr`" if receipt == "pass" else "pass `loopzero check`"
assert hint in out


def test_status_shows_local_pass_with_pending_ci(wt, gh, capsys, head):
arm_approved_pr_with_check_result(gh, head, wt, "pending")

code, out, _ = run(capsys, "status")

assert code == 0 and "local checks: passed" in out
assert "ready: no" in out and "required check 'checks' is pending" in out


def test_status_silently_ignores_legacy_report_without_dirty(
wt: Path, gh: FakeGh, capsys, head
) -> None:
Expand Down
Loading