From d1fb062287e705a1a82075066dbce425a82febaa Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:24:13 +0100 Subject: [PATCH 1/5] Isolate Git fixture subprocesses from caller repository state Co-Authored-By: Codex --- tests/conftest.py | 14 ++++++-------- tests/test_worktree.py | 10 ++++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e0f43426..07d2fa24 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,7 @@ import pytest -from loopzero import github +from loopzero import _proc, github GIT_ENV = {"GIT_CONFIG_GLOBAL": "/dev/null", "GIT_CONFIG_NOSYSTEM": "1"} @@ -24,16 +24,14 @@ def no_real_app_helper(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: GIT_ENV |= {f"GIT_{_role}_NAME": "test", f"GIT_{_role}_EMAIL": "test@example.com"} +def git_environment() -> dict[str, str]: + return _proc.build_env(("PATH", "LANG", "LC_ALL"), GIT_ENV) + + def git(repo: Path, *args: str) -> str: """Run git in `repo` with a deterministic identity; return stdout.""" - env = {**os.environ, **GIT_ENV} - for key in os.environ: - if key in {"GIT_CONFIG_COUNT", "GIT_CONFIG_PARAMETERS"} or key.startswith( - ("GIT_CONFIG_KEY_", "GIT_CONFIG_VALUE_") - ): - env.pop(key) return subprocess.run( - ["git", *args], cwd=repo, env=env, capture_output=True, text=True, check=True + ["git", *args], cwd=repo, env=git_environment(), capture_output=True, text=True, check=True ).stdout diff --git a/tests/test_worktree.py b/tests/test_worktree.py index d4c30478..edcd0f8d 100644 --- a/tests/test_worktree.py +++ b/tests/test_worktree.py @@ -8,7 +8,7 @@ import pytest from loopzero import worktree -from tests.conftest import commit_file, git +from tests.conftest import commit_file, git, git_environment @pytest.fixture @@ -34,11 +34,13 @@ def commit_on_origin(repo: Path, name: str) -> str: return git(clone, "rev-parse", "HEAD").strip() -def test_branch_preserves_unicode_whitespace(repo: Path) -> None: +def test_branch_preserves_unicode_whitespace(repo: Path, monkeypatch) -> None: + ambient = repo.parent / "ambient.git" + monkeypatch.setenv("GIT_DIR", str(ambient)) name = worktree.branch_name(repo, "zażółć\u00a0") git(repo, "switch", "-c", name) - assert worktree.branch(repo) == "lz/zażółć\u00a0" + assert worktree.branch(repo) == "lz/zażółć\u00a0" and not ambient.exists() def test_branch_refuses_detached_head(repo: Path) -> None: @@ -310,7 +312,7 @@ def test_abandoned_worktree_guide(repo: Path, tmp_path: Path, state: str) -> Non commands = section.split("```sh\n", 1)[1].split("```", 1)[0] result = subprocess.run( ["sh", "-c", commands, "cleanup-guide", str(wt), "abandoned", head], - cwd=caller, capture_output=True, text=True, check=False, + cwd=caller, env=git_environment(), capture_output=True, text=True, check=False, ) assert (result.returncode == 0) == (state == "clean"), result.stderr 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/5] 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 cd324368edfc441cab06ae72b134d1f51f0c45d2 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:27:02 +0100 Subject: [PATCH 3/5] Use the isolated Git environment for the raw reviewer diff Co-Authored-By: Codex --- tests/test_codex_transport.py | 4 ++-- tests/test_worktree.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/test_codex_transport.py b/tests/test_codex_transport.py index b954c896..57e66692 100644 --- a/tests/test_codex_transport.py +++ b/tests/test_codex_transport.py @@ -13,7 +13,7 @@ from loopzero import cli, eligibility, github, runners from loopzero.types import CheckReport, CheckResult, Config from tests import test_cli, test_runners -from tests.conftest import commit_file, git +from tests.conftest import commit_file, git, git_environment fake_bwrap = test_runners.fake_bwrap gh = test_cli.gh @@ -379,7 +379,7 @@ def test_large_publication_confirmation_and_hosted_agreement(native, gh, tmp_pat proof = runners.codex_evidence(result) assert proof["kind"] == "delta" and proof["calls"][0]["base"] == reviewed != merge_base argv = ["git", "diff", "--no-color", reviewed, head] - delta_diff = subprocess.check_output(argv, cwd=native[2]) + delta_diff = subprocess.check_output(argv, cwd=native[2], env=git_environment()) assert b"-hello\n+" + content in delta_diff if kind == "delta_legacy": assert "+caf\\xe9\r\n" in runners.render_patch(delta_diff) diff --git a/tests/test_worktree.py b/tests/test_worktree.py index edcd0f8d..75606638 100644 --- a/tests/test_worktree.py +++ b/tests/test_worktree.py @@ -8,7 +8,7 @@ import pytest from loopzero import worktree -from tests.conftest import commit_file, git, git_environment +from tests.conftest import commit_file, git, git_environment, init_git_repo @pytest.fixture @@ -34,13 +34,18 @@ def commit_on_origin(repo: Path, name: str) -> str: return git(clone, "rev-parse", "HEAD").strip() -def test_branch_preserves_unicode_whitespace(repo: Path, monkeypatch) -> None: - ambient = repo.parent / "ambient.git" +def test_git_fixture_ignores_inherited_directory(tmp_path, monkeypatch): + ambient = tmp_path / "ambient.git" monkeypatch.setenv("GIT_DIR", str(ambient)) + checkout = init_git_repo(tmp_path / "checkout") + assert (checkout / ".git").is_dir() and not ambient.exists() + + +def test_branch_preserves_unicode_whitespace(repo: Path) -> None: name = worktree.branch_name(repo, "zażółć\u00a0") git(repo, "switch", "-c", name) - assert worktree.branch(repo) == "lz/zażółć\u00a0" and not ambient.exists() + assert worktree.branch(repo) == "lz/zażółć\u00a0" def test_branch_refuses_detached_head(repo: Path) -> None: 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 4/5] 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 5/5] 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