c5e033dd0e
build / build (push) Failing after 15s
- 同作业号重跑读持久日志+已封存清单按首次请求重放(source_read=false, writers_stopped=false),换范围/绑定库或清单校验失败即拒绝 - 归档用量按跨版本去重统计内容字节,清单/未引用 blob/实际分配单列, 不再用各版本 unique 之和冒充归档占用 - 冻结窗口内复核来源契约,不一致即中止;拒绝组外同镜像运行容器 - 补齐整库只读接口的 OpenAPI 契约 - 按用户确认取消 A06:文档/页面/接口不再把效果测试列为封版门槛
127 lines
4.4 KiB
Go
127 lines
4.4 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"knowledge-governance/internal/libraryfreeze"
|
|
"knowledge-governance/internal/librarysnapshot"
|
|
)
|
|
|
|
// sealedFixture writes one complete sealed candidate and returns its ID.
|
|
func sealedFixture(t *testing.T, archive *librarysnapshot.Archive, scope, knowledgeBaseID string, createdAt time.Time) string {
|
|
t.Helper()
|
|
rows := func(count int) string {
|
|
if count == 0 {
|
|
return "[]"
|
|
}
|
|
items := make([]string, count)
|
|
for i := range items {
|
|
items[i] = fmt.Sprintf(`{"id":"00000000-0000-4000-8000-%012d"}`, i)
|
|
}
|
|
return "[" + strings.Join(items, ",") + "]"
|
|
}
|
|
parts := []struct {
|
|
kind, name string
|
|
count int64
|
|
}{
|
|
{"database", "knowledges", 4},
|
|
{"database", "chunks", 38},
|
|
{"database", "resources", 0},
|
|
{"database", "resource_bindings", 0},
|
|
{"database", "knowledge_tags", 0},
|
|
{"database", "knowledge_tag_relations", 0},
|
|
{"index", "chunks", 122},
|
|
{"wiki", "wiki_pages", 31},
|
|
{"wiki", "wiki_folders", 21},
|
|
{"wiki", "wiki_page_issues", 0},
|
|
{"wiki", "wiki_log_entries", 11},
|
|
}
|
|
manifest := librarysnapshot.Manifest{ValidationPolicy: librarysnapshot.ArtifactAcceptancePolicy,
|
|
Format: librarysnapshot.Format, Scope: scope, TenantID: 10000, KnowledgeBaseID: knowledgeBaseID,
|
|
CreatedAt: createdAt, Compatibility: librarysnapshot.Compatibility{WeKnoraVersion: "v0.7.1",
|
|
SchemaVersion: 74, RetrieverEngine: "elasticsearch_v8", EmbeddingModel: "text-embedding-v4",
|
|
EmbeddingDimension: 1024, IndexMappingSHA256: strings.Repeat("b", 64)}}
|
|
for _, part := range parts {
|
|
stored, err := archive.Put(bytes.NewReader([]byte(rows(int(part.count)))))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
stored.Kind, stored.Name, stored.Count = part.kind, part.name, part.count
|
|
manifest.Parts = append(manifest.Parts, stored)
|
|
}
|
|
id, err := archive.Seal(manifest)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
func fixtureArchive(t *testing.T) (*librarysnapshot.Archive, string) {
|
|
t.Helper()
|
|
root, err := os.MkdirTemp(os.TempDir(), "kglc-")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { os.RemoveAll(root) })
|
|
if err = os.Chmod(root, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
archive, err := librarysnapshot.Open(root, 1024*1024)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { archive.Close() })
|
|
return archive, root
|
|
}
|
|
|
|
const fixtureKB = "0c84a098-d3ed-4b82-a165-e6de9691d6a8"
|
|
|
|
// A repeated job with the same parameters must return the original candidate
|
|
// without touching the source or stopping a writer (this function has no access
|
|
// to either), instead of failing with a conflicting-request error.
|
|
func TestReplayCaptureReturnsOriginalCandidate(t *testing.T) {
|
|
archive, _ := fixtureArchive(t)
|
|
created := time.Date(2026, 10, 28, 3, 34, 57, 0, time.UTC)
|
|
id := sealedFixture(t, archive, "internal", fixtureKB, created)
|
|
manifest, err := replayCapture("lib-internal-1", "internal", fixtureKB,
|
|
libraryfreeze.Result{State: "succeeded", SnapshotID: id}, archive)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !manifest.CreatedAt.Equal(created) || manifest.Compatibility.EmbeddingModel != "text-embedding-v4" {
|
|
t.Fatalf("replay lost the original request identity: %+v", manifest)
|
|
}
|
|
}
|
|
|
|
func TestReplayCaptureRejectsChangedParameters(t *testing.T) {
|
|
archive, root := fixtureArchive(t)
|
|
id := sealedFixture(t, archive, "internal", fixtureKB, time.Date(2026, 10, 28, 3, 34, 57, 0, time.UTC))
|
|
// Different scope.
|
|
if _, err := replayCapture("lib-internal-1", "external", fixtureKB,
|
|
libraryfreeze.Result{State: "succeeded", SnapshotID: id}, archive); err == nil {
|
|
t.Fatal("scope conflict was accepted")
|
|
}
|
|
// Binding moved to another knowledge base.
|
|
if _, err := replayCapture("lib-internal-1", "internal", "aec3dfc9-4ad3-4a39-926b-5bfa5d6a9654",
|
|
libraryfreeze.Result{State: "succeeded", SnapshotID: id}, archive); err == nil {
|
|
t.Fatal("knowledge base binding change was accepted")
|
|
}
|
|
// A job that never succeeded must not be answered as success.
|
|
if _, err := replayCapture("lib-internal-1", "internal", fixtureKB,
|
|
libraryfreeze.Result{State: "failed"}, archive); err == nil {
|
|
t.Fatal("failed job replayed as success")
|
|
}
|
|
// A sealed candidate that no longer verifies must not be reported as replay.
|
|
if err := os.Remove(root + "/versions/" + id + ".json"); err == nil {
|
|
if _, err := replayCapture("lib-internal-1", "internal", fixtureKB,
|
|
libraryfreeze.Result{State: "succeeded", SnapshotID: id}, archive); err == nil {
|
|
t.Fatal("missing sealed candidate replayed as success")
|
|
}
|
|
}
|
|
}
|