From 028e9d058d2e649a73d4e69e82669764d12d205e Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:14:21 +0100 Subject: [PATCH 1/4] Reject invalid UTF-8 in trusted workflow blobs Architecture-Review: unchanged; Git still resolves the same trusted ref. Decoder failures report the existing source label. Co-Authored-By: Codex --- src/loopzero/config.py | 6 ++++-- tests/test_cli.py | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/loopzero/config.py b/src/loopzero/config.py index 6563d33b..81388cfa 100644 --- a/src/loopzero/config.py +++ b/src/loopzero/config.py @@ -124,12 +124,14 @@ def _remote_workflow(worktree: Path, branch: str, previous: Config | None) -> tu return previous, revision shown = _proc.run( ["git", "show", f"{revision}:workflow.toml"], - cwd=worktree, env_allowlist=worktree_mod.GIT_ENV, timeout=60, + cwd=worktree, env_allowlist=worktree_mod.GIT_ENV, timeout=60, preserve_newlines=True, encoding="utf-8", ) if shown.exit_code != 0: raise ConfigError(f"cannot read {source}. {hint}") try: - data = tomllib.loads(shown.stdout) + data = tomllib.loads(shown.stdout.encode("utf-8", errors="surrogateescape").decode("utf-8")) + except UnicodeDecodeError as exc: + raise ConfigError(f"{source}: {exc}") from exc except tomllib.TOMLDecodeError as exc: raise ConfigError(f"{source}: invalid TOML: {exc}. {hint}") from None try: diff --git a/tests/test_cli.py b/tests/test_cli.py index 81376235..f9470c70 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -695,15 +695,23 @@ def test_config_flag_overrides_root(wt: Path, tmp_path: Path, capsys, bootstrap) assert out.startswith("checks are unpinned because --config was provided\n") -def test_invalid_workflow_utf8_names_file(wt, capsys): - filename = "broken-workflow.toml" - (wt / filename).write_bytes(bytes([255])) - args = ["--config", filename, "status"] +@pytest.mark.parametrize("trusted", [False, True]) +def test_invalid_workflow_utf8_names_file(wt, capsys, trusted): + data = WORKFLOW.encode().replace(b"echo ok", b"echo \xff") + filename = "origin/main:workflow.toml" if trusted else "broken-workflow.toml" + if trusted: + (wt / "workflow.toml").write_bytes(data) + git(wt, "add", "workflow.toml") + git(wt, "commit", "-qm", "invalid workflow bytes") + git(wt, "update-ref", "refs/remotes/origin/main", "HEAD") + else: + (wt / filename).write_bytes(data) + args = ["status"] if trusted else ["--config", filename, "status"] code, _, err = run(capsys, *args) assert code == 1 - assert filename in err and "utf-8" in err.lower() and "position 0" in err + assert filename in err and "utf-8" in err.lower() and "position " in err assert "Traceback" not in err From 64c42fd50642b247b1e45d9f0e23c2f96fdcbad7 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:24:28 +0100 Subject: [PATCH 2/4] Isolate fake GitHub tests from caller credentials Co-Authored-By: Codex --- tests/conftest.py | 10 ++++++++-- tests/test_gh_contract.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e0f43426..7fb3c9e8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,12 +14,18 @@ GIT_ENV = {"GIT_CONFIG_GLOBAL": "/dev/null", "GIT_CONFIG_NOSYSTEM": "1"} -@pytest.fixture(autouse=True) -def no_real_app_helper(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: +def isolate_github_auth(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + for name in ("GH_TOKEN", "GITHUB_TOKEN"): + monkeypatch.delenv(name, raising=False) monkeypatch.setattr(github, "APP_TOKEN_HELPER", tmp_path / "absent-app-token", raising=False) monkeypatch.setattr(github, "_app_token_cache", ("", 0.0), raising=False) +@pytest.fixture(autouse=True) +def no_host_github_credentials(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + isolate_github_auth(tmp_path, monkeypatch) + + for _role in ("AUTHOR", "COMMITTER"): GIT_ENV |= {f"GIT_{_role}_NAME": "test", f"GIT_{_role}_EMAIL": "test@example.com"} diff --git a/tests/test_gh_contract.py b/tests/test_gh_contract.py index 7a06d0e9..bebf7f92 100644 --- a/tests/test_gh_contract.py +++ b/tests/test_gh_contract.py @@ -13,6 +13,7 @@ from loopzero import github from loopzero.types import Finding, ReviewResult +from tests.conftest import isolate_github_auth from tests.test_github import ( HEAD, PR_FILES, @@ -50,8 +51,7 @@ def captured_argv(tmp_path_factory: pytest.TempPathFactory) -> list[dict]: with pytest.MonkeyPatch.context() as env: env.setenv("PATH", str(tmp_path), prepend=os.pathsep) - env.setattr(github, "APP_TOKEN_HELPER", tmp_path / "absent-app-token") - env.setattr(github, "_app_token_cache", ("", 0.0)) + isolate_github_auth(tmp_path, env) github.pr_for_branch(REPO, "lz/x") github.pr_view(REPO, 7) github.create_draft_pr(REPO, "lz/x", "main", "Title", "Body\n") From 0da46d91a7621984683641954eb00750ab69c386 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:33:08 +0100 Subject: [PATCH 3/4] Keep the check coordinator pinned through delivery Architecture-Review: unchanged; the setup guide explains how to retain the existing coordinator and receipt compatibility. Co-Authored-By: Codex --- SETUP.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SETUP.md b/SETUP.md index 0cc199fb..2c478fcb 100644 --- a/SETUP.md +++ b/SETUP.md @@ -349,11 +349,11 @@ access to the configured GitHub repository even before a PR exists. See the ### Check receipts with remote execution -Run the current `loopzero check` coordinator from the task worktree with -the same effective settings used by `loopzero ready`. To execute stages -remotely, configure an operator-trusted `[checks].runner` that implements the -[stage protocol](docs/ARCHITECTURE.md#check-stage-runners). The local coordinator -writes the receipt. +Use one pinned CLI revision and the same effective settings for `check`, +`ready`, and `merge`. If a shared install can change mid-task, use the +[isolated install](#install). The coordinator runs in the task worktree and +writes the receipt. For remote stages, configure an operator-trusted +`[checks].runner` using the [stage protocol](docs/ARCHITECTURE.md#check-stage-runners). Without a stage adapter, run the whole check locally. Use a local slot if the host requires one. On miki, run this from the task worktree. From 1ec1df760a19e614fb20b7d17b7fe5a3887a2e89 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:43:44 +0100 Subject: [PATCH 4/4] Use the isolated coordinator in the slotted example Architecture-Review: unchanged; the example keeps the existing coordinator and effective PATH together through delivery. Co-Authored-By: Codex --- SETUP.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SETUP.md b/SETUP.md index 2c478fcb..2bed476a 100644 --- a/SETUP.md +++ b/SETUP.md @@ -356,10 +356,15 @@ writes the receipt. For remote stages, configure an operator-trusted `[checks].runner` using the [stage protocol](docs/ARCHITECTURE.md#check-stage-runners). Without a stage adapter, run the whole check locally. Use a local slot if the -host requires one. On miki, run this from the task worktree. +host requires one. On miki, if you used the isolated install, run these from +the task worktree with the `install_dir` from that recipe. ```sh +export PATH="$install_dir/venv/bin:$PATH" HEAVY_SLOT_REMOTE_HOSTS="$HOME/.cache/intelflo-scratch/locks/no-remote-hosts.json" "$HOME/.cache/intelflo-scratch/locks/heavy-slot.sh" loopzero check +# After opening and reviewing the PR, keep this PATH for delivery. +loopzero ready --wait +loopzero merge --wait ``` A whole-job remote worker writes its own receipt. Ready can use it only if it