From 57a402b9333d40077045f9f4e2ac3bf9875746dc Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sat, 31 Oct 2026 13:10:51 -0700 Subject: [PATCH] test(cli): build the permission hook binary with the real Go caches TestPermissionHookBuiltBinary moved HOME to a temporary directory before running go build. With GOPATH unset, go then downloaded every module into a cache under that HOME, whose files are read-only, so the test failed at cleanup ("TempDir RemoveAll cleanup: unlinkat ... permission denied") on any machine without GOMODCACHE set, and took 25 seconds. CI sets the cache paths, so it passed there. The build now uses the module and build caches go reports before HOME moves. The test passes locally in about 3 seconds. --- internal/cli/hook_prompt_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/cli/hook_prompt_test.go b/internal/cli/hook_prompt_test.go index 505bb053..b2564562 100644 --- a/internal/cli/hook_prompt_test.go +++ b/internal/cli/hook_prompt_test.go @@ -66,12 +66,21 @@ func writePromptTranscript(t *testing.T, path, text string) { } } func TestPermissionHookBuiltBinary(t *testing.T) { + // readEnv moves HOME to a temporary directory. Build with the real Go + // caches: with GOPATH unset, go would otherwise fill a module cache under + // that HOME with read-only files the test cannot remove. + caches, err := exec.Command("go", "env", "GOMODCACHE", "GOCACHE").Output() + if err != nil { + t.Fatal(err) + } + modCache, buildCache, _ := strings.Cut(strings.TrimSpace(string(caches)), "\n") readEnv(t) bin := filepath.Join(t.TempDir(), "driga") if runtime.GOOS == "windows" { bin += ".exe" } build := exec.Command("go", "build", "-o", bin, "../../cmd/driga") + build.Env = append(os.Environ(), "GOMODCACHE="+strings.TrimSpace(modCache), "GOCACHE="+strings.TrimSpace(buildCache)) if out, err := build.CombinedOutput(); err != nil { t.Fatalf("build: %v: %s", err, out) }