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:
Ethan
2026-05-15 17:37:08 +10:00
committed by GitHub
parent a59b951565
commit 5e701d3075
3 changed files with 27 additions and 10 deletions
@@ -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")