- 为什么:白盒复检 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:
@@ -2,7 +2,11 @@ package reconciliation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -10,6 +14,8 @@ import (
|
||||
|
||||
"knowledge-governance/internal/governance"
|
||||
"knowledge-governance/internal/platform/weknora"
|
||||
"knowledge-governance/internal/readiness"
|
||||
"knowledge-governance/internal/weknoraaccess"
|
||||
)
|
||||
|
||||
func TestMatrixCoversEveryLedgerAndUpstreamState(t *testing.T) {
|
||||
@@ -199,9 +205,63 @@ func TestExecuteRunFindsR1ToR8WithoutRemoteWrites(t *testing.T) {
|
||||
ledger: ledger,
|
||||
removal: []governance.ReconciliationLedgerRow{{PublicationID: "pub-r6"}},
|
||||
}
|
||||
remote := &fakeReconciliationRemote{
|
||||
items: items, missing: map[string]bool{"doc-r1": true},
|
||||
gets: map[string]weknora.Knowledge{"doc-r2": items[0]},
|
||||
// The ledger scan must be read-only over the wire, not merely against a fake
|
||||
// that remembers it has no write methods. This server speaks the real client
|
||||
// protocol and records every non-GET request.
|
||||
var mu sync.Mutex
|
||||
var writes []string
|
||||
var pageSizes []int
|
||||
listInFlight, maxInFlight := 0, 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
mu.Lock()
|
||||
if r.Method != http.MethodGet {
|
||||
writes = append(writes, r.Method+" "+r.URL.Path)
|
||||
}
|
||||
mu.Unlock()
|
||||
path := r.URL.Path
|
||||
switch {
|
||||
case path == "/api/v1/knowledge-bases/kb-1":
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"success": true, "data": map[string]any{"id": "kb-1", "tenant_id": 7}})
|
||||
case path == "/api/v1/knowledge-bases/kb-1/knowledge":
|
||||
size, _ := strconv.Atoi(r.URL.Query().Get("page_size"))
|
||||
mu.Lock()
|
||||
pageSizes = append(pageSizes, size)
|
||||
listInFlight++
|
||||
if listInFlight > maxInFlight {
|
||||
maxInFlight = listInFlight
|
||||
}
|
||||
mu.Unlock()
|
||||
defer func() {
|
||||
mu.Lock()
|
||||
listInFlight--
|
||||
mu.Unlock()
|
||||
}()
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"success": true, "data": items, "total": len(items), "page": 1, "page_size": size})
|
||||
case strings.HasPrefix(path, "/api/v1/knowledge/"):
|
||||
id := strings.TrimPrefix(path, "/api/v1/knowledge/")
|
||||
if id == "doc-r1" {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"success": false, "message": "not found"})
|
||||
return
|
||||
}
|
||||
for _, item := range items {
|
||||
if item.ID == id {
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"success": true, "data": item})
|
||||
return
|
||||
}
|
||||
}
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"success": false, "message": "not found"})
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
remote := &weknoraaccess.Client{
|
||||
Resolver: readiness.Resolver{ResolveConnection: func(context.Context) (string, string, error) {
|
||||
return server.URL, "test-key", nil
|
||||
}},
|
||||
Timeout: 5 * time.Second,
|
||||
}
|
||||
service, err := New(Config{Store: store, Remote: remote, Now: func() time.Time { return now },
|
||||
Grace: 30 * time.Minute, StallAfter: 2 * time.Hour, StaleAfter: 6 * time.Hour,
|
||||
@@ -214,16 +274,18 @@ func TestExecuteRunFindsR1ToR8WithoutRemoteWrites(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if store.completedRun == nil {
|
||||
t.Fatal("run was not completed")
|
||||
t.Fatalf("run was not completed: fail code %q", store.failCode)
|
||||
}
|
||||
if remote.deleteCalls != 0 {
|
||||
t.Fatalf("reconciliation wrote remotely: %d", remote.deleteCalls)
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if len(writes) != 0 {
|
||||
t.Fatalf("reconciliation wrote remotely over HTTP: %v", writes)
|
||||
}
|
||||
if len(remote.pageSizes) == 0 || remote.pageSizes[0] != scanPageSize {
|
||||
t.Fatalf("page size = %v, want %d", remote.pageSizes, scanPageSize)
|
||||
if len(pageSizes) == 0 || pageSizes[0] != scanPageSize {
|
||||
t.Fatalf("page size = %v, want %d", pageSizes, scanPageSize)
|
||||
}
|
||||
if remote.maxInFlight != 1 {
|
||||
t.Fatalf("scan in-flight peak = %d, want 1", remote.maxInFlight)
|
||||
if maxInFlight != 1 {
|
||||
t.Fatalf("scan in-flight peak = %d, want 1", maxInFlight)
|
||||
}
|
||||
got := map[string]int{}
|
||||
for _, finding := range store.findings {
|
||||
|
||||
Reference in New Issue
Block a user