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 @@ -1692,10 +1692,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

When a PR exists, cmd_status checks the receipt once through _current_check_report to print the status line. Then _readiness (cli.py:286-287) loads the same receipt again and recomputes sandbox.settings_fingerprint. If a check runner is configured, that also re-hashes the runner executable. The two results should agree, but the work is duplicated, and the line and the readiness reason could drift if either path changes later. Smallest fix: compute _load_report plus _check_report_problem once in status and pass the result to _readiness through an optional parameter. Alternatively, accept the extra cost, since status is not a hot path.

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 label breaks the aligned status columns

Every other status line pads its label to a 10-character column (dirty: , pr: , ready: ). local checks: is wider and misaligns the output. Consider a shorter label that fits the column, such as checks: passed or local: passed, and update the test strings to match. This is cosmetic only.

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
38 changes: 37 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3668,12 +3668,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"])

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: Clean-tree dirty receipt is not covered in the no-PR test

The acceptance criteria include rejecting dirty worktrees and dirty receipts. test_status_full covers a dirty worktree only with a PR present. The new parametrized test has no case for a receipt whose "dirty": true on a clean tree. Adding a "dirty" parameter that sets report["dirty"] = True would cover the report.dirty branch of _check_report_problem on the no-PR path.

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


@pytest.mark.parametrize(("signum", "status"), [
(signal.SIGTERM, -signal.SIGTERM),
(signal.SIGINT, 130),
Expand Down Expand Up @@ -3703,7 +3739,7 @@ def announce(process, *args, **kwargs):
child = None
try:
# Read until the supervisor enters communicate on the offline gh child.
for _ in range(6):
for _ in range(7):
assert select([process.stdout], [], [], 5)[0]
line = process.stdout.readline().strip()
if line.isdigit():
Expand Down
Loading