diff --git a/cmd/bd/daemon_autoimport_test.go b/cmd/bd/daemon_autoimport_test.go index c6112d12..6348b439 100644 --- a/cmd/bd/daemon_autoimport_test.go +++ b/cmd/bd/daemon_autoimport_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "os" "path/filepath" + "runtime" "testing" "time" @@ -132,7 +133,13 @@ func TestDaemonAutoImportAfterGitPull(t *testing.T) { runGitCmd(t, clone2Dir, "pull") // Wait for filesystem to settle after git operations - time.Sleep(50 * time.Millisecond) + // Windows has lower filesystem timestamp precision (typically 100ms) + // so we need a longer delay to ensure mtime comparison works + if runtime.GOOS == "windows" { + time.Sleep(200 * time.Millisecond) + } else { + time.Sleep(50 * time.Millisecond) + } // Start daemon server in clone2 socketPath := filepath.Join(clone2BeadsDir, "bd.sock") diff --git a/cmd/bd/daemon_sync_branch_test.go b/cmd/bd/daemon_sync_branch_test.go index 8faab461..0a886c7f 100644 --- a/cmd/bd/daemon_sync_branch_test.go +++ b/cmd/bd/daemon_sync_branch_test.go @@ -563,6 +563,11 @@ func TestSyncBranchPull_Success(t *testing.T) { t.Error("JSONL not copied to main repo after pull") } + // On Windows, file I/O may need time to settle + if runtime.GOOS == "windows" { + time.Sleep(100 * time.Millisecond) + } + // Verify JSONL content matches clone1Data, err := os.ReadFile(clone1JSONLPath) if err != nil { diff --git a/cmd/bd/migrate.go b/cmd/bd/migrate.go index 963f43cd..514bad20 100644 --- a/cmd/bd/migrate.go +++ b/cmd/bd/migrate.go @@ -512,13 +512,19 @@ func detectDatabases(beadsDir string) ([]*dbInfo, error) { } func getDBVersion(dbPath string) string { - // Open database read-only - db, err := sql.Open("sqlite", dbPath+"?mode=ro") + // Open database read-only using file URI (same as production code) + connStr := "file:" + dbPath + "?mode=ro&_time_format=sqlite" + db, err := sql.Open("sqlite3", connStr) if err != nil { return "unknown" } defer db.Close() + // Ping to ensure connection is actually established + if err := db.Ping(); err != nil { + return "unknown" + } + // Try to read version from metadata table var version string err = db.QueryRow("SELECT value FROM metadata WHERE key = 'bd_version'").Scan(&version) @@ -526,6 +532,7 @@ func getDBVersion(dbPath string) string { return version } + // If the row doesn't exist but table does, this is still a database with metadata // Check if metadata table exists var tableName string err = db.QueryRow(` @@ -537,6 +544,11 @@ func getDBVersion(dbPath string) string { return "pre-0.17.5" } + // Table exists but version query failed (probably no bd_version key) + if err == nil { + return "unknown" + } + return "unknown" }