mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-26 04:25:46 +02:00
TestRegisterTaskReposSurvivesWorkspaceRefresh started flaking on CI after #1988 (`feat: support repo checkout ref selection`) extended the bare-clone path to run an extra `git fetch` to backfill refs/remotes/origin/* under the new refspec layout. The race was already latent: registerTaskRepos kicks off `go syncWorkspaceRepos(...)` to clone a repo into the cache root, which in tests is `t.TempDir()`. Once the test waited on `repoCache.Lookup` to return a path it would proceed and return — but the bg goroutine was still inside `ensureRemoteTrackingLayout` running git operations on the clone dir. `t.TempDir`'s cleanup then races with those git commands and surfaces either as "directory not empty" or "fatal: cannot change to ... No such file or directory", with no hint that the failure is unrelated to the test's actual assertion. Track the background goroutine on the Daemon via a sync.WaitGroup and expose `waitBackgroundSyncs()` for tests. `newRepoReadyTestDaemon` registers a t.Cleanup that calls it, so every test that uses the helper now drains in-flight syncs before t.TempDir cleanup runs. No production-behavior change — registerTaskRepos still fires-and-forgets from the caller's perspective. Verified with `go test ./internal/daemon -run TestRegisterTaskReposSurvivesWorkspaceRefresh -count=30` (was failing within ~10 iterations before, 30 green after) and the full `go test ./internal/daemon/...` suite. Co-authored-by: multica-agent <github@multica.ai>