From 77a9abb98352945fca2d431cddd235fe5aff8b1e Mon Sep 17 00:00:00 2001 From: Jim Wordelman Date: Wed, 19 Aug 2026 20:41:21 -0700 Subject: [PATCH] fix: cmd/bd no-workspace tests depend on temp-dir ancestry and a stale git cache (#5798) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: green — cmd/bd no-workspace tests depend on temp-dir ancestry and a stale git cache (refs be-vnkv) TestWhereNoWorkspace and TestBootstrapNoWorkspace now git-init their temp dir so the no-workspace ancestor walk has an explicit boundary and cannot escape to a real ancestor .beads/ (e.g. $HOME/.beads) when GOTMPDIR/TMPDIR resolve under the caller's home directory. TestResolveWhereBeadsDir_ReturnsEmptyWithoutWorkspace gets the same git-init boundary, and all three TestResolveWhereBeadsDir_* tests that os.Chdir now call git.ResetCaches() after chdiring and again in cleanup after chdiring back, since internal/git memoizes git-root lookups once per process and otherwise leaks a stale cwd's cached result across same-package tests that run in the same test binary. * fix(test): move initGitRepoAt to the pure-Go helper file (refs be-87jk) initGitRepoAt was defined in cmd/bd/init_embedded_test.go, which carries //go:build cgo. Every other caller is cgo-tagged too, but cmd/bd/where_test.go has no build tag, so it compiles under CGO_ENABLED=0 -- where the helper does not exist: cmd/bd/where_test.go:85:2: undefined: initGitRepoAt That broke two required lanes on PR #5798: "Check pure-Go and js/wasm boundaries (CGO_ENABLED=0)" and "Worktree remove boundary (Windows)" (-tags gms_pure_go, CGO_ENABLED=0). The helper is stdlib-only (os/exec + testing), so it belongs in test_helpers_pure_test.go, whose header already states the rule: helpers there must stay stdlib-only so pure-Go tests in this package compile under CGO_ENABLED=0. Moved verbatim -- no behavior change -- with a comment recording why it must stay there. Local verification (both configurations): CGO_ENABLED=0 go test -tags gms_pure_go -c ./cmd/bd -> ok (was: build failed) CGO_ENABLED=1 go test -tags gms_pure_go -c ./cmd/bd -> ok CGO_ENABLED=0 go test -tags gms_pure_go -run '^TestWorktreeRemove' ./cmd/bd -> ok CGO_ENABLED=0 go test -tags gms_pure_go -run '^TestResolveWhereBeadsDir' ./cmd/bd -> 3/3 PASS go vet ./cmd/bd/... under CGO_ENABLED=0 and =1 -> clean * ci: retrigger — unrelated Ryuk reaper flake in storage/uow/tracker job The "Test (storage domain + uow)" job failed on an infrastructure flake unrelated to this PR's diff, taking the CI Gate / Required rollup with it. That job runs three package trees in one go test invocation (.github/workflows/pr.yml:676), so Go runs their test binaries in parallel and each starts its own Dolt testcontainer. The binaries share a single testcontainers Ryuk reaper; in this run the internal/tracker binary reused a sibling's reaper and its handshake failed: 18:26:20 Reaper obtained from Docker for this test session 72a9750d 18:26:20 Reaper handshake failed: read ack: EOF With no live connection holding the session open, Ryuk reaped the session's containers. The tracker package's Dolt container (f2b3addaf5ea) started healthy at 18:26:21 and served tests for 26 seconds, then went down at 18:26:47 — every subsequent store-backed test failed instantly on 127.0.0.1:32772 with "invalid connection" and then "connection refused". All 50 failures in that job are that one dead container: 34 connection refused, 16 invalid connection, 1 write commit result indeterminate. No assertion failed. domain, domain/db, domain/fs, domain/git and uow all passed in the same job. This is be-2on, root-caused on a different PR (#5339) with the identical signature. The durable fix is PR #5770 (disable Ryuk on the Dolt testcontainer steps), which is open and awaiting upstream merge. This PR touches only cmd/bd/*_test.go files in package main, which nothing can import, and internal/tracker contains no reference to cmd/bd. Empty commit to re-trigger CI. --- cmd/bd/bootstrap_embedded_test.go | 1 + cmd/bd/init_embedded_test.go | 17 ----------------- cmd/bd/test_helpers_pure_test.go | 25 +++++++++++++++++++++++++ cmd/bd/where_embedded_test.go | 1 + cmd/bd/where_test.go | 8 ++++++++ 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/cmd/bd/bootstrap_embedded_test.go b/cmd/bd/bootstrap_embedded_test.go index 6d30145df..3b72b6aab 100644 --- a/cmd/bd/bootstrap_embedded_test.go +++ b/cmd/bd/bootstrap_embedded_test.go @@ -42,6 +42,7 @@ func TestBootstrapNoWorkspace(t *testing.T) { bd := buildEmbeddedBD(t) dir := t.TempDir() + initGitRepoAt(t, dir) t.Run("default_output", func(t *testing.T) { out, err := bdBootstrapAllowError(t, bd, dir) diff --git a/cmd/bd/init_embedded_test.go b/cmd/bd/init_embedded_test.go index b20d34fc7..ee27208a0 100644 --- a/cmd/bd/init_embedded_test.go +++ b/cmd/bd/init_embedded_test.go @@ -63,23 +63,6 @@ func buildEmbeddedBD(t *testing.T) string { return embeddedBD } -func initGitRepoAt(t *testing.T, dir string) { - t.Helper() - for _, args := range [][]string{ - {"init"}, - {"config", "user.email", "test@test.com"}, - {"config", "user.name", "Test"}, - // Force repo-local hooks so tests ignore any global hooksPath override. - {"config", "core.hooksPath", ".git/hooks"}, - } { - cmd := exec.Command("git", args...) - cmd.Dir = dir - if out, err := cmd.CombinedOutput(); err != nil { - t.Fatalf("git %s failed: %v\n%s", args[0], err, out) - } - } -} - func bdEnv(dir string) []string { var env []string for _, e := range os.Environ() { diff --git a/cmd/bd/test_helpers_pure_test.go b/cmd/bd/test_helpers_pure_test.go index 0ac228a25..03c2a6f05 100644 --- a/cmd/bd/test_helpers_pure_test.go +++ b/cmd/bd/test_helpers_pure_test.go @@ -354,3 +354,28 @@ func runGitForBootstrapTest(t *testing.T, dir string, args ...string) { t.Fatalf("git %v failed: %v\n%s", args, err, string(output)) } } + +// initGitRepoAt turns dir into a git repository with a test identity, giving +// the no-workspace tests a walk boundary so FindBeadsDir cannot climb out of +// the temp dir into a real .beads above it. +// +// This lives in the pure-Go helper file, not alongside the embedded-Dolt +// helpers: cmd/bd/where_test.go carries no build tag, so it compiles under +// CGO_ENABLED=0 where every `//go:build cgo` file is excluded. Keep this +// helper stdlib-only and keep it here. +func initGitRepoAt(t *testing.T, dir string) { + t.Helper() + for _, args := range [][]string{ + {"init"}, + {"config", "user.email", "test@test.com"}, + {"config", "user.name", "Test"}, + // Force repo-local hooks so tests ignore any global hooksPath override. + {"config", "core.hooksPath", ".git/hooks"}, + } { + cmd := exec.Command("git", args...) + cmd.Dir = dir + if out, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("git %s failed: %v\n%s", args[0], err, out) + } + } +} diff --git a/cmd/bd/where_embedded_test.go b/cmd/bd/where_embedded_test.go index a9b7edad6..7775caa73 100644 --- a/cmd/bd/where_embedded_test.go +++ b/cmd/bd/where_embedded_test.go @@ -41,6 +41,7 @@ func TestWhereNoWorkspace(t *testing.T) { bd := buildEmbeddedBD(t) dir := t.TempDir() + initGitRepoAt(t, dir) t.Run("default_output", func(t *testing.T) { out, err := bdWhereAllowError(t, bd, dir) diff --git a/cmd/bd/where_test.go b/cmd/bd/where_test.go index 42bc84f37..15e4540d5 100644 --- a/cmd/bd/where_test.go +++ b/cmd/bd/where_test.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/cobra" "github.com/steveyegge/beads/internal/beads" "github.com/steveyegge/beads/internal/configfile" + "github.com/steveyegge/beads/internal/git" "github.com/steveyegge/beads/internal/utils" ) @@ -41,8 +42,10 @@ func TestResolveWhereBeadsDir_FallsBackToFindBeadsDir(t *testing.T) { if err := os.Chdir(repoDir); err != nil { t.Fatalf("chdir(%q): %v", repoDir, err) } + git.ResetCaches() t.Cleanup(func() { _ = os.Chdir(originalWD) + git.ResetCaches() }) t.Setenv("BEADS_DIR", "") @@ -79,6 +82,7 @@ func TestResolveWhereBeadsDir_ReturnsEmptyWithoutWorkspace(t *testing.T) { resetCommandContext() workspace := t.TempDir() + initGitRepoAt(t, workspace) originalWD, err := os.Getwd() if err != nil { t.Fatalf("getwd: %v", err) @@ -86,8 +90,10 @@ func TestResolveWhereBeadsDir_ReturnsEmptyWithoutWorkspace(t *testing.T) { if err := os.Chdir(workspace); err != nil { t.Fatalf("chdir(%q): %v", workspace, err) } + git.ResetCaches() t.Cleanup(func() { _ = os.Chdir(originalWD) + git.ResetCaches() }) t.Setenv("BEADS_DIR", "") @@ -146,8 +152,10 @@ func TestResolveWhereBeadsDir_UsesInitializedDBPath(t *testing.T) { if err := os.Chdir(cwd); err != nil { t.Fatalf("chdir: %v", err) } + git.ResetCaches() t.Cleanup(func() { _ = os.Chdir(originalWD) + git.ResetCaches() }) t.Setenv("BEADS_DIR", "")