diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index efb9567c..f86942a3 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -114,7 +114,9 @@ loading the delivery [commands](../src/loopzero/cli.py), which implement the con 5. `ready` derives readiness from the current head, its check receipt, an eligible review at that head or an eligible review covering an ancestor, blocking findings (unresolved threads a review publisher opened with a head-bound marker line), - target branch and required CI. The receipt must record a clean passing run + target branch and required CI. Ready and merge stop on an invalid receipt + after checking the pushed head and merge-authority hold. Status still gathers + remote gates for its diagnostics. The receipt must record a clean passing run at that head with the current commands and check settings digest. A settings change or an older receipt without the digest requires a fresh check. The digest covers execution and stage reuse settings without recording raw diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index abbbcad7..9bc940c6 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -193,8 +193,8 @@ def _require_task_branch(config: Config, branch: str) -> None: ) -def _require_pr(config: Config, branch: str, *, allow_merged: bool = False) -> github.PR: - pr = github.pr_for_branch(config.repo, branch) +def _require_pr(config: Config, branch: str, *, allow_merged: bool = False, list_only: bool = False) -> github.PR: + pr = github.pr_for_branch(config.repo, branch, list_only=list_only) if pr is None: raise CliError(f"no pull request for {branch}; run `loopzero pr` first") if pr.state != "OPEN" and not (allow_merged and pr.state == "MERGED"): @@ -311,12 +311,9 @@ def _readiness( ) report = _load_report(wt) receipt_problem = _check_report_problem(report, wt, config, head) - if receipt_problem: - result = github.Readiness( - ready=False, - reasons=(*result.reasons, receipt_problem), - ) - elif announce_receipt: + result = (github.Readiness(False, (*result.reasons, receipt_problem)) + if receipt_problem else result) + if announce_receipt and not receipt_problem: _print_receipt(wt, report, "accepted") if config.merge_strategy == "mergify" and pr.state == "OPEN": behind = github.behind_reason(pr, head if review else None) @@ -1250,10 +1247,13 @@ def _pr_readiness( """PR plus readiness; readiness is None only for an already merged PR (allow_merged).""" head = worktree.head(wt) _require_task_branch(config, branch) - pr = _require_pr(config, branch, allow_merged=allow_merged) + problem = _check_report_problem(_load_report(wt), wt, config, head) + pr = _require_pr(config, branch, allow_merged=allow_merged, list_only=bool(problem)) _require_pushed(pr, head) if pr.state == "MERGED": return pr, None + if problem: + return pr, github.Readiness(False, (github.merge_hold(pr.number, pr.labels) or problem,)) return pr, _readiness(wt, config, pr, head, workflow_wait=workflow_wait, announce_receipt=True) diff --git a/src/loopzero/github.py b/src/loopzero/github.py index e40611b9..cc9fef95 100644 --- a/src/loopzero/github.py +++ b/src/loopzero/github.py @@ -671,9 +671,9 @@ def _confirm_branch_pr(repo: str, branch: str, endpoint: str, number: int, state return pr -def pr_for_branch(repo: str, branch: str, *, open_only: bool = False) -> PR | None: +def pr_for_branch(repo: str, branch: str, *, open_only: bool = False, list_only: bool = False) -> PR | None: """Return the open PR, falling back to the most recent closed PR unless open_only.""" - endpoint, matches = _commit_branch_prs(repo, branch) + endpoint, matches = ("", ()) if list_only else _commit_branch_prs(repo, branch) open_matches = [row for row in matches if row["state"] == "open"] if open_matches: newest = max(open_matches, key=lambda row: (row["created_at"], row["number"])) diff --git a/tests/test_cli.py b/tests/test_cli.py index 1cc17eba..57ef876b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3094,6 +3094,7 @@ def test_ready_requires_clean_successful_local_report_at_head(wt, gh, capsys, co out, _ = expect_cli(capsys, int(reason is not None), "ready") if reason: assert f"not ready: {reason}" in out + assert [call["argv"][:2] for call in gh.calls] == LOOKUP_CALLS[1:] if draft: assert "receipt accepted:" not in out if condition in {"legacy", "incompatible"}: @@ -3101,6 +3102,18 @@ def test_ready_requires_clean_successful_local_report_at_head(wt, gh, capsys, co "settings as ready, using a local coordinator for delegated stages." in out) +@pytest.mark.parametrize("associations", [0, 100]) +def test_merge_missing_receipt_skips_remote_gates(wt, gh, capsys, head, associations): + commit_mergify_configuration(wt) + arm_pr(gh, head, isDraft=False) + gh.respond(branch_head_key(), {"commit": {"sha": head}}) + gh.respond(f"api repos/{REPO}/commits/{head}/pulls?per_page=100&page=1", + [{"head": {"ref": "lz/other"}}] * associations) + expect_cli(capsys, 1, "merge", "--wait", stderr_contains=("run loopzero check at this head",)) + assert [call["argv"][:2] for call in gh.calls] == LOOKUP_CALLS[1:] + assert all("--method" not in call["argv"] and "--input" not in call["argv"] for call in gh.calls) + + @pytest.fixture def check_environment(wt, gh, head, tmp_path): arm_approved_ready_pr(gh, head, wt, readiness={"local_exit": None}, isDraft=False)