fix(api): 执行明细补齐 action 与目标知识库字段
逐项明细 DTO 漏了 action(前端 parseReleaseItemExecution 必需),点 「查看结果」整个明细区报 invalid release item execution。同时把遷移 000044 的 target_knowledge_base_id 读出来透出,页面逐项结果显示「目标库」, 让'目标知识库可选'在界面上可核对。测试:Go 契约用例 + 前端解析回归用例。
This commit is contained in:
@@ -107,6 +107,8 @@ type ReleaseItemExecutionView struct {
|
||||
ErrorCode string `json:"error_code"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
CompletedAt *time.Time `json:"completed_at"`
|
||||
// TargetKnowledgeBaseID 是该项冻结的目标知识库(迁移 000044 起)。旧行可能为空。
|
||||
TargetKnowledgeBaseID string `json:"target_knowledge_base_id"`
|
||||
}
|
||||
|
||||
type ReleaseExecutionDetail struct {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -336,7 +336,8 @@ WHERE id = $1
|
||||
const listReleaseExecutionItemsSQL = `
|
||||
SELECT item.publication_id, source.title, item.action, item.state,
|
||||
item.previous_production_revision, item.production_revision,
|
||||
item.error_code, item.created_at, item.completed_at
|
||||
item.error_code, item.created_at, item.completed_at,
|
||||
COALESCE(item.target_knowledge_base_id, '')
|
||||
FROM release_item_executions AS item
|
||||
JOIN test_publications AS publication ON publication.id = item.publication_id
|
||||
JOIN source_item_versions AS version ON version.id = publication.source_item_version_id
|
||||
@@ -483,7 +484,7 @@ func (s *Store) GetReleaseExecution(ctx context.Context, executionID string) (go
|
||||
var item governance.ReleaseItemExecutionView
|
||||
if err := rows.Scan(&item.PublicationID, &item.Title, &item.Action, &item.State,
|
||||
&item.PreviousProductionRevision, &item.ProductionRevision, &item.ErrorCode,
|
||||
&item.CreatedAt, &item.CompletedAt); err != nil {
|
||||
&item.CreatedAt, &item.CompletedAt, &item.TargetKnowledgeBaseID); err != nil {
|
||||
return governance.ReleaseExecutionDetail{}, fmt.Errorf("scan release execution item: %w", err)
|
||||
}
|
||||
if item.Action != "upsert" && item.Action != "delete" {
|
||||
|
||||
Reference in New Issue
Block a user