- 为什么:白盒复检 P1——平台侧文件详情抽屉 503 只有文案,需求 §8 要求跳转链接;/monitor/tasks 行没有 URL。 - 做什么:抽出 KnowledgeBaseConsoleURL,finding 与 /monitor/tasks 共用同一拼接;handler 用当前生效测试端点填 weknora_url,前端抽屉透传给 WeKnoraProgress;openapi/需求 §7 同步。 - 补证据:stage=weknora 真库合并用例;对账扫描改为真实 HTTP 桩断言零写;progress 投影断言上游密钥字段不外泄。 - 验证:make verify 17 项 success;go test ./... exit 0;web 648 测试 + build;monitor_tasks 真库集成用例 PASS。
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
postgresstore "knowledge-governance/internal/platform/postgres"
|
||||
"knowledge-governance/internal/platform/weknora"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -97,6 +98,14 @@ func listMonitorTasks(w http.ResponseWriter, r *http.Request, config Config) {
|
||||
writeJSON(w, 500, map[string]string{"error": "无法读取文件处理状态"})
|
||||
return
|
||||
}
|
||||
// One origin per request: every row uses the same effective test endpoint the
|
||||
// reconciliation scan used, so a KB opens at the same place from both tabs.
|
||||
if config.WeKnoraWebBase != nil {
|
||||
origin := config.WeKnoraWebBase(r.Context())
|
||||
for i := range page.Items {
|
||||
page.Items[i].WeKnoraURL = weknora.KnowledgeBaseConsoleURL(origin, page.Items[i].TargetKB)
|
||||
}
|
||||
}
|
||||
// 目标同名不罕见(两侧都叫“对内知识库”):把当前生效绑定随页返回,
|
||||
// 前端才能在同一口径下标注“当前绑定/历史”,而不是拿本页条目反推全局。
|
||||
internal, external := config.effectiveRoutingTargets(r.Context())
|
||||
|
||||
@@ -11,11 +11,16 @@ import (
|
||||
type monitorTasksTestStore struct {
|
||||
fakeJobStore
|
||||
filter postgresstore.MonitorTaskFilter
|
||||
items []postgresstore.MonitorTask
|
||||
}
|
||||
|
||||
func (s *monitorTasksTestStore) ListMonitorTasks(_ context.Context, f postgresstore.MonitorTaskFilter) (postgresstore.MonitorTaskPage, error) {
|
||||
s.filter = f
|
||||
return postgresstore.MonitorTaskPage{Items: []postgresstore.MonitorTask{}, Total: 145, Limit: f.Limit, Offset: f.Offset}, nil
|
||||
items := s.items
|
||||
if items == nil {
|
||||
items = []postgresstore.MonitorTask{}
|
||||
}
|
||||
return postgresstore.MonitorTaskPage{Items: items, Total: 145, Limit: f.Limit, Offset: f.Offset}, nil
|
||||
}
|
||||
func TestMonitorTasksRoute(t *testing.T) {
|
||||
s := &monitorTasksTestStore{}
|
||||
@@ -95,3 +100,62 @@ func TestMonitorTasksReportsEffectiveTargetBindings(t *testing.T) {
|
||||
t.Fatalf("bindings = %#v, want the persisted current bindings", payload.Data.Bindings)
|
||||
}
|
||||
}
|
||||
|
||||
// The platform drawer's 503 fallback needs the same jump link a finding carries.
|
||||
// The handler, not the browser, decides the origin: it must use the effective
|
||||
// test endpoint, and an unwired resolver must leave the field empty instead of
|
||||
// inventing a host.
|
||||
func TestMonitorTasksAddsWeKnoraConsoleURL(t *testing.T) {
|
||||
store := &monitorTasksTestStore{items: []postgresstore.MonitorTask{{ID: "mt-1", TargetKB: "kb-1"}}}
|
||||
handler, err := NewHandler(Config{
|
||||
Store: store,
|
||||
WeKnoraWebBase: func(context.Context) string { return "https://weknora.test/" },
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req := httptest.NewRequest("GET", "/api/v1/monitor/tasks?limit=20", nil)
|
||||
req = req.WithContext(context.WithValue(req.Context(), sessionKey{}, sessionIdentity{Username: "tester", Role: roleViewer}))
|
||||
recorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(recorder, req)
|
||||
if recorder.Code != 200 {
|
||||
t.Fatalf("status %d: %s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
var payload struct {
|
||||
Data struct {
|
||||
Items []struct {
|
||||
WeKnoraURL string `json:"weknora_url"`
|
||||
} `json:"items"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(recorder.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(payload.Data.Items) != 1 || payload.Data.Items[0].WeKnoraURL != "https://weknora.test/platform/knowledge-bases/kb-1" {
|
||||
t.Fatalf("weknora_url = %#v", payload.Data.Items)
|
||||
}
|
||||
|
||||
store.items = []postgresstore.MonitorTask{{ID: "mt-1", TargetKB: "kb-1"}}
|
||||
unwired, err := NewHandler(Config{Store: store})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
recorder = httptest.NewRecorder()
|
||||
unwired.ServeHTTP(recorder, req)
|
||||
if recorder.Code != 200 {
|
||||
t.Fatalf("unwired status %d: %s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
payload = struct {
|
||||
Data struct {
|
||||
Items []struct {
|
||||
WeKnoraURL string `json:"weknora_url"`
|
||||
} `json:"items"`
|
||||
} `json:"data"`
|
||||
}{}
|
||||
if err := json.Unmarshal(recorder.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(payload.Data.Items) != 1 || payload.Data.Items[0].WeKnoraURL != "" {
|
||||
t.Fatalf("unwired weknora_url = %#v", payload.Data.Items)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,11 @@ type Config struct {
|
||||
Monitor MonitorProvider
|
||||
// Reconciliation is the T6 reconciliation domain. Nil keeps the routes
|
||||
// unavailable instead of returning fake empty batches.
|
||||
Reconciliation ReconciliationService
|
||||
Reconciliation ReconciliationService
|
||||
// WeKnoraWebBase resolves the test WeKnora console origin used to build the
|
||||
// drawer jump link on /monitor/tasks rows. Nil (or an empty answer) leaves
|
||||
// weknora_url empty; the contract allows that, and no host is invented.
|
||||
WeKnoraWebBase func(context.Context) string
|
||||
InternalRoutingKnowledgeBaseID string
|
||||
ExternalRoutingKnowledgeBaseID string
|
||||
RoutingBindings RoutingBindingStore
|
||||
|
||||
Reference in New Issue
Block a user