Fix bd migrate loop: skip prefix validation during auto-import

When auto-importing issues from JSONL, issues with different prefixes
(e.g., gt-1 vs gastown-) would fail validation and cause an infinite
loop of failed migrations.

The fix adds SkipPrefixValidation option to CreateIssuesWithFullOptions
which propagates through EnsureIDs to skip prefix validation for issues
that already have IDs during import. This allows importing issues with
any prefix while still validating new issues created interactively.

🤖 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-27 21:45:42 -08:00
parent 7447a5004c
commit 22d34a22dc
4 changed files with 50 additions and 10 deletions

View File

@@ -270,7 +270,7 @@ func TestGenerateBatchIDs(t *testing.T) {
{Title: "Issue 3", Description: "Third", CreatedAt: time.Now()},
}
err = s.generateBatchIDs(ctx, conn, issues, "test-actor", OrphanAllow)
err = s.generateBatchIDs(ctx, conn, issues, "test-actor", OrphanAllow, false)
if err != nil {
t.Fatalf("failed to generate IDs: %v", err)
}
@@ -299,11 +299,29 @@ func TestGenerateBatchIDs(t *testing.T) {
{ID: "wrong-prefix-123", Title: "Wrong", CreatedAt: time.Now()},
}
err = s.generateBatchIDs(ctx, conn, issues, "test-actor", OrphanAllow)
err = s.generateBatchIDs(ctx, conn, issues, "test-actor", OrphanAllow, false)
if err == nil {
t.Fatal("expected error for wrong prefix")
}
})
t.Run("skips prefix validation when flag is set", func(t *testing.T) {
conn, err := s.db.Conn(ctx)
if err != nil {
t.Fatalf("failed to get connection: %v", err)
}
defer conn.Close()
issues := []*types.Issue{
{ID: "wrong-prefix-123", Title: "Wrong", CreatedAt: time.Now()},
}
// With skipPrefixValidation=true, should not error
err = s.generateBatchIDs(ctx, conn, issues, "test-actor", OrphanAllow, true)
if err != nil {
t.Fatalf("should not error with skipPrefixValidation=true: %v", err)
}
})
}
func TestBulkOperations(t *testing.T) {