From 4452eab9b6f67232c5c95a677bd68a05979f0582 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 10:47:58 +0100 Subject: [PATCH 1/3] Reuse eligible check receipts after a final checkout check Co-Authored-By: Codex --- docs/ARCHITECTURE.md | 13 +++++---- src/loopzero/cli.py | 20 +++++++++++++ src/loopzero/sandbox.py | 22 ++++++++++++-- tests/test_cli.py | 63 ++++++++++++++++++++++++++++------------- tests/test_sandbox.py | 20 ++++++------- 5 files changed, 100 insertions(+), 38 deletions(-) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 57956e14..63c4cdf8 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -442,8 +442,9 @@ index, README and AGENTS guidance without network access. The repository's CI enforce it against the event's base SHA. Push-to-main CI runs `--links-only`, because squash merging can drop authored trailers and landed history cannot re-establish the pre-merge acknowledgement; that mode still rejects broken local links and anchors. -`loopzero check` pins checks to trusted base configuration, so run a new or -changed gate directly until its configuration lands on the base. +`loopzero check` pins checks to trusted base configuration and reuses a passing +receipt when readiness validation, the clean checkout and declared inputs still +match. Run a new or changed gate directly until its configuration lands on the base. The checker watches source-owned contracts, skill routing, the example and actual workflow, hosted workflow files, itself, and selected CLI/configuration interfaces; @@ -524,11 +525,11 @@ The receipt fingerprint also binds the base SHA when reuse is configured, so advancing the base invalidates a pass at the same task head. With explicit `--config`, reuse can fall back to the recorded task base if the remote ref is absent. Without either base, local stages run fresh. -The `"*"` entry adds shared inputs to listed commands. Unlisted commands reuse only -when `"*"` includes `"."` (the whole tree); a partial or empty `"*"` leaves them unkeyed. +The `"*"` entry adds shared inputs to listed commands. For unlisted commands it +supplies a key only when `"*"` includes `"."` (the whole tree). Consumers own complete input declarations. -Reuse only successful keyed stages from this worktree's clean receipt or -checkpoint. Dirty trees run fresh. A tracked receipt is never eligible for reuse. +For individual stage reuse, use only successful keyed results from this worktree's +clean receipt or checkpoint. Dirty trees run fresh. A tracked receipt is ineligible. Receipts that use saved stage results bind the current head and check settings. For delegated checks, both the receipt and the stage key bind the runner's launch path, resolved executable path and executable bytes. Unavailable runner identity diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 6c99472e..acc5fd10 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -626,10 +626,30 @@ def cmd_start(args: argparse.Namespace) -> int: return 0 +def _reusable_check_report(wt: Path, config: Config) -> CheckReport | None: + with suppress(OSError, sandbox.SandboxUnavailable, _proc.ProcTimeout, worktree.WorktreeError): + if not (wt / CHECKS_FILE).is_file(): + return None + with _lock_task_state(wt): + if worktree.is_dirty(wt) or not sandbox.has_untracked_task_state(config, wt): + return None + head = worktree.head(wt) + report = _current_check_report(wt, config, head) + if (report is not None and sandbox.receipt_checkout_matches(config, wt, report) + and not worktree.is_dirty(wt) and worktree.head(wt) == head): + _refresh_existing_pr_checks(wt, config) + return report + return None + + def cmd_check(args: argparse.Namespace) -> int: wt, config = _context(args, pin_checks=True) if not config.checks: raise config_mod.ConfigError("checks.commands must list at least one command to run checks") + if (receipt := _reusable_check_report(wt, config)) is not None: + _print_receipt(wt, receipt, f"reused from {CHECKS_FILE}") + print("PASS") + return 0 try: report = sandbox.run_checks(config, wt, progress=lambda command: print( f"running: {command}", flush=True), diff --git a/src/loopzero/sandbox.py b/src/loopzero/sandbox.py index 6f725e28..873896f5 100644 --- a/src/loopzero/sandbox.py +++ b/src/loopzero/sandbox.py @@ -183,8 +183,22 @@ def _checkpoint_success(checkpoint: Callable[[CheckReport], None] | None, checkpoint(replace(report, results=(*report.results, *unvisited, incomplete))) +def has_untracked_task_state(config: Config, worktree: Path) -> bool: + return not _git(config, worktree, "ls-files", "--", ".loopzero") + + +def receipt_checkout_matches(config: Config, worktree: Path, report: CheckReport) -> bool: + if not _stage_unchanged(config, worktree, report.head): + return False + base = _check_base(config, worktree) + return all( + result.input_key is not None and result.input_key == _input_key(config, worktree, result.command, base) + for result in report.results if _has_inputs(config, result.command) + ) and _stage_unchanged(config, worktree, report.head) + + def _previous(config: Config, worktree: Path, settings_sha256: str) -> dict[str, CheckResult]: - if _git(config, worktree, "ls-files", "--", ".loopzero"): + if not has_untracked_task_state(config, worktree): return {} try: data = json.loads((worktree / ".loopzero/checks.json").read_text()) @@ -274,10 +288,14 @@ def _input_blobs(config: Config, worktree: Path, paths: tuple[str, ...]) -> str raise +def _has_inputs(config: Config, command: str) -> bool: + return command in config.inputs or "." in config.inputs.get("*", ()) + + def _input_key(config: Config, worktree: Path, command: str, base: str, *, status: Callable[[str], None] | None = None, workflow: str | Path = "workflow.toml") -> str | None: - if command not in config.inputs and "." not in config.inputs.get("*", ()): + if not _has_inputs(config, command): return None if not base and status is None: return None diff --git a/tests/test_cli.py b/tests/test_cli.py index 5e41347f..184ff58e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -412,25 +412,48 @@ def test_start_without_config(git_repo: Path, monkeypatch, capsys) -> None: assert code == 1 and "workflow.toml" in err and err.count("\n") == 1 -def test_check_pass_writes_report(wt: Path, gh: FakeGh, capsys) -> None: +@pytest.mark.parametrize("move_head", [False, True]) +def test_check_pass_writes_and_reuses_report(wt, gh, capsys, monkeypatch, move_head): code, out, _ = run(capsys, "check") - assert gh.calls == [] - lines = out.splitlines() - assert code == 0 and lines[-1] == "PASS" - assert lines[0].startswith("checks pinned to origin/main@") - assert lines[1] == "running: echo ok" - assert lines[2].startswith("stage 1/2: exit 0 (") - assert lines[3] == "running: test -f README.md" - assert lines[4].startswith("stage 2/2: exit 0 (") - assert sum("exit 0" in line for line in lines) == 2 - report = json.loads((wt / ".loopzero" / "checks.json").read_text()) - assert report["head"] == head_of(wt) - assert report["dirty"] is False - assert f"receipt produced: head={report['head']} content=" in out - assert "config=commands-sha256:" in out and "environment=unknown" in out - assert [(r["command"], r["exit_code"]) for r in report["results"]] == [ - ("echo ok", 0), ("test -f README.md", 0)] - assert report["results"][0]["tail"] == "ok" + pin, first, first_exit, second, second_exit, receipt, verdict = out.splitlines() + assert code == 0 and verdict == "PASS" and not gh.calls + assert pin.startswith("checks pinned to origin/main@") + assert (first, second) == ("running: echo ok", "running: test -f README.md") + assert first_exit.startswith("stage 1/2: exit 0 (") and second_exit.startswith("stage 2/2: exit 0 (") + path = wt / ".loopzero/checks.json" + report = json.loads(original := path.read_bytes()) + assert report["head"] == head_of(wt) and report["dirty"] is False + assert receipt.startswith(f"receipt produced: head={report['head']} content=") + assert "config=commands-sha256:" in receipt and "environment=unknown" in receipt + first_result, second_result = report["results"] + assert (first_result["command"], first_result["exit_code"], first_result["tail"]) == ("echo ok", 0, "ok") + assert (second_result["command"], second_result["exit_code"]) == ("test -f README.md", 0) + run_checks, lock = cli.sandbox.run_checks, cli._lock_task_state + monkeypatch.setattr(cli.sandbox, "run_checks", Mock(side_effect=AssertionError("stages ran"))) + code, out, err = run(capsys, "check") + reused = receipt.replace("receipt produced", "receipt reused from .loopzero/checks.json", 1) + assert (code, out.splitlines(), err, path.read_bytes()) == (0, [pin, reused, "PASS"], "", original) + + def edit_during_lock_wait(worktree): + (wt / "README.md").write_text("edited while waiting\n") + monkeypatch.setattr(cli, "_lock_task_state", lock) + return lock(worktree) + + validate_checkout = cli.sandbox.receipt_checkout_matches + + def advance_after_validation(*args): + matches = validate_checkout(*args) + git(wt, "commit", "-qm", "advance HEAD", "--allow-empty") + return matches + + if move_head: + monkeypatch.setattr(cli.sandbox, "receipt_checkout_matches", advance_after_validation) + else: + monkeypatch.setattr(cli, "_lock_task_state", edit_during_lock_wait) + monkeypatch.setattr(cli.sandbox, "run_checks", run_checks) + expect_cli(capsys, 0, "check", stdout_contains=("running: echo ok",)) + report = json.loads(path.read_bytes()) + assert report["head"] == head_of(wt) and report["dirty"] is not move_head @pytest.mark.parametrize("state", [None, "CLOSED", "MERGED"]) @@ -2237,9 +2260,9 @@ def test_late_check_preserves_receipt_when_head_moves(wt, gh, capsys, monkeypatc monkeypatch.setattr(cli, "_refresh_pr_checks", lambda *_: refreshed.append(head_of(wt))) if phase != "stage": expect_cli(capsys, 0, "check") - saved_receipt = receipt.read_bytes() + saved_receipt = receipt.read_bytes().replace(b'"settings_sha256"', b'"obsolete_settings_sha256"') + receipt.write_bytes(saved_receipt) run_stage, run_checks, save_report = cli.sandbox._run_one, cli.sandbox.run_checks, cli._save_report - def advance_head(*, rerun=True): nonlocal saved_receipt git(wt, "commit", "--allow-empty", "-qm", "advance HEAD") diff --git a/tests/test_sandbox.py b/tests/test_sandbox.py index b8ea47f6..ee1947cc 100644 --- a/tests/test_sandbox.py +++ b/tests/test_sandbox.py @@ -831,22 +831,22 @@ def timed_out(*args): assert report.ok and report.dirty and report.results[0].command == command -def test_local_check_reuse_tracks_checkout_bytes(git_repo, bwrap_log, fetched_base, cache_check): +def test_local_check_reuse_tracks_checkout_bytes(git_repo, bwrap_log, fetched_base, cache_check, monkeypatch): path = git_repo / "README.md" command = "python3 -c 'from pathlib import Path; exit(13 in Path(\"README.md\").read_bytes())'" config = make_config(checks=(command,), inputs={command: ("README.md",)}) assert path.read_bytes() == b"hello\n" assert cache_check(config, clean=True, verify_reuse=True).head == fetched_base - + monkeypatch.setattr(cli, "_context", lambda *args, **kwargs: (git_repo, config)) git(git_repo, "config", "core.autocrlf", "true") path.unlink() git(git_repo, "checkout-index", "-u", "--", path.name) assert path.read_bytes() == b"hello\r\n" assert not git(git_repo, "status", "--porcelain") - report = sandbox.run_checks(config, git_repo) + assert cli.main(["check"]) == 1 + report = cli._load_report(git_repo) assert not report.dirty and report.head == fetched_base - assert report.results[0].exit_code == 1 - assert report.results[0].reused_from is None + assert (report.results[0].exit_code, report.results[0].reused_from) == (1, None) @pytest.mark.parametrize("base", ["tracked", "recorded", "absent"]) @@ -929,7 +929,7 @@ def fail_fingerprint(argv, **kwargs): @pytest.mark.parametrize('symlink', [False, True]) -def test_tracked_forged_receipt_runs_failing_stage(git_repo, bwrap_log, fetched_base, symlink): +def test_tracked_forged_receipt_runs_failing_stage(git_repo, bwrap_log, fetched_base, symlink, monkeypatch): from loopzero.types import CheckReport, CheckResult command = 'echo stage-ran; exit 7' @@ -947,12 +947,12 @@ def test_tracked_forged_receipt_runs_failing_stage(git_repo, bwrap_log, fetched_ git(git_repo, 'commit', '-m', 'forge passing receipt') assert not git(git_repo, 'status', '--porcelain').strip() assert key == sandbox._input_key(cfg, git_repo, command, fetched_base) - + receipt_reader = Mock(side_effect=AssertionError("tracked receipt opened")) + monkeypatch.setattr(cli, "_current_check_report", receipt_reader) + assert cli._reusable_check_report(git_repo, cfg) is None report = sandbox.run_checks(cfg, git_repo) - assert not report.dirty - assert report.results[0].exit_code == 7 + assert not report.dirty and (report.results[0].exit_code, report.results[0].reused_from) == (7, None) assert 'stage-ran' in report.results[0].tail - assert not report.results[0].reused_from def test_no_inputs_preserves_receipt(git_repo, bwrap_log): From f858f58bba5c8ce0ede93ad38edd59b92f390198 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 10:55:30 +0100 Subject: [PATCH 2/3] Require complete declared inputs for check receipt reuse Co-Authored-By: Codex --- docs/ARCHITECTURE.md | 2 +- src/loopzero/sandbox.py | 9 ++++--- tests/test_cli.py | 52 ++++++++++++++++------------------------- tests/test_sandbox.py | 21 +++++++++-------- 4 files changed, 38 insertions(+), 46 deletions(-) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 63c4cdf8..bcc77a90 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -520,7 +520,7 @@ existing local execution path is unchanged. Declared `[checks.inputs]` pathspecs opt commands into local passing-result reuse. Keys bind committed paths/blob IDs, the bytes of the checked-out regular files, command, version, sandbox configuration and the resolved base SHA. A stage runs -fresh when a matched path cannot be identified as a readable regular file. +fresh when a declared pattern has no matches or a matched file cannot be hashed. The receipt fingerprint also binds the base SHA when reuse is configured, so advancing the base invalidates a pass at the same task head. With explicit `--config`, reuse can fall back to the recorded task base if the diff --git a/src/loopzero/sandbox.py b/src/loopzero/sandbox.py index 873896f5..43ed606f 100644 --- a/src/loopzero/sandbox.py +++ b/src/loopzero/sandbox.py @@ -193,7 +193,7 @@ def receipt_checkout_matches(config: Config, worktree: Path, report: CheckReport base = _check_base(config, worktree) return all( result.input_key is not None and result.input_key == _input_key(config, worktree, result.command, base) - for result in report.results if _has_inputs(config, result.command) + for result in report.results if result.command in config.inputs or "*" in config.inputs ) and _stage_unchanged(config, worktree, report.head) @@ -300,14 +300,17 @@ def _input_key(config: Config, worktree: Path, command: str, base: str, *, if not base and status is None: return None entries = {key: config.inputs[key] for key in (command, "*") if key in config.inputs} + paths = tuple(path for group in entries.values() for path in group) try: - blobs = _input_blobs(config, worktree, tuple(path for paths in entries.values() for path in paths)) + blobs = _input_blobs(config, worktree, paths) + if blobs and len(paths) > 1 and not all(_input_blobs(config, worktree, (path,)) for path in paths): + blobs = "" except (SandboxUnavailable, _proc.ProcTimeout, OSError, ValueError): if not base: return None raise if blobs == "" and status: - status(f"{workflow}: checks.inputs for {command!r} matches no files in HEAD. " + status(f"{workflow}: checks.inputs for {command!r} is empty or has a pathspec that matches no files in HEAD. " f"Correct these entries: {entries!r}. Running the check fresh.") if not blobs or not base: return None diff --git a/tests/test_cli.py b/tests/test_cli.py index 184ff58e..9d5d0a63 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -414,46 +414,35 @@ def test_start_without_config(git_repo: Path, monkeypatch, capsys) -> None: @pytest.mark.parametrize("move_head", [False, True]) def test_check_pass_writes_and_reuses_report(wt, gh, capsys, monkeypatch, move_head): - code, out, _ = run(capsys, "check") + out, _ = expect_cli(capsys, 0, "check") pin, first, first_exit, second, second_exit, receipt, verdict = out.splitlines() - assert code == 0 and verdict == "PASS" and not gh.calls - assert pin.startswith("checks pinned to origin/main@") + assert verdict == "PASS" and not gh.calls and pin.startswith("checks pinned to origin/main@") assert (first, second) == ("running: echo ok", "running: test -f README.md") assert first_exit.startswith("stage 1/2: exit 0 (") and second_exit.startswith("stage 2/2: exit 0 (") path = wt / ".loopzero/checks.json" report = json.loads(original := path.read_bytes()) assert report["head"] == head_of(wt) and report["dirty"] is False - assert receipt.startswith(f"receipt produced: head={report['head']} content=") - assert "config=commands-sha256:" in receipt and "environment=unknown" in receipt - first_result, second_result = report["results"] - assert (first_result["command"], first_result["exit_code"], first_result["tail"]) == ("echo ok", 0, "ok") - assert (second_result["command"], second_result["exit_code"]) == ("test -f README.md", 0) - run_checks, lock = cli.sandbox.run_checks, cli._lock_task_state - monkeypatch.setattr(cli.sandbox, "run_checks", Mock(side_effect=AssertionError("stages ran"))) - code, out, err = run(capsys, "check") + assert receipt.startswith(f"receipt produced: head={report['head']} content=") and "environment=unknown" in receipt + assert "config=commands-sha256:" in receipt + assert [(r["command"], r["exit_code"]) for r in report["results"]] == [("echo ok", 0), ("test -f README.md", 0)] + assert report["results"][0]["tail"] == "ok" reused = receipt.replace("receipt produced", "receipt reused from .loopzero/checks.json", 1) - assert (code, out.splitlines(), err, path.read_bytes()) == (0, [pin, reused, "PASS"], "", original) - - def edit_during_lock_wait(worktree): + with monkeypatch.context() as patch: + patch.setattr(cli.sandbox, "run_checks", Mock(side_effect=AssertionError("stages ran"))) + expect_cli(capsys, 0, "check", stdout=f"{pin}\n{reused}\nPASS\n", stderr="") + assert path.read_bytes() == original + + def change_checkout(*args, lock=cli._lock_task_state): + if move_head: + git(wt, "commit", "-qm", "advance HEAD", "--allow-empty") + return True (wt / "README.md").write_text("edited while waiting\n") - monkeypatch.setattr(cli, "_lock_task_state", lock) - return lock(worktree) + return lock(*args) - validate_checkout = cli.sandbox.receipt_checkout_matches - - def advance_after_validation(*args): - matches = validate_checkout(*args) - git(wt, "commit", "-qm", "advance HEAD", "--allow-empty") - return matches - - if move_head: - monkeypatch.setattr(cli.sandbox, "receipt_checkout_matches", advance_after_validation) - else: - monkeypatch.setattr(cli, "_lock_task_state", edit_during_lock_wait) - monkeypatch.setattr(cli.sandbox, "run_checks", run_checks) + target, hook = (cli.sandbox, "receipt_checkout_matches") if move_head else (cli, "_lock_task_state") + monkeypatch.setattr(target, hook, change_checkout) expect_cli(capsys, 0, "check", stdout_contains=("running: echo ok",)) - report = json.loads(path.read_bytes()) - assert report["head"] == head_of(wt) and report["dirty"] is not move_head + assert (updated := json.loads(path.read_bytes()))["head"] == head_of(wt) and updated["dirty"] is not move_head @pytest.mark.parametrize("state", [None, "CLOSED", "MERGED"]) @@ -2260,8 +2249,7 @@ def test_late_check_preserves_receipt_when_head_moves(wt, gh, capsys, monkeypatc monkeypatch.setattr(cli, "_refresh_pr_checks", lambda *_: refreshed.append(head_of(wt))) if phase != "stage": expect_cli(capsys, 0, "check") - saved_receipt = receipt.read_bytes().replace(b'"settings_sha256"', b'"obsolete_settings_sha256"') - receipt.write_bytes(saved_receipt) + receipt.write_bytes(saved_receipt := receipt.read_bytes().replace(b'"settings_sha256"', b'"obsolete_settings_sha256"')) run_stage, run_checks, save_report = cli.sandbox._run_one, cli.sandbox.run_checks, cli._save_report def advance_head(*, rerun=True): nonlocal saved_receipt diff --git a/tests/test_sandbox.py b/tests/test_sandbox.py index ee1947cc..8bb2ce0d 100644 --- a/tests/test_sandbox.py +++ b/tests/test_sandbox.py @@ -26,7 +26,7 @@ from loopzero.cli import _current_check_report, _save_report from loopzero.types import Config, ResourceLimits -from .conftest import git +from .conftest import commit_file, git FAKE_BWRAP = '''#!/usr/bin/python3 import os @@ -745,6 +745,7 @@ def cache(config, *, clean=False, verify_reuse=False): 'failed', 'boolean_exit_code', 'dirty_receipt', 'keyless', 'dirty_tree', 'legacy', 'grant']) def test_declared_input_reuse(git_repo, bwrap_log, monkeypatch, fetched_base, change, cache_check, receipt_path): + commit_file(git_repo, "shared", "initial", "add shared input") cfg = make_config(checks=('echo one', 'echo two'), inputs={'echo one': ('*.md',), 'echo two': ('*.md',), '*': ('shared',)}) if change == 'grant': @@ -755,7 +756,7 @@ def test_declared_input_reuse(git_repo, bwrap_log, monkeypatch, fetched_base, ch whole = replace(cfg, inputs={'*': ('.',)}) key = sandbox._input_key(whole, git_repo, 'unlisted', fetched_base) assert key is not None - cache_check(cfg, clean=True) + initial_head = cache_check(cfg, clean=True).head if change in {'other', 'input', 'shared', 'dirty_tree'}: path = 'README.md' if change in {'input', 'dirty_tree'} else 'src.py' if change == 'other' else change (git_repo / path).write_text('new content') @@ -769,12 +770,12 @@ def test_declared_input_reuse(git_repo, bwrap_log, monkeypatch, fetched_base, ch cfg = replace(cfg, network=True) elif change == 'environment': monkeypatch.setenv('LZ_KEEP', 'changed') - assert _current_check_report(git_repo, cfg, fetched_base) is None + assert _current_check_report(git_repo, cfg, initial_head) is None elif change == 'grant': monkeypatch.setenv("HEAVY_SLOT_GRANTED_CORES", "4") - assert _current_check_report(git_repo, cfg, fetched_base) is not None + assert _current_check_report(git_repo, cfg, initial_head) is not None monkeypatch.delenv("HEAVY_SLOT_GRANTED_CORES") - assert _current_check_report(git_repo, cfg, fetched_base) is not None + assert _current_check_report(git_repo, cfg, initial_head) is not None elif change == 'version': monkeypatch.setattr(sandbox, '__version__', 'new') else: @@ -800,7 +801,7 @@ def test_declared_input_reuse(git_repo, bwrap_log, monkeypatch, fetched_base, ch @pytest.mark.parametrize("case", ["typo", "empty", "dirty", "no_base"]) def test_unmatched_inputs_run_fresh(git_repo, bwrap_log, fetched_base, case, cache_check): command = 'test "$(cat README.md)" = hello' - paths = () if case == "empty" else ("ipnut.txt",) + paths = {"empty": (), "typo": ("README.md", "ipnut.txt")}.get(case, ("ipnut.txt",)) config = make_config(checks=(command,), inputs={command: paths}) cache_check(config) (git_repo / "README.md").write_text("fail\n") @@ -831,12 +832,12 @@ def timed_out(*args): assert report.ok and report.dirty and report.results[0].command == command -def test_local_check_reuse_tracks_checkout_bytes(git_repo, bwrap_log, fetched_base, cache_check, monkeypatch): +@pytest.mark.parametrize("partial_wildcard", [False, True]) +def test_local_check_reuse_tracks_checkout_bytes(git_repo, fetched_base, cache_check, monkeypatch, partial_wildcard): path = git_repo / "README.md" command = "python3 -c 'from pathlib import Path; exit(13 in Path(\"README.md\").read_bytes())'" - config = make_config(checks=(command,), inputs={command: ("README.md",)}) - assert path.read_bytes() == b"hello\n" - assert cache_check(config, clean=True, verify_reuse=True).head == fetched_base + config = make_config(checks=(command,), inputs={"*" if partial_wildcard else command: ("README.md",)}) + assert cache_check(config, clean=True, verify_reuse=not partial_wildcard).head == fetched_base monkeypatch.setattr(cli, "_context", lambda *args, **kwargs: (git_repo, config)) git(git_repo, "config", "core.autocrlf", "true") path.unlink() From 9aaeb122a69ed54281906292f97a6212579bbc1f Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 10:56:40 +0100 Subject: [PATCH 3/3] Keep check failure reporting within the complexity cap Architecture-Review: unchanged; extracting check failure output preserves its behavior and the delivery contract. Co-Authored-By: Codex --- src/loopzero/cli.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index fdc6ca27..a2965e6c 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -659,25 +659,9 @@ def _check_failure_preview(tail: str, limit: int = 1536) -> str: return preview.decode(errors="ignore") -def cmd_check(args: argparse.Namespace) -> int: - wt, config = _context(args, pin_checks=True) - if not config.checks: - raise config_mod.ConfigError("checks.commands must list at least one command to run checks") - if (receipt := _reusable_check_report(wt, config)) is not None: - _print_receipt(wt, receipt, f"reused from {CHECKS_FILE}") - print("PASS") - return 0 - try: - report = sandbox.run_checks(config, wt, progress=lambda command: print( - f"running: {command}", flush=True), - status=lambda message: print(message, flush=True), - checkpoint=lambda partial: _save_report(wt, partial), - workflow=args.config or f"origin/{config.base_branch}:workflow.toml") - except sandbox.SandboxUnavailable as exc: - print(f"sandbox unavailable: {exc}", file=sys.stderr) - return 2 +def _print_check_failures(config: Config, results: tuple[CheckResult, ...]) -> bool: shortened = False - for result in report.results: + for result in results: if result.exit_code != 0: print(f"--- {result.command} (exit {result.exit_code}) ---", file=sys.stderr) tail = _proc.tail(result.tail) @@ -694,6 +678,27 @@ def cmd_check(args: argparse.Namespace) -> int: "(use the required groups) so the cache under `[checks] writable` is warm, " "or set `[checks] env` UV_CACHE_DIR to a warm cache.", file=sys.stderr, ) + return shortened + + +def cmd_check(args: argparse.Namespace) -> int: + wt, config = _context(args, pin_checks=True) + if not config.checks: + raise config_mod.ConfigError("checks.commands must list at least one command to run checks") + if (receipt := _reusable_check_report(wt, config)) is not None: + _print_receipt(wt, receipt, f"reused from {CHECKS_FILE}") + print("PASS") + return 0 + try: + report = sandbox.run_checks(config, wt, progress=lambda command: print( + f"running: {command}", flush=True), + status=lambda message: print(message, flush=True), + checkpoint=lambda partial: _save_report(wt, partial), + workflow=args.config or f"origin/{config.base_branch}:workflow.toml") + except sandbox.SandboxUnavailable as exc: + print(f"sandbox unavailable: {exc}", file=sys.stderr) + return 2 + shortened = _print_check_failures(config, report.results) if (current_head := _save_report(wt, report)) is not None: print(f"check result discarded: checked HEAD {report.head}, current HEAD {current_head}", file=sys.stderr)