- 回收 SQL 占位符改为 $1/$2,消除 pgx 扩展协议 42P18(手动/定时对账 500) - 直接写入 finding 时归一空 confirmation_state,避免 23514 - 修正 R6/overview 同谓词用例夹具,两条台账各自持有 source version - 页面顶部统一服务与队列单行状态条,删除 Embedding/LLM 常量卡 - 平台阶段筛选合并为「WeKnora 处理中」,后端支持 stage=weknora - weknora_url 由测试 WeKnora 源构造,详情与 503 提供跳转链接 - 补 1000/页线上查询、R8 合法收养、weknora 阶段筛选用例
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -152,6 +153,11 @@ 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)
|
||||
}
|
||||
}
|
||||
findings = append(findings, finding)
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,9 @@ type Config struct {
|
||||
ConfirmConcurrency int
|
||||
KeepRuns int
|
||||
MaxAge time.Duration
|
||||
// WeKnoraWebBase resolves the WeKnora origin used to build the finding's
|
||||
// jump link. Empty or nil leaves weknora_url empty, which the contract allows.
|
||||
WeKnoraWebBase func(context.Context) string
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
@@ -86,6 +89,7 @@ type Service struct {
|
||||
confirmConcurrency int
|
||||
keepRuns int
|
||||
maxAge time.Duration
|
||||
weKnoraWebBase func(context.Context) string
|
||||
}
|
||||
|
||||
func New(config Config) (*Service, error) {
|
||||
@@ -120,6 +124,7 @@ func New(config Config) (*Service, error) {
|
||||
store: config.Store, remote: config.Remote, runtime: config.Runtime, queue: config.Queue,
|
||||
now: config.Now, grace: config.Grace, stallAfter: config.StallAfter, staleAfter: config.StaleAfter,
|
||||
confirmConcurrency: config.ConfirmConcurrency, keepRuns: config.KeepRuns, maxAge: config.MaxAge,
|
||||
weKnoraWebBase: config.WeKnoraWebBase,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package reconciliation
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -203,7 +204,8 @@ func TestExecuteRunFindsR1ToR8WithoutRemoteWrites(t *testing.T) {
|
||||
}
|
||||
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,
|
||||
ConfirmConcurrency: 1, KeepRuns: 30, MaxAge: 90 * 24 * time.Hour})
|
||||
ConfirmConcurrency: 1, KeepRuns: 30, MaxAge: 90 * 24 * time.Hour,
|
||||
WeKnoraWebBase: func(context.Context) string { return "https://test.example/" }})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -234,6 +236,44 @@ func TestExecuteRunFindsR1ToR8WithoutRemoteWrites(t *testing.T) {
|
||||
if store.completedRun.Counts["R8"] != 1 || store.completedRun.LedgerCount != len(ledger) || store.completedRun.KBCount != len(items) {
|
||||
t.Fatalf("run counts = %#v", store.completedRun)
|
||||
}
|
||||
// Every finding carries the WeKnora jump link built from the resolved test
|
||||
// origin; an empty base would leave it empty, but a resolved one must not.
|
||||
for _, finding := range store.findings {
|
||||
if finding.WeKnoraURL != "https://test.example/platform/knowledge-bases/kb-1" {
|
||||
t.Fatalf("%s weknora_url = %q", finding.Type, finding.WeKnoraURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Two ledger publications may legitimately hold the same bytes in one test KB
|
||||
// (adoption). R8 is keyed by publication_id, so that case must stay silent.
|
||||
func TestR8DoesNotFlagAdoptedDuplicatesWithDistinctPublications(t *testing.T) {
|
||||
now := time.Date(2026, 12, 1, 12, 0, 0, 0, time.UTC)
|
||||
sha := strings.Repeat("a", 64)
|
||||
md5 := strings.Repeat("b", 32)
|
||||
row := func(pub, doc string) governance.ReconciliationLedgerRow {
|
||||
return governance.ReconciliationLedgerRow{
|
||||
PublicationID: pub, KnowledgeID: doc, ProcessingState: "completed", RetrievalState: "unpublished",
|
||||
TargetScope: "internal", Title: doc, SHA256: sha, UploadMD5: md5, UpdatedAt: now.Add(-time.Hour),
|
||||
}
|
||||
}
|
||||
ledger := []governance.ReconciliationLedgerRow{row("pub-a", "doc-a"), row("pub-b", "doc-b")}
|
||||
items := []weknora.Knowledge{
|
||||
{ID: "doc-a", KnowledgeBaseID: "kb-1", Channel: "governance", ParseStatus: "completed", FileHash: md5, Metadata: map[string]any{"publication_id": "pub-a", "content_sha256": sha}},
|
||||
{ID: "doc-b", KnowledgeBaseID: "kb-1", Channel: "governance", ParseStatus: "completed", FileHash: md5, Metadata: map[string]any{"publication_id": "pub-b", "content_sha256": sha}},
|
||||
}
|
||||
service, err := New(Config{Store: &fakeReconciliationStore{}, Remote: &fakeReconciliationRemote{}, Now: func() time.Time { return now }})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
run := governance.ReconciliationRun{ID: "run-1", KBID: "kb-1", StartedAt: now}
|
||||
findings, err := service.buildFindings(context.Background(), run, ledger, items, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(findings) != 0 {
|
||||
t.Fatalf("adopted duplicates produced findings: %#v", findings)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecuteRunFailsWholeBatchWithoutFindings(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user