Skip to content

test: add Vitest suite covering AI fallback, rate limiter, audit scoring, admin auth - #1

Draft
riteshbonthalakoti wants to merge 8 commits into
mainfrom
claude/test-coverage-analysis-wraan9
Draft

test: add Vitest suite covering AI fallback, rate limiter, audit scoring, admin auth#1
riteshbonthalakoti wants to merge 8 commits into
mainfrom
claude/test-coverage-analysis-wraan9

Conversation

@riteshbonthalakoti

Copy link
Copy Markdown
Owner

What

Adds a Vitest test suite to a codebase that previously had zero automated tests, covering the highest-risk pure/isolable logic:

  • lib/ai/providers.tsisRetryableError, withFallback, and getProviders() key filtering
  • lib/rate-limit.ts — free-tier window/reset/per-IP behavior and getClientIp header parsing
  • lib/ai/analyze.tsrunAudit score clamping/rounding, markdown-fence stripping, malformed-JSON fallback, and multi-dimension score averaging
  • lib/email.tsscoreColor/scoreVerdict threshold boundaries (exported for direct testing)
  • app/api/admin/upgrade-self/route.ts — the admin-email authorization gate (401/403/200 paths)

Also fixes a real bug found while writing the provider tests: getProviders() built all 5 OpenAI clients eagerly before filtering by key presence, and the OpenAI SDK throws synchronously on an empty apiKey — so any environment missing even one of the five provider keys would crash the whole audit request instead of gracefully skipping that provider. Fixed by filtering configs by key presence before constructing clients.

Why

The repo had no test runner, no config, and no test files across 91 TS/TSX files, despite containing payment webhooks, an admin authorization gate, and the core AI scoring pipeline. This adds test infrastructure (Vitest) and an initial suite targeting the areas where a silent regression would be costliest: entitlement/auth checks, the AI provider fallback chain (the app's core reliability mechanism), and audit score integrity.

Type

  • Bug fix
  • Chore (test infra)

Checklist

  • npx vitest run passes (44/44 tests)
  • npx tsc --noEmit passes
  • npx eslint passes on all new/changed files
  • npm run build — not verified in this sandbox; it fails here because RESEND_API_KEY/STRIPE_SECRET_KEY aren't configured in this environment (pre-existing eager SDK client construction in lib/email.ts and app/api/stripe/route.ts, unrelated to this change)
  • PR is focused — test infra + one small bug fix surfaced by testing

Generated by Claude Code

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
roastlab Error Error Jul 1, 2026 9:21am

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ff63e532-537f-4cc4-b471-e673e4d32fe8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/test-coverage-analysis-wraan9

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

2 participants