fix(billing): re-apply lost C.2 review nits (warn-on-unknown-priceId + 4 hardening)#3758
Conversation
…+ 4 hardening) 5 Copilot review findings from PR #3743 (#1250 P0) were silently lost because a controller-side fix commit was never pushed to origin before the squash-merge. Re-applied fixes: 1. JSDoc for buildPriceIdToPlanMap: accurate description with @returns tag 2. resolvePlan: warn log when priceId not in map and metadata empty (operationally critical — same silent-free-downgrade shape as the P0 it was meant to prevent) 3. cancel_at truthy check → typeof === 'number' (prevents cancel_at=0 being skipped) 4. previousPlan: validatePlan() before comparison (rejects stale/invalid metadata values) 5. Test comment: corrects misleading "retryWithBackoff setTimeout suppression" claim Refs: #3743, plan 2026-05-30-trawl-devkit-perfect-alignment.md
|
Warning Review limit reached
More reviews will be available in 56 minutes and 6 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughUpdated billing webhook service to harden plan-resolution and subscription-update logic: plan fallback now validates legacy metadata and logs warnings on unknown priceIds, subscription updates enforce stricter ChangesBilling Webhook Plan Resolution and Subscription Update Tightening
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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
Re-applies five previously lost hardening/observability fixes in the billing Stripe webhook flow (priceId→plan resolution), to prevent silent plan downgrades and make plan-change detection more robust.
Changes:
- Updates
buildPriceIdToPlanMap()JSDoc to accurately describe behavior and return type. - Adds a
logger.warnwhen falling back tofreedue to an unmappedpriceIdand missing metadata, and hardenscancel_at+previousPlanhandling. - Corrects a misleading unit-test comment about retry delay suppression.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| modules/billing/services/billing.webhook.service.js | Adds warning on last-resort free fallback; hardens cancellation timestamp handling and previous-plan validation; updates JSDoc. |
| modules/billing/tests/billing.webhook.priceid-map.unit.tests.js | Corrects test comment to accurately describe what the mock does (no retry delay suppression). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3758 +/- ##
=======================================
Coverage 90.13% 90.14%
=======================================
Files 150 150
Lines 4956 4961 +5
Branches 1573 1574 +1
=======================================
+ Hits 4467 4472 +5
Misses 384 384
Partials 105 105
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Copilot review finding on PR #3758: the previous warn fired whenever priceId was present and metadata didn't validate, but the log message said "metadata empty" — misleading when metadata IS present but invalid (validatePlan already warns in that case → double-warn). Gate: only emit the warn when rawMeta is also absent (!rawMeta), and update the message from "metadata empty" to "no metadata" to be precise.
Context
PR #3743 (
fix(billing): resolve plan via priceId map, not price.metadata.planId (#1250), merge commit0693e497) was merged to devkit master with 5 unfixed Copilot review findings. A controller-side fix commit (11b00505) was prepared locally but never pushed toorigin/feat/resolveplan-priceid-map— the push silently appeared to succeed (RTK wrapper reported "ok") whilegit ls-remoteshows the SHA never reached origin. The 5 review threads were resolved on GitHub against the wrong commit, and the squash-merge captured only the agent's original content.Net: 5 known bugs were live in devkit master. This PR re-applies all 5 fixes.
Closes #3757. Refs: #3743, plan
2026-05-30-trawl-devkit-perfect-alignment.md.Findings re-applied
buildPriceIdToPlanMap): replaced stale comment with accurate description +@returnstagresolvePlan): addslogger.warnwhen priceId is present but not in the map and metadata is empty — the operationally critical one, same silent-downgrade shape as the P0 from build(deps-dev): bump husky from 5.1.1 to 5.1.2 #1250cancel_attypeof check:if (subscription.cancel_at)→if (typeof subscription.cancel_at === 'number')— preventscancel_at = 0(epoch) from being silently skippedpreviousPlanvalidatePlan(): raw priceIdToPlan/metadata value validated before comparison — prevents stale/invalid metadata from triggeringplan.changed+forceRotateForPlanChangewith junk plan namessetTimeoutdelaysVerification
npm run lint→ ESLint: No issues foundnpm run test:unit -- modules/billing/tests/billing.webhook→ 1714/1714 passnpm audit --audit-level=high→ pre-existing baseline (no new vulnerabilities)git ls-remote:6ec833edb3dba2bb914f818f2db06041d502c055Summary by CodeRabbit
Bug Fixes
Tests