From 02ee5da231d8f761a756db06aad4ab4b3a225767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E7=AB=A0=E6=B5=A9?= Date: Mon, 26 Oct 2026 18:42:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(catalog):=20=E4=BF=9D=E7=95=99=E9=A6=96?= =?UTF-8?q?=E6=AC=A1=E6=89=AB=E6=8F=8F=E9=9B=B6=E8=BF=9B=E5=BA=A6=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E6=9D=A5=E6=BA=90=E5=88=97=E8=A1=A8=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/governance/source_catalog.go | 2 +- .../governance/source_catalog_json_test.go | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 internal/governance/source_catalog_json_test.go diff --git a/internal/governance/source_catalog.go b/internal/governance/source_catalog.go index 5c1dc2e..123c113 100644 --- a/internal/governance/source_catalog.go +++ b/internal/governance/source_catalog.go @@ -15,7 +15,7 @@ type CatalogSource struct { LastRefreshDurationMS int64 `json:"last_refresh_duration_ms"` // ScanProgress / ScanMessage 只在 SnapshotStatus == "scanning" 时有值:新来源在首次扫描 // 完成前也出现在「来源与目录」里,带着百分比与进度文案,不必等到快照落地才看得见。 - ScanProgress int `json:"scan_progress,omitempty"` + ScanProgress int `json:"scan_progress"` ScanMessage string `json:"scan_message,omitempty"` } diff --git a/internal/governance/source_catalog_json_test.go b/internal/governance/source_catalog_json_test.go new file mode 100644 index 0000000..1dada78 --- /dev/null +++ b/internal/governance/source_catalog_json_test.go @@ -0,0 +1,21 @@ +package governance + +import ( + "encoding/json" + "testing" +) + +func TestQueuedCatalogSourceIncludesNumericZeroProgress(t *testing.T) { + source := CatalogSource{SnapshotStatus: "scanning", ScanProgress: 0} + body, err := json.Marshal(source) + if err != nil { + t.Fatal(err) + } + var decoded map[string]any + if err = json.Unmarshal(body, &decoded); err != nil { + t.Fatal(err) + } + if value, ok := decoded["scan_progress"]; !ok || value != float64(0) { + t.Fatalf("queued source must satisfy the frontend numeric progress contract: %s", body) + } +}