From 5e1b6ecea0790d58b2a55fc4c05ba886640e4024 Mon Sep 17 00:00:00 2001 From: Ilker Manap Date: Wed, 30 Sep 2026 01:14:12 +0200 Subject: [PATCH] Read a queued change as a success in ctl ctl accepted only 200, so the first real `ctl restart --all` printed "Error: 202 Accepted" over a request that had queued nine restarts, all of which then happened. Any 2xx is now a success, and its body is read. Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 5 +++++ internal/cli/ctl.go | 5 ++++- internal/cli/ctl_status_test.go | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 internal/cli/ctl_status_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 963f6b65..a57fb1ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,11 @@ grace period and the new one starts in its place. This is how running engines pick up the keys introduced in v0.10.3, an edited profile, or a new engine version. +### Fixes + +- `ctl` reported a change the API had queued (202 Accepted) as an error, as + `ctl restart` did on its first real use. + ### Releases Small fixes are published as release candidates of the next version — diff --git a/internal/cli/ctl.go b/internal/cli/ctl.go index fca09b6f..c75fcd9b 100644 --- a/internal/cli/ctl.go +++ b/internal/cli/ctl.go @@ -83,7 +83,10 @@ func (c *ctlClient) do(ctx context.Context, method, path string, body, out any) } defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { + // Any 2xx. The API answers a change it has queued rather than made — a + // restart — with 202, and treating that as a failure printed + // "Error: 202 Accepted" over a request that had worked. + if resp.StatusCode < 200 || resp.StatusCode > 299 { var e struct { Error string `json:"error"` } diff --git a/internal/cli/ctl_status_test.go b/internal/cli/ctl_status_test.go new file mode 100644 index 00000000..e579ee47 --- /dev/null +++ b/internal/cli/ctl_status_test.go @@ -0,0 +1,24 @@ +package cli + +import ( + "net/http" + "net/http/httptest" + "testing" +) + +func TestAQueuedChangeIsNotReportedAsAnError(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusAccepted) + _, _ = w.Write([]byte(`{"queued":["r1"]}`)) + })) + defer srv.Close() + var out struct { + Queued []string `json:"queued"` + } + if err := newCtlClient(srv.URL).post(t.Context(), "/api/v1/restart", []byte(`{}`), &out); err != nil { + t.Fatalf("202 read as a failure: %v", err) + } + if len(out.Queued) != 1 { + t.Errorf("the body of a 202 was not read: %+v", out) + } +}