fix(home): test isolation — duplicate key error#3359
Conversation
Non-obvious bug fixes should be documented in ERRORS.md (symptom, root cause, fix) so future sessions avoid repeat debugging. Closes #3354
requireQuota middleware and getUsage controller built counter keys with dots (resource.action) which are rejected by SAFE_KEY_RE in the usage repository, causing 422 errors on quota-checked endpoints. Switch to underscore separator to match the allowed pattern. Closes #3350
Clean up admin user in afterAll and use a unique email prefix (admin-home-health) to avoid E11000 collisions when running all test suites together via test:coverage. Closes #3348
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 10 minutes and 44 seconds. ⌛ 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: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ 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 |
There was a problem hiding this comment.
Pull request overview
Improves test-suite isolation for the Home integration tests (avoiding duplicate admin-user collisions) and updates billing quota/usage key formatting used by middleware/controller, along with corresponding unit test + documentation updates.
Changes:
- Clean up and namespace the Home integration test admin user (pre-delete + afterAll delete) to prevent E11000 duplicate key failures in full-suite runs.
- Switch billing quota/usage counter keys from
resource.actiontoresource_actionin the quota middleware and usage endpoint (and update related unit tests/docs). - Extend the feature skill checklist with an ERRORS.md documentation reminder.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| modules/home/tests/home.integration.tests.js | Namespaces + cleans up the admin test user to prevent duplicate-key collisions across suites. |
| modules/billing/middlewares/billing.requireQuota.js | Changes quota counter lookup key format to underscore-delimited. |
| modules/billing/controllers/billing.controller.js | Changes flattened limits key format to underscore-delimited. |
| modules/billing/README.md | Updates BillingUsageService.increment example key format. |
| modules/billing/tests/billing.usage.endpoint.unit.tests.js | Updates unit test expectations for underscore-delimited usage/limit keys. |
| modules/billing/tests/billing.quota.unit.tests.js | Updates unit test expectations for underscore-delimited counter keys. |
| .claude/skills/feature/SKILL.md | Adds checklist item about documenting bugs in ERRORS.md. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3359 +/- ##
==========================================
- Coverage 90.21% 83.39% -6.83%
==========================================
Files 56 110 +54
Lines 1186 2764 +1578
Branches 239 769 +530
==========================================
+ Hits 1070 2305 +1235
- Misses 105 359 +254
- Partials 11 100 +89 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Changes already included in #3361 after cross-branch finalization |
Summary
afterAllto prevent E11000 duplicate key errors when running all test suites together (npm run test:coverage)admin-health@test.comtoadmin-home-health@test.comfor namespace isolationdeleteOnebeforecreateto handle stale data from previous interrupted runsresource_action) instead of dot (resource.action) for consistency betweenrequireQuotamiddleware andusageendpoint. This is an internal format — no external API contract changes since the billing module is not yet exposed to consumers.Test plan
npm run lintpassesnpm run test:coverageno longer fails on home integration testsCloses #3348