From 0c29ab3a965a4806a5927c5369954492b92ef950 Mon Sep 17 00:00:00 2001 From: Lemon-miaow Date: Thu, 24 Sep 2026 17:04:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20=E6=9C=AA=E6=94=B9=E5=8A=A8?= =?UTF-8?q?=E4=BB=BB=E4=BD=95=E5=AD=97=E6=AE=B5=E7=9A=84=20PATCH=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=A9=BA=20patched=20=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E8=80=8C=E9=9D=9E=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/api/handlers_user.go | 4 +++- internal/api/images_pin_test.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/api/handlers_user.go b/internal/api/handlers_user.go index 7103c61..1ea38d4 100644 --- a/internal/api/handlers_user.go +++ b/internal/api/handlers_user.go @@ -683,7 +683,9 @@ func (a *API) handlePatchServer(w http.ResponseWriter, r *http.Request) { // the SAME helpers the create form uses. `changed` records what actually moves // so the response and audit name the real mutation. var patch ServerSpecPatch - var changed []string + // Non-nil so a patch that moves nothing (re-picking the image a server is + // already pinned to) still answers "patched": [], as the API documents. + changed := []string{} // imageFrom is the image a confirmed image change replaced, for the audit row. var imageFrom string diff --git a/internal/api/images_pin_test.go b/internal/api/images_pin_test.go index cfba1a1..43acf88 100644 --- a/internal/api/images_pin_test.go +++ b/internal/api/images_pin_test.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "net/http" + "strings" "testing" "felis.lolicon.best/internal/imagepin" @@ -136,6 +137,9 @@ func TestPatchServerImageSamePinIsNoChange(t *testing.T) { if p := cl.patched["survival"]; p.Image != nil { t.Errorf("patched image = %q, want no image change", *p.Image) } + if !strings.Contains(w.Body.String(), `"patched":[]`) { + t.Errorf("body = %s, want an empty patched list", w.Body.String()) + } if len(repo.audits) != 1 || repo.audits[0].Payload != nil { t.Errorf("audits = %+v, want a plain server.patch", repo.audits) }