Skip to content

test: isolate git config in attach tests to fix TempDir cleanup flake (COR-394) - #1448

Merged
Soph merged 1 commit into
mainfrom
soph/fix-attach-review-tempdir-flake
Jun 17, 2026
Merged

test: isolate git config in attach tests to fix TempDir cleanup flake (COR-394)#1448
Soph merged 1 commit into
mainfrom
soph/fix-attach-review-tempdir-flake

Conversation

@Soph

@Soph Soph commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

https://entire.io/gh/entireio/cli/trails/590

Problem

TestAttachCmd_* / TestReviewAttach_* intermittently fail in CI — not on an assertion, but during t.TempDir() cleanup:

testing.go:1464: TempDir RemoveAll cleanup: unlinkat .../001/.git/objects: directory not empty

"directory not empty" during os.RemoveAll means a process created a new file mid-removal — a concurrent writer into the test repo's .git/objects.

Root cause (COR-394)

attach runs git commit --amend via the git CLI (attach.go), which inherits this process's env and therefore the developer's real global/system git config. With default gc.auto / gc.autoDetach=true, that commit forks a detached background git gc that keeps packing/writing into .git/objects after rootCmd.Execute() returns — racing Go's deferred t.TempDir os.RemoveAll.

setupAttachTestRepo configured repo-local identity (testutil.InitRepo) but never isolated global/system git config, so the gc-disabling pins this repo already ships (in testutil) weren't applied to attach's git invocations.

Ruled out as writers: detached telemetry analytics (gated off — no telemetry key 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 .git is the git-forked gc.

Fix

Add testutil.IsolateGitConfigEnv(t) to setupAttachTestRepo. It points GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEM at the isolation config (gc.auto=0, gc.autoDetach=false, maintenance.auto=false, fetch.writeCommitGraph=false) — the central remedy testutil documents for exactly this race. It both removes the dependence on the developer's git config and prevents the detached gc.

IsolateGitConfigEnv uses t.Setenv, so it's non-parallel — already satisfied since the helper uses t.Chdir.

Notes

🤖 Generated with Claude Code


Note

Cursor Bugbot is generating a summary for commit 33cb6db. Configure here.

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
@Soph
Soph requested a review from a team as a code owner June 17, 2026 15:18
Copilot AI review requested due to automatic review settings June 17, 2026 15:18
@Soph
Soph enabled auto-merge June 17, 2026 15:26
@Soph
Soph merged commit 6cbd6b1 into main Jun 17, 2026
11 checks passed
@Soph
Soph deleted the soph/fix-attach-review-tempdir-flake branch June 17, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants