fix(catalog): 保留首次扫描零进度避免来源列表解析失败
build / build (push) Successful in 1m15s

This commit is contained in:
姚章浩
2026-10-26 18:42:47 +08:00
parent e744114ff4
commit 02ee5da231
2 changed files with 22 additions and 1 deletions
+1 -1
View File
@@ -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"`
}
@@ -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)
}
}