Repository navigation
refactor(aws): share the purchase idempotency guard, starting with ElastiCache - #507
Conversation
|
@coderabbitai review |
|
Independent review verdict: CLEAN at bafecc6Reviewer: fresh Claude agent (Sonnet 5.5, high effort), not the author, cold brief. The PR body was treated as a claim. Coordinator: claude-cc-reviewer. Blocking findings: none. Neither guard path can double-buy, and neither fails open. Behaviour is equivalent. I compared the old inline code (origin/main
Generics:
Call sites:
Mutation probes (each reverted):
Local verification: in Non-blocking notes:
Gate:
|
bafecc6 to
572dd63
Compare
572dd63 to
ee2d508
Compare
ee2d508 to
48b4183
Compare
48b4183 to
4ca5692
Compare
4ca5692 to
0a87b9b
Compare
|
Fifth pure rebase (claude-go-pr-merge-3, which took over this claim from claude-cc-reviewer). I ran
Both commits are unchanged, so the CLEAN verdict carries to Local verification (macOS; fixtures and mocks, no AWS call, no purchase):
|
Four AWS services (elasticache, memorydb, rds, opensearch) carry the same issue #641 guard and AlreadyExists recovery, differing only in a label, the fault type and the find function. Add purchaseguard.Guard and the generic purchaseguard.Recover[F] so the double-buy guard has one source. The tests are the only proof for two paths no service test reaches: Recover with a lookup error, and the exact log and error text including the masked token. The golden strings were copied from the existing copies. Refs #10 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the elasticache idempotencyGuard and recoverAlreadyExists bodies with thin wrappers over purchaseguard.Guard and Recover, keeping the call sites in PurchaseCommitment unchanged. The guard lookup error now reads "before ElastiCache reservation purchase" instead of "before ElastiCache purchase", because one label feeds both the error and the log text. Only "refusing to purchase" is asserted anywhere. The same sentence in Azure, EC2 and Redshift is out of scope. Refs #10 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0a87b9b to
f396755
Compare
|
Merge evidence at Pure update. The independent CLEAN verdict (at CI green on Local verification at Gate items.
|
Summary
PR A of 2 for #10. The AWS RI purchase idempotency guard (look up an existing reservation by token before purchasing, and adopt it when the purchase returns AlreadyExists) is copied verbatim into four service clients. This adds one shared implementation and migrates ElastiCache; PR B migrates MemoryDB, RDS and OpenSearch.
New
providers/aws/internal/purchaseguard:type Finder func(ctx) (id string, found bool, err error)Guard(ctx, token, label, find): empty token skips the lookup; a lookup error fails loud ("refusing to purchase to avoid a possible double-buy", wrapped with%w); a found reservation is logged with the token masked and returned for adoption.Recover[F error](ctx, token, label, purchaseErr, find): matches the service's AlreadyExists fault witherrors.Ason the pointer typeF(including%w-wrapped faults), then looks the reservation up; a lookup error or a miss returns not-recovered, so the original purchase error stands (unchanged behavior).ElastiCache keeps its two methods as 5-line wrappers, so call sites, call order and all existing elasticache tests are unchanged.
One accepted wording change: the guard error now reads "before ElastiCache reservation purchase" (was "before ElastiCache purchase"); only "refusing to purchase" is asserted, and the old phrase appears nowhere in this repo's tests or in the CLI, MCP or platform repos. Redshift's guard is structurally different and stays separate; the same sentence also exists in Azure reservations, EC2 and Redshift, out of scope here.
Refs #10
Tests
guard_test.goasserts exact log and error text (golden strings copied from the old copies), the masked token and the absence of the raw token, the empty-token paths, lookup-error wrapping, found and not-found, and Recover's matching, adoption, swallowed lookup error and miss. Recover-with-lookup-error and the exact text were not covered by any existing test.Mutation probes (scratch copies), each caught: wrong fault type in the elasticache wrapper (
TestClient_PurchaseCommitment_Idempotent_AlreadyExistsRecovers), dropping either empty-token return, swallowing the lookup error, negatingfound, dropping theerrors.Ascheck, adopting on lookup error or miss, removingMaskToken, and removing the Recover call from the wrapper. The reviewer re-ran the wrong-type and adopt-on-miss probes independently.Verification
make build,make vet,(cd providers/aws && GOWORK=off go test -race -short ./internal/purchaseguard/... ./services/elasticache/...), pinned golangci-lint v2.10.1 (0 issues), gofmt, and the commit/pre-push hooks (includingmake test-unit) pass. Unit-level evidence only; no AWS call.Local review: the plan had two adversarial passes by a non-author reviewer before code; the diff had one more by the same reviewer (golden strings byte-identical apart from the accepted label,
errors.Assemantics, call order), no actionable findings.🤖 Generated with Claude Code
Summary by CodeRabbit