From e38c0a58aa4075f72c7d6b7fae3b53ff91bf3a70 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Fri, 21 Nov 2025 16:13:21 -0500 Subject: [PATCH] test: Refactor duplicates_test.go to use shared DB pattern (P2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit METRICS: - Tests: 5 tests - DB setups removed: 1 → 1 shared - Tests needing DB: 1/5 - Savings: setupTestDB() → newTestStore() DETAILS: - TestFindDuplicateGroups: Pure in-memory logic (no DB) - TestChooseMergeTarget: Pure in-memory logic (no DB) - TestCountReferences: Pure in-memory logic (no DB) - TestDuplicateGroupsWithDifferentStatuses: Pure in-memory (no DB) - TestDuplicatesIntegration: Uses shared DB (was: setupTestDB) Also fixed: Removed hardcoded IDs, let DB assign them. All 5 tests pass! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- cmd/bd/duplicates_test.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/cmd/bd/duplicates_test.go b/cmd/bd/duplicates_test.go index 3d6a408c..812b6667 100644 --- a/cmd/bd/duplicates_test.go +++ b/cmd/bd/duplicates_test.go @@ -198,14 +198,13 @@ func TestDuplicateGroupsWithDifferentStatuses(t *testing.T) { } func TestDuplicatesIntegration(t *testing.T) { + tmpDir := t.TempDir() + testStore := newTestStore(t, tmpDir+"/.beads/beads.db") ctx := context.Background() - testStore, cleanup := setupTestDB(t) - defer cleanup() - // Create duplicate issues + // Create duplicate issues (let DB assign IDs) issues := []*types.Issue{ { - ID: "bd-1", Title: "Fix authentication bug", Description: "Users can't login", Status: types.StatusOpen, @@ -213,7 +212,6 @@ func TestDuplicatesIntegration(t *testing.T) { IssueType: types.TypeBug, }, { - ID: "bd-2", Title: "Fix authentication bug", Description: "Users can't login", Status: types.StatusOpen, @@ -221,7 +219,6 @@ func TestDuplicatesIntegration(t *testing.T) { IssueType: types.TypeBug, }, { - ID: "bd-3", Title: "Different task", Description: "Different description", Status: types.StatusOpen, @@ -253,13 +250,15 @@ func TestDuplicatesIntegration(t *testing.T) { t.Fatalf("Expected 2 issues in group, got %d", len(groups[0])) } - // Verify the duplicate group contains bd-1 and bd-2 - ids := make(map[string]bool) + // Verify the duplicate group contains the two issues with "Fix authentication bug" + dupCount := 0 for _, issue := range groups[0] { - ids[issue.ID] = true + if issue.Title == "Fix authentication bug" { + dupCount++ + } } - if !ids["bd-1"] || !ids["bd-2"] { - t.Errorf("Expected duplicate group to contain bd-1 and bd-2") + if dupCount != 2 { + t.Errorf("Expected duplicate group to contain 2 'Fix authentication bug' issues, got %d", dupCount) } }