fix(api/validation): provider-canonical payment-option whitelist (closes #717) - #793
Conversation
Replace the hand-maintained purchasePaymentWhitelist var with purchasePaymentSet(), which derives the accepted token set from config.ValidPaymentOptionsByProvider -- the same source used by the plan-validator in #709, eliminating drift between the two boundaries. Apply config.NormalizePaymentOption before the whitelist check so legacy AWS-style tokens on Azure/GCP are coerced to canonical spellings (e.g. all-upfront -> upfront on Azure) before validation, preserving backward compatibility for existing callers. Tighten the rejection error to name the provider and list its valid options: `invalid payment option for azure service: "foo" (valid for azure: upfront, monthly)`. Add 15 new test cases covering the per-provider canonical sets, the cross-provider normalization paths, and the error message shape.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR tightens purchase recommendation validation to enforce provider-specific payment-option sets instead of a monolithic global whitelist. The validation now derives canonical valid payments from ChangesProvider-scoped purchase payment validation
Sequence DiagramsequenceDiagram
participant RecommendationInput
participant validatePurchaseRecommendation
participant purchasePaymentSet
participant NormalizePaymentOption
participant ValidPaymentOptionsByProvider
RecommendationInput->>validatePurchaseRecommendation: (provider, payment)
validatePurchaseRecommendation->>purchasePaymentSet: normalized provider
purchasePaymentSet->>ValidPaymentOptionsByProvider: lookup canonical set
ValidPaymentOptionsByProvider-->>purchasePaymentSet: payment token set
purchasePaymentSet-->>validatePurchaseRecommendation: derived set or nil
validatePurchaseRecommendation->>NormalizePaymentOption: (provider, payment) for alias coercion
NormalizePaymentOption-->>validatePurchaseRecommendation: normalized payment token
validatePurchaseRecommendation->>validatePurchaseRecommendation: check normalized token in set
validatePurchaseRecommendation-->>RecommendationInput: valid or error with provider + valid options
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
Actionable comments posted: 0 |
|
@coderabbitai full review |
Rate Limit Exceeded
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
purchasePaymentWhitelistvar withpurchasePaymentSet(), which derives the accepted token set directly fromconfig.ValidPaymentOptionsByProvider-- single source of truth, no drift between the plan-validator and the purchase-execute boundary.config.NormalizePaymentOptionbefore the whitelist check so legacy AWS-style tokens submitted against Azure/GCP are coerced to the provider-canonical spelling before validation (preserving backward compatibility for existing callers).invalid payment option for azure service: "foo" (valid for azure: upfront, monthly).Before / after whitelist shape
Before (hand-maintained, over-permissive):
After (derived from
config.ValidPaymentOptionsByProvider, #709's canonical source):Legacy cross-provider tokens (e.g.
all-upfronton Azure) are coerced viaNormalizePaymentOptionat ingest, so existing callers continue to work.Error message format
Test counts
28 test cases in
TestValidatePurchaseRecommendation(up from 14), plus 1 newTestValidatePurchaseRecommendation_ErrorMessage. All 1367 tests ininternal/api/...pass.Closes #717
Summary by CodeRabbit