Skip to content

test: exercise real route handlers instead of hand-copied stubs, close major coverage gaps - #12

Merged
projectamazonph merged 2 commits into
mainfrom
claude/test-coverage-analysis-l787jy
Aug 10, 2026
Merged

test: exercise real route handlers instead of hand-copied stubs, close major coverage gaps#12
projectamazonph merged 2 commits into
mainfrom
claude/test-coverage-analysis-l787jy

Conversation

@projectamazonph

Copy link
Copy Markdown
Owner

Problem

A coverage analysis found that most of the API test suite (11 of 13 files in __tests__/api/) never imported or executed the real src/app/api/**/route.ts handlers. Instead they hand-copied a parallel reimplementation of each route's logic into the test file itself ("Replicate route logic") and tested that. This meant real bugs in sanitize calls, Prisma queries, or auth wiring could ship with a fully green suite. Several other modules (middleware.ts, password.ts, the AI prompt-builder configs, ai/client.ts, email-verification.ts, subscription-guard.ts) and most feature components (notably the 849-line AdminPanel) had no tests at all.

Solution

  • Rewrote the 7 stub-based API test files (auth-login, auth-register, assessments, interview-session + session completion, profile-dashboard, resume-coverletter, questions) to import and exercise the real route handlers with mocked db/auth-helpers/etc., following the pattern already used correctly in questions-count.test.ts and auth-verify-email.test.ts.
  • Added tests for previously-untested modules: src/middleware.ts (Edge rate limiter), src/lib/password.ts (bcrypt + legacy SHA-256 migration), src/lib/ai/{coach,resume,cover-letter,assessment}.ts (validation/prompt-building/fallbacks, plus assertions that each system prompt actually contains the required truthfulness/no-fabrication guardrail language per docs/07-guardrails.md), src/lib/ai/client.ts (timeout/abort/JSON extraction), src/lib/email-verification.ts, src/lib/subscription-guard.ts.
  • Added component tests for AdminPanel, CoverLetterStudio, DashboardView (previously only MockInterview, OnboardingQuiz, ResumeLab had coverage).
  • Fixed 4 pre-existing stale assertions in types-constants.test.ts that checked AI route files for a literal getUserFromRequest string; those routes were refactored onto the createAIHandler factory (which enforces auth internally) and no longer contain that literal.
  • __tests__/setup.ts: polyfilled scrollIntoView/pointer-capture APIs jsdom lacks, needed once component tests started driving Radix Select/Tabs.

Along the way this surfaced two real discrepancies between the old stub tests and shipped behavior, now captured as passing assertions rather than silently missed:

  • POST /api/cover-letter returns truthFlags as a raw JSON string (GET/PUT by id parse it back out, POST does not).
  • GET /api/questions?difficulty=all unexpectedly trips the auth-required branch — the gate excludes only 'beginner', not 'all'. (Documented as-is; not changed, since this PR is test-only.)

Scope

