From bc909834c2e7f9cdcc69a8e7630d38a64d314feb Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Fri, 12 Jun 2026 17:58:55 -0400 Subject: [PATCH] test(cmd/bd): preserve GOMODCACHE across the test HOME re-home MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit testMainInner already pins GOCACHE before pointing HOME at a temp dir, but GOMODCACHE (default $HOME/go/pkg/mod) was left to follow the fake HOME, so every buildEmbeddedBD run re-downloaded the full module set — several minutes per run and a hard failure offline. Co-Authored-By: Claude Fable 5 --- cmd/bd/test_repo_beads_guard_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/bd/test_repo_beads_guard_test.go b/cmd/bd/test_repo_beads_guard_test.go index ed376ba81..c276bb70e 100644 --- a/cmd/bd/test_repo_beads_guard_test.go +++ b/cmd/bd/test_repo_beads_guard_test.go @@ -72,6 +72,16 @@ func testMainInner(m *testing.M) int { } } + // Same for the module cache: GOMODCACHE defaults to $HOME/go/pkg/mod, + // so without this the in-test `go build` (buildEmbeddedBD) re-downloads + // every dependency into the temp HOME on each run — slow, and a hard + // failure when the network is unavailable. + if os.Getenv("GOMODCACHE") == "" { + if out, err := exec.Command("go", "env", "GOMODCACHE").Output(); err == nil { + _ = os.Setenv("GOMODCACHE", strings.TrimSpace(string(out))) + } + } + _ = os.Setenv("HOME", tmp) _ = os.Setenv("USERPROFILE", tmp) // Windows compatibility _ = os.Setenv("XDG_CONFIG_HOME", filepath.Join(tmp, "xdg-config"))