fix(billing): withhold the free allowance from Gmail aliases of an existing account

Merged
WA
1d ago
+32087-14

Summary

  • Gmail delivers every dot and +tag variant of an address (and its googlemail.com twin) to one inbox, so a single person could register a.b@gmail.com, ab+1@gmail.com, … and get a fresh free allowance on each
  • A new account whose Gmail inbox another account (banned or not) already holds is now created with no free allowance — same "one free trial per identity" treatment returning deleted-account identities already get; signup itself is never refused, and paid plans and prepaid credit are untouched
  • Applied on both allowance paths: handleNewUser and the createUserStatsIfMissing fallback, via one identityHadFreeAllowance check
  • New gmailMailbox() SQL expression in the schema (built on foldedEmail) plus partial index user_gmail_mailbox_idx, so the lookup is an index probe instead of a scan of user; migration builds it CONCURRENTLY
  • Non-Gmail domains are never folded; fails open (logs, grants the allowance) on lookup error

Type of Change

  • Bug fix

Testing

  • lib/users/gmail-alias.integration.ts against real Postgres with INTEGRATION_DB_PROVISION=migrate (exercises migration 0439): 5/5 pass. Disabling the check turns the 3 withholding tests red; one test asserts the plan uses user_gmail_mailbox_idx
  • lib/billing/core/usage.test.ts: 25/25 pass
  • check:migrations, check:file-names, check:test-patterns, check:comment-hygiene, biome on touched files; drizzle-kit generate reports no drift
  • Full type-check / audits / suite left to CI

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)