From 77d8bae5032597ba38e88c75fd221ab34d99a609 Mon Sep 17 00:00:00 2001 From: "tao.chen" Date: Fri, 10 Jul 2026 17:24:40 +0800 Subject: [PATCH] =?UTF-8?q?Linus=20=E4=BF=AE=E5=A4=8D:=20=E7=A9=BA=20list?= =?UTF-8?q?=20JSON=20=E5=BA=8F=E5=88=97=E5=8C=96=E6=88=90=20[]=20+=20seed.?= =?UTF-8?q?sh=20curl=20=E7=BB=AD=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Linus 视角问题: ClusterRepo.List / AuditRepo.List 在空 list 时 返 nil, encoding/json 默认序列化成 null, 不是 []。 LLM/前端期望一致空数组语义。 - internal/storage/cluster_repo.go: List 返回前 out = []*cluster.Cluster{} - internal/audit/repo.go: List 返回前 out = []*Entry{} scripts/seed.sh curl 续行 bug: 在 set -euo pipefail 下 \\ 续行 被解析成多行, curl 收到混乱 argv 报 "URL rejected: Bad hostname"。 改为单行 + backslash 续行在 bash 中更稳。 Co-Authored-By: Claude --- internal/audit/repo.go | 4 ++++ internal/storage/cluster_repo.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/internal/audit/repo.go b/internal/audit/repo.go index 65eb011..f55af6b 100644 --- a/internal/audit/repo.go +++ b/internal/audit/repo.go @@ -102,6 +102,10 @@ func (r *Repo) List(ctx context.Context, limit int) ([]*Entry, error) { if err := rows.Err(); err != nil { return nil, fmt.Errorf("audit: rows: %w", err) } + if out == nil { + // Force empty array (not null) in JSON. + out = []*Entry{} + } return out, nil } diff --git a/internal/storage/cluster_repo.go b/internal/storage/cluster_repo.go index 721d58c..89b2bb8 100644 --- a/internal/storage/cluster_repo.go +++ b/internal/storage/cluster_repo.go @@ -118,6 +118,10 @@ func (r *ClusterRepo) List(ctx context.Context) ([]*cluster.Cluster, error) { if err := rows.Err(); err != nil { return nil, fmt.Errorf("storage: list clusters: %w", err) } + if out == nil { + // Force empty array (not null) in JSON for LLM/front-end ergonomics. + out = []*cluster.Cluster{} + } return out, nil }