From 4bcb1d659674f1e62af840789a8987f699c0861b Mon Sep 17 00:00:00 2001 From: Torben Nehmer Date: Sat, 5 Dec 2026 07:09:48 +0100 Subject: [PATCH 1/2] Isolate git environment for all tests Move the _isolated_git fixture to tests/conftest.py so git rebase --exec cannot leak GIT_DIR into any test; add a test outside tests/evals. Co-Authored-By: Claude Sonnet 5.5 --- tests/conftest.py | 19 +++++++++++++++++++ tests/evals/conftest.py | 16 ---------------- tests/test_git_isolation.py | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 tests/conftest.py delete mode 100644 tests/evals/conftest.py create mode 100644 tests/test_git_isolation.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..5aeece3 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,19 @@ +import os + +import pytest + +# Only these git variables survive; they keep the user's and system git config out. +_GIT_ENV: dict[str, str] = {"GIT_CONFIG_GLOBAL": "/dev/null", "GIT_CONFIG_NOSYSTEM": "1"} + + +def pytest_configure(config: pytest.Config) -> None: + """Keep git in tests away from the repository and config running them. + + `git rebase --exec` and hooks export GIT_DIR and friends, `git -c` exports + GIT_CONFIG_PARAMETERS; without this, `git init` and `git commit` in a test + would act on the checkout itself or run its hooks. Runs before collection, + so session fixtures and import-time code are covered too. + """ + for name in [name for name in os.environ if name.startswith("GIT_")]: + del os.environ[name] + os.environ.update(_GIT_ENV) diff --git a/tests/evals/conftest.py b/tests/evals/conftest.py deleted file mode 100644 index d2c7fe5..0000000 --- a/tests/evals/conftest.py +++ /dev/null @@ -1,16 +0,0 @@ -import pytest - -from chemenu.evals.baseline import GIT_REPO_ENV - - -@pytest.fixture(autouse=True) -def _isolated_git(monkeypatch: pytest.MonkeyPatch) -> None: - """Keep git in tests away from the repository running them. - - `git rebase --exec` and hooks export GIT_DIR; without this, `git init` and - `git commit` in a test would act on the checkout itself. - """ - for name in GIT_REPO_ENV: - monkeypatch.delenv(name, raising=False) - monkeypatch.setenv("GIT_CONFIG_GLOBAL", "/dev/null") - monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1") diff --git a/tests/test_git_isolation.py b/tests/test_git_isolation.py new file mode 100644 index 0000000..74886af --- /dev/null +++ b/tests/test_git_isolation.py @@ -0,0 +1,17 @@ +import os + + +def test_git_repo_env_is_removed() -> None: + leaked = [ + n + for n in os.environ + if n.startswith("GIT_") + and n + not in { + "GIT_CONFIG_GLOBAL", + "GIT_CONFIG_NOSYSTEM", + } + ] + assert leaked == [] + assert os.environ["GIT_CONFIG_GLOBAL"] == "/dev/null" + assert os.environ["GIT_CONFIG_NOSYSTEM"] == "1" -- 2.54.1 From 115d3fb73429538ad9db285d4e56b88fa960b532 Mon Sep 17 00:00:00 2001 From: Torben Nehmer Date: Sat, 5 Dec 2026 07:10:11 +0100 Subject: [PATCH 2/2] Run /build per-commit checks without inherited GIT_DIR git rebase --exec exports GIT_DIR, so tests calling git wrote into the repo. Wrap the check command with env -u. Co-Authored-By: Claude Sonnet 5.5 --- .claude/skills/build/SKILL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.claude/skills/build/SKILL.md b/.claude/skills/build/SKILL.md index 5981138..8caf477 100644 --- a/.claude/skills/build/SKILL.md +++ b/.claude/skills/build/SKILL.md @@ -42,7 +42,7 @@ Der Bericht ist nur ein Hinweis, maßgeblich sind Diff und Tests. ## 4. Gesamtprüfung -1. History glätten: Fixups einarbeiten (`GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash origin/main`). Jeder Commit grün (`git rebase origin/main --exec ''`). +1. History glätten: Fixups einarbeiten (`GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash origin/main`). Jeder Commit grün (`git rebase origin/main --exec 'env -u GIT_DIR -u GIT_WORK_TREE -u GIT_INDEX_FILE sh -c ""'`). `rebase --exec` setzt `GIT_DIR`; ohne `env -u` schreiben Tests, die git aufrufen, ins Repo. `` ohne doppelte Anführungszeichen, `$` und Backticks; sonst die Checks in ein Skript im Scratchpad legen und `sh ` aufrufen. 2. Volle Checks und Prüfbefehl aus dem Issue. 3. Wurde ein Schritt-Prompt geändert: Agent `eval-runner`. 4. `git diff origin/main...HEAD > /review.diff`, dann Agent `reviewer` mit Issue-Text und Diff-Pfad. Befunde beheben. -- 2.54.1