fix(purchase): map canonical slugs to canonical ServiceType (closes #626) - #630
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughRefactors purchase service-type mapping to distinguish canonical slugs from AWS-legacy slugs, normalizing Savings Plans first, and updates unit and integration tests so Azure/GCP receive canonical ServiceType constants while AWS legacy mappings remain supported. ChangesCanonical vs. legacy service type mapping
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
|
) Manager.mapServiceType collapsed the canonical service slugs (compute, relational-db, cache, search, data-warehouse) onto the AWS-legacy ServiceType constants (ServiceEC2, ServiceRDS, ServiceElastiCache, ServiceOpenSearch, ServiceRedshift). The AWS provider's GetServiceClient accepts both legacy and canonical, so AWS approves kept working. Azure and GCP providers are canonical-only, so passing ServiceEC2 for a Service:"compute" rec fell through to the default branch and returned "unsupported service: ec2". User-visible production failure on execution 757c9a6e-b22a-4a81-bf04-b11043cbf658 (Standard_B1ls Azure compute). Split the switch so canonical slugs map to canonical ServiceType constants and legacy slugs keep mapping to the AWS-legacy constants. Backward-compatible for AWS (provider switch accepts both); unblocks Azure now and pre-emptively fixes the same shape of bug for GCP once those code paths are exercised. After deploy, the failed execution above must be cancelled and re-created by the user to retry approval.
TestExecutePurchase_SingleAccount_AzureUsesResolvedCreds wired its mock GetServiceClient to expect common.ServiceEC2 for a rec carrying Service:"compute". The mock returned success regardless of the ServiceType passed in, so CI stayed green while the real Azure provider rejected the same call in production as "unsupported service: ec2". Flip the expectation to ServiceCompute so this test now exercises the correct contract.
…ping Two regression guards for issue #626: 1. Extend TestMapServiceType_AllBranches with the canonical-arm assertions that were missing: relational-db -> ServiceRelationalDB, cache -> ServiceCache, search -> ServiceSearch, data-warehouse -> ServiceDataWarehouse, plus the corrected compute -> ServiceCompute. These pin the canonical/legacy split so it cannot silently regress. 2. New TestExecutePurchase_AzureCanonicalServiceTypes drives executePurchase end-to-end with Azure recs carrying canonical Service slugs (compute, cache, relational-db) and asserts the mock GetServiceClient is called with the canonical ServiceType constants (ServiceCompute, ServiceCache, ServiceRelationalDB), not the AWS-legacy ones. This is the integration-style test that would have caught the production failure.
c4f1abd to
a87c0c4
Compare
|
Rebased onto latest feat/multicloud-web-frontend. Conflicts came from PR #629 (already merged on the base) which addressed the same Azure-purchase failure by collapsing both legacy and canonical service slugs onto the canonical ServiceType constants. This PR's canonical/legacy split is the strict superset — it fixes the same Azure regression while preserving Conflict resolution:
Local verification on the rebased tip:
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
Summary
Fixes #626.
Manager.mapServiceTypecollapsed canonical service slugs onto AWS-legacyServiceTypeconstants, breaking every Azure (and pre-emptively GCP) approve for Compute, Cache, RelationalDB, Search, and DataWarehouse. AWS provider accepts both forms so AWS kept working; Azure/GCP are canonical-only and rejected the legacy constants withunsupported service: ec2(or the equivalent).Root cause
internal/purchase/execution.go:566-581mapped"compute"tocommon.ServiceEC2instead ofcommon.ServiceCompute(same shape for"cache","relational-db","search","data-warehouse"). The existing Azure-rec mock inexecution_test.go:1036encoded the bug by expectingServiceEC2for aService:"compute"rec, so CI passed while production failed.Changes
internal/purchase/execution.go— splitmapServiceTypecases so canonical slugs map to canonical constants. Legacy AWS slugs still map to the AWS-legacy constants for backward compat (AWS provider accepts both forms).internal/purchase/execution_test.go— fixTestExecutePurchase_SingleAccount_AzureUsesResolvedCredsmock expectation fromServiceEC2toServiceCompute. AddTestExecutePurchase_AzureCanonicalServiceTypescoveringcompute/cache/relational-dbAzure paths end-to-end.internal/purchase/coverage_extra_test.go— extendTestMapServiceType_AllBrancheswith canonical-arm assertions for every service.Test plan
go test ./internal/purchase/... -count=1— all green including new tests.go vet ./...clean.go build ./...succeeds.757c9a6e-b22a-4a81-bf04-b11043cbf658and re-creates the Standard_B1ls Azure compute purchase; approval succeeds.Deploy note
The user has a stuck Azure approval (execution
757c9a6e-b22a-4a81-bf04-b11043cbf658) that needs to be cancelled and re-created after this lands and the Lambda deploys.Summary by CodeRabbit
Bug Fixes
Tests