3f2626f621
build / build (push) Failing after 1m32s
按 schema 版本选 profile 并以 information_schema 能力探测放行,取代写死的 version==74;未知版本、脏库、缺表缺列、跨版本搬运一律拒绝并点名原因。 0.9.0 的索引名改从部署配置解析,wiki_log_entries 按 profile 变为可选, 归档部件集合随之一致。
59 lines
2.3 KiB
Go
59 lines
2.3 KiB
Go
package librarysnapshot
|
||
|
||
import (
|
||
"strings"
|
||
"testing"
|
||
"time"
|
||
)
|
||
|
||
// 归档部件的完整性按 schema 版本判定:0.9.0 没有 wiki_log_entries,
|
||
// 0.7.1 缺了它就是残包。这里直接对 manifest 编码做判定,不依赖数据库。
|
||
func TestManifestPartSetFollowsSchemaProfile(t *testing.T) {
|
||
part := func(kind, name string) Part {
|
||
return Part{Kind: kind, Name: name, SHA256: strings.Repeat("a", 64), Count: 1}
|
||
}
|
||
parts := []Part{
|
||
part("database", "knowledges"), part("database", "chunks"), part("database", "resources"),
|
||
part("database", "resource_bindings"), part("database", "knowledge_tags"),
|
||
part("database", "knowledge_tag_relations"),
|
||
part("wiki", "wiki_pages"), part("wiki", "wiki_folders"), part("wiki", "wiki_page_issues"),
|
||
part("index", "chunks"),
|
||
}
|
||
manifest := func(version int, weknora string, parts []Part) Manifest {
|
||
return Manifest{
|
||
ValidationPolicy: ArtifactAcceptancePolicy,
|
||
Format: Format,
|
||
Scope: "internal",
|
||
TenantID: 10000,
|
||
KnowledgeBaseID: "kb-v090",
|
||
CreatedAt: time.Now().UTC(),
|
||
Parts: parts,
|
||
Compatibility: Compatibility{
|
||
WeKnoraVersion: weknora, SchemaVersion: version,
|
||
RetrieverEngine: "elasticsearch_v8", EmbeddingModel: "bge-m3",
|
||
EmbeddingDimension: 1024, IndexMappingSHA256: strings.Repeat("b", 64),
|
||
},
|
||
}
|
||
}
|
||
|
||
if _, err := encodeManifest(manifest(134, "v0.9.0", parts)); err != nil {
|
||
t.Fatalf("0.9.0 manifest without wiki_log_entries must be complete: %v", err)
|
||
}
|
||
if _, err := encodeManifest(manifest(74, "v0.7.1", parts)); err == nil || !strings.Contains(err.Error(), "incomplete") {
|
||
t.Fatalf("0.7.1 manifest missing wiki_log_entries must be refused, got %v", err)
|
||
}
|
||
withLog := append(append([]Part{}, parts...), part("wiki", "wiki_log_entries"))
|
||
if _, err := encodeManifest(manifest(74, "v0.7.1", withLog)); err != nil {
|
||
t.Fatalf("0.7.1 manifest with wiki_log_entries must pass: %v", err)
|
||
}
|
||
if _, err := encodeManifest(manifest(134, "v0.9.0", withLog)); err != nil {
|
||
t.Fatalf("0.9.0 manifest may still carry an optional wiki_log_entries part: %v", err)
|
||
}
|
||
if _, err := encodeManifest(manifest(74, "v0.9.0", withLog)); err == nil {
|
||
t.Fatal("version string and profile version must agree")
|
||
}
|
||
if _, err := encodeManifest(manifest(135, "v0.9.0", parts)); err == nil {
|
||
t.Fatal("unknown schema version must be refused")
|
||
}
|
||
}
|