test: isolate git config in attach tests to fix TempDir cleanup flake (COR-394) - #1448
Merged
Conversation
TestAttachCmd_* / TestReviewAttach_* intermittently failed in t.TempDir
cleanup, not on an assertion:
TempDir RemoveAll cleanup: unlinkat .../001/.git/objects: directory not empty
Root cause (COR-394): attach runs `git commit --amend` via the git CLI
(attach.go), which inherits the process env and the developer's real git
config. With default gc.auto/gc.autoDetach, the commit forks a detached
`git gc` that keeps writing into the temp repo's .git/objects after
rootCmd.Execute() returns, racing Go's deferred os.RemoveAll.
setupAttachTestRepo set up repo-local identity (testutil.InitRepo) but never
isolated global/system git config, so the gc-disabling pins didn't apply.
Add testutil.IsolateGitConfigEnv(t) — it sets GIT_CONFIG_GLOBAL/SYSTEM to the
isolation config (gc.auto=0, gc.autoDetach=false, maintenance.auto=false),
the central remedy for exactly this race. Compatible with the helper's
existing t.Chdir (both non-parallel).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 9a948bc09627
pjbgf
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://entire.io/gh/entireio/cli/trails/590
Problem
TestAttachCmd_*/TestReviewAttach_*intermittently fail in CI — not on an assertion, but duringt.TempDir()cleanup:"directory not empty" during
os.RemoveAllmeans a process created a new file mid-removal — a concurrent writer into the test repo's.git/objects.Root cause (COR-394)
attachrunsgit commit --amendvia the git CLI (attach.go), which inherits this process's env and therefore the developer's real global/system git config. With defaultgc.auto/gc.autoDetach=true, that commit forks a detached backgroundgit gcthat keeps packing/writing into.git/objectsafterrootCmd.Execute()returns — racing Go's deferredt.TempDiros.RemoveAll.setupAttachTestRepoconfigured repo-local identity (testutil.InitRepo) but never isolated global/system git config, so the gc-disabling pins this repo already ships (intestutil) weren't applied to attach's git invocations.Ruled out as writers: detached telemetry analytics (gated off — no
telemetrykey in the test settings, and the child never touches the repo) and version-check (early-returns on dev/test builds). The only async writer to the test repo's.gitis the git-forkedgc.Fix
Add
testutil.IsolateGitConfigEnv(t)tosetupAttachTestRepo. It pointsGIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEMat the isolation config (gc.auto=0,gc.autoDetach=false,maintenance.auto=false,fetch.writeCommitGraph=false) — the central remedytestutildocuments for exactly this race. It both removes the dependence on the developer's git config and prevents the detached gc.IsolateGitConfigEnvusest.Setenv, so it's non-parallel — already satisfied since the helper usest.Chdir.Notes
setupAttachTestRepoand thegit commit --amendpath.testutil.GitAdd/GitCommituse go-git (not the CLI), so they never forked gc — the leak was specific to attach's CLI amend.🤖 Generated with Claude Code
Note
Cursor Bugbot is generating a summary for commit 33cb6db. Configure here.