42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package v071
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestLibraryCandidateLegacyChunkIndexCoverage(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name, kind string
|
|
status int
|
|
indexed, valid bool
|
|
}{
|
|
{"legacy text missing", "text", 0, false, false},
|
|
{"legacy text indexed", "text", 0, true, true},
|
|
{"legacy unknown type missing", "", 0, false, false},
|
|
{"context parent not indexed", "parent_text", 0, false, true},
|
|
{"stored parent not indexed", "parent_text", 1, false, true},
|
|
{"indexed parent missing", "parent_text", 2, false, false},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
pg, es, _ := libraryCandidateFixture()
|
|
raw, err := json.Marshal(map[string]any{"id": "chunk-safe", "tenant_id": 10000, "knowledge_base_id": "kb-safe", "knowledge_id": "doc-safe", "content": "chunk", "status": tc.status, "chunk_type": tc.kind})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pg.Tables[1] = newTableSnapshot("chunks", []json.RawMessage{raw})
|
|
if !tc.indexed {
|
|
es.Documents = nil
|
|
es.DocumentsSHA256, _ = searchDocumentsDigest(es.Documents)
|
|
}
|
|
err = validateLibraryCandidate(PostgresIdentity{TenantID: 10000, KnowledgeBaseID: "kb-safe"}, pg, es)
|
|
if tc.valid && err != nil {
|
|
t.Fatalf("valid chunk rejected: %v", err)
|
|
}
|
|
if !tc.valid && err == nil {
|
|
t.Fatal("missing legacy index escaped completeness validation")
|
|
}
|
|
})
|
|
}
|
|
}
|