When choosing which duplicate to keep, the merge target now considers
both dependentCount (children/blocked-by) AND dependsOnCount (dependencies).
This ensures issues with ANY structural connections are preferred over
empty shells, rather than only considering children.
- Updated chooseMergeTarget to calculate weight = dependentCount + dependsOnCount
- Updated display output to show weight instead of just dependents
- Updated JSON output to include dependencies and weight fields
- Added tests for dependsOnCount inclusion and combined weight calculation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The duplicate merge target selection now considers structural relationships:
1. Dependent count (children, blocked-by) - highest priority
2. Text reference count - secondary
3. Lexicographically smallest ID - tiebreaker
This fixes the bug where `bd duplicates --auto-merge` would suggest closing
an epic with 17 children instead of the empty shell duplicate.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When --auto-merge is used, performMerge now automatically:
1. Closes source issues with "Duplicate of <target>" reason
2. Links each source to target with a "related" dependency
Closes bd-hdt
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Analysis shows main_test.go is NOT a good candidate for shared DB pattern
due to global state manipulation and integration test characteristics.
Changes:
- Added MAIN_TEST_REFACTOR_NOTES.md documenting findings
- Fixed unused import in duplicates_test.go (from recent pull)
Key findings:
- 18 tests with 14 newTestStore() calls
- Tests manipulate global state (autoFlushEnabled, isDirty, etc.)
- Tests simulate workflows (flush, import) not just CRUD
- Shared DB causes deadlocks between flush ops and cleanup
- Integration tests need process-level isolation
Recommendation: Leave as-is or use Option 2 (grouped tests without
shared DB). Focus P2 efforts on integrity_test.go instead.
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
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>
Refactored 3 smaller test files for test suite optimization:
FILES ANALYZED:
- validate_test.go (9 tests): NO DB needed - pure validation logic
- epic_test.go (3 tests): 2 DB setups → 1 shared pattern
- duplicates_test.go (5 tests): 1 old setupTestDB → newTestStore
CHANGES:
epic_test.go:
- Replaced 2× manual sqlite.New() with newTestStore()
- Removed duplicate SetConfig calls
- Removed manual Close/defer (handled by helper)
- -40 lines, +6 lines = net -34 lines
duplicates_test.go:
- Replaced old setupTestDB pattern with newTestStore
- Updated test data: bd-1/2/3 → test-1/2/3 (matches prefix)
- Added filepath import
- Removed cleanup() function pattern
- Net changes: proper shared pattern adoption
METRICS:
- Total files changed: 2/3 (validate_test.go needs no DB!)
- DB setups eliminated: 3 → 1 (epic: 2→1, duplicates: 1→0+shared)
- Lines saved: 30 net reduction
- Tests passing: 13/13 ✓
validate_test.go required NO changes - all tests are pure functions
with in-memory data. Even git conflict tests use temp files, not DB.
Part of Phase 2/3 test suite optimization.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- New 'bd duplicates' command finds content duplicates across database
- Groups by content hash (title, description, design, acceptance criteria)
- Chooses merge target by reference count or smallest ID
- Supports --auto-merge and --dry-run flags
- Added --dedupe-after flag to 'bd import' for post-import detection
- Comprehensive test coverage for duplicate detection
- Updated AGENTS.md and ADVANCED.md with usage examples
Amp-Thread-ID: https://ampcode.com/threads/T-6f99566f-c979-43ed-bd8f-5aa38b0f6191
Co-authored-by: Amp <amp@ampcode.com>