fix(api): 执行明细补齐 action 与目标知识库字段
逐项明细 DTO 漏了 action(前端 parseReleaseItemExecution 必需),点 「查看结果」整个明细区报 invalid release item execution。同时把遷移 000044 的 target_knowledge_base_id 读出来透出,页面逐项结果显示「目标库」, 让'目标知识库可选'在界面上可核对。测试:Go 契约用例 + 前端解析回归用例。
This commit is contained in:
@@ -3,6 +3,7 @@ package httpapi
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
@@ -130,3 +131,58 @@ func TestProductionActionPagePathStillRespectsGates(t *testing.T) {
|
||||
t.Fatalf("body=%s", response.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
// 前端 parseReleaseItemExecution 要求每项明细都带 action,列表还要求批次进度字段;
|
||||
// DTO 一旦漏字段,一条不合法就让整块明细/列表报 invalid release ...(线上就是这样)。
|
||||
func TestReleaseExecutionDetailExposesItemFieldsThePageRequires(t *testing.T) {
|
||||
now := time.Date(2026, time.October, 8, 9, 0, 0, 0, time.UTC)
|
||||
store := &fakeJobStore{releaseExecutionDetailResult: governance.ReleaseExecutionDetail{
|
||||
ReleaseExecution: governance.ReleaseExecution{
|
||||
ID: "rx-1", ReleaseBatchID: "rb-1", Operation: governance.ReleaseOperationPublish,
|
||||
State: governance.ReleaseExecutionCompleted, TargetEnvironment: "production",
|
||||
AuthorizedBy: "admin", JobID: "job-1", BatchSize: 50, CurrentBatch: 1, TotalBatches: 1,
|
||||
ItemCount: 1, CompletedItemCount: 1, CreatedAt: now,
|
||||
},
|
||||
Items: []governance.ReleaseItemExecutionView{{
|
||||
PublicationID: "tp-1", Title: "手册.pdf", Action: "upsert", State: "verified",
|
||||
ProductionRevision: "rv-1", TargetKnowledgeBaseID: "kb-target-1", CreatedAt: now,
|
||||
}},
|
||||
}}
|
||||
handler, err := NewHandler(Config{Store: store, Now: func() time.Time { return now }})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
response := httptest.NewRecorder()
|
||||
handler.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/api/v1/release-executions/rx-1", nil))
|
||||
if response.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d body=%s", response.Code, response.Body.String())
|
||||
}
|
||||
var payload struct {
|
||||
Data struct {
|
||||
BatchSize float64 `json:"batch_size"`
|
||||
TotalBatch float64 `json:"total_batches"`
|
||||
Items []struct {
|
||||
Action string `json:"action"`
|
||||
TargetKnowledgeBase string `json:"target_knowledge_base_id"`
|
||||
ProductionRevision string `json:"production_revision"`
|
||||
PreviousProductionRV string `json:"previous_production_revision"`
|
||||
} `json:"items"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(response.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if payload.Data.BatchSize != 50 || payload.Data.TotalBatch != 1 {
|
||||
t.Fatalf("batch progress missing: %+v", payload.Data)
|
||||
}
|
||||
if len(payload.Data.Items) != 1 {
|
||||
t.Fatalf("items=%+v", payload.Data.Items)
|
||||
}
|
||||
item := payload.Data.Items[0]
|
||||
if item.Action != "upsert" {
|
||||
t.Fatalf("action=%q, want upsert (前端解析必需)", item.Action)
|
||||
}
|
||||
if item.TargetKnowledgeBase != "kb-target-1" {
|
||||
t.Fatalf("target_knowledge_base_id=%q", item.TargetKnowledgeBase)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1857,10 +1857,11 @@ func getReleaseExecution(w http.ResponseWriter, r *http.Request, store Store) {
|
||||
items := make([]map[string]any, 0, len(detail.Items))
|
||||
for _, item := range detail.Items {
|
||||
items = append(items, map[string]any{
|
||||
"publication_id": item.PublicationID, "title": item.Title, "state": item.State,
|
||||
"publication_id": item.PublicationID, "title": item.Title, "action": item.Action, "state": item.State,
|
||||
"previous_production_revision": item.PreviousProductionRevision,
|
||||
"production_revision": item.ProductionRevision, "error_code": item.ErrorCode,
|
||||
"created_at": item.CreatedAt, "completed_at": item.CompletedAt,
|
||||
"target_knowledge_base_id": item.TargetKnowledgeBaseID,
|
||||
})
|
||||
}
|
||||
result["items"] = items
|
||||
|
||||
Reference in New Issue
Block a user