diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index c474e6e7..c02c07aa 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -114,6 +114,7 @@ The [CLI](../src/loopzero/cli.py) implements the contract's that requested changes also requires resolved findings at the reviewed head. After its own draft-to-ready write, `ready --wait` revalidates through the same waiter and original deadline. + The shared check waiter reports initial blockers and subsequent changes. This is best-effort observation: an immediate green read may precede asynchronous CI scheduling, there is no unconditional delay, and merge admission checks readiness again. Missing-run diagnosis keeps its two-minute diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 48a64159..bf0cd0a0 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -1330,6 +1330,16 @@ def _verify_wait_snapshot( raise CliError(f"{changed} changed while waiting; retry with the current settings") +def _print_wait_changes(shown: tuple[str, ...], pending: tuple[str, ...]) -> None: + def by_check(reasons: tuple[str, ...]) -> dict[str, str]: + return {reason.rpartition("' ")[0] or reason: reason for reason in reasons} + previous, current = by_check(shown), by_check(pending) + if changed := [reason for key, reason in current.items() if previous.get(key) != reason]: + print("waiting: " + "; ".join(changed)) + if cleared := [key.removeprefix("required check '") for key in previous if key not in current]: + print("cleared: " + "; ".join(cleared)) + + def _wait_for_checks( wt: Path, config: Config, pr: github.PR, timeout: float, *, kicked: bool, started: float | None = None, shown: tuple[str, ...] = (), @@ -1362,11 +1372,11 @@ def _wait_for_checks( pending = _pending_checks( config, current, readiness, allow_skipped=kicked or (allow_skipped and not current.is_draft), ) + if pending or readiness.ready: + _print_wait_changes(shown, pending) if not pending: return current, readiness, kicked - if pending != shown: - print("waiting: " + "; ".join(pending)) - shown = pending + shown = pending elapsed = time.monotonic() - grace_started if readiness.stale_verdicts and not stale_notice: print( diff --git a/tests/test_cli.py b/tests/test_cli.py index c09d043c..27d45a78 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -307,6 +307,42 @@ def run(capsys, *argv: str) -> tuple[int, str, str]: return code, captured.out, captured.err +# Transcript size regressions +@pytest.mark.parametrize("command", ["ready", "merge"]) +@pytest.mark.parametrize("stable", [False, True]) +def test_wait_reports_only_check_changes(wt, gh, head, capsys, monkeypatch, stable, command): + names = ["checks"] + [f"verify deployment / integration shard {n:02d}" for n in range(23)] + cfg = cli.dataclasses.replace(config.load(wt / "workflow.toml"), required_ci=tuple(names)) + monkeypatch.setattr(cli, "_context", lambda *a, **k: (wt, cfg)) + monkeypatch.setattr(cli, "_verify_wait_snapshot", lambda *a: None) + monkeypatch.setattr(cli, "WAIT_INTERVAL", 0.1) + monkeypatch.setattr(github, "time", SimpleNamespace(monotonic=lambda: clock[0])) + arm_approved_pr_with_check_result(gh, head, wt, "pending", isDraft=False) + runs = [ + [{"name": name, "status": "completed", "conclusion": "success"} + if i < cleared else {"name": name, "status": "in_progress"} + for i, name in enumerate(names)] + for cleared in ([0] if stable else [0, *range(25)]) + ] + arm_check_runs(gh, head, *runs) + clock = [0.0] + monkeypatch.setattr(cli, "time", SimpleNamespace(monotonic=lambda: clock[0])) + monkeypatch.setattr(cli, "_sleep", lambda seconds: clock.__setitem__(0, clock[0] + seconds)) + if command == "merge": + monkeypatch.setattr(github, "merge", lambda *a: "c" * 40) + monkeypatch.setattr(cli, "_cleanup_remote_refs", lambda *a: None) + monkeypatch.setattr(cli, "_cleanup", lambda *a: None) + code, out, err = run(capsys, command, "--wait=1" if stable else "--wait=1800") + assert len((out + err).encode()) < 3200 and out.count("waiting:") == 1 + assert not err and all(f"required check '{name}' is pending" in out for name in names) + if stable: + assert code == 3 and f"timed out waiting for required checks on {head[:12]}" in out + assert "cleared:" not in out + else: + assert code == 0 and out.endswith(f"ready: {URL}\n" if command == "ready" else "c" * 40 + "\n") + assert all(f"cleared: {name}\n" in out for name in names) + + # --- start / check -------------------------------------------------------------------- @@ -2436,6 +2472,7 @@ def test_ready_wait_reports_initial_draft_blocker_once(wt, gh, capsys, monkeypat assert without_accepted_receipt(out).splitlines() == [ "marked ready; required check 'checks' is skipped", "waiting: required check 'checks' is pending", + "cleared: checks", f"ready: {URL}", ]