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", "")