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) } }