test(library): 隔离数据契约与 r11 身份自然键矩阵
真实本机 PG/ES/MinIO:v071 目录镜像 10 模式、结构引用/游标 15 模式、 8 表×2 外部范围身份矩阵、13 模式自然键(含软删除与合法同 parent 正例)、 备份期间三注入、收尾故障与授权撤销两个真实治理 PG 用例。 需隔离服务的用例在 test-scope.json 显式声明:普通 CI 跳过不算通过。
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"knowledge-governance/internal/governance"
|
||||
"knowledge-governance/internal/librarysnapshot"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func (f *fakeLibraryStore) LibrarySourceCandidate(_ context.Context, scope, sourceID string) (governance.LibraryVersion, bool, error) {
|
||||
if f.sourceCandidate != nil && f.sourceCandidate.Scope == scope && f.sourceCandidate.Evidence["source_id"] == sourceID {
|
||||
return *f.sourceCandidate, true, nil
|
||||
}
|
||||
return governance.LibraryVersion{}, false, nil
|
||||
}
|
||||
|
||||
// These fixtures now contain the same capture identity and real immutable
|
||||
// manifest required by the production admission path. No production bypass.
|
||||
func bindSourceFixture(t *testing.T, config *Config, store *fakeLibraryStore, target *string) string {
|
||||
t.Helper()
|
||||
if config.LibraryArchiveRoot == "" {
|
||||
config.LibraryArchiveRoot = libraryFixtureRoot(t)
|
||||
*target = sealSharedVersions(t, config.LibraryArchiveRoot, 1, 4)[0]
|
||||
}
|
||||
archive, err := librarysnapshot.Open(config.LibraryArchiveRoot, 256*1024*1024)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer archive.Close()
|
||||
manifest, err := archive.Load(*target)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
config.LibrarySourceProject = "fixture-project"
|
||||
config.LibrarySourceApp = "fixture-app"
|
||||
config.LibrarySourceTenantID = manifest.TenantID
|
||||
config.LibrarySourceInternalKB = manifest.KnowledgeBaseID
|
||||
source := configuredLibrarySource(*config, "internal")
|
||||
id, err := source.ID()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store.sourceCandidate = &governance.LibraryVersion{Scope: "internal", Kind: governance.LibraryVersionTestSealed, SnapshotID: *target, Evidence: map[string]any{"source_id": id}}
|
||||
if store.grant != nil {
|
||||
store.grant.SnapshotID = *target
|
||||
store.grant.ParamsDigest, _ = librarySyncParamsDigest("internal", *target)
|
||||
}
|
||||
return id
|
||||
}
|
||||
func sourceRequestBody(t *testing.T, body, id string) string {
|
||||
t.Helper()
|
||||
var v map[string]any
|
||||
if err := json.Unmarshal([]byte(body), &v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v["source_id"] = id
|
||||
raw, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return string(raw)
|
||||
}
|
||||
Reference in New Issue
Block a user