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:
@@ -43,13 +43,9 @@ func gitCmd(t *testing.T, dir string, args ...string) {
|
||||
// and returns the repo root path.
|
||||
func initTestRepo(t *testing.T) string {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
// Resolve symlinks and short (8.3) names on Windows so test
|
||||
// expectations match the canonical paths returned by git.
|
||||
resolved, err := filepath.EvalSymlinks(dir)
|
||||
if err == nil {
|
||||
dir = resolved
|
||||
}
|
||||
dir := testutil.TempDirResolved(t)
|
||||
|
||||
gitCmd(t, dir, "init")
|
||||
gitCmd(t, dir, "config", "user.name", "Test")
|
||||
@@ -557,12 +553,9 @@ func TestScanDeletedWorktreeGitdirEmitsRemoved(t *testing.T) {
|
||||
mainRepoDir := initTestRepo(t)
|
||||
|
||||
// Create a linked worktree using git CLI.
|
||||
wtBase := t.TempDir()
|
||||
// Resolve symlinks and short (8.3) names on Windows so test
|
||||
// expectations match the canonical paths returned by git.
|
||||
if resolved, err := filepath.EvalSymlinks(wtBase); err == nil {
|
||||
wtBase = resolved
|
||||
}
|
||||
wtBase := testutil.TempDirResolved(t)
|
||||
worktreeDir := filepath.Join(wtBase, "wt")
|
||||
gitCmd(t, mainRepoDir, "branch", "worktree-branch")
|
||||
gitCmd(t, mainRepoDir, "worktree", "add", worktreeDir, "worktree-branch")
|
||||
|
||||
Reference in New Issue
Block a user