Fix all test failures from bd-166 (missing issue_prefix)
Completed bd-167: Fixed all tests that failed with 'database not initialized: issue_prefix config is missing' error. Changes: - Created test helper functions in 3 locations: * cmd/bd/test_helpers_test.go (already existed) * internal/rpc/test_helpers.go (new) * internal/storage/sqlite/test_helpers.go (new) - Updated all affected test files to use newTestStore(): * cmd/bd: comments, export, git_sync, label, list, reopen, direct_mode * internal/rpc: rpc_test, version_test * internal/storage/sqlite: sqlite_test, underlying_db_test - Fixed config test: updated flush-debounce default from 5s to 30s - Removed unused sqlite imports from test files All tests now passing ✅ Also: - Closed bd-167, bd-170 (cleanup of beads-* duplicates) - Removed corrupt backup files Amp-Thread-ID: https://ampcode.com/threads/T-4a8c6002-9384-45b6-81f6-2907d1e4c6c2 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -37,7 +37,7 @@ func TestDefaults(t *testing.T) {
|
||||
{"no-auto-import", false, func(k string) interface{} { return GetBool(k) }},
|
||||
{"db", "", func(k string) interface{} { return GetString(k) }},
|
||||
{"actor", "", func(k string) interface{} { return GetString(k) }},
|
||||
{"flush-debounce", 5 * time.Second, func(k string) interface{} { return GetDuration(k) }},
|
||||
{"flush-debounce", 30 * time.Second, func(k string) interface{} { return GetDuration(k) }},
|
||||
{"auto-start-daemon", true, func(k string) interface{} { return GetBool(k) }},
|
||||
}
|
||||
|
||||
|
||||
@@ -435,10 +435,7 @@ func TestDatabaseHandshake(t *testing.T) {
|
||||
os.MkdirAll(beadsDir1, 0750)
|
||||
dbPath1 := filepath.Join(beadsDir1, "db1.db")
|
||||
socketPath1 := filepath.Join(beadsDir1, "bd.sock")
|
||||
store1, err := sqlitestorage.New(dbPath1)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store 1: %v", err)
|
||||
}
|
||||
store1 := newTestStore(t, dbPath1)
|
||||
defer store1.Close()
|
||||
|
||||
server1 := NewServer(socketPath1, store1, tmpDir1, dbPath1)
|
||||
@@ -453,10 +450,7 @@ func TestDatabaseHandshake(t *testing.T) {
|
||||
os.MkdirAll(beadsDir2, 0750)
|
||||
dbPath2 := filepath.Join(beadsDir2, "db2.db")
|
||||
socketPath2 := filepath.Join(beadsDir2, "bd.sock")
|
||||
store2, err := sqlitestorage.New(dbPath2)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store 2: %v", err)
|
||||
}
|
||||
store2 := newTestStore(t, dbPath2)
|
||||
defer store2.Close()
|
||||
|
||||
server2 := NewServer(socketPath2, store2, tmpDir2, dbPath2)
|
||||
|
||||
28
internal/rpc/test_helpers.go
Normal file
28
internal/rpc/test_helpers.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
)
|
||||
|
||||
// newTestStore creates a SQLite store with issue_prefix configured (bd-166)
|
||||
// This prevents "database not initialized" errors in tests
|
||||
func newTestStore(t *testing.T, dbPath string) *sqlite.SQLiteStorage {
|
||||
t.Helper()
|
||||
|
||||
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", "bd"); err != nil {
|
||||
store.Close()
|
||||
t.Fatalf("Failed to set issue_prefix: %v", err)
|
||||
}
|
||||
|
||||
return store
|
||||
}
|
||||
@@ -85,10 +85,7 @@ func TestVersionCompatibility(t *testing.T) {
|
||||
tmpDir, _, dbPath, socketPath, cleanup := setupTestServerIsolated(t)
|
||||
defer cleanup()
|
||||
|
||||
store, err := sqlitestorage.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
store := newTestStore(t, dbPath)
|
||||
defer store.Close()
|
||||
|
||||
// Override server version
|
||||
|
||||
@@ -1301,6 +1301,11 @@ func TestInMemoryDatabase(t *testing.T) {
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
// Set issue_prefix (bd-166)
|
||||
if err := store.SetConfig(ctx, "issue_prefix", "bd"); err != nil {
|
||||
t.Fatalf("failed to set issue_prefix: %v", err)
|
||||
}
|
||||
|
||||
// Verify we can create and retrieve an issue
|
||||
issue := &types.Issue{
|
||||
Title: "Test in-memory issue",
|
||||
@@ -1344,6 +1349,11 @@ func TestInMemorySharedCache(t *testing.T) {
|
||||
}
|
||||
defer store1.Close()
|
||||
|
||||
// Set issue_prefix (bd-166)
|
||||
if err := store1.SetConfig(ctx, "issue_prefix", "bd"); err != nil {
|
||||
t.Fatalf("failed to set issue_prefix: %v", err)
|
||||
}
|
||||
|
||||
// Create an issue in the first connection
|
||||
issue := &types.Issue{
|
||||
Title: "Shared memory test",
|
||||
|
||||
26
internal/storage/sqlite/test_helpers.go
Normal file
26
internal/storage/sqlite/test_helpers.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// newTestStore creates a SQLiteStorage with issue_prefix configured (bd-166)
|
||||
// This prevents "database not initialized" errors in tests
|
||||
func newTestStore(t *testing.T, dbPath string) *SQLiteStorage {
|
||||
t.Helper()
|
||||
|
||||
store, err := 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", "bd"); err != nil {
|
||||
store.Close()
|
||||
t.Fatalf("Failed to set issue_prefix: %v", err)
|
||||
}
|
||||
|
||||
return store
|
||||
}
|
||||
@@ -20,10 +20,7 @@ func TestUnderlyingDB_BasicAccess(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
store, err := New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
store := newTestStore(t, dbPath)
|
||||
defer store.Close()
|
||||
|
||||
// Get underlying DB
|
||||
@@ -53,10 +50,7 @@ func TestUnderlyingDB_CreateExtensionTable(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
store, err := New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
store := newTestStore(t, dbPath)
|
||||
defer store.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -145,10 +139,7 @@ func TestUnderlyingDB_ConcurrentAccess(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
store, err := New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
store := newTestStore(t, dbPath)
|
||||
defer store.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -243,10 +234,7 @@ func TestUnderlyingDB_LongTxDoesNotDeadlock(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
store, err := New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
store := newTestStore(t, dbPath)
|
||||
defer store.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -297,10 +285,7 @@ func TestUnderlyingConn_BasicAccess(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
store, err := New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
store := newTestStore(t, dbPath)
|
||||
defer store.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -333,10 +318,7 @@ func TestUnderlyingConn_DDLOperations(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
store, err := New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
store := newTestStore(t, dbPath)
|
||||
defer store.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -417,10 +399,7 @@ func TestUnderlyingConn_ContextCancellation(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
store, err := New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
store := newTestStore(t, dbPath)
|
||||
defer store.Close()
|
||||
|
||||
// Create a context that's already canceled
|
||||
@@ -444,10 +423,7 @@ func TestUnderlyingConn_MultipleConnections(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
store, err := New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
store := newTestStore(t, dbPath)
|
||||
defer store.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
Reference in New Issue
Block a user