- profile 新增 137(由 v090 克隆),声明知识域关联表 copied/derived/excluded 分类。 - 导出前与导入写事务内各跑漏表门禁;未声明有数据拒绝,空表警告写入 WriteSet。 - chunk_revisions/wiki_page_revisions 接入范围改写、目标身份映射、自然键与回滚顺序。
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
package libraryprofile
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestForV091IsDeclaredAndSharesV090Contract(t *testing.T) {
|
||||
profile, err := For(V091Version)
|
||||
if err != nil {
|
||||
t.Fatalf("For(137): %v", err)
|
||||
}
|
||||
if profile.SchemaVersion != 137 || profile.Name != "v091" || profile.WeKnoraVersion != "v0.9.1" {
|
||||
t.Fatalf("unexpected v0.9.1 profile: %+v", profile)
|
||||
}
|
||||
supported := Supported()
|
||||
if !reflect.DeepEqual(supported, []int{74, 134, 137}) {
|
||||
t.Fatalf("Supported()=%v", supported)
|
||||
}
|
||||
v090, err := For(V090Version)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// 除了版本三字段,v091 必须与 v090 完全一致;任何分叉都意味着表/列/触发器
|
||||
// 被复制或漂移,升级后会与真实 schema 对不上。
|
||||
v091 := profile
|
||||
v091.Name, v091.SchemaVersion, v091.WeKnoraVersion = v090.Name, v090.SchemaVersion, v090.WeKnoraVersion
|
||||
if !reflect.DeepEqual(v090, v091) {
|
||||
t.Fatal("v0.9.1 must be a version-only clone of v0.9.0")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeclaredTablesAreAllClassifiedCopied(t *testing.T) {
|
||||
for _, version := range Supported() {
|
||||
profile, err := For(version)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, table := range append(append([]string{}, profile.RequiredTables...), profile.OptionalTables...) {
|
||||
class, ok := profile.RelatedTableClass(table)
|
||||
if !ok {
|
||||
t.Fatalf("%s: declared table %s has no classification", profile.Name, table)
|
||||
}
|
||||
if class.Class != RelatedCopied || strings.TrimSpace(class.Reason) == "" {
|
||||
t.Fatalf("%s: declared table %s must be copied with a reason, got %+v", profile.Name, table, class)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEveryRealKnowledgeScopedTableIsClassified(t *testing.T) {
|
||||
// 真实测试 WeKnora 0.9.0 的只读 information_schema 结果(2026-11-30):
|
||||
// 带 knowledge_base_id/knowledge_id/kb_id 的 public 表共 18 张。漏一张,
|
||||
// 漏表门禁就会在该表有数据时拒绝发布;这里把它锁成契约。
|
||||
realTables := []string{
|
||||
"chunk_images", "chunk_revisions", "chunks", "data_sources", "im_channels",
|
||||
"knowledge_processing_spans", "knowledge_tag_relations", "knowledge_tags",
|
||||
"knowledges", "kb_shares", "memory_doc_affinity", "messages", "sessions",
|
||||
"user_kb_pins", "wiki_folders", "wiki_page_issues", "wiki_page_revisions", "wiki_pages",
|
||||
}
|
||||
// embeddings 是条件迁移(仅 PG 检索模式)创建的,真实测试库不存在,也必须
|
||||
// 预置分类,避免未来启用后被误判为未声明表。
|
||||
optionalRealTables := []string{"embeddings"}
|
||||
for _, version := range []int{V090Version, V091Version} {
|
||||
profile, err := For(version)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, table := range append(append([]string{}, realTables...), optionalRealTables...) {
|
||||
class, ok := profile.RelatedTableClass(table)
|
||||
if !ok {
|
||||
t.Fatalf("%s: real knowledge-scoped table %s is unclassified", profile.Name, table)
|
||||
}
|
||||
if strings.TrimSpace(class.Reason) == "" {
|
||||
t.Fatalf("%s: %s has an empty classification reason", profile.Name, table)
|
||||
}
|
||||
}
|
||||
if class, _ := profile.RelatedTableClass("chunk_images"); class.Class != RelatedDerived {
|
||||
t.Fatalf("chunk_images must be derived, got %+v", class)
|
||||
}
|
||||
for _, table := range []string{"sessions", "messages", "knowledge_processing_spans", "data_sources"} {
|
||||
if class, _ := profile.RelatedTableClass(table); class.Class != RelatedExcluded {
|
||||
t.Fatalf("%s must be excluded, got %+v", table, class)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRevisionTablesAreCopiedAndOrderedAfterParents(t *testing.T) {
|
||||
profile, err := For(V091Version)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
position := func(table string) int {
|
||||
for index, name := range profile.RequiredTables {
|
||||
if name == table {
|
||||
return index
|
||||
}
|
||||
}
|
||||
t.Fatalf("required table %s missing", table)
|
||||
return -1
|
||||
}
|
||||
if position("chunk_revisions") < position("chunks") {
|
||||
t.Fatal("chunk_revisions must be written after chunks")
|
||||
}
|
||||
if position("wiki_page_revisions") < position("wiki_pages") {
|
||||
t.Fatal("wiki_page_revisions must be written after wiki_pages")
|
||||
}
|
||||
if !profile.RequiresPart("database/chunk_revisions") || !profile.RequiresPart("wiki/wiki_page_revisions") {
|
||||
t.Fatal("both revision parts must be required archive parts")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user