Fix remaining test database initialization errors (bd-207)
Fixed 38 tests failing with 'database not initialized: issue_prefix config is missing' by replacing manual sqlite.New() calls with test helper functions. Modified files: - dep_test.go (4 tests) - merge_test.go (4 tests) - export_import_test.go (4 instances) - import_collision_test.go (10 instances) - import_bug_test.go (1 instance) - import_collision_regression_test.go (2 instances) - import_idempotent_test.go (2 instances) - init_test.go (4 instances) - integrity_test.go (3 tests) - main_test.go (multiple tests) All database initialization errors are now resolved. Remaining test failures (2) are unrelated to database initialization. Amp-Thread-ID: https://ampcode.com/threads/T-a6b09458-b899-49eb-9a62-346fa67f62c7 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -3,12 +3,10 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
@@ -16,15 +14,7 @@ func TestDepAdd(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dbPath := filepath.Join(tmpDir, ".beads", "beads.db")
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sqliteStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer sqliteStore.Close()
|
||||
sqliteStore := newTestStore(t, dbPath)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -85,15 +75,7 @@ func TestDepTypes(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dbPath := filepath.Join(tmpDir, ".beads", "beads.db")
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sqliteStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer sqliteStore.Close()
|
||||
sqliteStore := newTestStore(t, dbPath)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -142,15 +124,7 @@ func TestDepCycleDetection(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dbPath := filepath.Join(tmpDir, ".beads", "beads.db")
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sqliteStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer sqliteStore.Close()
|
||||
sqliteStore := newTestStore(t, dbPath)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -235,15 +209,7 @@ func TestDepRemove(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dbPath := filepath.Join(tmpDir, ".beads", "beads.db")
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sqliteStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer sqliteStore.Close()
|
||||
sqliteStore := newTestStore(t, dbPath)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -134,22 +133,9 @@ func (h *exportImportHelper) validateJSONLines(buf *bytes.Buffer, expectedCount
|
||||
}
|
||||
|
||||
func TestExportImport(t *testing.T) {
|
||||
// Create temp directory for test database
|
||||
tmpDir, err := os.MkdirTemp("", "bd-test-*")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp dir: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := os.RemoveAll(tmpDir); err != nil {
|
||||
t.Logf("Warning: cleanup failed: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
store := newTestStoreWithPrefix(t, dbPath, "test")
|
||||
|
||||
h := newExportImportHelper(t, store)
|
||||
now := time.Now()
|
||||
@@ -177,10 +163,7 @@ func TestExportImport(t *testing.T) {
|
||||
t.Run("Import", func(t *testing.T) {
|
||||
exported := h.searchIssues(types.IssueFilter{})
|
||||
newDBPath := filepath.Join(tmpDir, "import-test.db")
|
||||
newStore, err := sqlite.New(newDBPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create new storage: %v", err)
|
||||
}
|
||||
newStore := newTestStoreWithPrefix(t, newDBPath, "test")
|
||||
newHelper := newExportImportHelper(t, newStore)
|
||||
for _, issue := range exported {
|
||||
newHelper.createIssue(issue.ID, issue.Title, issue.Description, issue.Status, issue.Priority, issue.IssueType, issue.Assignee, issue.ClosedAt)
|
||||
@@ -216,22 +199,9 @@ func TestExportImport(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExportEmpty(t *testing.T) {
|
||||
tmpDir, err := os.MkdirTemp("", "bd-test-*")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp dir: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := os.RemoveAll(tmpDir); err != nil {
|
||||
t.Logf("Warning: cleanup failed: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
dbPath := filepath.Join(tmpDir, "empty.db")
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
|
||||
store := newTestStore(t, dbPath)
|
||||
ctx := context.Background()
|
||||
|
||||
// Export from empty database
|
||||
@@ -263,23 +233,9 @@ func TestImportInvalidJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRoundTrip(t *testing.T) {
|
||||
// Create original database
|
||||
tmpDir, err := os.MkdirTemp("", "bd-test-*")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp dir: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := os.RemoveAll(tmpDir); err != nil {
|
||||
t.Logf("Warning: cleanup failed: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
dbPath := filepath.Join(tmpDir, "original.db")
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
|
||||
store := newTestStoreWithPrefix(t, dbPath, "test")
|
||||
h := newExportImportHelper(t, store)
|
||||
original := h.createFullIssue("test-1", 120)
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
@@ -22,16 +21,8 @@ func TestImportReturnsCorrectCounts(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dbPath := filepath.Join(tmpDir, ".beads", "issues.db")
|
||||
if err := os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil {
|
||||
t.Fatalf("Failed to create .beads dir: %v", err)
|
||||
}
|
||||
|
||||
// Initialize database
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
store := newTestStore(t, dbPath)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -32,11 +32,7 @@ func TestRemapCollisionsRemapsImportedNotExisting(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create storage: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
store := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -201,11 +197,7 @@ func TestRemapCollisionsDoesNotUpdateNonexistentDependencies(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create storage: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
store := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -27,15 +27,7 @@ func TestImportSimpleCollision(t *testing.T) {
|
||||
}()
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := testStore.Close(); err != nil {
|
||||
t.Logf("Warning: failed to close store: %v", err)
|
||||
}
|
||||
}()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -139,15 +131,7 @@ func TestImportMultipleCollisions(t *testing.T) {
|
||||
}()
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := testStore.Close(); err != nil {
|
||||
t.Logf("Warning: failed to close store: %v", err)
|
||||
}
|
||||
}()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -253,15 +237,7 @@ func TestImportDependencyUpdates(t *testing.T) {
|
||||
}()
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := testStore.Close(); err != nil {
|
||||
t.Logf("Warning: failed to close store: %v", err)
|
||||
}
|
||||
}()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -399,15 +375,7 @@ func TestImportTextReferenceUpdates(t *testing.T) {
|
||||
}()
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := testStore.Close(); err != nil {
|
||||
t.Logf("Warning: failed to close store: %v", err)
|
||||
}
|
||||
}()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -546,15 +514,7 @@ func TestImportChainDependencies(t *testing.T) {
|
||||
}()
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := testStore.Close(); err != nil {
|
||||
t.Logf("Warning: failed to close store: %v", err)
|
||||
}
|
||||
}()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -648,15 +608,7 @@ func TestImportPartialIDMatch(t *testing.T) {
|
||||
}()
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := testStore.Close(); err != nil {
|
||||
t.Logf("Warning: failed to close store: %v", err)
|
||||
}
|
||||
}()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -771,15 +723,7 @@ func TestImportExactMatch(t *testing.T) {
|
||||
}()
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := testStore.Close(); err != nil {
|
||||
t.Logf("Warning: failed to close store: %v", err)
|
||||
}
|
||||
}()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -836,15 +780,7 @@ func TestImportMixedScenario(t *testing.T) {
|
||||
}()
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := testStore.Close(); err != nil {
|
||||
t.Logf("Warning: failed to close store: %v", err)
|
||||
}
|
||||
}()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -922,15 +858,7 @@ func TestImportWithDependenciesInJSONL(t *testing.T) {
|
||||
}()
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := testStore.Close(); err != nil {
|
||||
t.Logf("Warning: failed to close store: %v", err)
|
||||
}
|
||||
}()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -989,15 +917,7 @@ func TestImportCounterSyncAfterHighID(t *testing.T) {
|
||||
}()
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := testStore.Close(); err != nil {
|
||||
t.Logf("Warning: failed to close store: %v", err)
|
||||
}
|
||||
}()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
@@ -230,11 +229,7 @@ func TestIdempotentImportNoTimestampChurn(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create store
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
@@ -316,11 +311,7 @@ func TestImportMultipleUnchangedIssues(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create store
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
|
||||
@@ -7,8 +7,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
)
|
||||
|
||||
func TestInitCommand(t *testing.T) {
|
||||
@@ -150,14 +148,15 @@ func TestInitCommand(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify database has correct prefix
|
||||
store, err := sqlite.New(dbPath)
|
||||
// Note: This database was already created by init command, just open it
|
||||
store, err := openExistingTestDB(t, dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to open created database: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
t.Fatalf("Failed to open database: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
prefix, err := store.GetConfig(ctx, "issue_prefix")
|
||||
ctx := context.Background()
|
||||
prefix, err := store.GetConfig(ctx, "issue_prefix")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get issue prefix from database: %v", err)
|
||||
}
|
||||
@@ -221,9 +220,9 @@ func TestInitAlreadyInitialized(t *testing.T) {
|
||||
|
||||
// Verify database still works (always beads.db now)
|
||||
dbPath := filepath.Join(tmpDir, ".beads", "beads.db")
|
||||
store, err := sqlite.New(dbPath)
|
||||
store, err := openExistingTestDB(t, dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to open database after re-init: %v", err)
|
||||
t.Fatalf("Failed to open database: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
@@ -279,7 +278,7 @@ func TestInitWithCustomDBPath(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify database works
|
||||
store, err := sqlite.New(customDBPath)
|
||||
store, err := openExistingTestDB(t, customDBPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to open database: %v", err)
|
||||
}
|
||||
@@ -320,7 +319,7 @@ func TestInitWithCustomDBPath(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify database works
|
||||
store, err := sqlite.New(envDBPath)
|
||||
store, err := openExistingTestDB(t, envDBPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to open database: %v", err)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
@@ -20,11 +19,7 @@ func TestValidatePreExport(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create empty database
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
store := newTestStore(t, dbPath)
|
||||
|
||||
// Create non-empty JSONL file
|
||||
jsonlContent := `{"id":"bd-1","title":"Test","status":"open","priority":1}
|
||||
@@ -34,7 +29,7 @@ func TestValidatePreExport(t *testing.T) {
|
||||
}
|
||||
|
||||
// Should fail validation
|
||||
err = validatePreExport(ctx, store, jsonlPath)
|
||||
err := validatePreExport(ctx, store, jsonlPath)
|
||||
if err == nil {
|
||||
t.Error("Expected error for empty DB over non-empty JSONL, got nil")
|
||||
}
|
||||
@@ -47,13 +42,10 @@ func TestValidatePreExport(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create database with issues
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
store := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
// Add an issue
|
||||
ctx := context.Background()
|
||||
issue := &types.Issue{
|
||||
ID: "bd-1",
|
||||
Title: "Test",
|
||||
@@ -74,7 +66,7 @@ func TestValidatePreExport(t *testing.T) {
|
||||
}
|
||||
|
||||
// Should pass validation
|
||||
err = validatePreExport(ctx, store, jsonlPath)
|
||||
err := validatePreExport(ctx, store, jsonlPath)
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, got: %v", err)
|
||||
}
|
||||
@@ -87,16 +79,12 @@ func TestValidatePreExport(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create empty database
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
store := newTestStore(t, dbPath)
|
||||
|
||||
// JSONL doesn't exist
|
||||
|
||||
// Should pass validation (new repo scenario)
|
||||
err = validatePreExport(ctx, store, jsonlPath)
|
||||
err := validatePreExport(ctx, store, jsonlPath)
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error for empty DB with no JSONL, got: %v", err)
|
||||
}
|
||||
@@ -109,11 +97,7 @@ func TestValidatePreExport(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create empty database
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
store := newTestStore(t, dbPath)
|
||||
|
||||
// Create corrupt/unreadable JSONL file with content
|
||||
corruptContent := `{"id":"bd-1","title":INVALID JSON`
|
||||
@@ -122,7 +106,7 @@ func TestValidatePreExport(t *testing.T) {
|
||||
}
|
||||
|
||||
// Should fail validation (can't verify JSONL content, DB is empty, file has content)
|
||||
err = validatePreExport(ctx, store, jsonlPath)
|
||||
err := validatePreExport(ctx, store, jsonlPath)
|
||||
if err == nil {
|
||||
t.Error("Expected error for empty DB over unreadable non-empty JSONL, got nil")
|
||||
}
|
||||
@@ -153,20 +137,15 @@ func TestValidatePostImport(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCountDBIssues(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("count issues in database", func(t *testing.T) {
|
||||
// Create temp directory
|
||||
tmpDir := t.TempDir()
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
|
||||
// Create database
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
store := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
// Initially 0
|
||||
count, err := countDBIssues(ctx, store)
|
||||
if err != nil {
|
||||
@@ -203,20 +182,15 @@ func TestCountDBIssues(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckOrphanedDeps(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("function executes without error", func(t *testing.T) {
|
||||
// Create temp directory
|
||||
tmpDir := t.TempDir()
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
|
||||
// Create database
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
store := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
// Create two issues
|
||||
issue1 := &types.Issue{
|
||||
ID: "bd-1",
|
||||
@@ -272,12 +246,9 @@ func TestCheckOrphanedDeps(t *testing.T) {
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
|
||||
// Create database
|
||||
store, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
store := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
// Create two issues
|
||||
issue1 := &types.Issue{
|
||||
ID: "bd-1",
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
@@ -103,11 +102,7 @@ func TestAutoFlushDebounce(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create store
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStore(t, dbPath)
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
@@ -232,10 +227,7 @@ func TestAutoFlushOnExit(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create store
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
testStore := newTestStore(t, dbPath)
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
@@ -411,10 +403,7 @@ func TestAutoFlushStoreInactive(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create store
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
testStore := newTestStore(t, dbPath)
|
||||
|
||||
store = testStore
|
||||
|
||||
@@ -457,11 +446,7 @@ func TestAutoFlushJSONLContent(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create store
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStore(t, dbPath)
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
@@ -577,11 +562,7 @@ func TestAutoFlushErrorHandling(t *testing.T) {
|
||||
dbPath = filepath.Join(tmpDir, "test.db")
|
||||
|
||||
// Create store
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStore(t, dbPath)
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
@@ -686,11 +667,7 @@ func TestAutoImportIfNewer(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create store
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStore(t, dbPath)
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
@@ -786,11 +763,7 @@ func TestAutoImportDisabled(t *testing.T) {
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
// Create store
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStore(t, dbPath)
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
@@ -863,11 +836,7 @@ func TestAutoImportWithCollision(t *testing.T) {
|
||||
dbPath = filepath.Join(tmpDir, "test.db")
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStore(t, dbPath)
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
@@ -942,11 +911,7 @@ func TestAutoImportNoCollision(t *testing.T) {
|
||||
dbPath = filepath.Join(tmpDir, "test.db")
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStore(t, dbPath)
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
@@ -1020,11 +985,7 @@ func TestAutoImportMergeConflict(t *testing.T) {
|
||||
dbPath = filepath.Join(tmpDir, "test.db")
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStore(t, dbPath)
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
@@ -1104,11 +1065,7 @@ func TestAutoImportClosedAtInvariant(t *testing.T) {
|
||||
dbPath = filepath.Join(tmpDir, "test.db")
|
||||
jsonlPath := filepath.Join(tmpDir, "issues.jsonl")
|
||||
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStore(t, dbPath)
|
||||
|
||||
store = testStore
|
||||
storeMutex.Lock()
|
||||
@@ -1167,19 +1124,10 @@ func TestImportOpenToClosedTransition(t *testing.T) {
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Initialize database with prefix
|
||||
if err := testStore.SetConfig(ctx, "issue_prefix", "bd"); err != nil {
|
||||
t.Fatalf("Failed to set issue_prefix: %v", err)
|
||||
}
|
||||
|
||||
// Step 1: Create an open issue in the database
|
||||
openIssue := &types.Issue{
|
||||
ID: "bd-transition-1",
|
||||
@@ -1233,19 +1181,10 @@ func TestImportClosedToOpenTransition(t *testing.T) {
|
||||
|
||||
dbPath := filepath.Join(tmpDir, "test.db")
|
||||
|
||||
testStore, err := sqlite.New(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
testStore := newTestStoreWithPrefix(t, dbPath, "bd")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Initialize database with prefix
|
||||
if err := testStore.SetConfig(ctx, "issue_prefix", "bd"); err != nil {
|
||||
t.Fatalf("Failed to set issue_prefix: %v", err)
|
||||
}
|
||||
|
||||
// Step 1: Create a closed issue in the database
|
||||
closedTime := time.Now()
|
||||
closedIssue := &types.Issue{
|
||||
|
||||
@@ -2,27 +2,17 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
func TestValidateMerge(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dbFile := filepath.Join(tmpDir, ".beads", "issues.db")
|
||||
if err := os.MkdirAll(filepath.Dir(dbFile), 0755); err != nil {
|
||||
t.Fatalf("Failed to create test directory: %v", err)
|
||||
}
|
||||
|
||||
testStore, err := sqlite.New(dbFile)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
|
||||
|
||||
testStore := newTestStoreWithPrefix(t, dbFile, "bd")
|
||||
store = testStore
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -52,13 +42,13 @@ func TestValidateMerge(t *testing.T) {
|
||||
Status: types.StatusOpen,
|
||||
}
|
||||
|
||||
if err := testStore.CreateIssue(ctx, issue1, "test"); err != nil {
|
||||
if err := testStore.CreateIssue(ctx, issue1, "bd"); err != nil {
|
||||
t.Fatalf("Failed to create issue1: %v", err)
|
||||
}
|
||||
if err := testStore.CreateIssue(ctx, issue2, "test"); err != nil {
|
||||
if err := testStore.CreateIssue(ctx, issue2, "bd"); err != nil {
|
||||
t.Fatalf("Failed to create issue2: %v", err)
|
||||
}
|
||||
if err := testStore.CreateIssue(ctx, issue3, "test"); err != nil {
|
||||
if err := testStore.CreateIssue(ctx, issue3, "bd"); err != nil {
|
||||
t.Fatalf("Failed to create issue3: %v", err)
|
||||
}
|
||||
|
||||
@@ -132,16 +122,8 @@ func TestValidateMerge(t *testing.T) {
|
||||
func TestValidateMergeMultipleSelfReferences(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dbFile := filepath.Join(tmpDir, ".beads", "issues.db")
|
||||
if err := os.MkdirAll(filepath.Dir(dbFile), 0755); err != nil {
|
||||
t.Fatalf("Failed to create test directory: %v", err)
|
||||
}
|
||||
|
||||
testStore, err := sqlite.New(dbFile)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
|
||||
|
||||
testStore := newTestStoreWithPrefix(t, dbFile, "bd")
|
||||
store = testStore
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -154,12 +136,12 @@ func TestValidateMergeMultipleSelfReferences(t *testing.T) {
|
||||
Status: types.StatusOpen,
|
||||
}
|
||||
|
||||
if err := testStore.CreateIssue(ctx, issue1, "test"); err != nil {
|
||||
if err := testStore.CreateIssue(ctx, issue1, "bd"); err != nil {
|
||||
t.Fatalf("Failed to create issue: %v", err)
|
||||
}
|
||||
|
||||
// Test merging multiple instances of same ID (should catch first one)
|
||||
err = validateMerge("bd-10", []string{"bd-10", "bd-10"})
|
||||
err := validateMerge("bd-10", []string{"bd-10", "bd-10"})
|
||||
if err == nil {
|
||||
t.Error("validateMerge() expected error for duplicate self-merge, got nil")
|
||||
}
|
||||
@@ -185,16 +167,8 @@ func containsSubstring(s, substr string) bool {
|
||||
func TestPerformMergeIdempotent(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dbFile := filepath.Join(tmpDir, ".beads", "issues.db")
|
||||
if err := os.MkdirAll(filepath.Dir(dbFile), 0755); err != nil {
|
||||
t.Fatalf("Failed to create test directory: %v", err)
|
||||
}
|
||||
|
||||
testStore, err := sqlite.New(dbFile)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
|
||||
|
||||
testStore := newTestStoreWithPrefix(t, dbFile, "bd")
|
||||
store = testStore
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -225,7 +199,7 @@ func TestPerformMergeIdempotent(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, issue := range []*types.Issue{issue1, issue2, issue3} {
|
||||
if err := testStore.CreateIssue(ctx, issue, "test"); err != nil {
|
||||
if err := testStore.CreateIssue(ctx, issue, "bd"); err != nil {
|
||||
t.Fatalf("Failed to create issue %s: %v", issue.ID, err)
|
||||
}
|
||||
}
|
||||
@@ -239,7 +213,7 @@ func TestPerformMergeIdempotent(t *testing.T) {
|
||||
IssueType: types.TypeTask,
|
||||
Status: types.StatusOpen,
|
||||
}
|
||||
if err := testStore.CreateIssue(ctx, issue4, "test"); err != nil {
|
||||
if err := testStore.CreateIssue(ctx, issue4, "bd"); err != nil {
|
||||
t.Fatalf("Failed to create issue4: %v", err)
|
||||
}
|
||||
|
||||
@@ -305,16 +279,8 @@ func TestPerformMergeIdempotent(t *testing.T) {
|
||||
func TestPerformMergePartialRetry(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dbFile := filepath.Join(tmpDir, ".beads", "issues.db")
|
||||
if err := os.MkdirAll(filepath.Dir(dbFile), 0755); err != nil {
|
||||
t.Fatalf("Failed to create test directory: %v", err)
|
||||
}
|
||||
|
||||
testStore, err := sqlite.New(dbFile)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test storage: %v", err)
|
||||
}
|
||||
defer testStore.Close()
|
||||
|
||||
|
||||
testStore := newTestStoreWithPrefix(t, dbFile, "bd")
|
||||
store = testStore
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -345,13 +311,13 @@ func TestPerformMergePartialRetry(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, issue := range []*types.Issue{issue1, issue2, issue3} {
|
||||
if err := testStore.CreateIssue(ctx, issue, "test"); err != nil {
|
||||
if err := testStore.CreateIssue(ctx, issue, "bd"); err != nil {
|
||||
t.Fatalf("Failed to create issue %s: %v", issue.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Simulate partial failure: manually close one source issue
|
||||
if err := testStore.CloseIssue(ctx, "bd-201", "Manually closed", "test"); err != nil {
|
||||
if err := testStore.CloseIssue(ctx, "bd-201", "Manually closed", "bd"); err != nil {
|
||||
t.Fatalf("Failed to manually close bd-201: %v", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user