Implement the following plan: Plan: Isolate integration tests from user git config…
- User
Implement the following plan:
Plan: Isolate integration tests from user git config
Context
The user's
~/.gitconfigsetscore.excludesFileto~/.gitignore-global, which contains*.log. This causedTestShadow_UntrackedFilePreservationto fail becausegit ls-files --others --exclude-standard(used bycollectUntrackedFiles()during rewind) treatedtemp-debug.logas gitignored and invisible.The first commit fixed
cliEnv()intestenv.goby addingGIT_CONFIG_GLOBAL=/dev/nullandGIT_CONFIG_SYSTEM=/dev/null. However, many other callsites in the integration test suite buildcmd.Envindependently or don't setcmd.Envat all, leaving them vulnerable to the same class of issues.Approach
- Add
gitIsolatedEnv()helper totestenv.go— returnsos.Environ()with git isolation vars appended - Update
cliEnv()to delegate togitIsolatedEnv()instead ofos.Environ() - Replace all
os.Environ()incmd.Envassignments withgitIsolatedEnv() - Add
cmd.Env = gitIsolatedEnv()for bareexec.Command("git", ...)calls that don't setcmd.Env
Files to modify
testenv.go— add helper, update existing code- Add
gitIsolatedEnv()function (beforecliEnv()) - Update
cliEnv()to usegitIsolatedEnv()instead ofos.Environ() - Line 560 (
GitCheckoutNewBranch): addcmd.Env = gitIsolatedEnv() - Line 1091 (
GitRm): addcmd.Env = gitIsolatedEnv()
hooks.go— 5 callsites (Pattern 1: replaceos.Environ())- Line 212:
runHookInRepoDir(Claude) - Line 393:
runHookWithOutput(Claude) - Line 543:
runGeminiHookInRepoDir - Line 562:
runGeminiHookWithOutput - Line 797:
- Add
Assistant
I'll start by reading the key files to understand the current code before making changes.
Assistant
Now let me read the remaining files that need modification.
Assistant
Let me read the remaining files.
Assistant
Let me find the specific sections in testenv.go I need to modify.
Assistant
Let me find the
cliEnvfunction.Assistant
Now I have a complete picture. Let me create task items and start implementing.
Assistant
First, add the
gitIsolatedEnv()helper and updatecliEnv()in testenv.go:Assistant
Now add
cmd.Env = gitIsolatedEnv()toGitCheckoutNewBranch:Assistant
Now add
cmd.Env = gitIsolatedEnv()toGitRm:Assistant
Now update hooks.go — 5 callsites replacing
os.Environ()withgitIsolatedEnv():Assistant
Good, all 5 hooks.go callsites are done. Now the
osimport is no longer needed in hooks.go since allos.Environ()calls were replaced. Let me check.Assistant
Good,
osis still used for file operations. Now update hook_logging_test.go — 2 callsites:Assistant
Now check if
osis still used in hook_logging_test.go:Assistant
Good,
osis still needed. Now update hook_bench_test.go — 3 callsites:Assistant
Now check if
osimport is still needed in hook_bench_test.go:Assistant
Need to remove
"os"from imports in hook_bench_test.go:Assistant
Now update subdirectory_test.go — 2 callsites:
Assistant
Check if
osis still needed in subdirectory_test.go:Assistant
Good,
osstill needed. Now update resume_test.go — 2 callsites:Assistant
Now update interactive.go — 1 callsite:
Assistant
Check if
osis still needed in interactive.go:Assistant
Good,
osstill needed. Now update mid_session_commit_test.go — 3 callsites:Assistant
Check if
osis still needed in mid_session_commit_test.go:Assistant
Need to remove
"os"from imports:Assistant
Now update mid_session_rebase_test.go — 3 callsites (bare git commands without cmd.Env):
Assistant
Now the second
git rebase masterinTestShadow_CommitThenRebaseMidSession:Assistant
Now update worktree_test.go — 1 callsite:
Assistant
Now update git_author_test.go — mixed callsites. First the Pattern 1 replacements (lines 83 and 251):
Assistant
Now handle the Pattern 2 callsites in
TestGetGitAuthorFallbackToGitCommand— the bare git commands that don't setcmd.Env:Assistant
Now handle
TestGetGitAuthorRemovingLocalConfig— the bare git commands (lines ~245, ~249, ~260):Assistant
Now let me verify I haven't missed any
os.Environ()callsites in the integration test directory (excluding the intentional ones inTestGetGitAuthorNoConfigReturnsDefaults):Assistant
There are more callsites I need to update. Let me check the remaining ones in testenv.go and deferred_finalization_test.go.
Assistant
These are all
prepCmd.Envassignments that build onos.Environ(). I need to replace them all withgitIsolatedEnv():Assistant
Now update deferred_finalization_test.go:
Assistant
Now let me do a final check — are there any remaining
os.Environ()callsites (excluding the one ingitIsolatedEnv()itself and the intentional ones ingit_author_test.go)?Assistant
Only the
gitIsolatedEnv()function itself usesos.Environ(). Now let me check which files may have unusedosimports after the changes:Assistant
Good — both files still use
osextensively. Now let me also check git_author_test.go to make sure theosimport is still needed:Assistant
Good,
osstill needed. Let me also check for any bareexec.Command("git",calls in testenv.go that I might have missed:Assistant
Let me also check for bare git commands in other test files that might not have been in the original plan:
Assistant
All git commands now have
cmd.Env = gitIsolatedEnv(), and the[]string{...}envs inTestGetGitAuthorNoConfigReturnsDefaults(lines 132-187) are intentionally left alone. Let me also check ifosimport can be removed from any files that we touched:Assistant
Both still need
os. Now let me also check hook_logging_test.go import — we need to verifyosis still imported but also check if"os"import is now unused:Actually wait, the grep above shows 8 occurrences, so
osis definitely still needed. Let me mark this task as complete and run the verification.Assistant
Lint passes. Now run the integration tests:
Assistant
All integration tests pass. Let me also run the unit tests to make sure nothing is broken:
- User
[Request interrupted by user for tool use]
- User
Commit with explanation.
Assistant
Committed as
02d4cc84. Summary of changes across 12 files:testenv.go: AddedgitIsolatedEnv()helper that returnsos.Environ()+GIT_CONFIG_GLOBAL=/dev/null+GIT_CONFIG_SYSTEM=/dev/null. UpdatedcliEnv()to delegate to it. Addedcmd.Env = gitIsolatedEnv()toGitCheckoutNewBranchandGitRm, and replaced allos.Environ()in prepare-commit-msg hook calls.hooks.go: 5 callsites — Claude, Gemini, and OpenCode hook runners all now usegitIsolatedEnv().hook_logging_test.go,hook_bench_test.go,subdirectory_test.go,resume_test.go,interactive.go,mid_session_commit_test.go,deferred_finalization_test.go: Replacedos.Environ()withgitIsolatedEnv().mid_session_rebase_test.go,worktree_test.go, : Added to bare commands that previously had no env set.