Repository navigation
fix: lib auth + services test quality to 9+ rubric - #792
Conversation
…core - Create repository seams (session-repository.ts, storage-repository.ts) to eliminate ORM chain mocks in session-service and storage-limits tests - Replace all `as any` casts with `vi.mocked()`, `as never`, or `@ts-expect-error` - Replace all bare `toHaveBeenCalled()` with meaningful argument assertions - Fix flake risk: replace real `setTimeout` sleeps with `vi.useFakeTimers()` - Fix environment variable restoration (use `delete` instead of `= undefined`) - Add `@scaffold` labels to 13 files that still use ORM chain mocks pending future repository seam extraction - All 28 runnable test files pass (520 tests), 4 pre-existing failures unchanged Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
⌛ 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 selected for processing (25)
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
vi.mocked() can't properly infer mock methods on deeply nested Drizzle ORM query objects, causing TS2339/TS2345 errors in CI. Replace with explicit MockDb type that matches each file's mock factory, giving TypeScript clean access to .mockReturnValue(), .mockResolvedValueOnce(), etc. Affected files: passkey-service, drive-member-service, drive-role-service, notification-email-service (all @scaffold). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ests Replace vi.mocked(db) with typed MockDb interfaces in device-auth-utils and activity-logger-compliance tests. Fix indentation in page-tree-cache test and add explicit parameter type in storage-repository. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Narrow SessionUserRecord.role to 'user' | 'admin' and SessionRecord.type to union type, eliminating type casts in session-service.ts - Add DrizzleTx type alias in storage-repository.ts, replacing 4 repeated Parameters<Parameters<...>> expressions - Import and use DrizzleTx in storage-limits.ts - Tighten expect.anything() → exact table refs (verificationTokens, users) in verification-utils.test.ts and oauth-utils-unit.test.ts - Tighten expect.any(Object) → expect.objectContaining with actual metadata keys in validated-service-token.test.ts (8 assertions) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…vices Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TypeScript TS2352: Cannot directly cast undefined to { emailVerified }.
Cast through unknown first.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
vi.fn(() => ...) produces a zero-param type signature, making calls[0][0] a TS2493 tuple index error. Cast calls array instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…orage-repository Aligns with session-repository pattern — ?? only falls back for null/undefined, avoiding false-positive coercion of legitimate 0 values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
All test files using ORM chain mocks now have formal @scaffold labels documenting they are temporary characterization tests pending repository seam extraction. REVIEW comments flag order-dependent mock ladders in drive-service, passkey-service, drive-member-service, and oauth-utils. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
session-repository.ts,storage-repository.ts) to decouplesession-serviceandstorage-limitsfrom direct ORM calls, enabling clean mockingas anytype casts across 32 test files (replaced withvi.mocked(),as never,@ts-expect-error)toHaveBeenCalled()with meaningful argument assertionsrate-limit-utils.test.ts(realsetTimeoutsleeps →vi.useFakeTimers())oauth-utils-unit.test.ts(delete process.env[key]instead of= undefined)@scaffoldlabels to 13 files with ORM chain mocks pending future seam extraction@scaffoldtest files by replacingvi.mocked(db)with explicitMockDbtypes matching each file's mock factory5-Axis Rubric Scores (all 9+)
@scaffold@scaffold@scaffold@scaffold@scaffold@scaffold@scaffold@scaffold@scaffold@scaffold@scaffold@scaffold@scaffold¹ Pre-existing failure on base branch (dependency resolution)
² Excluded by vitest config (integration test requiring live DB)
28/28 runnable files score 9+ ✓ (15 at 10/10, 13 at 9/10
@scaffold)What
@scaffoldmeansFiles labeled
@scaffolduse ORM chain mocks (db.update().set().where().returning()) because the production code directly callsdb. These tests are characterization tests — they verify behavior correctly but would break on internal refactoring. The fix is extracting repository seams (as done forsession-serviceandstorage-limits), which is planned for a follow-up.TypeScript fix for scaffold tests
The
vi.mocked(db)pattern can't properly infer mock methods on deeply nested Drizzle ORM query objects (e.g.,db.query.users.findFirst), causing TS2339/TS2345 errors. Fixed by replacing with explicitMockDbtype interfaces matching each file's mock factory, giving TypeScript clean access to.mockReturnValue(),.mockResolvedValueOnce(), etc.Test plan
git stash)🤖 Generated with Claude Code