test: Refactor duplicates_test.go to use shared DB pattern (P2)

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 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-21 16:13:21 -05:00
parent b57ae7981f
commit e38c0a58aa

View File

@@ -198,14 +198,13 @@ func TestDuplicateGroupsWithDifferentStatuses(t *testing.T) {
} }
func TestDuplicatesIntegration(t *testing.T) { func TestDuplicatesIntegration(t *testing.T) {
tmpDir := t.TempDir()
testStore := newTestStore(t, tmpDir+"/.beads/beads.db")
ctx := context.Background() ctx := context.Background()
testStore, cleanup := setupTestDB(t)
defer cleanup()
// Create duplicate issues // Create duplicate issues (let DB assign IDs)
issues := []*types.Issue{ issues := []*types.Issue{
{ {
ID: "bd-1",
Title: "Fix authentication bug", Title: "Fix authentication bug",
Description: "Users can't login", Description: "Users can't login",
Status: types.StatusOpen, Status: types.StatusOpen,
@@ -213,7 +212,6 @@ func TestDuplicatesIntegration(t *testing.T) {
IssueType: types.TypeBug, IssueType: types.TypeBug,
}, },
{ {
ID: "bd-2",
Title: "Fix authentication bug", Title: "Fix authentication bug",
Description: "Users can't login", Description: "Users can't login",
Status: types.StatusOpen, Status: types.StatusOpen,
@@ -221,7 +219,6 @@ func TestDuplicatesIntegration(t *testing.T) {
IssueType: types.TypeBug, IssueType: types.TypeBug,
}, },
{ {
ID: "bd-3",
Title: "Different task", Title: "Different task",
Description: "Different description", Description: "Different description",
Status: types.StatusOpen, Status: types.StatusOpen,
@@ -253,13 +250,15 @@ func TestDuplicatesIntegration(t *testing.T) {
t.Fatalf("Expected 2 issues in group, got %d", len(groups[0])) t.Fatalf("Expected 2 issues in group, got %d", len(groups[0]))
} }
// Verify the duplicate group contains bd-1 and bd-2 // Verify the duplicate group contains the two issues with "Fix authentication bug"
ids := make(map[string]bool) dupCount := 0
for _, issue := range groups[0] { for _, issue := range groups[0] {
ids[issue.ID] = true if issue.Title == "Fix authentication bug" {
dupCount++
}
} }
if !ids["bd-1"] || !ids["bd-2"] { if dupCount != 2 {
t.Errorf("Expected duplicate group to contain bd-1 and bd-2") t.Errorf("Expected duplicate group to contain 2 'Fix authentication bug' issues, got %d", dupCount)
} }
} }