Skip to content

Commit 3dda7ee

Browse files
gtrrz-victorclaude
andcommitted
test(import): fully isolate git config in author fallback test
TestRun_UnconfiguredGitIdentityFallsBackToDefaults overrode only HOME and XDG_CONFIG_HOME, but GetGitAuthorFromRepo resolves GlobalScope through go-git's Auto loader, which also honors GIT_CONFIG_GLOBAL and system /etc/gitconfig. On any machine/CI where one of those carries a git identity the "Unknown"/"unknown@local" assertion would flake. Neutralize every global source the way the checkpoint package's pointHomeAt helper already does: set GIT_CONFIG_NOSYSTEM=1 and unset GIT_CONFIG_GLOBAL. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 01KY9MM18RHEBYFH4Y4QVJK7RT
1 parent 4df67dc commit 3dda7ee

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

cmd/entire/cli/agentimport/agentimport_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,22 @@ func TestRun_StampsImporterGitAuthorOnCheckpointCommit(t *testing.T) {
438438
// same "Unknown"/"unknown@local" default checkpoint.GetGitAuthorFromRepo
439439
// already applies elsewhere, rather than an empty one.
440440
func TestRun_UnconfiguredGitIdentityFallsBackToDefaults(t *testing.T) {
441-
// Cannot use t.Parallel(): isolates HOME via t.Setenv so this repo's
442-
// global git config resolution can't see the developer's real ~/.gitconfig.
441+
// Cannot use t.Parallel(): isolates git config resolution via t.Setenv so
442+
// this repo can't see any real identity. GetGitAuthorFromRepo resolves
443+
// GlobalScope through go-git's Auto loader, which reads all of git's global
444+
// sources; neutralize every one or the fallback assertion is flaky wherever
445+
// an identity is configured (~/.gitconfig, XDG, GIT_CONFIG_GLOBAL, or system
446+
// /etc/gitconfig). Mirrors the checkpoint package's pointHomeAt helper.
443447
home := t.TempDir()
444448
t.Setenv("HOME", home)
445449
t.Setenv("XDG_CONFIG_HOME", "")
450+
t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
451+
// t.Setenv registers restoration of the original value; unset it for the
452+
// test since an empty GIT_CONFIG_GLOBAL disables global config entirely.
453+
t.Setenv("GIT_CONFIG_GLOBAL", "")
454+
if err := os.Unsetenv("GIT_CONFIG_GLOBAL"); err != nil {
455+
t.Fatal(err)
456+
}
446457

447458
repoDir := t.TempDir()
448459
repo, err := git.PlainInit(repoDir, false)

0 commit comments

Comments
 (0)