fix: make tests resilient to project .beads/redirect
Tests were failing because beads.FindDatabasePath() follows the project's .beads/redirect file, causing tests to find unexpected databases. Fixed by: - Setting BEADS_DIR in tests that need isolation from git repo detection - Clearing BEADS_DIR in TestMain to prevent global contamination - Updating migration test schema to include owner column This ensures tests work correctly in crew directories that have redirect files pointing to shared .beads directories. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Executed-By: beads/crew/dave Rig: beads Role: crew
This commit is contained in:
committed by
Steve Yegge
parent
f79e636000
commit
ac24a63187
@@ -10,16 +10,25 @@ import (
|
||||
)
|
||||
|
||||
func TestFindDatabasePathEnvVar(t *testing.T) {
|
||||
// Save original env var
|
||||
originalEnv := os.Getenv("BEADS_DB")
|
||||
// Save original env vars
|
||||
originalDB := os.Getenv("BEADS_DB")
|
||||
originalDir := os.Getenv("BEADS_DIR")
|
||||
defer func() {
|
||||
if originalEnv != "" {
|
||||
_ = os.Setenv("BEADS_DB", originalEnv)
|
||||
if originalDB != "" {
|
||||
_ = os.Setenv("BEADS_DB", originalDB)
|
||||
} else {
|
||||
_ = os.Unsetenv("BEADS_DB")
|
||||
}
|
||||
if originalDir != "" {
|
||||
_ = os.Setenv("BEADS_DIR", originalDir)
|
||||
} else {
|
||||
_ = os.Unsetenv("BEADS_DIR")
|
||||
}
|
||||
}()
|
||||
|
||||
// Clear BEADS_DIR to prevent it from interfering
|
||||
_ = os.Unsetenv("BEADS_DIR")
|
||||
|
||||
// Set env var to a test path (platform-agnostic)
|
||||
testPath := filepath.Join("test", "path", "test.db")
|
||||
_ = os.Setenv("BEADS_DB", testPath)
|
||||
@@ -33,17 +42,23 @@ func TestFindDatabasePathEnvVar(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFindDatabasePathInTree(t *testing.T) {
|
||||
// Save original env var
|
||||
originalEnv := os.Getenv("BEADS_DB")
|
||||
// Save original env vars
|
||||
originalDB := os.Getenv("BEADS_DB")
|
||||
originalDir := os.Getenv("BEADS_DIR")
|
||||
defer func() {
|
||||
if originalEnv != "" {
|
||||
os.Setenv("BEADS_DB", originalEnv)
|
||||
if originalDB != "" {
|
||||
os.Setenv("BEADS_DB", originalDB)
|
||||
} else {
|
||||
os.Unsetenv("BEADS_DB")
|
||||
}
|
||||
if originalDir != "" {
|
||||
os.Setenv("BEADS_DIR", originalDir)
|
||||
} else {
|
||||
os.Unsetenv("BEADS_DIR")
|
||||
}
|
||||
}()
|
||||
|
||||
// Clear env var
|
||||
// Clear env vars
|
||||
os.Unsetenv("BEADS_DB")
|
||||
|
||||
// Create temporary directory structure
|
||||
@@ -67,6 +82,9 @@ func TestFindDatabasePathInTree(t *testing.T) {
|
||||
}
|
||||
f.Close()
|
||||
|
||||
// Set BEADS_DIR to our test .beads directory to override git repo detection
|
||||
os.Setenv("BEADS_DIR", beadsDir)
|
||||
|
||||
// Create a subdirectory and change to it
|
||||
subDir := filepath.Join(tmpDir, "sub", "nested")
|
||||
err = os.MkdirAll(subDir, 0o750)
|
||||
|
||||
Reference in New Issue
Block a user