Included: test files only (__tests__/**), plus the jsdom polyfills in __tests__/setup.ts.
Excluded: no application code in src/ was changed. The difficulty=all auth quirk noted above is documented in a test comment but intentionally left as-is — a behavior change belongs in a separate PR.

Acceptance criteria

  • Observable behavior matches the requirement — no src/ changes, so app behavior is unchanged
  • Important failure paths are handled — new tests cover 401/403/404/500 branches, rate-limit denial, provider-error fallbacks, etc.
  • AI-generated content meets guardrails policy — added tests asserting each AI system prompt contains the required truthfulness/no-fabrication language
  • Subscription tier access controls work correctly — not applicable (subscriptions are dormant; subscription-guard.test.ts locks in the always-allow no-op contract)

Validation

  • Formatting: bun run lint — 0 errors, only pre-existing warnings unrelated to this change
  • Type checking: bunx tsc --noEmit — clean
  • Tests: bun run test — 411 passed (up from 319 on main), 0 unexpected failures. The only failures are the 4 live-server-only integration files (auth.test.ts, resources.test.ts, questions-interview-ai.test.ts, user-paths.test.ts), which fail identically on main with no server running locally — by design, CI runs those separately against a live build (TEST_BASE_URL=http://localhost:3000)
  • API tests: bun run test:api — same result as above
  • Build: bun run build — succeeds

Risk and rollback

Test-only change; no production code, schema, or environment variables touched. No deployment or data risk. Revert is a plain git revert if needed.

Documentation

No documentation changes needed — this is test coverage only, no behavior or API surface changed.


🤖 Generated with Claude Code

https://claude.ai/code/session_01GY57BayVeQkrRKqTmvNuKZ


Generated by Claude Code

…e major coverage gaps

Rewrites 7 API test files that previously reimplemented route logic
in-test ("Replicate route logic") rather than importing and exercising
the actual src/app/api/**/route.ts handlers, so real bugs in sanitize
calls, Prisma queries, or auth wiring could ship undetected:

- auth-login.test.ts, auth-register.test.ts: real login/register routes
  with mocked db/password/rate-limit, incl. legacy-hash auto-upgrade
- assessments.test.ts, interview-session.test.ts (+ session complete),
  profile-dashboard.test.ts, resume-coverletter.test.ts, questions.test.ts:
  same treatment for their routes

Along the way this surfaced two real discrepancies between the old stub
tests and shipped behavior, now captured as passing assertions:
- POST /api/cover-letter returns truthFlags as a raw JSON string (GET/PUT
  by id parse it back out, POST does not)
- GET /api/questions?difficulty=all unexpectedly trips the auth-required
  branch (the gate excludes only 'beginner', not 'all')

Also adds coverage for previously-untested areas:
- src/middleware.ts (Edge rate limiter) — was untested; only the separate
  DB-backed rate-limit.ts had coverage
- src/lib/password.ts — bcrypt + legacy SHA-256 migration path
- src/lib/ai/{coach,resume,cover-letter,assessment}.ts — validation,
  prompt building, and fallback behavior, plus assertions that the
  required truthfulness/no-fabrication guardrail language is present
  in each system prompt (docs/07-guardrails.md)
- src/lib/ai/client.ts (ZAIProvider/completeJson) — timeout, abort,
  JSON extraction, via a mocked z-ai-web-dev-sdk
- src/lib/email-verification.ts, src/lib/subscription-guard.ts
- AdminPanel, CoverLetterStudio, DashboardView components (previously
  the only tested feature components were MockInterview, OnboardingQuiz,
  ResumeLab)

Fixes 4 pre-existing stale assertions in types-constants.test.ts that
checked AI route files for a literal 'getUserFromRequest' string; those
routes were refactored onto the createAIHandler factory (which enforces
auth internally) and no longer contain that literal.

__tests__/setup.ts: polyfill scrollIntoView/pointer-capture APIs jsdom
lacks, needed once component tests started driving Radix Select/Tabs.

bun run test / tsc --noEmit / lint / build all pass; the only test
failures are the 4 live-server-only integration files (auth.test.ts,
resources.test.ts, questions-interview-ai.test.ts, user-paths.test.ts),
which fail identically at baseline with no server running — unchanged,
by design (CI runs them against a live build separately).
Copilot AI lite review requested due to automatic review settings August 10, 2026 00:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
interview-lab Ready Ready Preview Aug 10, 2026 12:07am

@ecc-tools

ecc-tools Bot commented Aug 10, 2026

Copy link
Copy Markdown

Analyzing 200 commits...

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@projectamazonph, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 399ba820-2cc7-4e2d-bbdb-d4f4ea69cc06

📥 Commits

Reviewing files that changed from the base of the PR and between 8b36b3c and e102e5a.

📒 Files selected for processing (18)
  • __tests__/api/assessments.test.ts
  • __tests__/api/auth-login.test.ts
  • __tests__/api/auth-register.test.ts
  • __tests__/api/interview-session.test.ts
  • __tests__/api/profile-dashboard.test.ts
  • __tests__/api/questions.test.ts
  • __tests__/api/resume-coverletter.test.ts
  • __tests__/components/admin-panel.test.tsx
  • __tests__/components/cover-letter-studio.test.tsx
  • __tests__/components/dashboard-view.test.tsx
  • __tests__/components/types-constants.test.ts
  • __tests__/lib/email-verification.test.ts
  • __tests__/lib/middleware.test.ts
  • __tests__/lib/password.test.ts
  • __tests__/lib/subscription-guard.test.ts
  • __tests__/setup.ts
  • __tests__/unit/ai-client.test.ts
  • __tests__/unit/ai-prompts.test.ts
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/test-coverage-analysis-l787jy

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.

@ecc-tools

ecc-tools Bot commented Aug 10, 2026

Copy link
Copy Markdown

Analysis Complete

Generated ECC bundle from 1 commits | Confidence: 60%

View Pull Request #13

Repository Profile
Attribute Value
Language TypeScript
Framework Not detected
Commit Convention conventional
Test Directory separate
Changed Files (18)
Metric Value
Files changed 18
Additions 2680
Deletions 1492

Top hotspots

Path Status +/-
__tests__/api/auth-register.test.ts modified +262 / -322
__tests__/api/interview-session.test.ts modified +325 / -123
__tests__/api/profile-dashboard.test.ts modified +190 / -231
__tests__/api/resume-coverletter.test.ts modified +229 / -188
__tests__/api/auth-login.test.ts modified +189 / -226

Top directories

Directory Files Total changes
__tests__/api 7 2952
__tests__/components 4 550
__tests__/lib 4 342
__tests__/unit 2 310
__tests__ 1 18
Analysis Depth Readiness (commit-history, 21%)

ECC Tools uses this to decide whether recommendations should stay at commit-history/setup guidance or expand into CI, security, harness, reference-set, AI-routing, and team backlog work.

Area Status Evidence / Next Step
Commit history Partial 1 commits sampled
CI/CD signals Missing Add workflow files or CI troubleshooting evidence so ECC Tools can reason about pipeline setup.
Security evidence Missing Add AgentShield, audit, SARIF, SBOM, or security review evidence so recommendations can cover security posture.
Harness configuration Missing Add Claude, Codex, OpenCode, Zed, dmux, MCP, plugin, or cross-harness config evidence for harness-agnostic recommendations.
Reference/eval evidence Missing Add fixtures, golden traces, reference sets, or evaluator benchmarks so deeper recommendations have regression evidence.
AI routing and cost controls Ready __tests__/lib/subscription-guard.test.ts
Team handoff and project tracking Missing Add roadmap, runbook, project, Linear, or follow-up tracking docs so generated work can land in a team queue.
Reference Set Readiness (0/7, 0%)
Area Status Evidence / Next Step
Deep analyzer corpus Missing Add analyzer fixture, golden, benchmark, or reference-set files that can catch analyzer regressions.
RAG/evaluator comparison Missing Add retrieval or evaluator reference-set comparison fixtures with expected ranking behavior.
PR salvage/review corpus Missing Add stale-PR, review-thread, reopen-flow, or salvage reference cases for queue cleanup automation.
Discussion triage corpus Missing Add public discussion triage fixtures, golden cases, or reference sets for informational, answered, and no-response classifications.
Harness compatibility Missing Add cross-harness, adapter-compliance, or harness-audit evidence for Claude, Codex, OpenCode, Zed, dmux, and agent surfaces.
Security evidence Missing Attach security evidence such as SBOMs, SARIF, audit reports, or AgentShield evidence packs.
CI failure-mode evidence Missing Add captured CI failure logs, dry-run fixtures, or troubleshooting docs for common workflow failure modes.
Likely Future Issues (3)
Severity Signal Why it may show up
HIGH API contract changes may ship without integration coverage 7 API surface paths changed; 0 integration or e2e tests changed
MEDIUM API implementation changes may ship without contract artifact updates 7 API implementation paths changed; 0 API contract/spec files changed
MEDIUM User-facing UI changes may ship without browser coverage 4 user-facing UI paths changed; 0 browser or e2e coverage files changed
  • API contract changes may ship without integration coverage: The PR changes API or route-facing files but does not touch any obvious integration or end-to-end tests.
  • API implementation changes may ship without contract artifact updates: The PR changes API implementation files but does not touch any obvious OpenAPI, GraphQL, or contract/spec artifact.
  • User-facing UI changes may ship without browser coverage: The PR changes components, pages, or other user-facing UI files without touching any obvious browser or end-to-end coverage.
Suggested Follow-up Work (3)
Type Suggested title Targets
PR test: add integration coverage for __tests__/api/assessments.test.ts + __tests__/api/auth-login.test.ts __tests__/api/assessments.test.ts, __tests__/api/auth-login.test.ts
PR docs: sync API contract for __tests__/api/assessments.test.ts + __tests__/api/auth-login.test.ts __tests__/api/assessments.test.ts, __tests__/api/auth-login.test.ts
PR test: add browser coverage for __tests__/components/admin-panel.test.tsx + __tests__/components/cover-letter-studio.test.tsx __tests__/components/admin-panel.test.tsx, __tests__/components/cover-letter-studio.test.tsx
  • test: add integration coverage for tests/api/assessments.test.ts + tests/api/auth-login.test.ts: Backfill integration or end-to-end coverage for the changed API surface before more contract changes land.
  • docs: sync API contract for tests/api/assessments.test.ts + tests/api/auth-login.test.ts: Backfill the missing API contract or spec update before another implementation change lands on top of the same surface.
  • test: add browser coverage for tests/components/admin-panel.test.tsx + tests/components/cover-letter-studio.test.tsx: Backfill browser coverage before another user-facing UI change lands on the touched surface.

Copy-ready bodies

test: add integration coverage for tests/api/assessments.test.ts + tests/api/auth-login.test.ts

## Summary
- Add integration or end-to-end coverage for the recently changed API surface.

## Why
- Backfill integration or end-to-end coverage for the changed API surface before more contract changes land.

## Touched paths
- `__tests__/api/assessments.test.ts`
- `__tests__/api/auth-login.test.ts`

## Validation
- Add or extend integration / e2e coverage for the changed API, route, or contract surface.
- Exercise the touched endpoints or route handlers against realistic request / response flows.

docs: sync API contract for tests/api/assessments.test.ts + tests/api/auth-login.test.ts

## Summary
- Update the API contract artifact that should reflect the recently changed implementation surface.

## Why
- Backfill the missing API contract or spec update before another implementation change lands on top of the same surface.

## Touched paths
- `__tests__/api/assessments.test.ts`
- `__tests__/api/auth-login.test.ts`

## Validation
- Update the relevant OpenAPI, GraphQL, or contract/spec artifact used by this repo.
- Run the contract validation, docs generation, or API verification flow that depends on that artifact.

test: add browser coverage for tests/components/admin-panel.test.tsx + tests/components/cover-letter-studio.test.tsx

## Summary
- Add browser or end-to-end coverage for the recently changed user-facing surface.

## Why
- Backfill browser coverage before another user-facing UI change lands on the touched surface.

## Touched paths
- `__tests__/components/admin-panel.test.tsx`
- `__tests__/components/cover-letter-studio.test.tsx`

## Validation
- Add or extend browser / e2e coverage for the changed component, page, or flow.
- Exercise the visible user journey that depends on the touched UI surface.
Review Activity (1 reviews, 0 inline comments, 0 unresolved threads)
Signal Count
Approvals 0
Change requests 0
Comment-only reviews 1
Dismissed reviews 0
Pending reviews 0
Review threads 0
Unresolved threads 0
Outdated threads 0
Latest review Commented
Latest submitted at 2026-08-10T00:03:11Z

Latest reviewer states

Reviewer State Submitted
@copilot-pull-request-reviewer[bot] Commented 2026-08-10T00:03:11Z
Review Follow-up Signals (1)
Severity Signal Evidence
MEDIUM Get an explicit approval No approving review is recorded for this PR

Recommended next actions

  • Ask for an approval after requested changes and unresolved discussions are addressed.
Generated Instincts (10)
Domain Count
git 2
code-style 3
testing 5

After merging, import with:

/instinct-import .claude/homunculus/instincts/inherited/Interview-lab-instincts.yaml

Files

  • .claude/ecc-tools.json
  • .claude/skills/Interview-lab/SKILL.md
  • .agents/skills/Interview-lab/SKILL.md
  • .agents/skills/Interview-lab/agents/openai.yaml
  • .claude/identity.json
  • .codex/config.toml
  • .codex/AGENTS.md
  • .codex/agents/explorer.toml
  • .codex/agents/reviewer.toml
  • .codex/agents/docs-researcher.toml
  • .claude/homunculus/instincts/inherited/Interview-lab-instincts.yaml

ECC Tools | Everything Claude Code

…f hardcoding defaults

CI's audit job sets API_RATE_LIMIT_MAX=100000 and AUTH_RATE_LIMIT_MAX=1000
at the job level (to relax limits for the live-server integration suite),
which also applies to the plain "Unit tests" step. middleware.test.ts
assumed the un-overridden defaults (60/10), so it never actually tripped
the limiter in CI and failed with 200 instead of 429.

Mirror middleware.ts's own `Number(process.env.X) || default` fallback in
the test so the loop count always matches whatever threshold is actually
configured, in CI or locally.
@projectamazonph
projectamazonph merged commit c425191 into main Aug 10, 2026
4 checks passed
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.

3 participants