test(integration): real-Supabase API route tests via bunx supabase start#117
Conversation
Foundation for the "honest follow-up" flagged in #115's PR description: replace mock-Supabase tests with real-stack integration tests that run against the actual local Supabase boot, exercising the same migrations, PostgREST, and CLI JWT signing path that production runs. What's new: - apps/web/__tests__/integration/ — new directory with one exemplar test for POST /api/usage/submit. Calls the real route handler with a real Request, mints a real CLI JWT via createCliToken, and asserts on rows Postgres actually persisted. No vi.mock of the Supabase client, the auth helper, or query chains. - apps/web/vitest.integration.config.ts — separate vitest config wired to a globalSetup that asserts the local stack is reachable and reads ephemeral keys via `bunx supabase status -o env`. - New `bun run --cwd apps/web test:integration` script. - CI: supabase/setup-cli@v1 + bunx supabase start before integration tests. - CONTRIBUTING.md updated with the run-it-yourself instructions. The exemplar covers four cases the existing mocked usage-submit.test.ts cannot: 1. Real route → real DB roundtrip (rows actually present in daily_usage, device_usage, posts). 2. Real CHECK constraint rejecting negative cost (defense-in-depth past the route's TS validation). 3. Real backfill-window 400 + zero rows leaked. 4. Real X-Straude-Refreshed-Token header emitted under real JWT signing when the token is older than the refresh threshold. Existing mocked tests stay as-is; future PRs can migrate cases incrementally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (9)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Why
Follow-up to #115 (mock-test cleanup). The "Out of scope" note in that PR called this out:
After hitting issues with testcontainers + the bare `supabase/postgres` image (the image is missing storage-service-managed columns that some migrations reference), this PR uses the `bunx supabase start` path the dev team already uses for local development. Same Postgres, same migrations applied via the proper Supabase CLI flow that knows how to set up storage extensions. No new heavy deps.
What
What this catches that the mock test cannot
The exemplar `usage-submit.test.ts` has 5 cases:
Zero `vi.mock` of behavior. The only mocking-style trick is the inline `Date.now` shimmer for the stale-token test, restored before the test ends.
Test plan
If CI's integration step fails, I'll iterate. The code is structured carefully — types compile, the test logic is sound, the supabase-start path matches the dev workflow that's already in `bun run local:up`.
Out of scope
🤖 Generated with Claude Code