f9457fab52
build / build (push) Successful in 1m35s
B1/B2:演练在同一维护切点做两次真实捕获(写前镜像与来源身份), 写集合在写第一笔之前落盘并登记;恢复走限定范围的 RestoreDrill, 复用同一份 DS01 身份合同与 Apply 原语整段回放,不再让同快照必被拒绝。 worker 接治理维护生命周期(实例+scope 行、真实入口状态、成功才释放), held 保留行并由同 job 的 library.recover 收口(kind 过滤贯通 verify)。 B3:证据优先,failed/invalid 与读取错误即使 env=true 也拒绝。 B4/B5:GET 投影在飞作业,子面板回调父页面轮询;观测绑定 scope 与代次, 刷新失败明确过期,不再显示旧的"已验证"。 迁移 79 不自动 down;未部署、未调用业务目标。
73 lines
3.3 KiB
Go
73 lines
3.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"knowledge-governance/internal/appconfig"
|
|
"knowledge-governance/internal/governance"
|
|
)
|
|
|
|
// 同步闸口的"恢复可验证"判断必须以当前目标的证据为准:
|
|
// 没有证据 ⇒ 拒绝并说清怎么补;有 passed 证据 ⇒ 放行;只有失败证据 ⇒ 拒绝并带失败原因。
|
|
// 历史 env 覆盖只在证据缺失时兜底(页面不再写它)。
|
|
type verifyEvidenceStore struct {
|
|
evidence governance.LibraryRestoreVerification
|
|
found bool
|
|
}
|
|
|
|
func (s verifyEvidenceStore) LatestLibraryRestoreVerification(context.Context, string) (governance.LibraryRestoreVerification, bool, error) {
|
|
return s.evidence, s.found, nil
|
|
}
|
|
|
|
// 审核 B3:读取失败不能被 env=true 洗成"满足"。
|
|
type unreadableEvidenceStore struct{}
|
|
|
|
func (unreadableEvidenceStore) LatestLibraryRestoreVerification(context.Context, string) (governance.LibraryRestoreVerification, bool, error) {
|
|
return governance.LibraryRestoreVerification{}, false, errors.New("evidence lookup failed")
|
|
}
|
|
|
|
func TestWorkerUnreadableEvidenceBeatsEnv(t *testing.T) {
|
|
ok, reason := libraryRestoreEvidenceSatisfied(context.Background(), unreadableEvidenceStore{},
|
|
appconfig.Config{ProductionBackupRestoreVerified: true}, "internal")
|
|
if ok {
|
|
t.Fatalf("unreadable evidence must block even with env=true; reason=%q", reason)
|
|
}
|
|
if !strings.Contains(reason, "读取恢复验证证据失败") {
|
|
t.Fatalf("reason=%q", reason)
|
|
}
|
|
}
|
|
|
|
func TestLibraryRestoreEvidenceSatisfied(t *testing.T) {
|
|
now := time.Now().UTC()
|
|
passed := verifyEvidenceStore{found: true, evidence: governance.LibraryRestoreVerification{
|
|
Scope: "internal", Status: governance.LibraryVerificationPassed, SnapshotID: "snap-1", FinishedAt: now}}
|
|
if ok, reason := libraryRestoreEvidenceSatisfied(context.Background(), passed, appconfig.Config{}, "internal"); !ok {
|
|
t.Fatalf("passed evidence must satisfy gate: %q", reason)
|
|
}
|
|
failed := verifyEvidenceStore{found: true, evidence: governance.LibraryRestoreVerification{
|
|
Scope: "internal", Status: governance.LibraryVerificationFailed, SnapshotID: "snap-1",
|
|
Failure: "恢复后内容仍与预备份不一致", FinishedAt: now}}
|
|
if ok, reason := libraryRestoreEvidenceSatisfied(context.Background(), failed, appconfig.Config{}, "internal"); ok ||
|
|
!strings.Contains(reason, "恢复后内容仍与预备份不一致") {
|
|
t.Fatalf("failed evidence must block with its own failure: ok=%v reason=%q", ok, reason)
|
|
}
|
|
missing := verifyEvidenceStore{}
|
|
if ok, reason := libraryRestoreEvidenceSatisfied(context.Background(), missing, appconfig.Config{}, "internal"); ok ||
|
|
!strings.Contains(reason, "恢复验证") {
|
|
t.Fatalf("missing evidence must block and point at the remedy: ok=%v reason=%q", ok, reason)
|
|
}
|
|
// 历史部署的 env 覆盖:证据缺失时才生效,证据存在时不再起作用。
|
|
if ok, reason := libraryRestoreEvidenceSatisfied(context.Background(), missing,
|
|
appconfig.Config{ProductionBackupRestoreVerified: true}, "internal"); !ok {
|
|
t.Fatalf("legacy env override must still allow when no evidence: %q", reason)
|
|
}
|
|
if ok, _ := libraryRestoreEvidenceSatisfied(context.Background(), failed,
|
|
appconfig.Config{ProductionBackupRestoreVerified: true}, "internal"); ok {
|
|
t.Fatal("evidence must win over the legacy env override")
|
|
}
|
|
}
|