Repository navigation
fix(api): refuse a ramp shape change on a plan with completed steps - #689
Merged
Merged
Conversation
updatePlan rebuilds the ramp schedule from the request. When the shape
(type, percent, interval, step count) differed from the stored one, the
plan restarted at step 0 and forgot the percentage already bought; a PUT
that omitted ramp_schedule did the same by defaulting to immediate.
Return 409 when the stored plan has CurrentStep > 0 and the requested
shape differs. The message tells the operator to resend the current
ramp_schedule or create a new plan. Same-shape edits and shape changes at
step 0 are unchanged. Documented the 409 on PUT /api/plans/{id}. The request-to-plan merge moves
into mergeUpdatedPlan to keep updatePlan under the cyclomatic limit.
Replaces TestHandler_updatePlan_ChangingRampScheduleStartsAtStepZero,
which asserted the restart behavior.
Refs #386
Contributor
|
Warning Review limit reached
This review includes 4 billable files and costs up to $1.00.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 10 minutes for your next included review. View limit detailsLimit details: You’ve used the included review currently available. Your 82 included PR review attempts over the past 7 days set your current allowance at 1 review per hour. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (4)
Comment |
Two mutants survived the review of the ramp shape check: moving the boundary from CurrentStep > 0 to > 1, and dropping PercentPerStep from the shape comparison. Add a CurrentStep=1 row and a row whose stored and requested schedules differ only in percent (custom 30% vs 33%, both 3 steps), so each mutant now fails. Refs #386
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.
What
PUT /api/plans/{id}rebuilds the ramp schedule from the request. When the requested shape (type, percent per step, interval, step count) differed from the stored one, the plan restarted at step 0 and forgot the percentage already bought. A PUT that omittedramp_scheduledid the same, because it defaults toimmediate.Now
updatePlanreturns 409 when the stored plan hasCurrentStep > 0and the requested shape differs. The message says to resend the currentramp_scheduleto keep it, or create a new plan. Same-shape edits (rename, coverage, ...) and shape changes at step 0 behave as before. The 409 is documented onPUT /api/plans/{id}inopenapi.yaml.Owner decision (fleet lead): reject rather than carry progress. Carrying the completed percentage into the new schedule (ceil(done/newPct) steps complete) remains an option if the owner wants it later; it needs an "effective target" definition that does not exist yet.
mergeUpdatedPlanis extracted fromupdatePlanonly to stay under the gocyclo limit.Scope of #386
Refs #386, which listed four follow-ups. Only item 1 was still open:
The issue stays open until this merges.
Tests
TestUpdatePlan_RampShapeChangedrives PUT through the router: step 3 weekly-25% to monthly-10% (409, nothing stored), omittedramp_schedule(409), different custom percent (409), same shape keeps step 3 (200), shape change at step 0 (200, new schedule saved). With the handler change reverted the step-3 rows fail (200 instead of 409).go test -short ./internal/apipasses. Fixture-based (mock store), not a live database.Removed
TestHandler_updatePlan_ChangingRampScheduleStartsAtStepZero, which asserted the old restart behavior.Local independent review (two passes): no actionable findings after the wording and test-coverage fixes.
🤖 Generated with Claude Code