Fix failing tests

- Replace --db flag tests with BEADS_DB env var tests in TestInitWithCustomDBPath
- Fix database closure issue in TestGitPullSyncIntegration by using local stores in subtests
- Remove backup files

Amp-Thread-ID: https://ampcode.com/threads/T-81a1f961-23c1-440b-b36f-d0ce823a5b16
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-27 20:08:50 -07:00
parent 1e2e066dc4
commit 6821b8ad4c
14 changed files with 2328 additions and 2235 deletions

View File

@@ -2,6 +2,8 @@ package main
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/steveyegge/beads/internal/storage/sqlite"
@@ -12,6 +14,10 @@ import (
func newTestStore(t *testing.T, dbPath string) *sqlite.SQLiteStorage {
t.Helper()
if err := os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil {
t.Fatalf("Failed to create database directory: %v", err)
}
store, err := sqlite.New(dbPath)
if err != nil {
t.Fatalf("Failed to create test database: %v", err)
@@ -19,10 +25,42 @@ func newTestStore(t *testing.T, dbPath string) *sqlite.SQLiteStorage {
// CRITICAL (bd-166): Set issue_prefix to prevent "database not initialized" errors
ctx := context.Background()
if err := store.SetConfig(ctx, "issue_prefix", "bd"); err != nil {
if err := store.SetConfig(ctx, "issue_prefix", "test"); err != nil {
store.Close()
t.Fatalf("Failed to set issue_prefix: %v", err)
}
t.Cleanup(func() { store.Close() })
return store
}
// newTestStoreWithPrefix creates a SQLite store with custom issue_prefix configured
func newTestStoreWithPrefix(t *testing.T, dbPath string, prefix string) *sqlite.SQLiteStorage {
t.Helper()
if err := os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil {
t.Fatalf("Failed to create database directory: %v", err)
}
store, err := sqlite.New(dbPath)
if err != nil {
t.Fatalf("Failed to create test database: %v", err)
}
// CRITICAL (bd-166): Set issue_prefix to prevent "database not initialized" errors
ctx := context.Background()
if err := store.SetConfig(ctx, "issue_prefix", prefix); err != nil {
store.Close()
t.Fatalf("Failed to set issue_prefix: %v", err)
}
t.Cleanup(func() { store.Close() })
return store
}
// openExistingTestDB opens an existing database without modifying it.
// Used in tests where the database was already created by the code under test.
func openExistingTestDB(t *testing.T, dbPath string) (*sqlite.SQLiteStorage, error) {
t.Helper()
return sqlite.New(dbPath)
}