From 121c081cd0ed1ec6c0eaaf35c0b6308c7c096909 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:15:20 +0100 Subject: [PATCH 1/5] Bound Git subprocesses in direct build and architecture commands Architecture-Review: unchanged; Git commands retain their existing outputs and fail through the current check when Git times out. Co-Authored-By: Codex --- hatch_build.py | 2 +- scripts/check_architecture_docs.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hatch_build.py b/hatch_build.py index 7e8e8be3..bbb922ff 100644 --- a/hatch_build.py +++ b/hatch_build.py @@ -13,7 +13,7 @@ def initialize(self, version, build_data): if not (root / ".git").exists(): return - tracked = subprocess.check_output(["git", "ls-files", "-z"], cwd=root) + tracked = subprocess.check_output(["git", "ls-files", "-z"], cwd=root, timeout=60) self.build_config.set_exclude_all() build_data["force_include"].update( (name, name) diff --git a/scripts/check_architecture_docs.py b/scripts/check_architecture_docs.py index 6d78847d..56c82ca8 100644 --- a/scripts/check_architecture_docs.py +++ b/scripts/check_architecture_docs.py @@ -24,7 +24,7 @@ def git(root, *args, text=True): return subprocess.run(["git", *args], cwd=root, check=True, - capture_output=True, text=text).stdout + capture_output=True, text=text, timeout=60).stdout def interface(text, names): @@ -115,7 +115,7 @@ def main(): else: base = args.base or git(root, "merge-base", "HEAD", "origin/main").strip() errors = check(root, base) - except (OSError, ValueError, SyntaxError, subprocess.CalledProcessError) as exc: + except (OSError, ValueError, SyntaxError, subprocess.SubprocessError) as exc: print(f"architecture docs: FAIL ({exc})", file=sys.stderr) return 1 if errors: From 90054edc59aa2a9cdd15c8f0d9603d569c2da931 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:20:21 +0100 Subject: [PATCH 2/5] Cover direct Git timeouts in architecture and sdist paths Co-Authored-By: Codex --- tests/test_architecture_docs.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_architecture_docs.py b/tests/test_architecture_docs.py index 25410cee..4dcda4e4 100644 --- a/tests/test_architecture_docs.py +++ b/tests/test_architecture_docs.py @@ -1,8 +1,10 @@ """Exercise the documentation check as a contributor/CI subprocess in real Git.""" import os +import runpy import subprocess import sys from pathlib import Path +from types import SimpleNamespace import pytest @@ -99,6 +101,26 @@ def test_missing_base_fails_closed(git_repo): assert run(git_repo, "not-a-revision").returncode == 1 +@pytest.mark.parametrize("entry", ["architecture", "sdist"]) +def test_direct_git_timeout(tmp_path, monkeypatch, capsys, entry): + def stalled_git(argv, *, timeout, **kwargs): + assert timeout == 60 + raise subprocess.TimeoutExpired(argv, timeout) + + monkeypatch.setattr(subprocess, "run", stalled_git) + if entry == "architecture": + monkeypatch.setattr(sys, "argv", [str(SCRIPT), "--links-only"]) + assert runpy.run_path(str(SCRIPT))["main"]() == 1 + assert "timed out" in capsys.readouterr().err + else: + monkeypatch.setitem(sys.modules, "hatchling.builders.hooks.plugin.interface", + SimpleNamespace(BuildHookInterface=object)) + hook = runpy.run_path(str(SCRIPT.parents[1] / "hatch_build.py"))["TrackedSdistFiles"] + (tmp_path / ".git").mkdir() + with pytest.raises(subprocess.TimeoutExpired): + hook.initialize(SimpleNamespace(root=tmp_path), "", {}) + + def test_tach_enforces_module_boundaries(tmp_path): import shutil From 75126a7eefca38cd068008ffa9cdf9aee93bbfbf Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 10:08:25 +0100 Subject: [PATCH 3/5] Read task handoffs as UTF-8 Architecture-Review: unchanged; task handoff reads match the writer without changing delivery interfaces. Co-Authored-By: Codex --- src/loopzero/worktree.py | 2 +- tests/test_cli.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/loopzero/worktree.py b/src/loopzero/worktree.py index 444c8d5e..755f8e79 100644 --- a/src/loopzero/worktree.py +++ b/src/loopzero/worktree.py @@ -244,7 +244,7 @@ def task_text(wt: Path) -> str: "or recreate the file using the handoff template at " "https://github.com/feder-positronics/loop-zero/blob/main/core/HANDOFF.md" ) - return task.read_text() + return task.read_text(encoding="utf-8") def base_sha(wt: Path) -> str: diff --git a/tests/test_cli.py b/tests/test_cli.py index 5c136d5d..d1140d03 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1049,12 +1049,12 @@ def test_pr_replaces_closed_never_merged_pr(wt: Path, gh: FakeGh, capsys) -> Non assert run(capsys, "pr") == (0, URL + "\n", "") -def test_pr_title_prefers_human_heading(wt: Path, gh: FakeGh, capsys) -> None: - task = wt / ".loopzero" / "task.md" - task.write_text("## Objective\nx\n\n# Add the feature flag\n") - assert cli._pr_title(wt, "lz/t1") == "Add the feature flag" - task.write_text("## Objective\nonly sections\n") - assert cli._pr_title(wt, "lz/t1") == "lz/t1" +@pytest.mark.parametrize("title", ["", "Zażółć gęślą jaźń"]) +def test_pr_title_prefers_human_heading(wt: Path, monkeypatch, title) -> None: + task, read_text = wt / ".loopzero" / "task.md", Path.read_text + monkeypatch.setattr(Path, "read_text", lambda path, encoding="ascii", **kw: read_text(path, encoding, **kw)) + task.write_text(f"## Objective\nZażółć gęślą jaźń\n\n# {title}\n", encoding="utf-8") + assert cli._pr_title(wt, "lz/t1") == (title or "lz/t1") @pytest.mark.parametrize("name,value", [ From 7adb2065e88c4ae7d6009f10c8bd0263f6d184e8 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 10:12:40 +0100 Subject: [PATCH 4/5] Keep the fallback handoff fixture section-only Co-Authored-By: Codex --- tests/test_cli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index d1140d03..95b38355 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1049,12 +1049,12 @@ def test_pr_replaces_closed_never_merged_pr(wt: Path, gh: FakeGh, capsys) -> Non assert run(capsys, "pr") == (0, URL + "\n", "") -@pytest.mark.parametrize("title", ["", "Zażółć gęślą jaźń"]) -def test_pr_title_prefers_human_heading(wt: Path, monkeypatch, title) -> None: +@pytest.mark.parametrize(("heading", "expected"), [("", "lz/t1"), ("\n# Zażółć gęślą jaźń\n", "Zażółć gęślą jaźń")]) +def test_pr_title_prefers_human_heading(wt: Path, monkeypatch, heading, expected) -> None: task, read_text = wt / ".loopzero" / "task.md", Path.read_text monkeypatch.setattr(Path, "read_text", lambda path, encoding="ascii", **kw: read_text(path, encoding, **kw)) - task.write_text(f"## Objective\nZażółć gęślą jaźń\n\n# {title}\n", encoding="utf-8") - assert cli._pr_title(wt, "lz/t1") == (title or "lz/t1") + task.write_text(f"## Objective\nZażółć gęślą jaźń\n{heading}", encoding="utf-8") + assert cli._pr_title(wt, "lz/t1") == expected @pytest.mark.parametrize("name,value", [ From 7f8e14d19028710f23d1b67ab7dc015a4c357e84 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 10:15:08 +0100 Subject: [PATCH 5/5] Report only changes while required checks settle Architecture-Review: unchanged; the command data flow and delivery roles still apply. Co-Authored-By: Codex --- src/loopzero/cli.py | 16 +++++++++++++--- tests/test_cli.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index f1645fb8..88fec5b2 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -1384,6 +1384,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, ...] = (), @@ -1417,11 +1427,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 5c136d5d..d114a912 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -358,6 +358,33 @@ def expect_cli(capsys, exit_code, *argv, stdout=None, stderr=None, stdout_contai return out, err +@pytest.mark.parametrize("command", ["ready", "merge"]) +def test_wait_reports_only_check_changes(wt, gh, head, capsys, monkeypatch, 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) + 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, *range(25)) + ] + arm_check_runs(gh, head, *runs) + poll_clock(monkeypatch) + 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=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) + 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 -------------------------------------------------------------------- @@ -2345,6 +2372,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}", ]