Repository navigation
test(purchase): refuse a mixed-account single-account execute - #388
Conversation
Add TestExecutePurchase_SingleAccount_MixedAccountRecs_Refused, which drives a direct-execute purchase whose selected recommendations name two distinct cloud accounts through the real executePurchase -> executeSingleAccount -> resolveSingleAccountProvider path and asserts the purchase is refused before the provider factory is ever touched. The existing TestSingleCloudAccountIDFromRecs only exercised the helper in isolation and labeled the two-account case "not this path", so nothing proved the guard actually stops an end-to-end execution. Confirmed the new test fails (mutation: dropped the len(ids) > 1 branch in SingleCloudAccountIDFromRecs so it silently returns the last seen account) and passes again once restored. Closes #232
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: LeanerCloud/cloud-commitments-platform/.coderabbit.yaml Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. 1 included review remains after this review. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour. 📝 WalkthroughWalkthroughA regression test covers plan-less execution with recommendations assigned to two cloud accounts. It checks for an ambiguous-account-scope error and confirms that execution does not create a provider or save purchase history. ChangesPurchase execution
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~8 minutes Change: Other Merge Risk: ⚪ Minimal · up to The new regression test targets mixed-account purchase refusal. No merge-blocking issue is identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
|
|
Independent review + local verification: MERGE at 8f25b2e. Test-only; mutation-checked: disabling scope-error propagation in resolveSingleAccountProvider makes the test fail through the real executePurchase path. |
Summary
Adds a regression test that drives a mixed-account single-account purchase
execution end to end and asserts it is refused, closing the A05-002 gap
described in #232.
Root cause
SingleCloudAccountIDFromRecsand its callerresolveSingleAccountProvideralready refuse a batch whose selected recommendations span more than one
cloud account (added in #2072 pre-split). But the only test covering the
two-distinct-accounts case,
TestSingleCloudAccountIDFromRecs, called thehelper directly in isolation. Nothing drove the error through the real
executePurchase->executeSingleAccount->resolveSingleAccountProviderpath and asserted the provider factory (and therefore any purchase) was
never touched, so a regression that silently picked one account instead of
refusing would have shipped through a green suite.
Fix
Test-only change: added
TestExecutePurchase_SingleAccount_MixedAccountRecs_Refusedininternal/purchase/execution_test.go. It builds a direct-execute purchase(
PlanID: "") with two selected recommendations naming two distinctCloudAccountIDs, callsmanager.executePurchasedirectly, and asserts:errAmbiguousAccountScopewith theexpected account list in the message
CreateAndValidateProvideris never called (registered with.Maybe()first so the
AssertNotCalledis a meaningful check, not a vacuous one)SavePurchaseHistoryis never calledNo production code changed; the guard was already correct.
Regression test proof (mutation check)
Confirmed the new test has teeth by temporarily breaking the guard:
switch { - case len(ids) > 1: - return nil, fmt.Errorf("%w: %d selected recommendation(s) target %d cloud accounts (%s); submit one purchase per account", - errAmbiguousAccountScope, selected, len(ids), strings.Join(ids, ", ")) case len(ids) == 1 && unattributed > 0:With that mutation,
SingleCloudAccountIDFromRecssilently returns the lastseen account instead of refusing. Re-ran the new test:
Reverted the mutation and confirmed the test passes again (
1 passed in 1 packages).Verification
All run with
GOTOOLCHAIN=go1.26.6 GOWORK=offfrom the repo root:go build ./...- okgo vet ./internal/purchase/...- okgo test -race -short ./internal/purchase/...-312 passed in 1 packagesgo mod tidy -diff- emptygolangci-lint run --timeout=10m ./internal/purchase/...at the exactCI-pinned version (v2.10.1) -
0 issuesCloses #232
Summary by CodeRabbit