diff --git a/cmd/bd/git_test_helpers.go b/cmd/bd/git_test_helpers.go index 8e812f1ea..cdada0978 100644 --- a/cmd/bd/git_test_helpers.go +++ b/cmd/bd/git_test_helpers.go @@ -4,11 +4,15 @@ import ( "os" "testing" + "github.com/steveyegge/beads/internal/beads" "github.com/steveyegge/beads/internal/git" ) -// runInDir changes into dir, resets git caches before/after, and executes fn. -// It ensures tests that mutate git repositories don't leak state across cases. +// runInDir changes into dir, resets the beads and git caches before/after, and +// executes fn. It ensures tests that mutate git repositories don't leak state +// across cases. Both caches are keyed on the working directory, so a chdir +// fixture has to clear the pair going in and coming out — clearing only one +// leaves the other answering for the previous directory. func runInDir(t *testing.T, dir string, fn func()) { t.Helper() origDir, err := os.Getwd() @@ -18,11 +22,13 @@ func runInDir(t *testing.T, dir string, fn func()) { if err := os.Chdir(dir); err != nil { t.Fatalf("failed to change to temp directory: %v", err) } + beads.ResetCaches() git.ResetCaches() defer func() { if err := os.Chdir(origDir); err != nil { t.Fatalf("failed to restore working directory: %v", err) } + beads.ResetCaches() git.ResetCaches() }() fn() diff --git a/cmd/bd/migrate_dolt_mode_test.go b/cmd/bd/migrate_dolt_mode_test.go index 76dc36f0c..658aa48b8 100644 --- a/cmd/bd/migrate_dolt_mode_test.go +++ b/cmd/bd/migrate_dolt_mode_test.go @@ -13,8 +13,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/steveyegge/beads/internal/beads" "github.com/steveyegge/beads/internal/config" "github.com/steveyegge/beads/internal/configfile" + "github.com/steveyegge/beads/internal/git" "github.com/steveyegge/beads/internal/storage/dbproxy/proxy" "github.com/steveyegge/beads/internal/storage/dbproxy/server" "github.com/steveyegge/beads/internal/storage/dbproxy/util" @@ -83,6 +85,12 @@ func migrateModeWorkspace(t *testing.T, mode string) string { require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "dolt", ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600)) writeMetadataConfig(t, beadsDir, mode, "myproj") t.Chdir(dir) + beads.ResetCaches() + git.ResetCaches() + t.Cleanup(func() { + beads.ResetCaches() + git.ResetCaches() + }) return beadsDir } diff --git a/cmd/bd/serve_registered_backend_test.go b/cmd/bd/serve_registered_backend_test.go index 3b584e235..c06f907f3 100644 --- a/cmd/bd/serve_registered_backend_test.go +++ b/cmd/bd/serve_registered_backend_test.go @@ -428,7 +428,11 @@ func TestServeRefusesStrictReadonlyOnARegisteredBackend(t *testing.T) { t.Chdir(dir) t.Setenv("BEADS_DIR", beadsDir) beads.ResetCaches() - t.Cleanup(beads.ResetCaches) + git.ResetCaches() + t.Cleanup(func() { + beads.ResetCaches() + git.ResetCaches() + }) origReadonly := readonlyMode readonlyMode = true diff --git a/cmd/bd/serve_store_identity_test.go b/cmd/bd/serve_store_identity_test.go index 605ff9c27..dc69978ed 100644 --- a/cmd/bd/serve_store_identity_test.go +++ b/cmd/bd/serve_store_identity_test.go @@ -16,6 +16,7 @@ import ( "github.com/steveyegge/beads/internal/beads" "github.com/steveyegge/beads/internal/configfile" + "github.com/steveyegge/beads/internal/git" "github.com/steveyegge/beads/internal/storage" "github.com/steveyegge/beads/internal/storage/backends" "github.com/steveyegge/beads/internal/types" @@ -73,7 +74,11 @@ func TestServeAnswersFromTheStoreTheRootCommandOpened(t *testing.T) { // that chdirs into its own workspace has to clear it going in and coming // out. beads.ResetCaches() - t.Cleanup(beads.ResetCaches) + git.ResetCaches() + t.Cleanup(func() { + beads.ResetCaches() + git.ResetCaches() + }) // Stand in for PersistentPreRunE, which opens the workspace through exactly // this dispatch and leaves it in `store`. This is the store bd already