mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
test: fix TestWatcher_SharedParentRefcount on macOS (#25379)
`TestWatcher_SharedParentRefcount` was deterministically broken on macOS: `t.TempDir()` lives under `/var` which is a symlink to `/private/var`, but the watcher canonicalizes paths via `filepath.EvalSymlinks` before storing them, so the test's `w.dirs[dir]` lookup missed and returned `0` instead of `2`. Adds `testutil.TempDirResolved`, a shared helper that returns `t.TempDir()` with symlinks resolved and falls back to the raw temp dir on error (Windows-friendly). Migrates the matching inline `EvalSymlinks(t.TempDir())` callsites in `agent/agentgit/agentgit_test.go` to use it. Closes https://github.com/coder/internal/issues/1531
This commit is contained in:
@@ -379,7 +379,11 @@ func TestWatcher_SharedParentRefcount(t *testing.T) {
|
||||
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
|
||||
dir := t.TempDir()
|
||||
// On macOS, t.TempDir() lives under /var which is a symlink
|
||||
// to /private/var. The watcher canonicalizes paths before
|
||||
// storing parent-dir keys in w.dirs, so the test must look up
|
||||
// the resolved form to match.
|
||||
dir := testutil.TempDirResolved(t)
|
||||
pathA := filepath.Join(dir, "a.mcp.json")
|
||||
pathB := filepath.Join(dir, "b.mcp.json")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user