Fix autoimport tests for content-hash collision scoring (bd-100)

This commit is contained in:
Steve Yegge
2025-10-28 19:19:06 -07:00
parent 9644d61de2
commit dd9541f300
2 changed files with 68 additions and 33 deletions

View File

@@ -223,20 +223,28 @@ func TestAutoImportMultipleCollisionsRemapped(t *testing.T) {
ctx := context.Background()
// Verify local versions are preserved (original IDs still have local content)
local1, _ := testStore.GetIssue(ctx, "test-mc-1")
if local1.Title != "Local version 1" {
t.Errorf("Expected local version preserved for test-mc-1, got: %s", local1.Title)
// Verify content-hash based collision resolution
// The winner is the version with the lexicographically lower content hash
// For deterministic testing, we check that the remapped version exists as new issue
// Check test-mc-1: Should have the winning version at original ID
issue1, _ := testStore.GetIssue(ctx, "test-mc-1")
if issue1 == nil {
t.Fatal("Expected test-mc-1 to exist")
}
local2, _ := testStore.GetIssue(ctx, "test-mc-2")
if local2.Title != "Local version 2" {
t.Errorf("Expected local version preserved for test-mc-2, got: %s", local2.Title)
// The winner should be either "Local version 1" or "Remote version 1 (conflict)"
// We don't assert which one, just that one exists at the original ID
// Check test-mc-2: Should have the winning version at original ID
issue2, _ := testStore.GetIssue(ctx, "test-mc-2")
if issue2 == nil {
t.Fatal("Expected test-mc-2 to exist")
}
local3, _ := testStore.GetIssue(ctx, "test-mc-3")
if local3.Title != "Local version 3" {
t.Errorf("Expected local version preserved for test-mc-3, got: %s", local3.Title)
// Check test-mc-3: Should have the winning version at original ID
issue3, _ := testStore.GetIssue(ctx, "test-mc-3")
if issue3 == nil {
t.Fatal("Expected test-mc-3 to exist")
}
// Verify new issue was imported
@@ -329,18 +337,23 @@ func TestAutoImportAllCollisionsRemapped(t *testing.T) {
ctx := context.Background()
// Verify all local versions preserved
local1, _ := testStore.GetIssue(ctx, "test-ac-1")
if local1.Title != "Local 1" {
t.Errorf("Expected local version preserved, got: %s", local1.Title)
// Verify content-hash based collision resolution
// The winner is the version with the lexicographically lower content hash
// Check that original IDs exist with winning version
issue1, _ := testStore.GetIssue(ctx, "test-ac-1")
if issue1 == nil {
t.Fatal("Expected test-ac-1 to exist")
}
// Winner could be either "Local 1" or "Remote 1 (conflict)" - don't assert which
local2, _ := testStore.GetIssue(ctx, "test-ac-2")
if local2.Title != "Local 2" {
t.Errorf("Expected local version preserved, got: %s", local2.Title)
issue2, _ := testStore.GetIssue(ctx, "test-ac-2")
if issue2 == nil {
t.Fatal("Expected test-ac-2 to exist")
}
// Winner could be either "Local 2" or "Remote 2 (conflict)" - don't assert which
// Verify remapping message mentions both
// Verify remapping message mentions both collisions
if !strings.Contains(stderrOutput, "remapped 2") {
t.Errorf("Expected '2' in remapping count, got: %s", stderrOutput)
}
@@ -725,19 +738,40 @@ func TestAutoImportCollisionRemapMultipleFields(t *testing.T) {
t.Logf("Expected remapping message for test-fields-1: %s", stderrOutput)
}
// Verify local version of issue is preserved with all fields
local, _ := testStore.GetIssue(ctx, "test-fields-1")
if local.Title != "Local title" {
t.Errorf("Expected local title preserved, got: %s", local.Title)
// Verify content-hash based collision resolution
// The winning version (lower content hash) keeps the original ID
// The loser is remapped to a new ID
issue, _ := testStore.GetIssue(ctx, "test-fields-1")
if issue == nil {
t.Fatal("Expected test-fields-1 to exist")
}
if local.Description != "Local description" {
t.Errorf("Expected local description preserved, got: %s", local.Description)
}
if local.Status != types.StatusOpen {
t.Errorf("Expected local status preserved, got: %s", local.Status)
}
if local.Priority != 1 {
t.Errorf("Expected local priority preserved, got: %d", local.Priority)
// Verify the issue has consistent fields (all from the same version)
// Don't assert which version won, just that it's internally consistent
if issue.Title == "Local title" {
// If local won, verify all local fields
if issue.Description != "Local description" {
t.Errorf("Expected local description with local title, got: %s", issue.Description)
}
if issue.Status != types.StatusOpen {
t.Errorf("Expected local status with local title, got: %s", issue.Status)
}
if issue.Priority != 1 {
t.Errorf("Expected local priority with local title, got: %d", issue.Priority)
}
} else if issue.Title == "Remote title (conflict)" {
// If remote won, verify all remote fields
if issue.Description != "Remote description (conflict)" {
t.Errorf("Expected remote description with remote title, got: %s", issue.Description)
}
if issue.Status != types.StatusClosed {
t.Errorf("Expected remote status with remote title, got: %s", issue.Status)
}
if issue.Priority != 3 {
t.Errorf("Expected remote priority with remote title, got: %d", issue.Priority)
}
} else {
t.Errorf("Unexpected title: %s", issue.Title)
}
}