81 lines
2.3 KiB
Go
81 lines
2.3 KiB
Go
package v071
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"knowledge-governance/internal/librarysnapshot"
|
|
)
|
|
|
|
func TestLibraryCandidateArchivesWikiStringStatuses(t *testing.T) {
|
|
for _, tc := range []struct{ table, status string }{
|
|
{"wiki_pages", "draft"}, {"wiki_pages", "published"}, {"wiki_pages", "archived"},
|
|
{"wiki_page_issues", "open"}, {"wiki_page_issues", "resolved"},
|
|
} {
|
|
t.Run(tc.table+"/"+tc.status, func(t *testing.T) {
|
|
pg, es, objects := libraryCandidateFixture()
|
|
raw := json.RawMessage(`{"id":"wiki-safe","tenant_id":10000,"knowledge_base_id":"kb-safe","content":"complete wiki body","status":"` + tc.status + `"}`)
|
|
for i := range pg.Tables {
|
|
if pg.Tables[i].Name == tc.table {
|
|
pg.Tables[i] = newTableSnapshot(tc.table, []json.RawMessage{raw})
|
|
}
|
|
}
|
|
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 {
|
|
t.Fatalf("valid Wiki string status rejected: %v", err)
|
|
}
|
|
saved, err := archive.Load(id)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
found := false
|
|
for _, part := range saved.Parts {
|
|
if part.Name != tc.table {
|
|
continue
|
|
}
|
|
found = true
|
|
r, e := archive.OpenPart(part)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
data, e := io.ReadAll(r)
|
|
r.Close()
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
var rows []json.RawMessage
|
|
if e = json.Unmarshal(data, &rows); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if len(rows) != 1 {
|
|
t.Fatalf("wiki rows=%d", len(rows))
|
|
}
|
|
var row map[string]any
|
|
if e = json.Unmarshal(rows[0], &row); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if row["status"] != tc.status || row["content"] != "complete wiki body" {
|
|
t.Fatal("Wiki status/body changed in archive")
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatal("Wiki part missing")
|
|
}
|
|
})
|
|
}
|
|
}
|