Repository navigation
feat: spawn capacity-block purchase with three typed gates + dry-run (#217) - #219
Merged
Merged
Conversation
…217) New 'spawn capacity-block purchase <offering-id>' — reserve an EC2 Capacity Block for ML. A non-refundable up-front charge (the most expensive action in the toolset), so it is heavily gated: - THREE typed confirmations in sequence, each an exact match or it aborts: 1. the exact up-front price, 2. 'purchase <offering-id>', 3. 'I UNDERSTAND THIS IS NON-REFUNDABLE'. A bare y/yes is NOT accepted. - Refuses on non-interactive stdin (stdinIsInteractive via os.Stdin.Stat ModeCharDevice); there is NO --yes bypass. - --dry-run previews price + terms with NO write API call. - Re-validates the offering and re-checks the price immediately before charging; aborts if it moved from what was confirmed. - Audit-logs initiated/success/failed (offering id, reservation id, price). - On success prints the reservation id + the 'spawn launch --reservation-id <id> --capacity-block --az <az>' command (#216). pkg/aws/capacity_block.go: FindCapacityBlockOffering (re-validate by id via DescribeCapacityBlockOfferings) + PurchaseCapacityBlock (PurchaseCapacityBlock, InstancePlatform default Linux/UNIX, tag support). cmd/utils.go: confirmTypedPhrase (exact-match gate) + stdinIsInteractive. Tests cover the gate logic exhaustively (wrong/empty/y/eof/case-mismatch all abort; only exact proceeds) for all three phrases. No real purchase in tests. Closes #217
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
The new capacity-block command must declare a Tier 0 coverage decision (TestTier0_CommandCoverageGate). Purchase is a non-refundable write never run in CI and offerings discovery hits real DescribeCapacityBlockOfferings, so it's deferred to Tier 1/3; the typed-gate logic is unit-tested in cmd.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #217. Step 3 of the Capacity Blocks for ML flow (find → purchase → launch). The paid write op.
What
spawn capacity-block purchase <offering-id> --region <r> --instance-type <t> --duration-hours <h> [--count N] [--platform] [--dry-run]— reserves a Capacity Block for ML viaec2:PurchaseCapacityBlock, returning a reservation id that feedsspawn launch --reservation-id … --capacity-block(#216). The offering id comes fromtruffle capacity-blocks(truffle#67).Cost-safety (the heart of #217) — all hard requirements met
A Capacity Block is a non-refundable up-front charge, the most expensive action in the toolset. Gated accordingly:
12480.00).purchase <offering-id>(binds intent to the specific offering).I UNDERSTAND THIS IS NON-REFUNDABLE.A bare
y/yesis explicitly not accepted.stdinIsInteractiveviaos.Stdin.Stat()ModeCharDevice) — no--yesbypass.--dry-runpreviews price + full terms with no write API call.Code
pkg/aws/capacity_block.go:FindCapacityBlockOffering(re-validate by id viaDescribeCapacityBlockOfferings) +PurchaseCapacityBlock(InstancePlatformdefault Linux/UNIX, tag support).cmd/capacity_block.go: thecapacity-block purchasecommand (parent + child, mirrorsslurm).cmd/utils.go:confirmTypedPhrase(exact-match gate) +stdinIsInteractive.Tests / verification
TestConfirmTypedPhraseexhaustively covers the gate: wrong text /y/yes/ empty / EOF / case-mismatch all abort; only the exact phrase proceeds — for all three phrases (price, offering, ack).PurchaseCapacityBlock.--dry-runreachesDescribeCapacityBlockOfferingsand makes no purchase (the dev account isn't Capacity-Block-enabled, which surfaces as a clean API limit error — request well-formed).Refs truffle#67 (discovery), spawn#216 (launch into the reservation), lagotto#49 (schedule the launch at the block's start). Also carries the [email protected] pin via the #216 merge.