Skip to content

test: run real-git tests in isolation and guard global-state leaks - #13

Merged
aorumbayev merged 2 commits into
mainfrom
fix/test-hermeticity
Jul 9, 2026
Merged

test: run real-git tests in isolation and guard global-state leaks#13
aorumbayev merged 2 commits into
mainfrom
fix/test-hermeticity

Conversation

@aorumbayev

Copy link
Copy Markdown
Member

What

Tests that spawn the real git binary now run through a sanitized runner (test/fixtures/git.ts): every GIT_* environment variable is stripped and GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEM point at /dev/null, so fixture repos can neither read nor write the user's global git config, and a leaked GIT_DIR can never redirect them onto the real repository.

A new guard (test/guards/hermeticity.test.ts) fails the suite if any test spawns git outside the helper or passes --global/--system.

Why

Running the suite inside this linked worktree's pre-commit hook exported GIT_DIR, which hijacked the fixture repos' git init/config/worktree/merge calls onto the real repository — it rewrote the repo-local user identity, flagged the repo bare, moved main, and registered six fixture worktrees/branches. The hook now unsets GIT_*, and this change makes the tests themselves safe in any invocation context.

Verification

  • bun run verify (verifyx all) green
  • bun run test: 587 pass, 0 fail
  • Teardown audited suite-wide: temp dirs, .opencode fixtures, and the hash-scoped ~/.kagan/worktrees dir all clean up in afterEach, failure-safe

@greptile-apps

greptile-apps Bot commented Jul 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR makes real-git tests run through a sanitized test helper. The main changes are:

  • A new hermetic git runner fixture that strips inherited GIT_* variables.
  • Real-git tests updated to use the helper instead of the production runner.
  • A guard test that rejects direct git spawns and global/system git config flags in tests.

Confidence Score: 5/5

This looks safe to merge after a small portability cleanup.

The changed test paths keep local git identity setup before commits, and the new helper matches the existing git runner contract.

test/fixtures/git.ts should avoid a POSIX-only null-device path in the helper.

T-Rex T-Rex Logs

What T-Rex did

  • Identified the exact polluted_git_env_validation.sh script that was used to run the polluted Git environment validation.
  • Executed the validation workflow with the identified script and captured the run transcript and hostile environment preamble.
  • Reviewed polluted_git_env_script_transcript.log to confirm the commands, working directory, and exit metadata.
  • Reviewed polluted_git_env_preamble.log to inspect the hostile GIT_* environment values used during the run.
  • Checked polluted_git_env_changed_scope.log to verify the full executed validation transcript and the final EXIT_CODE: 0.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
test/fixtures/git.ts Adds the sanitized git runner used by real-git tests, with one portability concern around the hard-coded null-device path.
test/git/runner.test.ts Updates the real-repo merge tests to use the hermetic runner while keeping repo-local identity setup.
test/tui/board/commands.test.ts Updates the board command real-git scenario to use the hermetic runner.
test/guards/hermeticity.test.ts Adds source guards for non-hermetic git usage in tests.

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
test/fixtures/git.ts:10-11
**Hard-Coded Null Device**

When these tests run on a platform where git does not resolve `/dev/null` as a valid config file, every hermetic git command can fail before the fixture repo is initialized. Using the platform null device keeps the isolation behavior without making the real-git tests depend on a POSIX path.

Reviews (1): Last reviewed commit: "test: run real-git tests in isolation an..." | Re-trigger Greptile

Comment thread test/fixtures/git.ts Outdated
Comment on lines +10 to +11
env.GIT_CONFIG_GLOBAL = "/dev/null"
env.GIT_CONFIG_SYSTEM = "/dev/null"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Hard-Coded Null Device

When these tests run on a platform where git does not resolve /dev/null as a valid config file, every hermetic git command can fail before the fixture repo is initialized. Using the platform null device keeps the isolation behavior without making the real-git tests depend on a POSIX path.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: test/fixtures/git.ts
Line: 10-11

Comment:
**Hard-Coded Null Device**

When these tests run on a platform where git does not resolve `/dev/null` as a valid config file, every hermetic git command can fail before the fixture repo is initialized. Using the platform null device keeps the isolation behavior without making the real-git tests depend on a POSIX path.

**Context Used:** AGENTS.md ([source](https://app.greptile.com/kagan/github/kagan-sh/kagan/-/custom-context?memory=88a14340-9a15-4297-925d-3656d144ad2a))

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

@aorumbayev
aorumbayev merged commit 922d104 into main Jul 9, 2026
3 checks passed
@aorumbayev
aorumbayev deleted the fix/test-hermeticity branch July 9, 2026 23:36
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 0.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant