eaa388f76b
build / build (push) Successful in 1m42s
按用户明确要求,治理封存不再替 WeKnora 判断正文块“应该”有独立索引: 删除 status/chunk_type/parent/mixed/flat 推导的 needOriginal、mixedDocs 及覆盖门槛;删除 parent 类型搭配限制,仅保留父引用存在与同 knowledge。 capture/preflight/archive/load/replay/writeset 共用校验同步更新,移除已无 用途的 worker 永久失败分类。 保留真实导出范围、PG/ES 原始正文/问题 metadata/vector、tenant/KB/ knowledge/chunk 身份、清单摘要、资源字节、Wiki/问题索引 source_id 及真实 悬空引用等完整性检查;不修改源端,不补数据/索引。旧测试改为原样捕获正例, 新增 status0/2 缺正文索引和父类型不匹配的接受回归,以及 archive/readback 逐行/逐记录比对。 验证:v071、cmd/worker、Go 全量、make verify 17 项。
44 lines
1.8 KiB
Go
44 lines
1.8 KiB
Go
package v071
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestLibraryCandidateGeneratedQuestionIndex(t *testing.T) {
|
|
for _, mode := range []string{"complete", "wrong-id", "wrong-content", "missing-question", "missing-body", "foreign-source", "question-as-body"} {
|
|
t.Run(mode, func(t *testing.T) {
|
|
pg, es, _ := libraryCandidateFixture()
|
|
pg.Tables[1] = newTableSnapshot("chunks", []json.RawMessage{json.RawMessage(`{"id":"chunk-safe","tenant_id":10000,"knowledge_base_id":"kb-safe","knowledge_id":"doc-safe","content":"chunk","chunk_type":"text","status":0,"metadata":{"generated_questions":[{"id":"q1","question":"How does it work?"}]}}`)})
|
|
questionID, content := "chunk-safe-q1", "How does it work?"
|
|
if mode == "wrong-id" {
|
|
questionID = "chunk-safe-q2"
|
|
}
|
|
if mode == "wrong-content" {
|
|
content = "Different question"
|
|
}
|
|
if mode == "foreign-source" {
|
|
questionID = "foreign-q1"
|
|
}
|
|
if mode == "question-as-body" {
|
|
content = "chunk"
|
|
}
|
|
raw, _ := json.Marshal(map[string]any{"chunk_id": "chunk-safe", "knowledge_id": "doc-safe", "knowledge_base_id": "kb-safe", "source_id": questionID, "content": content})
|
|
q := SearchDocument{ID: "question-index", Source: raw}
|
|
if mode == "missing-body" {
|
|
es.Documents = []SearchDocument{q}
|
|
} else if mode != "missing-question" {
|
|
es.Documents = append(es.Documents, q)
|
|
}
|
|
es.DocumentsSHA256, _ = searchDocumentsDigest(es.Documents)
|
|
err := validateLibraryCandidate(PostgresIdentity{TenantID: 10000, KnowledgeBaseID: "kb-safe"}, pg, es)
|
|
if (mode == "complete" || mode == "missing-body") && err != nil {
|
|
t.Fatalf("valid persisted question rejected: %v", err)
|
|
}
|
|
if mode != "complete" && mode != "missing-body" && err == nil {
|
|
t.Fatal("incomplete or inconsistent question index accepted")
|
|
}
|
|
})
|
|
}
|
|
}
|