Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

test(execenv): stop the test repo template racing git auto maintenance (#8730)

Bohan Jiang81f0fb418ab8
diff --git a/server/internal/daemon/execenv/local_worktree_test.go b/server/internal/daemon/execenv/local_worktree_test.go
index 0fae1a7254..6543ddf1d3 100644
--- a/server/internal/daemon/execenv/local_worktree_test.go
+++ b/server/internal/daemon/execenv/local_worktree_test.go
@@ -68,6 +68,17 @@ func buildTestRepoTemplate() (string, error) {
{"init", "-b", "main"},
{"config", "user.name", "Test User"},
{"config", "user.email", "[email protected]"},
+ // git commit forks a DETACHED `git maintenance run --auto` and
+ // returns without waiting for it. That background process creates
+ // and removes lock files under .git/ after this function is done,
+ // so newTestRepo's os.CopyFS can list .git/objects/maintenance.lock
+ // and then fail to open it — failing whichever test happened to copy
+ // the template at that moment, in a package that has nothing to do
+ // with git maintenance. Every copy inherits this config, which also
+ // keeps the git commands tests run on their own copy from spawning a
+ // background process that races the assertions against it.
+ {"config", "gc.auto", "0"},
+ {"config", "maintenance.auto", "false"},
{"add", "."},
{"commit", "-m", "initial"},
} {
@@ -138,6 +149,25 @@ func prepareForTest(t *testing.T, localPath string) *LocalWorktree {
return wt
}
+// Nothing may write inside a repo this package hands to a test while the test
+// is reading it, and git's auto maintenance is the one writer tests do not
+// spawn themselves: it runs detached, outliving the command that started it.
+// In the template that made os.CopyFS race a lock file git was removing; in a
+// copy it would race the test's own assertions. Asserting on a copy covers
+// both, since the copy inherits the template's config.
+func TestTestRepoDisablesGitAutoMaintenance(t *testing.T) {
+ t.Parallel()
+ repo := newTestRepo(t)
+ for key, want := range map[string]string{"gc.auto": "0", "maintenance.auto": "false"} {
+ // An unset key exits 1, which is the regression itself — read it
+ // without letting that exit code stand in for the comparison.
+ got, _ := gitTry(t, repo, "config", "--get", key)
+ if got != want {
+ t.Errorf("%s = %q, want %q", key, got, want)
+ }
+ }
+}
+
// The agent must see the user's uncommitted work, not a clean HEAD checkout.
// This is the property that makes worktree mode usable rather than confusing:
// otherwise the agent silently reviews code the user hasn't got open.