Fix: RemapCollisions deletes existing issue dependencies (GH #120, bd-56)

Bug: updateDependencyReferences() was incorrectly updating ALL dependencies
in the database during collision resolution with --resolve-collisions,
including dependencies belonging to existing issues.

Root cause: The function checked if dep.IssueID was in idMapping keys
(old imported IDs like 'bd-1'), but those are also the IDs of existing
database issues. This caused existing dependencies to be incorrectly
modified or deleted.

Fix: Changed logic to only update dependencies where IssueID is in
idMapping VALUES (new remapped IDs like 'bd-295'). This ensures only
dependencies from remapped issues are updated, not existing ones.

During normal import flow, this is effectively a no-op since imported
dependencies haven't been added to the database yet when RemapCollisions
runs (they're added later in Phase 5 of import_shared.go).

Changes:
- Updated updateDependencyReferences() in collision.go to build a set
  of new remapped IDs and only update dependencies with those IDs
- Added comprehensive documentation explaining the correct semantics
- Added regression tests: TestRemapCollisionsRemapsImportedNotExisting
  and TestRemapCollisionsDoesNotUpdateNonexistentDependencies
- Skipped 3 tests that expected the old buggy behavior with clear
  notes about why they need to be rewritten

Real-world impact: In one case, 125 dependencies were incorrectly
deleted from 157 existing issues during collision resolution.

Fixes https://github.com/steveyegge/beads/issues/120
Fixes bd-56
This commit is contained in:
Steve Yegge
2025-10-23 10:25:13 -07:00
parent e4b0820449
commit e3ff12448f
4 changed files with 336 additions and 0 deletions

View File

@@ -894,7 +894,12 @@ func TestRemapCollisions(t *testing.T) {
}
}
// SKIPPED: This test expects the OLD buggy behavior where existing issue dependencies
// get updated during collision resolution. Per GH issue #120, existing dependencies
// should be preserved, not updated. This test needs to be rewritten to test the correct
// semantics (only update dependencies belonging to remapped issues, not existing ones).
func TestUpdateDependencyReferences(t *testing.T) {
t.Skip("Test expects old buggy behavior - needs rewrite for GH#120 fix")
// Create temporary database
tmpDir, err := os.MkdirTemp("", "dep-remap-test-*")
if err != nil {