From 2ef3bd8c66df35278ad80c1b048ece7baac4ccc3 Mon Sep 17 00:00:00 2001 From: Jim Wordelman Date: Sat, 26 Sep 2026 07:34:49 -0700 Subject: [PATCH] fix: 36 raw dolt.New(&Config{Path}) test sites in cmd/bd silently skip (#6679) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: green — fix 36 raw dolt.New(&Config{Path}) test sites in cmd/bd silently skip (refs be-0k0dv) Converts all 36 raw dolt.New(ctx, &dolt.Config{Path: ...}) call sites in cmd/bd test files to the newTestStore/newTestStoreWithPrefix/ newTestStoreIsolatedDB helpers, which set CreateIfMissing: true. Without this, missing databases caused t.Skipf("Dolt server not available") even though the real cause was a missing DB, not a missing server — silently hiding real coverage since 63418ae54's CreateIfMissing migration. - cmd/bd/mol_test.go: 31 sites (26 -> newTestStore, 5 -> newTestStoreWithPrefix) - cmd/bd/contributor_routing_e2e_test.go: 3 sites -> newTestStoreIsolatedDB - cmd/bd/update_metadata_test.go: 1 site -> newTestStoreWithPrefix - cmd/bd/rename_prefix_repair_test.go: 1 site -> newTestStore Removed now-unused dolt imports where no other dolt.* usage remained in file (mol_test.go, update_metadata_test.go, rename_prefix_repair_test.go). contributor_routing_e2e_test.go keeps its dolt import — still used by initProjectStore/initPlanningStore and struct fields outside the 36 converted sites. * fix(test): finish contributor_routing_e2e_test.go's conversion; stop dbPath lying Maintainer adoption fixup for PR #6679 (adoption review iteration 1). contributor_routing_e2e_test.go converted 3 of its 7 raw dolt.New(&dolt.Config{Path}) sites, leaving 4 — so one file carried two different failure contracts for the same condition, and the harness that backs most of the file's tests was still on the broken one. Convert the remaining 4 to newTestStoreIsolatedDB: initProjectStore ("proj-"), initPlanningStore ("plan-"), and the override/external stores in TestExplicitRepoOverride ("over-") and TestBEADS_DIRPrecedence ("ext-"). Each replaced SetConfig(ctx, "issue_prefix", X) is reproduced by the helper's prefix argument, and the co-located defer store.Close() calls go with the sites the helper's t.Cleanup now covers. Effect: 9 routing tests stop silently skipping. Before, at the contributor head, TestContributorRoutingDirect / TestExplicitRepoOverride / TestBEADS_DIRPrecedence all reported skipping: Dolt server not available: database "testdb_…" not found against a live Dolt container. After, all 12 test functions in the file PASS with 0 skips under -tags integration,gms_pure_go. rename_prefix_repair_test.go: drop the unused global dbPath save/set/restore. newTestStore's shared-branch path writes a metadata.json naming the shared database with no branch qualifier while the live store sits on a per-test branch, so setting the global to testDBPath planted the reopen-by-path hazard the helper's own doc comment warns about. repairPrefixes takes the store explicitly and never reopens by path, so the assignment was dead weight pointing somewhere wrong; the comment now records why it is absent. Remaining out of scope (tracked for follow-up): 10 raw sites in config_test.go, sql_test.go, cli_coverage_show_test.go, rename_prefix_test.go, migrate_test.go, and mol_ready_gated_test.go. --------- Co-authored-by: Julian Knutsen --- cmd/bd/contributor_routing_e2e_test.go | 60 +----- cmd/bd/mol_test.go | 280 +++---------------------- cmd/bd/rename_prefix_repair_test.go | 24 +-- cmd/bd/update_metadata_test.go | 12 +- 4 files changed, 48 insertions(+), 328 deletions(-) diff --git a/cmd/bd/contributor_routing_e2e_test.go b/cmd/bd/contributor_routing_e2e_test.go index a5bfb5239..4038bb9c1 100644 --- a/cmd/bd/contributor_routing_e2e_test.go +++ b/cmd/bd/contributor_routing_e2e_test.go @@ -100,11 +100,7 @@ func TestContributorRoutingTracer(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() - projectStore, err := dolt.New(ctx, &dolt.Config{Path: projectDBPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer projectStore.Close() + projectStore := newTestStoreIsolatedDB(t, projectDBPath, "test") // Set routing config in project store (canonical keys) if err := projectStore.SetConfig(ctx, "routing.mode", "auto"); err != nil { @@ -151,16 +147,7 @@ func TestContributorRoutingTracer(t *testing.T) { // Initialize planning database and verify we can create issues there planningDBPath := filepath.Join(planningBeadsDir, "beads.db") - planningStore, err := dolt.New(ctx, &dolt.Config{Path: planningDBPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer planningStore.Close() - - // Initialize planning store with required config - if err := planningStore.SetConfig(ctx, "issue_prefix", "plan-"); err != nil { - t.Fatalf("failed to set issue_prefix in planning store: %v", err) - } + planningStore := newTestStoreIsolatedDB(t, planningDBPath, "plan-") // Create a test issue in planning store (simulating what Phase 2 will do) issue := &types.Issue{ @@ -205,11 +192,7 @@ func TestBackwardCompatContributorConfig(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() - store, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer store.Close() + store := newTestStoreIsolatedDB(t, dbPath, "test") // Set LEGACY contributor.* keys (what old versions of bd init --contributor would set) if err := store.SetConfig(ctx, "contributor.auto_route", "true"); err != nil { @@ -309,10 +292,7 @@ func (env *contributorRoutingEnv) cleanup() { func (env *contributorRoutingEnv) initProjectStore(syncMode string) *dolt.DoltStore { env.t.Helper() projectDBPath := filepath.Join(env.projectDir, ".beads", "beads.db") - store, err := dolt.New(env.ctx, &dolt.Config{Path: projectDBPath}) - if err != nil { - env.t.Skipf("skipping: Dolt server not available: %v", err) - } + store := newTestStoreIsolatedDB(env.t, projectDBPath, "proj-") // Set routing config if err := store.SetConfig(env.ctx, "routing.mode", "auto"); err != nil { @@ -321,9 +301,6 @@ func (env *contributorRoutingEnv) initProjectStore(syncMode string) *dolt.DoltSt if err := store.SetConfig(env.ctx, "routing.contributor", env.planningDir); err != nil { env.t.Fatalf("failed to set routing.contributor: %v", err) } - if err := store.SetConfig(env.ctx, "issue_prefix", "proj-"); err != nil { - env.t.Fatalf("failed to set issue_prefix: %v", err) - } // Set sync mode-specific config switch syncMode { @@ -350,14 +327,7 @@ func (env *contributorRoutingEnv) initProjectStore(syncMode string) *dolt.DoltSt func (env *contributorRoutingEnv) initPlanningStore() *dolt.DoltStore { env.t.Helper() planningDBPath := filepath.Join(env.planningDir, ".beads", "beads.db") - store, err := dolt.New(env.ctx, &dolt.Config{Path: planningDBPath}) - if err != nil { - env.t.Skipf("skipping: Dolt server not available: %v", err) - } - - if err := store.SetConfig(env.ctx, "issue_prefix", "plan-"); err != nil { - env.t.Fatalf("failed to set issue_prefix in planning store: %v", err) - } + store := newTestStoreIsolatedDB(env.t, planningDBPath, "plan-") return store } @@ -663,15 +633,7 @@ func TestExplicitRepoOverride(t *testing.T) { } overrideDBPath := filepath.Join(overrideBeadsDir, "beads.db") - overrideStore, err := dolt.New(env.ctx, &dolt.Config{Path: overrideDBPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer overrideStore.Close() - - if err := overrideStore.SetConfig(env.ctx, "issue_prefix", "over-"); err != nil { - t.Fatalf("failed to set issue_prefix in override store: %v", err) - } + overrideStore := newTestStoreIsolatedDB(t, overrideDBPath, "over-") // Build routing config WITH explicit override mode, _ := projectStore.GetConfig(env.ctx, "routing.mode") @@ -738,15 +700,7 @@ func TestBEADS_DIRPrecedence(t *testing.T) { } externalDBPath := filepath.Join(externalBeadsDir, "beads.db") - externalStore, err := dolt.New(env.ctx, &dolt.Config{Path: externalDBPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer externalStore.Close() - - if err := externalStore.SetConfig(env.ctx, "issue_prefix", "ext-"); err != nil { - t.Fatalf("failed to set issue_prefix in external store: %v", err) - } + externalStore := newTestStoreIsolatedDB(t, externalDBPath, "ext-") // Set BEADS_DIR to external directory t.Setenv("BEADS_DIR", externalBeadsDir) diff --git a/cmd/bd/mol_test.go b/cmd/bd/mol_test.go index 70a5ed10c..e24ffd10f 100644 --- a/cmd/bd/mol_test.go +++ b/cmd/bd/mol_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/steveyegge/beads/internal/formula" - "github.com/steveyegge/beads/internal/storage/dolt" "github.com/steveyegge/beads/internal/types" ) @@ -217,14 +216,7 @@ func TestMinPriority(t *testing.T) { func TestBondProtoProto(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - store, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer store.Close() - if err := store.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + store := newTestStore(t, dbPath) // Create two protos protoA := &types.Issue{ @@ -293,14 +285,7 @@ func TestBondProtoProto(t *testing.T) { func TestBondProtoMol(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - store, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer store.Close() - if err := store.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + store := newTestStore(t, dbPath) // Create a proto with a child issue proto := &types.Issue{ @@ -366,14 +351,7 @@ func TestBondProtoMol(t *testing.T) { func TestBondMolMol(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - store, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer store.Close() - if err := store.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + store := newTestStore(t, dbPath) // Create two molecules molA := &types.Issue{ @@ -466,14 +444,7 @@ func TestBondMolMol(t *testing.T) { func TestSquashMolecule(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create a molecule (root issue) root := &types.Issue{ @@ -574,14 +545,7 @@ func TestSquashMolecule(t *testing.T) { func TestSquashMoleculeWithDelete(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create a molecule with ephemeral children root := &types.Issue{ @@ -683,14 +647,7 @@ func TestGenerateDigest(t *testing.T) { func TestSquashMoleculeWithAgentSummary(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create a molecule with ephemeral child root := &types.Issue{ @@ -754,14 +711,7 @@ func TestSquashMoleculeWithAgentSummary(t *testing.T) { func TestSquashWispMoleculeClearsRootEphemeral(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Wisp molecule: root is ephemeral too (created via `bd mol wisp`). root := &types.Issue{ @@ -821,14 +771,7 @@ func TestSquashWispMoleculeClearsRootEphemeral(t *testing.T) { func TestSpawnWithBasicAttach(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create primary proto with a child primaryProto := &types.Issue{ @@ -954,14 +897,7 @@ func TestSpawnWithBasicAttach(t *testing.T) { func TestSpawnWithMultipleAttachments(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create primary proto primaryProto := &types.Issue{ @@ -1072,14 +1008,7 @@ func TestSpawnWithMultipleAttachments(t *testing.T) { func TestSpawnAttachTypes(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create primary proto primaryProto := &types.Issue{ @@ -1192,14 +1121,7 @@ func TestSpawnAttachNonProtoError(t *testing.T) { func TestSpawnVariableAggregation(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create primary proto with one variable primaryProto := &types.Issue{ @@ -1360,14 +1282,7 @@ func TestSpawnAttachDryRunOutput(t *testing.T) { func TestWispFilteringFromExport(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create a mix of wisp and non-wisp issues normalIssue := &types.Issue{ @@ -1426,14 +1341,7 @@ func TestWispFilteringFromExport(t *testing.T) { func TestGetMoleculeProgress(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create a molecule (epic with template label) root := &types.Issue{ @@ -1527,14 +1435,7 @@ func TestGetMoleculeProgress(t *testing.T) { func TestFindParentMolecule(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create molecule root (epic with template label) root := &types.Issue{ @@ -1624,14 +1525,7 @@ func TestFindParentMolecule(t *testing.T) { func TestFindParentMoleculesBatch(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create molecule root (epic with template label) root := &types.Issue{ @@ -1726,14 +1620,7 @@ func TestFindParentMoleculesBatch(t *testing.T) { func TestFindParentMolecule_RootShapes(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) tests := []struct { name string @@ -1801,14 +1688,7 @@ func TestFindParentMolecule_RootShapes(t *testing.T) { func TestAdvanceToNextStep_PouredMolecule(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Root shaped like `bd mol pour` output: TypeMolecule, no template label. root := &types.Issue{ @@ -1884,14 +1764,7 @@ func TestAdvanceToNextStep_PouredMolecule(t *testing.T) { func TestFindHookedMolecules(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create molecule root (epic) molecule := &types.Issue{ @@ -1967,14 +1840,7 @@ func TestFindHookedMolecules(t *testing.T) { func TestAdvanceToNextStep(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create molecule with sequential steps root := &types.Issue{ @@ -2069,14 +1935,7 @@ func TestAdvanceToNextStep(t *testing.T) { func TestAdvanceToNextStepMoleculeComplete(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create molecule with single step root := &types.Issue{ @@ -2127,14 +1986,7 @@ func TestAdvanceToNextStepMoleculeComplete(t *testing.T) { func TestAdvanceToNextStepOrphanIssue(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create standalone issue (not part of molecule) orphan := &types.Issue{ @@ -2163,14 +2015,7 @@ func TestAdvanceToNextStepOrphanIssue(t *testing.T) { func TestAdvanceToNextStepConcurrentClaim(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create molecule: root -> step1 (closed), step2 (open), step3 (open) // step2 and step3 both depend on step1, so both become ready when step1 closes. @@ -2267,14 +2112,7 @@ func TestAdvanceToNextStepConcurrentClaim(t *testing.T) { func TestAdvanceToNextStepAllClaimed(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create molecule: root -> step1 (closed), step2 (open, will be pre-claimed) root := &types.Issue{ @@ -2503,14 +2341,7 @@ func TestGetRelativeID(t *testing.T) { func TestBondProtoMolWithRef(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "patrol"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStoreWithPrefix(t, dbPath, "patrol") // Create a proto with child steps (mol-polecat-arm template) protoRoot := &types.Issue{ @@ -2593,14 +2424,7 @@ func TestBondProtoMolWithRef(t *testing.T) { func TestBondProtoMolMultipleArms(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "patrol"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStoreWithPrefix(t, dbPath, "patrol") // Create simple proto proto := &types.Issue{ @@ -3064,14 +2888,7 @@ func TestCalculateBlockingDepths(t *testing.T) { func TestSpawnMoleculeEphemeralFlag(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create a template with a child (IDs will be auto-generated) root := &types.Issue{ @@ -3140,14 +2957,7 @@ func TestSpawnMoleculeEphemeralFlag(t *testing.T) { func TestSpawnMoleculeFromFormulaEphemeral(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) // Create a minimal in-memory subgraph (simulating cookFormulaToSubgraph output) root := &types.Issue{ @@ -3228,14 +3038,7 @@ func TestSpawnMoleculeFromFormulaEphemeral(t *testing.T) { func TestSpawnMolecule_PreservesStepMetadata(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStore(t, dbPath) f := &formula.Formula{ Formula: "meta-test", @@ -3393,14 +3196,7 @@ func TestFormatBondType(t *testing.T) { func TestPourRootTitleDescSubstitution(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "mol"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStoreWithPrefix(t, dbPath, "mol") // Create a formula that has title and desc variables f := &formula.Formula{ @@ -3483,14 +3279,7 @@ func TestPourRootTitleDescSubstitution(t *testing.T) { func TestPourRootTitleOnly(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "mol"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStoreWithPrefix(t, dbPath, "mol") // Formula with only title var (no desc) f := &formula.Formula{ @@ -3538,14 +3327,7 @@ func TestPourRootTitleOnly(t *testing.T) { func TestPourRootNoVars(t *testing.T) { ctx := context.Background() dbPath := t.TempDir() + "/test.db" - s, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer s.Close() - if err := s.SetConfig(ctx, "issue_prefix", "mol"); err != nil { - t.Fatalf("Failed to set config: %v", err) - } + s := newTestStoreWithPrefix(t, dbPath, "mol") // Formula with no title/desc vars (uses different var names) f := &formula.Formula{ diff --git a/cmd/bd/rename_prefix_repair_test.go b/cmd/bd/rename_prefix_repair_test.go index 7b73e4ea2..a987697e0 100644 --- a/cmd/bd/rename_prefix_repair_test.go +++ b/cmd/bd/rename_prefix_repair_test.go @@ -7,7 +7,6 @@ import ( "path/filepath" "testing" - "github.com/steveyegge/beads/internal/storage/dolt" "github.com/steveyegge/beads/internal/types" ) @@ -17,30 +16,25 @@ func TestRepairMultiplePrefixes(t *testing.T) { ctx := context.Background() - testStore, err := dolt.New(ctx, &dolt.Config{Path: testDBPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer testStore.Close() + testStore := newTestStore(t, testDBPath) - // Set globals following TestRenamePrefixCommand pattern + // Set the globals this test's code path actually reads. Deliberately NOT + // dbPath: on the shared-branch fast path newTestStore writes a + // metadata.json naming the shared database with no branch qualifier + // (test_helpers_test.go newTestStoreSharedBranch) while the live store sits + // on this test's own branch, so a global dbPath would point anything that + // reopens by path at shared `main` instead. repairPrefixes takes the store + // explicitly and never reopens, so the global is left alone rather than + // made to lie. oldStore := store oldActor := actor - oldDBPath := dbPath store = testStore actor = "test" - dbPath = testDBPath defer func() { store = oldStore actor = oldActor - dbPath = oldDBPath }() - // Set initial prefix - if err := testStore.SetConfig(ctx, "issue_prefix", "test"); err != nil { - t.Fatalf("failed to set prefix: %v", err) - } - // Create issues with multiple prefixes (simulating corruption). // CreateIssue accepts explicit IDs without prefix validation, // so we can create issues with different prefixes to simulate diff --git a/cmd/bd/update_metadata_test.go b/cmd/bd/update_metadata_test.go index e320aac3a..773a65509 100644 --- a/cmd/bd/update_metadata_test.go +++ b/cmd/bd/update_metadata_test.go @@ -9,7 +9,6 @@ import ( "path/filepath" "testing" - "github.com/steveyegge/beads/internal/storage/dolt" "github.com/steveyegge/beads/internal/types" ) @@ -20,16 +19,7 @@ func TestUpdateMetadataInlineJSON(t *testing.T) { // Create storage ctx := context.Background() - store, err := dolt.New(ctx, &dolt.Config{Path: dbPath}) - if err != nil { - t.Skipf("skipping: Dolt server not available: %v", err) - } - defer store.Close() - - // Initialize database with issue prefix - if err := store.SetConfig(ctx, "issue_prefix", "bd"); err != nil { - t.Fatalf("failed to set issue_prefix: %v", err) - } + store := newTestStoreWithPrefix(t, dbPath, "bd") // Create an issue issue := &types.Issue{