Skip to content

fix(frontend): stop double-scaling the Savings Plans group row savings - #380

Merged
cristim merged 1 commit into
mainfrom
fix/252-sp-group-double-scale
Sep 28, 2026
Merged

cristim merged 1 commit into
mainfrom
fix/252-sp-group-double-scale

Conversation

@cristim

@cristim cristim commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Summary

The Savings Plans group parent row on the Opportunities page scaled its savings total with scaleCost and then passed the already-scaled value into formatCostForPeriod, 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) computed scaledSpSavings = scaleCost(spSavingsTotal, period) and then called formatCostForPeriod(scaledSpSavings, period), but formatCostForPeriod (line ~1592) already calls scaleCost internally. Every sibling row in the same table passes the raw monthly value into formatCostForPeriod, or uses formatScaledRange (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 spSavingsTotal directly to formatCostForPeriod and drop the outer scaleCost call.

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 at period: '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.ts then ran the new test -- it failed with Expected substring: "$3600" / Received string: "$43200/ yr" (12x too high, matching the double-scale). Restored via git stash pop and reran: passes.

Verification

  • npm test -- recommendations.test.ts -- 409 passed
  • npx eslint src/recommendations.ts src/__tests__/recommendations.test.ts -- no issues
  • npm run build -- webpack production build succeeds (pre-existing entrypoint-size warning only)

Closes #252

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>
@coderabbitai

coderabbitai Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 2 billable files and costs up to $0.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: LeanerCloud/cloud-commitments-platform/.coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: 4dd1f736-69eb-4968-881a-f435558700e5

📥 Commits

Reviewing files that changed from the base of the PR and between 4b7bc93 and a17b7e9.

📒 Files selected for processing (2)
  • frontend/src/__tests__/recommendations.test.ts
  • frontend/src/recommendations.ts

Comment @coderabbitai help to get the list of available commands.

@cristim cristim added urgency/this-sprint Within the current sprint priority/p1 Next up; this sprint severity/high Significant harm impact/many Affects most users effort/xs Trivial / one-liner type/bug Defect triaged Item has been triaged labels Sep 28, 2026
@cristim

cristim commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

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.

@cristim
cristim merged commit 51369c1 into main Sep 28, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/many Affects most users priority/p1 Next up; this sprint severity/high Significant harm triaged Item has been triaged type/bug Defect urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(frontend): the Savings Plans group row applies the cost-period factor twice

1 participant