Files
knowledge-governance/internal/releaseadapter/v071/library_index_completeness_test.go
T
姚章浩 eaa388f76b
build / build (push) Successful in 1m42s
fix(release): 取消封存正文索引与父类型推断规则
按用户明确要求,治理封存不再替 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 项。
2026-11-05 18:24:36 +08:00

45 lines
1.7 KiB
Go

package v071
import (
"context"
"encoding/json"
"os"
"testing"
"time"
"knowledge-governance/internal/librarysnapshot"
)
// R3f: the source owns whether a body chunk has an original-text index.
// Governance captures the actual PG/ES sets and must not infer an index from
// status, chunk type or parent shape. This replaces the old missing-index
// negative test, which encoded that inferred rule.
func TestLibraryCandidateCapturesBodyWithoutIndex(t *testing.T) {
pg, es, objects := 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","status":2,"chunk_type":"text"}`)})
es.Documents = nil
es.DocumentsSHA256, _ = searchDocumentsDigest(es.Documents)
root := t.TempDir()
if err := os.Chmod(root, 0700); err != nil {
t.Fatal(err)
}
archive, err := librarysnapshot.Open(root, 1024*1024)
if err != nil {
t.Fatal(err)
}
defer archive.Close()
contract := librarysnapshot.Compatibility{WeKnoraVersion: "v0.7.1", SchemaVersion: 74, RetrieverEngine: "elasticsearch_v8", EmbeddingModel: "fixture-model", EmbeddingDimension: 1024, IndexMappingSHA256: es.MappingSHA256}
id, err := ArchiveLibraryCandidate(context.Background(), archive, "internal",
PostgresIdentity{TenantID: 10000, KnowledgeBaseID: "kb-safe"}, contract, pg, es, objects, time.Now().UTC())
if err != nil || id == "" {
t.Fatalf("body without original-text index must be captured as-is: id=%q err=%v", id, err)
}
manifest, err := archive.Load(id)
if err != nil {
t.Fatal(err)
}
if err := validateArchivedLibraryClosure(archive, manifest); err != nil {
t.Fatalf("readback of the captured body failed: %v", err)
}
}