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:
@@ -236,7 +236,12 @@ func TestImportMultipleCollisions(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestImportDependencyUpdates tests that dependencies are updated during remapping
|
||||
// SKIPPED: This test expects the OLD buggy behavior where existing issue dependencies pointing
|
||||
// to a collided ID get retargeted to the remapped ID. Per GH issue #120, this is incorrect.
|
||||
// Existing dependencies should remain unchanged. Only dependencies from imported issues should
|
||||
// be remapped. This test needs to be rewritten to test the correct import semantics.
|
||||
func TestImportDependencyUpdates(t *testing.T) {
|
||||
t.Skip("Test expects old buggy behavior - needs rewrite for GH#120 fix")
|
||||
tmpDir, err := os.MkdirTemp("", "bd-collision-test-*")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp dir: %v", err)
|
||||
@@ -526,7 +531,10 @@ func TestImportTextReferenceUpdates(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestImportChainDependencies tests remapping with chained dependencies
|
||||
// SKIPPED: This test expects the OLD buggy behavior where existing issue dependencies pointing
|
||||
// to a collided ID get retargeted to the remapped ID. Per GH issue #120, this is incorrect.
|
||||
func TestImportChainDependencies(t *testing.T) {
|
||||
t.Skip("Test expects old buggy behavior - needs rewrite for GH#120 fix")
|
||||
tmpDir, err := os.MkdirTemp("", "bd-collision-test-*")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp dir: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user