Skip to content

Commit 7613d72

Browse files
fix(billing): guard rejectIfTestCohort against nil h.db (dedup-test panic)
W0's rejectIfTestCohort runs models.IsTestCohort(ctx, h.db, teamID) at the top of CreateCheckoutAPI/ChangePlanAPI. billing_checkout_dedup_test.go wires NewBillingHandler(nil, ...) (db-independent — it only exercises the Redis SETNX dedup guard), so the new DB query panicked on a nil *sql.DB in CI build-and-test. Skip the cohort check when h.db == nil (prod always has a db). Targeted dedup + cohort + checkout tests green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 76c68fd commit 7613d72

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

internal/handlers/billing.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,12 @@ func (h *BillingHandler) requireVerifiedEmail(c *fiber.Ctx, action string) (bool
684684
// the already-written fiber response (or ErrResponseWritten) and the caller must
685685
// return it unchanged.
686686
func (h *BillingHandler) rejectIfTestCohort(c *fiber.Ctx, teamID uuid.UUID, action string) (ok bool, resp error) {
687+
// No DB wired: only happens on db-independent handler paths exercised in
688+
// tests (e.g. the Redis SETNX dedup guard, which short-circuits before any
689+
// DB use). In prod h.db is always set. Nothing to check — proceed.
690+
if h.db == nil {
691+
return true, nil
692+
}
687693
isTest, err := models.IsTestCohort(c.Context(), h.db, teamID)
688694
if err != nil {
689695
// Fail open: a real customer's charge must not be blocked by a DB blip.

0 commit comments

Comments
 (0)