8febe12d7d
真实本机 PG/ES/MinIO:v071 目录镜像 10 模式、结构引用/游标 15 模式、 8 表×2 外部范围身份矩阵、13 模式自然键(含软删除与合法同 parent 正例)、 备份期间三注入、收尾故障与授权撤销两个真实治理 PG 用例。 需隔离服务的用例在 test-scope.json 显式声明:普通 CI 跳过不算通过。
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"knowledge-governance/internal/governance"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestContractSourceCandidateBeyondHistoryWindow(t *testing.T) {
|
|
store, _ := newIdentityStore(t)
|
|
ctx := context.Background()
|
|
now := time.Now().UTC()
|
|
source := governance.LibrarySourceIdentity{Project: "source-project", App: "source-app", Scope: "internal", TenantID: 10000, KnowledgeBaseID: "kb-source"}
|
|
id, err := source.ID()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for i := 0; i < 65; i++ {
|
|
sid := "other-source"
|
|
if i == 0 {
|
|
sid = id
|
|
}
|
|
snapshot := fmt.Sprintf("candidate-%d", i)
|
|
if err := store.RecordLibraryVersion(ctx, governance.LibraryVersion{ID: governance.LibraryVersionID(governance.LibraryVersionTestSealed, "internal", snapshot), Scope: "internal", Kind: governance.LibraryVersionTestSealed, SnapshotID: snapshot, Evidence: map[string]any{"source_id": sid}, CreatedAt: now.Add(time.Duration(i) * time.Second)}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
candidate, found, err := store.LibrarySourceCandidate(ctx, "internal", id)
|
|
if err != nil || !found || candidate.SnapshotID != "candidate-0" {
|
|
t.Fatalf("exact candidate missing: %+v %v %v", candidate, found, err)
|
|
}
|
|
source.KnowledgeBaseID = "new-kb"
|
|
newID, _ := source.ID()
|
|
if _, found, err = store.LibrarySourceCandidate(ctx, "internal", newID); err != nil || found {
|
|
t.Fatalf("new source inherited old candidate: %v %v", found, err)
|
|
}
|
|
if _, found, err = store.LibrarySourceCandidate(ctx, "external", id); err != nil || found {
|
|
t.Fatalf("cross scope candidate: %v %v", found, err)
|
|
}
|
|
}
|