Skip to content

fix(home): test isolation — duplicate key error#3359

Closed
PierreBrisorgueil wants to merge 4 commits into
masterfrom
fix/home-test-duplicate-key-3348
Closed

fix(home): test isolation — duplicate key error#3359
PierreBrisorgueil wants to merge 4 commits into
masterfrom
fix/home-test-duplicate-key-3348

Conversation

@PierreBrisorgueil

@PierreBrisorgueil PierreBrisorgueil commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Clean up admin user created during home integration tests in afterAll to prevent E11000 duplicate key errors when running all test suites together (npm run test:coverage)
  • Rename test email from admin-health@test.com to admin-home-health@test.com for namespace isolation
  • Add defensive deleteOne before create to handle stale data from previous interrupted runs
  • Billing key format change: Quota counter keys and usage response keys now use underscore separator (resource_action) instead of dot (resource.action) for consistency between requireQuota middleware and usage endpoint. This is an internal format — no external API contract changes since the billing module is not yet exposed to consumers.

Test plan

  • npm run lint passes
  • npm run test:coverage no longer fails on home integration tests
  • Billing unit tests pass with updated key format
  • CI passes on this branch

Closes #3348

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
Copilot AI review requested due to automatic review settings March 30, 2026 16:37
@coderabbitai

coderabbitai Bot commented Mar 30, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@PierreBrisorgueil has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 44 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e135011a-6107-4a22-8849-e5b45fe72bd6

📥 Commits

Reviewing files that changed from the base of the PR and between 14b8763 and 22c411a.

📒 Files selected for processing (7)
  • .claude/skills/feature/SKILL.md
  • modules/billing/README.md
  • modules/billing/controllers/billing.controller.js
  • modules/billing/middlewares/billing.requireQuota.js
  • modules/billing/tests/billing.quota.unit.tests.js
  • modules/billing/tests/billing.usage.endpoint.unit.tests.js
  • modules/home/tests/home.integration.tests.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/home-test-duplicate-key-3348

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 and usage tips.

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.

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.action to resource_action in 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.

Comment thread modules/billing/middlewares/billing.requireQuota.js
Comment thread modules/billing/controllers/billing.controller.js
Comment thread .claude/skills/feature/SKILL.md Outdated
@codecov

codecov Bot commented Mar 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.39%. Comparing base (904d1c5) to head (22c411a).
⚠️ Report is 155 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PierreBrisorgueil

Copy link
Copy Markdown
Contributor Author

Changes already included in #3361 after cross-branch finalization

@PierreBrisorgueil
PierreBrisorgueil deleted the fix/home-test-duplicate-key-3348 branch March 31, 2026 05:21
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.

fix(home): test isolation — duplicate key error when running all tests together

2 participants