Repository navigation
fix(recs): disambiguate min-savings dollar (API) vs percent (CLI) filters - #1091
Conversation
|
Warning Review limit reached
More reviews will be available in 34 minutes and 56 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: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
…ters Closes #1089 The CLI `--min-savings-pct` flag filters by savings percentage while the API/GUI `min_savings` parameter was intended to filter by absolute dollar savings -- two differently-scaled concepts with near-identical names. A user who knows `--min-savings-pct 30` from the CLI would set `min_savings=30` in the GUI and silently filter by $30, not 30%. Additionally, the `min_savings` query parameter was never parsed by the Go handler, so it was silently dropped server-side despite being sent by the frontend. Changes: - Rename `RecommendationFilter.MinSavings` to `MinSavingsUSD` (Go) - Add `RecommendationFilter.MinSavingsPct` (0-100 percentage floor) - Parse both `min_savings_usd` and `min_savings_pct` from query params in getRecommendations, with input validation (400 on bad values) - MinSavingsUSD is pushed into SQL (existing monthly_savings column) - MinSavingsPct is applied in-process via recEffectiveSavingsPct helper (mirrors the frontend effectiveSavingsPct formula) - Rename `RecommendationFilters.minSavings` to `minSavingsUsd` in TS - Add `minSavingsPct` to RecommendationFilters in TS with clear JSDoc - Update getRecommendations API call to use new distinct param names - Regression tests: Go (handler + config + validation) and JS (api.test) assert the % and $ paths are distinct and cannot be conflated
…mplexity getRecommendations had cyclomatic complexity of 12 (limit: 10) after the min-savings parameter additions. Extract parameter validation and filter construction into parseRecommendationFilter, dropping getRecommendations to complexity 5. No behaviour change; all existing tests pass.
1700339 to
94bdc39
Compare
|
@coderabbitai review Generated by Claude Code |
|
🧠 Learnings used✅ Action performedReview finished.
|
|
@coderabbitai full review |
✅ Action performedFull review finished. |
Summary
minSavings(ambiguous) tominSavingsUsd(dollar floor) and adds a new distinctminSavingsPct(percentage floor, 0-100)handler_recommendations.go) -- previouslymin_savingswas sent by the frontend but silently dropped server-side (never parsed)MinSavingsUSDis pushed into SQL via the existingmonthly_savingscolumn;MinSavingsPctis applied in-process via a newrecEffectiveSavingsPcthelper that mirrors the frontendeffectiveSavingsPctformulaparseMinSavingsParamvalidation helper (non-negative numeric, 0-100 range check for pct)Rationale (issue #1089)
CLI
--min-savings-pctfilters by savings percentage (e.g. 30%); the old APImin_savingswas a dollar amount. A user who knows--min-savings-pct 30from the CLI would setmin_savings=30in the GUI and silently filter by $30 -- not 30%. The fix makes both concepts explicit and independently accessible.Files changed
internal/config/types.go--RecommendationFilter:MinSavingsrenamed toMinSavingsUSD, newMinSavingsPctfieldinternal/config/store_postgres_recommendations.go-- SQL builder usesMinSavingsUSD;ListStoredRecommendationsappliesMinSavingsPctin-process; newrecEffectiveSavingsPcthelperinternal/api/handler_recommendations.go-- parses both new query params with validationinternal/api/validation.go-- newparseMinSavingsParamhelperfrontend/src/api/types.ts--RecommendationFilters:minSavingsrenamed tominSavingsUsdwith JSDoc, newminSavingsPctfieldfrontend/src/api/recommendations.ts--getRecommendationssendsmin_savings_usd/min_savings_pctquery paramsRegression tests
internal/api/handler_recommendations_test.go):TestGetRecommendations_MinSavingsFilters-- asserts dollar and percentage params map to distinct filter fieldsinternal/api/validation_test.go):TestParseMinSavingsParam-- validates parse edge casesinternal/config/store_postgres_savings_filter_test.go):TestRecEffectiveSavingsPct_Config,TestRecommendationFilter_UnitDistinction,TestBuildRecommendationFilter_MinSavingsUSD-- asserts the same numeric value "30" produces opposite filter outcomes as USD vs PCTfrontend/src/__tests__/api.test.ts): 3 new tests assertminSavingsUsd->min_savings_usdandminSavingsPct->min_savings_pct, never conflatedVerification
go test ./internal/api/... ./internal/config/...-- 2095 tests passnpx tsc --noEmit-- no type errorsjest --testPathPattern=api.test.ts-- 75 tests passCloses #1089