test: run real-git tests in isolation and guard global-state leaks - #13
Conversation
Greptile SummaryThis PR makes real-git tests run through a sanitized test helper. The main changes are:
Confidence Score: 5/5This 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.
What T-Rex did
|
| 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. |
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
| env.GIT_CONFIG_GLOBAL = "/dev/null" | ||
| env.GIT_CONFIG_SYSTEM = "/dev/null" |
There was a problem hiding this comment.
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!
|
🎉 This PR is included in version 0.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What
Tests that spawn the real
gitbinary now run through a sanitized runner (test/fixtures/git.ts): everyGIT_*environment variable is stripped andGIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEMpoint at/dev/null, so fixture repos can neither read nor write the user's global git config, and a leakedGIT_DIRcan 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/mergecalls onto the real repository — it rewrote the repo-local user identity, flagged the repo bare, movedmain, and registered six fixture worktrees/branches. The hook now unsetsGIT_*, and this change makes the tests themselves safe in any invocation context.Verification
bun run verify(verifyx all) greenbun run test: 587 pass, 0 fail.opencodefixtures, and the hash-scoped~/.kagan/worktreesdir all clean up inafterEach, failure-safe