test(library): 隔离数据契约与 r11 身份自然键矩阵

真实本机 PG/ES/MinIO:v071 目录镜像 10 模式、结构引用/游标 15 模式、
8 表×2 外部范围身份矩阵、13 模式自然键(含软删除与合法同 parent 正例)、
备份期间三注入、收尾故障与授权撤销两个真实治理 PG 用例。

需隔离服务的用例在 test-scope.json 显式声明:普通 CI 跳过不算通过。
This commit is contained in:
姚章浩
2026-11-01 11:35:09 +08:00
parent 5eef13b615
commit 8febe12d7d
62 changed files with 7329 additions and 167 deletions
+2 -1
View File
@@ -119,7 +119,8 @@ func TestRunRefusesExpiredOrMismatchedGrantBeforeTouchingTarget(t *testing.T) {
mutate func(*Request)
want error
}{
{"expired", func(r *Request) { r.Now = r.Grant.ExpiresAt.Add(time.Minute) }, ErrGrantExpired},
// Run uses the live clock, not the caller's diagnostic timestamp.
{"expired", func(r *Request) { r.Grant.ExpiresAt = time.Now().Add(-time.Minute) }, ErrGrantExpired},
{"other target", func(r *Request) { r.Target = "external-prod" }, ErrGrantTarget},
{"other snapshot", func(r *Request) { r.SnapshotID = "snap-2" }, ErrGrantSnapshot},
{"params changed", func(r *Request) { r.ParamsDigest = "digest-2" }, ErrGrantParams},
@@ -0,0 +1,43 @@
package libraryrelease
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"testing"
)
// Literal canonical bytes follow d0c6d57's V1 field order, not today's struct.
const historicalV1Canonical = `{"version":1,"job_id":"job-v1","target":"internal","tenant_id":10001,"knowledge_base_id":"kb-target","backup_snapshot_id":"before","target_snapshot_id":"source","created_at":"2026-01-01T00:00:00Z","rows":[],"universe":{"chunks":{"count":0,"digest":"empty"}},"digest":""}`
func TestContractHistoricalV1CanonicalBytesFrozen(t *testing.T) {
var set WriteSet
if err := json.Unmarshal([]byte(historicalV1Canonical), &set); err != nil {
t.Fatal(err)
}
raw, err := set.CanonicalBytes()
if err != nil {
t.Fatal(err)
}
if string(raw) != historicalV1Canonical {
t.Fatalf("V1 bytes changed: %s", raw)
}
hash := sha256.Sum256([]byte(historicalV1Canonical))
set.Digest = hex.EncodeToString(hash[:])
if err := set.Verify(); err != nil {
t.Fatal(err)
}
}
func TestContractV1CannotCarryNewExecutionSemantics(t *testing.T) {
var set WriteSet
if err := json.Unmarshal([]byte(historicalV1Canonical), &set); err != nil {
t.Fatal(err)
}
set.ContractVersion = 1
set.SourceTenantID = 10000
set.SourceKnowledgeBaseID = "source"
if err := set.Seal(); err == nil {
t.Fatal("new execution fields were sealed as historical V1")
}
}