Repository navigation
[Fix] Keep a closed maintenance from returning to an open status - #131
Conversation
There was a problem hiding this comment.
Summary
Small, targeted fix: checkPatchData now rejects a PATCH that would move a maintenance that is already completed or cancelled back to a non-terminal status (planned/in_progress/…), which previously slipped through because a maintenance always carries an end date so the checker couldn't distinguish a finished event from an open one. New error ErrIncidentPatchClosedMaintenanceStatus added, completed ↔ cancelled still allowed, incident/info branches untouched. Tests added, CI green (build, go-test, go-test-acc, golangci-lint, CodeQL all pass).
Findings
No correctness, security, or build-blocking issues found. The change is correct and well tested.
Suggestions / open questions (non-blocking)
-
Possible redundancy with the existing maintenance transition validation —
internal/api/v2/v2.go:1279-1284adds the terminal-status guard insidecheckPatchData(called at ~2244), while there is already a maintenance status-transition conflict check aroundinternal/api/v2/v2.go:2137-2156that raisesErrMaintenanceStatusTransitionConflict. The two guards now overlap for the closed→open case, and they return different error codes depending on which runs first. This works, but it's worth confirming the intended error/HTTP status is consistent for the client. Consider whether one of these is the canonical enforcement point and the other can be consolidated, or at least documented, so the API surface stays predictable. -
Scope of "non-terminal" — the new check blocks
plannedandin_progress(and, since only completed/cancelled are allowed through, implicitlypending_review/reviewedtoo). That appears intentional given the PR description, but it's worth a quick sanity check thatpending_review/reviewedare also legitimately closed for acompleted/cancelledmaintenance, so the guard isn't wider than intended.
Notes (verified)
- The guard is placed after the type/status validation (line ~1241), so
incoming.Statusis already guaranteed to be a valid maintenance status when the new branch runs; no nil/zero-value edge case is introduced. - The
completed → cancelledandcancelled → cancelledpaths correctly fall through, matching the added test table (internal/api/v2/v2_test.go:250-306).
Verdict: approve — no changes required to merge; the two suggestions above are worth a quick follow-up but do not block.
A maintenance always carries an end date, so
checkPatchDatacould not tell a finished event from an open one: a completed or cancelled maintenance could be patched toplannedorin_progresswhile the stored end date stayed in the past, and the checker then reopened it. Reject non-terminal statuses once the stored maintenance is completed or cancelled; completed ↔ cancelled remains allowed and the incident and info branches are unchanged.Verified with
go build ./... && go vet ./... && go test ./internal/....Closes #121