Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import pytest

from loopzero import github
from loopzero import _proc, github
Comment thread
eowca marked this conversation as resolved.
Resolved

GIT_ENV = {"GIT_CONFIG_GLOBAL": "/dev/null", "GIT_CONFIG_NOSYSTEM": "1"}

Expand All @@ -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


Expand Down
4 changes: 2 additions & 2 deletions tests/test_codex_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions tests/test_worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, init_git_repo


@pytest.fixture
Expand All @@ -34,6 +34,13 @@ def commit_on_origin(repo: Path, name: str) -> str:
return git(clone, "rev-parse", "HEAD").strip()


def test_git_fixture_ignores_inherited_directory(tmp_path, monkeypatch):
ambient = tmp_path / "ambient.git"
monkeypatch.setenv("GIT_DIR", str(ambient))
Comment thread
eowca marked this conversation as resolved.
Resolved
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)
Expand Down Expand Up @@ -310,7 +317,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
Expand Down
Loading