From cb59bb3ec8cd3dde81d7c2f60dba154deb134713 Mon Sep 17 00:00:00 2001 From: "Charles P. Cross" Date: Thu, 18 Dec 2025 16:07:09 -0500 Subject: [PATCH] fix(ci): resolve lint and test failures Fix two CI failures that were blocking main: 1. Lint error in cmd/bd/onboard.go:126 - Unchecked fmt.Fprintf return value - Fixed by explicitly ignoring with _, _ 2. Test failures in internal/storage/sqlite - TestCreateIssues/duplicate_ID_error was passing but TestCreateIssuesRollback/rollback_on_conflict_with_existing_ID failed - Root cause: CreateIssues used INSERT OR IGNORE which silently ignored duplicate IDs instead of returning an error - Fixed by adding duplicate ID detection in EnsureIDs(): a) Check for duplicates within the batch b) Check for conflicts with existing database IDs Both fixes are minimal and targeted to unblock CI. --- cmd/bd/onboard.go | 2 +- internal/storage/sqlite/ids.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/bd/onboard.go b/cmd/bd/onboard.go index 5edba664..1c77add3 100644 --- a/cmd/bd/onboard.go +++ b/cmd/bd/onboard.go @@ -123,7 +123,7 @@ The old approach of embedding full instructions in AGENTS.md is deprecated because it wasted tokens and got stale when bd upgraded.`, Run: func(cmd *cobra.Command, args []string) { if err := renderOnboardInstructions(cmd.OutOrStdout()); err != nil { - fmt.Fprintf(cmd.ErrOrStderr(), "Error: %v\n", err) + _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Error: %v\n", err) } }, } diff --git a/internal/storage/sqlite/ids.go b/internal/storage/sqlite/ids.go index 774c6a96..3b3a438e 100644 --- a/internal/storage/sqlite/ids.go +++ b/internal/storage/sqlite/ids.go @@ -223,9 +223,24 @@ func tryResurrectParent(parentID string, issues []*types.Issue) bool { func EnsureIDs(ctx context.Context, conn *sql.Conn, prefix string, issues []*types.Issue, actor string, orphanHandling OrphanHandling, skipPrefixValidation bool) error { usedIDs := make(map[string]bool) - // First pass: record explicitly provided IDs + // First pass: record explicitly provided IDs and check for duplicates within batch for i := range issues { if issues[i].ID != "" { + // Check for duplicate IDs within the batch + if usedIDs[issues[i].ID] { + return fmt.Errorf("duplicate issue ID within batch: %s", issues[i].ID) + } + + // Check if ID already exists in database + var existingCount int + err := conn.QueryRowContext(ctx, `SELECT COUNT(*) FROM issues WHERE id = ?`, issues[i].ID).Scan(&existingCount) + if err != nil { + return fmt.Errorf("failed to check ID existence: %w", err) + } + if existingCount > 0 { + return fmt.Errorf("issue ID already exists: %s", issues[i].ID) + } + // Validate that explicitly provided ID matches the configured prefix (bd-177) // Skip validation during import to allow issues with different prefixes (e.g., from renamed repos) if !skipPrefixValidation {