fix(frontend/api): preserve details + engine on purchase POST (closes #597) - #600
Conversation
…597) Both handleExecutePurchase and handleFanOutExecute reconstructed the recommendation object field-by-field before POSTing to /api/purchases/execute, silently dropping details, engine, and cloud_account_id. The backend's DecodeServiceDetailsFor received nil Details, fell back to zero-valued ComputeDetails, and substituted Platform=Linux/UNIX, Tenancy=default, Scope=Region for every purchase regardless of the actual recommendation. Windows EC2, dedicated-tenancy, and AZ-scoped RIs mis-purchased as Linux/regional/default; non-default-engine RDS/Cache rows failed with "no offerings found". Only Linux/regional/shared recs accidentally worked. Fix: - Add details?: unknown to Recommendation (api/types.ts) and LocalRecommendation (types.ts) as an opaque pass-through blob matching the backend's json.RawMessage field (added in #454). - Replace both field-by-field map() reconstructions in app.ts with spread syntax: { ...r, payment: ..., selected: true, purchased: false }. All server-provided fields (details, engine, cloud_account_id, and any future additions) now flow through unchanged. - Add 4 regression tests in purchase-execution-toast.test.ts asserting that executePurchase receives details and engine for an EC2 Windows fixture and an RDS Postgres fixture on both the single-rec and fan-out paths. Refs #453, #454
|
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 (4)
📝 WalkthroughWalkthroughThis PR fixes a critical bug where the frontend's ChangesDetails field preservation in purchase execution
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 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.
|
Summary
The dashboard purchase flow was silently dropping the
details(andengine,cloud_account_id) fields from every recommendation before POSTing to/api/purchases/execute. BothhandleExecutePurchaseandhandleFanOutExecuteinapp.tsreconstructed the recommendation object field-by-field, leavingdetailsout. The backend'sDecodeServiceDetailsForreceivedniland fell back to zero-valued defaults:Platform=Linux/UNIX,Tenancy=default,Scope=Region. Windows EC2, dedicated-tenancy, and AZ-scoped RIs mis-purchased as Linux/regional/default; non-default-engine RDS/Cache rows failed with "no offerings found for Linux/UNIX default". Only Linux/regional/shared recs accidentally worked. Thedetailsfield itself was missing from both theRecommendationAPI interface and theLocalRecommendationfront-end type, making the omission invisible to TypeScript.What changed
frontend/src/api/types.ts: Addeddetails?: unknowntoRecommendationinterface. The field is typed as opaqueunknown(not a strict union) because the frontend treats it as a pass-through blob matching the backend'sjson.RawMessagefield.frontend/src/types.ts: Addeddetails?: unknowntoLocalRecommendationinterface so the field is preserved in the local cache from the GET /api/recommendations response.frontend/src/app.ts: Replaced the field-by-fieldmap()reconstructions in bothhandleExecutePurchase(single-rec path) andhandleFanOutExecute(fan-out path) with spread syntax:{ ...r, monthly_cost: r.monthly_cost ?? null, payment: ..., selected: true, purchased: false }. All server-provided fields includingdetails,engine,cloud_account_id, and any future additions now flow through unchanged.frontend/src/__tests__/purchase-execution-toast.test.ts: Added 4 regression tests assertingexecutePurchaseis called withdetails(andengine) preserved for an EC2 Windows fixture and an RDS Postgres fixture on both the single-rec and fan-out paths.Why it matters
This is a P0 silent mis-purchase bug affecting every dashboard purchase that is NOT Linux/regional/shared-tenancy. Windows EC2, dedicated-tenancy RIs, AZ-scoped RIs, and non-default-engine RDS/ElastiCache rows were either purchasing the wrong configuration or failing outright. The backend codec fix in #454 completed the server-side round-trip but the frontend was never sending
detailsin the first place.Test plan
npm test -- --testPathPattern=purchase-execution-toast- all 15 tests pass (11 existing + 4 new)npm test --no-coverage- 1902 tests, 0 failurestsc --noEmit- 0 errorsdetailskeyCloses #597
Refs #453, #454
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests