Skip to content

test(v1.4): close coverage gaps surfaced during production validation#35

Merged
MP2EZ merged 1 commit into
devfrom
test/v1.4-coverage-gaps
May 29, 2026
Merged

test(v1.4): close coverage gaps surfaced during production validation#35
MP2EZ merged 1 commit into
devfrom
test/v1.4-coverage-gaps

Conversation

@MP2EZ
Copy link
Copy Markdown
Owner

@MP2EZ MP2EZ commented May 29, 2026

Adds 12 tests + small CSP defensive fix for SUPABASE_URL bare-hostname bug. 1202 tests passing, zero regressions.

🤖 Generated with Claude Code

Comprehensive review of v1.4 test coverage after tonight's end-to-end
validation. Five real bugs surfaced during the upgrade-flow walkthrough;
three were unit-testable, plus seven additional coverage gaps in
production-critical paths.

Backend (+10, 999 total)

Stripe API shape (3) — current_period_end migration to items[] caused
empty subscription_expires_at after live cancellation testing:
- test_subscription_updated_root_period_end_preferred_over_items locks
  in the backwards-compat ordering: root wins when both are present
- test_subscription_updated_empty_items_array_safe defends against
  malformed payloads with empty items.data
- (test_subscription_updated_reads_period_end_from_items_array already
  added in slice 5 hotfix)

Webhook audit + forensics (3) — previously untested branches:
- test_payment_failed_audit_row_preserves_status asserts the old/new
  status equality on payment_failed (analytics depends on this shape)
- test_unknown_event_type_still_recorded_for_forensics covers the
  "ignore unknown event_type" code path that must still save the
  payload to stripe_events for operator forensics
- test_handler_crash_preserves_claim_row_for_operator_runbook locks in
  the contract documented in billing.handle_webhook_event's docstring:
  partial-failure mid-handler leaves the claim row, requiring manual
  DELETE FROM stripe_events to re-enable Stripe's retry

CSP defensive coding (4) — fix + tests for SUPABASE_URL bare-hostname
bug that surfaced in production:
- new api._supabase_csp_origin() helper prepends https:// when missing,
  preventing silent CSP breakage from operator-set env var typos
- TestCSPSupabaseOrigin class covers: bare hostname gets https://,
  https:// passthrough, unset → empty, whitespace trimmed
- Same helper now used in CSP middleware; backend auth.py JWKS lookup
  is unaffected (it builds its own URL from project ref)

Frontend (+2, 203 total)

- useAuth: persisted session triggers getMe() on mount without waiting
  for onAuthStateChange — regression test for tonight's silent
  INITIAL_SESSION race condition where returning users were stuck on
  "Loading…" forever
- useBilling: strips ?billing=success from URL after refresh — covers
  the post-checkout URL cleanup that was implemented but untested

Verification: 1202 tests pass (999 backend + 203 frontend), zero
regressions, ruff + typescript clean.

What's deliberately NOT added (out of scope or different defense):
- E2E test framework (would have caught the build-time env var bug
  more decisively than any unit test — separate effort)
- CI workflow assertion that VITE_PUBLIC_SUPABASE_* are present
  (lint-style check on workflows, not in test suite)
- Modal width computed-style assertion (CSS specificity bug; better
  addressed by adopting a CSS-in-JS or design-system constraint)
- Live webhook fixture recorder (would help future API version
  migrations like the items[] one; separate tooling effort)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@MP2EZ MP2EZ merged commit cc45b7e into dev May 29, 2026
4 checks passed
@MP2EZ MP2EZ deleted the test/v1.4-coverage-gaps branch May 29, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant