43 lines
2.0 KiB
Go
43 lines
2.0 KiB
Go
package v071
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
// Scheme A archives artifact bytes; these cases do not certify semantic quality.
|
|
func TestLibraryCandidatePreservesArtifactContentWithoutReconstruction(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name, kind, body, index string
|
|
valid bool
|
|
}{
|
|
{"current title prefix", "text", "\n chunk \t", "Document title\nchunk", true},
|
|
{"legacy raw body", "text", "\n chunk \t", "\n chunk \t", true},
|
|
{"trimmed body", "text", "\n chunk \t", "chunk", true},
|
|
{"wrong title", "text", "chunk", "Other title\nchunk", true},
|
|
{"missing body", "text", "chunk", "Document title\n", true},
|
|
{"different body", "text", "chunk", "Document title\nchanged", true},
|
|
{"unverifiable context header", "text", "chunk", "Document title\nTransient heading\n\nchunk", true},
|
|
{"nontext transform not assumed", "faq", "chunk", "Document title\nchunk", true},
|
|
{"empty artifact content", "text", "chunk", " \n", false},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
pg, es, _ := libraryCandidateFixture()
|
|
k, _ := json.Marshal(map[string]any{"id": "doc-safe", "tenant_id": 10000, "knowledge_base_id": "kb-safe", "title": " Document title\n"})
|
|
c, _ := json.Marshal(map[string]any{"id": "chunk-safe", "tenant_id": 10000, "knowledge_base_id": "kb-safe", "knowledge_id": "doc-safe", "content": tc.body, "chunk_type": tc.kind, "status": 2})
|
|
x, _ := json.Marshal(map[string]any{"knowledge_base_id": "kb-safe", "knowledge_id": "doc-safe", "chunk_id": "chunk-safe", "content": tc.index})
|
|
pg.Tables[0] = newTableSnapshot("knowledges", []json.RawMessage{k})
|
|
pg.Tables[1] = newTableSnapshot("chunks", []json.RawMessage{c})
|
|
es.Documents[0].Source = x
|
|
es.DocumentsSHA256, _ = searchDocumentsDigest(es.Documents)
|
|
err := validateLibraryCandidate(PostgresIdentity{TenantID: 10000, KnowledgeBaseID: "kb-safe"}, pg, es)
|
|
if tc.valid && err != nil {
|
|
t.Fatalf("valid indexed text refused: %v", err)
|
|
}
|
|
if !tc.valid && err == nil {
|
|
t.Fatal("empty index content accepted")
|
|
}
|
|
})
|
|
}
|
|
}
|