From 0dde418dfde8726fb30e874f25f5f867d410adfa Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 19:45:52 -0800 Subject: [PATCH] test(cli): specify plain detach request and seal readout --- .../cmd/sw-block/chunk_plain_test.go | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 seaweed-block/cmd/sw-block/chunk_plain_test.go diff --git a/seaweed-block/cmd/sw-block/chunk_plain_test.go b/seaweed-block/cmd/sw-block/chunk_plain_test.go new file mode 100644 index 0000000000..875a43414a --- /dev/null +++ b/seaweed-block/cmd/sw-block/chunk_plain_test.go @@ -0,0 +1,52 @@ +package main + +import ( + "net/http" + "strings" + "testing" +) + +// M5 PlainStop -> Quiesce, INV-CUT-PLAIN-DETACH-001: encode the existing +// idle seal request; preserve JSON stdout for existing operator tooling. +func TestOpsChunkPlainDetachSendsTheExistingRequest(t *testing.T) { + const reply = `{"volumeID":"vol","headGen":11,"headState":"detached"}` + srv, got := chunkServer(t, http.StatusOK, reply) + code, out, errOut := runChunk("detach", "--plain", "--volume", "vol", "--status-addr", srv.URL, "--timeout", "2s") + if code != 0 || out != reply || !strings.Contains(errOut, "sealed HEAD generation: 11\n") { + t.Fatalf("exit=%d stdout=%q stderr=%q", code, out, errOut) + } + if len(*got) != 1 || (*got)[0].path != "/chunk/detach" || (*got)[0].body["plain"] != true || (*got)[0].body["volumeID"] != "vol" || (*got)[0].body["timeoutMs"] != float64(2000) { + t.Fatalf("plain request=%+v", *got) + } + for _, key := range []string{"frozen", "freezeStartedAtNs", "allowOverBudget"} { + if _, ok := (*got)[0].body[key]; ok { + t.Fatalf("plain request contains %s", key) + } + } +} + +func TestOpsChunkPlainDetachRefusesInvalidMixBeforeHTTP(t *testing.T) { + srv, got := chunkServer(t, http.StatusOK, `{}`) + for _, extra := range [][]string{ + {"--frozen", "--freeze-started-at-ns", "1"}, {"--freeze-started-at-ns", "1"}, {"--allow-over-budget"}, + {"--timeout", "0s"}, {"--timeout", "-1s"}, {"unexpected"}, + } { + args := append([]string{"detach", "--plain", "--volume", "vol", "--status-addr", srv.URL}, extra...) + if code, _, _ := runChunk(args...); code != 2 || len(*got) != 0 { + t.Fatalf("%v: exit=%d requests=%d", extra, code, len(*got)) + } + } +} + +func TestOpsChunkPlainDetachPreservesTypedFailure(t *testing.T) { + for _, reason := range []string{"busy", "fenced", "outcome_unknown"} { + t.Run(reason, func(t *testing.T) { + reply := `{"code":"` + reason + `","message":"seal refused","retryable":true}` + srv, got := chunkServer(t, http.StatusConflict, reply) + code, out, errOut := runChunk("detach", "--plain", "--volume", "vol", "--status-addr", srv.URL) + if code != 1 || out != reply+"\n" || len(*got) != 1 || strings.Contains(errOut, "sealed HEAD generation:") { + t.Fatalf("exit=%d stdout=%q stderr=%q requests=%d", code, out, errOut, len(*got)) + } + }) + } +}