Repository navigation
fix(frontend): stop double-scaling the Savings Plans group row savings - #380
Conversation
The SP group parent row computed its savings total with scaleCost and then passed the already-scaled value to formatCostForPeriod, which scales internally. On "yearly" a $1,000/mo SP group rendered as $144,000/yr instead of $12,000/yr; on "hourly" it rendered roughly 1/720th of the right figure. Every sibling row passes raw monthly values into formatCostForPeriod (or uses formatScaledRange, which does not re-scale), so the SP group row was the only outlier. The default period is monthly (factor 1), so the bug was invisible until a user switched the selector. Pass the raw spSavingsTotal to formatCostForPeriod and drop the redundant scaleCost call. Co-Authored-By: claude-flow <ruv@ruv.net>
|
Warning Review limit reached
This review includes 2 billable files and costs up to $0.50.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 15 minutes for your next included review. View limit detailsLimit details: You’ve used all 4 included reviews currently available. Your 30 included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour. Review configuration: ⚙️ Run configurationConfiguration used: Repository: LeanerCloud/cloud-commitments-platform/.coderabbit.yaml Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (2)
Comment |
|
Independent adversarial review + local verification: MERGE at a17b7e9. The backend emits monthly figures and formatCostForPeriod scales internally, so the SP group row now passes raw monthly; every other scaleCost call site verified not to double-scale. Pre-fix test shows $43200/yr for a $300/mo total; passes after; jest 409/409, lint/build OK. |
Summary
The Savings Plans group parent row on the Opportunities page scaled its savings total with
scaleCostand then passed the already-scaled value intoformatCostForPeriod, which scales internally. With the cost-period selector on "yearly" a $1,000/mo SP group rendered as $144,000/yr instead of $12,000/yr; on "hourly" it rendered roughly 1/720th of the right figure.Root cause
frontend/src/recommendations.ts(SP group parent row rendering) computedscaledSpSavings = scaleCost(spSavingsTotal, period)and then calledformatCostForPeriod(scaledSpSavings, period), butformatCostForPeriod(line ~1592) already callsscaleCostinternally. Every sibling row in the same table passes the raw monthly value intoformatCostForPeriod, or usesformatScaledRange(which does not re-scale), so the SP group row was the sole double-scaled outlier. The default period is monthly (factor 1), so the bug was invisible until a user changed the selector, and the only existing test ran at the default period.Fix
Pass the raw
spSavingsTotaldirectly toformatCostForPeriodand drop the outerscaleCostcall.Regression test
Extended
frontend/src/__tests__/recommendations.test.ts's "Issue #135: SP group parent row rendered in table" describe block with a new test asserting the group savings text atperiod: 'yearly'on a $300/mo SP group total: expects$3600, not the double-scaled$36000.Proved pre-fix failure:
git stash push -- frontend/src/recommendations.tsthen ran the new test -- it failed withExpected substring: "$3600"/Received string: "$43200/ yr"(12x too high, matching the double-scale). Restored viagit stash popand reran: passes.Verification
npm test -- recommendations.test.ts-- 409 passednpx eslint src/recommendations.ts src/__tests__/recommendations.test.ts-- no issuesnpm run build-- webpack production build succeeds (pre-existing entrypoint-size warning only)Closes #252