## Summary When metadata.json gets deleted (git clean, merge conflict, rebase), the version tracking code auto-recreates it using DefaultConfig() which hardcoded jsonl_export to 'issues.jsonl'. But many repos (including beads itself) use 'beads.jsonl', causing a mismatch between config and actual JSONL file. ## Changes 1. **bd doctor --fix auto-detection** (cmd/bd/doctor/fix/database_config.go) - New DatabaseConfig() fix function that auto-detects actual JSONL file - Prefers beads.jsonl over issues.jsonl (canonical name) - Skips backup files and merge artifacts - Wired into doctor.go applyFixes() 2. **Version tracking auto-detection** (cmd/bd/version_tracking.go) - trackBdVersion() now scans for existing JSONL files before defaulting - Prevents mismatches when metadata.json gets recreated - Added findActualJSONLFile() helper function 3. **Canonical default name** (internal/configfile/configfile.go) - DefaultConfig() changed from issues.jsonl to beads.jsonl - Aligns with canonical naming convention 4. **FindJSONLPath preference** (internal/beads/beads.go) - Now prefers beads.jsonl over issues.jsonl when scanning - Default changed from issues.jsonl to beads.jsonl 5. **Test coverage** - Added comprehensive tests for DatabaseConfig fix - Updated configfile tests for new default - Verified backup file skipping logic ## Testing - All existing tests pass - New tests verify auto-fix behavior - Integration tested with simulated mismatches Closes: bd-afd
122 lines
2.6 KiB
Go
122 lines
2.6 KiB
Go
package configfile
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestDefaultConfig(t *testing.T) {
|
|
cfg := DefaultConfig()
|
|
|
|
if cfg.Database != "beads.db" {
|
|
t.Errorf("Database = %q, want beads.db", cfg.Database)
|
|
}
|
|
|
|
// bd-afd: Default changed from issues.jsonl to beads.jsonl (canonical name)
|
|
if cfg.JSONLExport != "beads.jsonl" {
|
|
t.Errorf("JSONLExport = %q, want beads.jsonl", cfg.JSONLExport)
|
|
}
|
|
}
|
|
|
|
func TestLoadSaveRoundtrip(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0750); err != nil {
|
|
t.Fatalf("failed to create .beads directory: %v", err)
|
|
}
|
|
|
|
cfg := DefaultConfig()
|
|
|
|
if err := cfg.Save(beadsDir); err != nil {
|
|
t.Fatalf("Save() failed: %v", err)
|
|
}
|
|
|
|
loaded, err := Load(beadsDir)
|
|
if err != nil {
|
|
t.Fatalf("Load() failed: %v", err)
|
|
}
|
|
|
|
if loaded == nil {
|
|
t.Fatal("Load() returned nil config")
|
|
}
|
|
|
|
if loaded.Database != cfg.Database {
|
|
t.Errorf("Database = %q, want %q", loaded.Database, cfg.Database)
|
|
}
|
|
|
|
if loaded.JSONLExport != cfg.JSONLExport {
|
|
t.Errorf("JSONLExport = %q, want %q", loaded.JSONLExport, cfg.JSONLExport)
|
|
}
|
|
}
|
|
|
|
func TestLoadNonexistent(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
|
|
cfg, err := Load(tmpDir)
|
|
if err != nil {
|
|
t.Fatalf("Load() returned error for nonexistent config: %v", err)
|
|
}
|
|
|
|
if cfg != nil {
|
|
t.Errorf("Load() = %v, want nil for nonexistent config", cfg)
|
|
}
|
|
}
|
|
|
|
func TestDatabasePath(t *testing.T) {
|
|
beadsDir := "/home/user/project/.beads"
|
|
cfg := &Config{Database: "beads.db"}
|
|
|
|
got := cfg.DatabasePath(beadsDir)
|
|
want := filepath.Join(beadsDir, "beads.db")
|
|
|
|
if got != want {
|
|
t.Errorf("DatabasePath() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestJSONLPath(t *testing.T) {
|
|
beadsDir := "/home/user/project/.beads"
|
|
|
|
tests := []struct {
|
|
name string
|
|
cfg *Config
|
|
want string
|
|
}{
|
|
{
|
|
name: "default",
|
|
cfg: &Config{JSONLExport: "issues.jsonl"},
|
|
want: filepath.Join(beadsDir, "issues.jsonl"),
|
|
},
|
|
{
|
|
name: "custom",
|
|
cfg: &Config{JSONLExport: "custom.jsonl"},
|
|
want: filepath.Join(beadsDir, "custom.jsonl"),
|
|
},
|
|
{
|
|
name: "empty falls back to default",
|
|
cfg: &Config{JSONLExport: ""},
|
|
want: filepath.Join(beadsDir, "issues.jsonl"),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := tt.cfg.JSONLPath(beadsDir)
|
|
if got != tt.want {
|
|
t.Errorf("JSONLPath() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestConfigPath(t *testing.T) {
|
|
beadsDir := "/home/user/project/.beads"
|
|
got := ConfigPath(beadsDir)
|
|
want := filepath.Join(beadsDir, "metadata.json")
|
|
|
|
if got != want {
|
|
t.Errorf("ConfigPath() = %q, want %q", got, want)
|
|
}
|
|
}
|