Implement bd-162: Enforce canonical database name (beads.db)

- Changed bd init to always create beads.db instead of {prefix}.db
- Added migration logic to detect and rename old databases
- Updated findDatabaseInTree to prefer beads.db and warn on multiple .db files
- Daemon now refuses to start if multiple .db files exist (ambiguity error)
- Updated tests to expect beads.db instead of prefix-based naming
- Tested migration, ambiguity detection, and warning messages
This commit is contained in:
Steve Yegge
2025-10-26 18:16:27 -07:00
parent dd82840886
commit ae5aee279b
4 changed files with 128 additions and 22 deletions

View File

@@ -143,19 +143,10 @@ func TestInitCommand(t *testing.T) {
}
}
// Verify database was created
var dbPath string
if tt.prefix != "" {
expectedPrefix := strings.TrimRight(tt.prefix, "-")
dbPath = filepath.Join(beadsDir, expectedPrefix+".db")
} else {
// Should use directory name as prefix
dirName := filepath.Base(tmpDir)
dbPath = filepath.Join(beadsDir, dirName+".db")
}
// Verify database was created (always beads.db now)
dbPath := filepath.Join(beadsDir, "beads.db")
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
t.Errorf("Database file was not created at %s", dbPath)
t.Errorf("Database file was not created at %s", dbPath)
}
// Verify database has correct prefix
@@ -228,8 +219,8 @@ func TestInitAlreadyInitialized(t *testing.T) {
t.Fatalf("Second init failed: %v", err)
}
// Verify database still works
dbPath := filepath.Join(tmpDir, ".beads", "test.db")
// Verify database still works (always beads.db now)
dbPath := filepath.Join(tmpDir, ".beads", "beads.db")
store, err := sqlite.New(dbPath)
if err != nil {
t.Fatalf("Failed to open database after re-init: %v", err)