- 为什么:白盒复检 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:
@@ -68,3 +68,42 @@ func TestRuntimeProviderUnavailableAndNotFound(t *testing.T) {
|
||||
t.Fatalf("missing document err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// The progress passthrough is a projection, not a proxy: whatever extra fields
|
||||
// the platform endpoint returns (keys, authorization headers, token echoes) must
|
||||
// never reach the browser. This guards the shape if someone later switches to
|
||||
// forwarding the upstream body.
|
||||
func TestRuntimeProviderDropsSensitiveUpstreamFields(t *testing.T) {
|
||||
const secret = "leak-sentinel"
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"success": true, "data": map[string]any{
|
||||
"document": map[string]any{
|
||||
"id": "doc-1", "parse_status": "completed", "ingestion_status": "completed", "wiki_status": "none",
|
||||
"api_key": secret, "apiKey": secret, "authorization": "Bearer " + secret,
|
||||
"headers": map[string]any{"X-API-Key": secret},
|
||||
},
|
||||
"failures": []map[string]any{},
|
||||
"has_more_failures": false,
|
||||
"api_key": secret,
|
||||
}})
|
||||
}))
|
||||
defer server.Close()
|
||||
provider := NewRuntimeProvider(RuntimeConfig{
|
||||
BaseURL: func(context.Context) string { return server.URL },
|
||||
APIKey: "runtime-key", Timeout: 5 * time.Second,
|
||||
})
|
||||
progress, err := provider.DocumentProgress(context.Background(), "doc-1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
payload, err := json.Marshal(progress)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(payload), secret) || strings.Contains(string(payload), "Bearer ") {
|
||||
t.Fatalf("progress leaked upstream credentials: %s", payload)
|
||||
}
|
||||
if progress.DocumentID != "doc-1" || progress.ParseStatus != "completed" {
|
||||
t.Fatalf("projection dropped real fields: %#v", progress)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -153,10 +152,8 @@ func (s *Service) buildFindings(ctx context.Context, run governance.Reconciliati
|
||||
}
|
||||
finding.ActionState = "open"
|
||||
finding.ID = deterministicFindingID(run.ID, finding)
|
||||
if finding.WeKnoraURL == "" && run.KBID != "" && s.weKnoraWebBase != nil {
|
||||
if base := strings.TrimSpace(s.weKnoraWebBase(ctx)); base != "" {
|
||||
finding.WeKnoraURL = strings.TrimSuffix(base, "/") + "/platform/knowledge-bases/" + url.PathEscape(run.KBID)
|
||||
}
|
||||
if finding.WeKnoraURL == "" && s.weKnoraWebBase != nil {
|
||||
finding.WeKnoraURL = weknora.KnowledgeBaseConsoleURL(s.weKnoraWebBase(ctx), run.KBID)
|
||||
}
|
||||
findings = append(findings, finding)
|
||||
}
|
||||
|
||||
@@ -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