Repository navigation
fix(exchange): fail loud on over-cap re-quote, empty region, non-positive count - #1082
Conversation
…tive count M4: executeWithAPI now re-quotes immediately before AcceptReservedInstancesExchangeQuote to narrow the quote-to-accept window. If the re-quoted payment exceeds MaxPaymentDueUSD, the exchange is aborted with an explicit error surfacing actual vs cap amounts rather than proceeding silently. Accept is never called on an over-cap re-quote. M3: loadCfg now returns an explicit error when region is empty or whitespace-only, refusing to default to us-east-1 on the RI exchange path. RIs are regional; an implicit region default on a spend path violates the fail-loud directive. L2: validateTargets now accepts legacyCount and validates Count >= 1 for both the multi-target and legacy-singleton paths. A zero or negative Count is an error, not a silent rewrite to 1. buildTargetConfigs no longer has a fallback-to-1 branch. L3: Correct the stale comment in pricingGatePasses: NormalizationFactorForSize returns 0 (not 1.0) for unknown sizes, causing passesDollarUnitsCheck to reject the alternative (fail-closed), not to bypass the dollar-units check. Regression tests added in fail_loud_test.go covering all three money-path fixes. Closes #1080.
|
Warning Review limit reached
More reviews will be available in 16 minutes and 36 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 (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
…ic complexity Extract resolvePaymentDue, checkInitialQuote, and checkReQuote from executeWithAPI to bring its cyclomatic complexity from 11 to 6, fixing the gocyclo pre-commit hook failure (limit: 10). Also deduplicate the ExchangeQuoteRequest literal by factoring it into a shared quoteReq variable used by both the initial and re-quote calls. Behavior is identical: all 94 exchange tests pass with -race.
|
refactor: extracted @coderabbitai review |
|
🧠 Learnings used✅ Action performedReview finished.
|
Summary
Fixes three money-safety / silent-fallback violations in
pkg/exchange(all on the RI exchange spend path). RI exchanges are irreversible -- the owner directive is fail-loud, no silent defaults, especially on money paths.M4 (most critical) --
executeWithAPInow performs a secondGetReservedInstancesExchangeQuoteimmediately beforeAcceptReservedInstancesExchangeQuoteto narrow the quote-to-accept window. If the re-quoted payment exceedsMaxPaymentDueUSD, the exchange is aborted with an explicit error surfacing the actual vs cap amounts. Accept is never called when the re-quote is over-cap.M3 --
loadCfgnow returns an explicit error when region is empty or whitespace-only. RIs are regional; silently targetingus-east-1on a spend path was a hardcoded region assumption the owner directive prohibits.L2 --
validateTargetsnow validatesCount >= 1for both the multi-target and legacy-singleton paths. A zero or negative count is an error, not a silent rewrite to1.buildTargetConfigsno longer has acount <= 0 => 1fallback branch.L3 -- Corrected stale comment in
pricingGatePasses:NormalizationFactorForSizereturns0(map miss) for unknown sizes, not1.0. The actual behavior is fail-closed (alternative excluded), not "no NF adjustment".Regression tests added in
fail_loud_test.gocovering all three money-path fixes (M4, M3, L2).Verification
Follow-up
L4 (
PurchaseHistoryRecord.MonthlyCostshould be*float64-- migration-bearing, out of scope here) is tracked in issue #1081.Closes #1080.