Add comprehensive unit tests for CreateIssues (bd-241)

- Added 12 table-driven test cases covering all validation scenarios
- Added 2 rollback tests (validation error + DB conflict)
- Added nil item detection to prevent panic
- Fixed nil pointer panic in CreateIssues
- Tests verify ID uniqueness, timestamps, closed_at invariant
- All tests pass

Amp-Thread-ID: https://ampcode.com/threads/T-61c584cd-d873-4a1a-bfa6-d739b630b3e5
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-15 19:33:53 -07:00
parent e7d4a9c822
commit 5ab7ff0f84
3 changed files with 432 additions and 2 deletions

View File

@@ -518,9 +518,13 @@ func (s *SQLiteStorage) CreateIssues(ctx context.Context, issues []*types.Issue,
return nil
}
// Phase 1: Set timestamps and validate all issues first (fail-fast)
// Phase 1: Check for nil and validate all issues first (fail-fast)
now := time.Now()
for i, issue := range issues {
if issue == nil {
return fmt.Errorf("issue %d is nil", i)
}
issue.CreatedAt = now
issue.UpdatedAt = now