Repository navigation
Bound check failures and elapsed-time updates #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -624,6 +624,20 @@ def cmd_start(args: argparse.Namespace) -> int: | |
| return 0 | ||
|
|
||
|
|
||
| def _check_failure_preview(tail: str, limit: int = 1536) -> str: | ||
| if len(tail.encode()) <= limit: | ||
| return tail | ||
| edge = limit // 8 | ||
| lines = (line.encode() for line in tail.splitlines()) | ||
| preview = b"\n".join( | ||
| line if len(line) <= 2 * edge else line[:edge] + b" [...] " + line[-edge:] | ||
| for line in lines | ||
| ) | ||
| if len(preview) > limit: | ||
| preview = b"[...]\n" + preview[6 - limit:] | ||
| return preview.decode(errors="ignore") | ||
|
|
||
|
|
||
| def cmd_check(args: argparse.Namespace) -> int: | ||
| wt, config = _context(args, pin_checks=True) | ||
| if not config.checks: | ||
|
|
@@ -637,32 +651,30 @@ def cmd_check(args: argparse.Namespace) -> int: | |
| except sandbox.SandboxUnavailable as exc: | ||
| print(f"sandbox unavailable: {exc}", file=sys.stderr) | ||
| return 2 | ||
| shortened = False | ||
| for result in report.results: | ||
| if result.exit_code != 0: | ||
| print(f"--- {result.command} (exit {result.exit_code}) ---", file=sys.stderr) | ||
| tail = _proc.tail(result.tail) | ||
| print(tail, file=sys.stderr) | ||
| preview = _check_failure_preview(tail) | ||
| shortened |= preview != tail | ||
| print(preview, file=sys.stderr) | ||
| if not config.network and (result.command.startswith("uv sync --offline --locked") | ||
| or OFFLINE_FAILURE_RE.search(tail)): | ||
| env = { | ||
| **sandbox.SANDBOX_ENV, | ||
| **_proc.build_env(config.env_allowlist), | ||
| **dict(config.env), | ||
| } | ||
| env = sandbox.SANDBOX_ENV | _proc.build_env(config.env_allowlist) | dict(config.env) | ||
| print( | ||
| "\nThe sandbox has no network because `[checks] network = false`; " | ||
| f"the effective UV_CACHE_DIR inside the sandbox is {env['UV_CACHE_DIR']}. " | ||
| "To prepare offline, run UV_CACHE_DIR=<effective-cache> uv sync --group dev " | ||
| "(use the groups your checks require) on the host, or the same commands, so the cache " | ||
| "under `[checks] writable` is warm, or set `[checks] env` UV_CACHE_DIR to " | ||
| "that cache.", | ||
| file=sys.stderr, | ||
| "Run UV_CACHE_DIR=<effective-cache> uv sync --group dev on the host " | ||
| "(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, | ||
| ) | ||
| current_head = _save_report(wt, report) | ||
| if current_head is not None: | ||
| 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) | ||
| return 1 | ||
| if shortened: | ||
| print(f"Full diagnostic tail: {CHECKS_FILE} (head {report.head})", file=sys.stderr) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Receipt pointer prints a path relative to the worktree, not the caller's directory The receipt is written to |
||
| if report.ok and report.settings_sha256 is None: | ||
| print("check stages passed but the receipt is unverified; rerun loopzero check from the task " | ||
| "worktree with a stable, readable configured runner before running ready", file=sys.stderr) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -358,6 +358,68 @@ def expect_cli(capsys, exit_code, *argv, stdout=None, stderr=None, stdout_contai | |
| return out, err | ||
|
|
||
|
|
||
| # Transcript size regressions | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. important: Branch fails the size-budget gate that
Smallest fix: trim the new tests so the tests tree is not larger than the base. For example, fold the three |
||
| @pytest.mark.parametrize("receipt", ["saved", "head moved", "write failed"]) | ||
| def test_check_bounds_large_failure_and_preserves_receipt(wt, head, capsys, monkeypatch, receipt): | ||
| tail = 'TEST_FAILURES={"detail":"' + "é" * 7500 + '","error":"Failed to fetch package"}\n' | ||
| tail += "migration failed: relation widgets already exists\nAssertionError: assert " + "x" * 1000 | ||
| monkeypatch.setattr(cli.sandbox, "run_checks", lambda *a, **k: CheckReport( | ||
| "a" * 40 if receipt == "head moved" else head, False, | ||
| (CheckResult("apply migrations", 7, 0.1, tail),), | ||
| )) | ||
| if receipt == "write failed": | ||
| monkeypatch.setattr(cli, "_save_report", Mock(side_effect=PermissionError("receipt write denied"))) | ||
| code, out, err = run(capsys, "check") | ||
| assert len((out + err).encode()) < 2500 | ||
| assert code == 1 and "apply migrations (exit 7)" in err | ||
| assert all(text in err for text in ("migration failed: relation widgets already exists", "AssertionError: assert", "[...]")) | ||
| assert "uv sync --group dev" in err | ||
| if receipt == "saved": | ||
| assert out.endswith("FAIL\n") and ".loopzero/checks.json" in err and head in err | ||
| assert json.loads((wt / ".loopzero/checks.json").read_text())["results"][0]["tail"] == tail | ||
| else: | ||
| assert ".loopzero/checks.json" not in err | ||
| assert ("current HEAD" if receipt == "head moved" else "receipt write denied") in err | ||
|
|
||
|
|
||
| def test_check_hour_long_stage_transcript(wt, head, gh, capsys, monkeypatch): | ||
| sandbox = cli.sandbox | ||
| clock = poll_clock(monkeypatch) | ||
| deadline = 0.0 | ||
|
|
||
| def wait(seconds): | ||
| clock.now += seconds | ||
| return clock.now >= deadline | ||
|
|
||
| monkeypatch.setattr(sandbox.threading, "Event", lambda: Mock(wait=wait)) | ||
| monkeypatch.setattr(sandbox.threading, "Thread", lambda *, target, daemon: Mock(start=target)) | ||
|
|
||
| def run_checks(cfg, path, *, progress, status, checkpoint, workflow): | ||
| nonlocal deadline | ||
| results = [] | ||
| for ordinal in range(1, 25): | ||
| command = f"run tool {ordinal:02d}" | ||
| duration = 3600.0 if ordinal == 1 else 0.1 | ||
| deadline = clock.now + duration | ||
| progress(command) | ||
| with sandbox._stage_status(status, ordinal, 24): | ||
| pass | ||
| status(f"stage {ordinal}/24: exit 0 ({duration:.1f}s)") | ||
| results.append(CheckResult(command, 0, duration, "")) | ||
| return CheckReport(head, False, tuple(results), sandbox.settings_fingerprint(cfg, path)) | ||
|
|
||
| monkeypatch.setattr(sandbox, "run_checks", run_checks) | ||
| code, out, err = run(capsys, "check") | ||
| assert len((out + err).encode()) < 2400 | ||
| assert (code, err, gh.calls) == (0, "", []) and out.endswith("PASS\n") | ||
| assert f"receipt produced: head={head}" in out and "stage 24/24: exit 0" in out | ||
| assert out.count("running: run tool") == 24 | ||
| assert [float(seconds) for seconds in re.findall(r"running \(([\d.]+)s elapsed\)", out)] == list( | ||
| range(30, 3600, 300) | ||
| ) | ||
| assert out.rindex("s elapsed)") < out.index("stage 1/24: exit 0 (3600.0s)") | ||
|
|
||
|
|
||
| # --- start / check -------------------------------------------------------------------- | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Unrelated rewrites inside cmd_check widen the diff
Several edits don't change behaviour and aren't needed for bounding output: the env dict is rewritten from
{**a, **b}toa | b | c,current_headis moved into a walrus, and the offline-remedy wording is reworded (it drops the 'or the same commands' alternative). They make the change harder to review and change user-facing remedy text without a stated reason. Consider reverting the parts that aren't needed so the diff stays focused on the preview and pointer.