fix(identity): 支持生效配置安全重验证
Active Revision 重验证成功后更新验证元数据并原子替换同配置 Runtime;验证失败时不修改数据库状态或当前运行时。\n\n验证:go test ./apps/api/internal/identityruntime ./apps/api/internal/store ./apps/api/internal/httpapi
This commit is contained in:
@@ -36,6 +36,15 @@ func (f *runtimeRepositoryFake) MarkIdentityRevisionValidated(_ context.Context,
|
||||
f.revisions[id] = revision
|
||||
return revision, nil
|
||||
}
|
||||
func (f *runtimeRepositoryFake) RevalidateActiveIdentityRevision(_ context.Context, id string, expected int64, traceID, auditID string) (identity.Revision, error) {
|
||||
revision := f.revisions[id]
|
||||
if revision.Version != expected || revision.State != identity.RevisionActive {
|
||||
return identity.Revision{}, identity.ErrRevisionConflict
|
||||
}
|
||||
revision.Version, revision.LastTraceID, revision.LastAuditID = revision.Version+1, traceID, auditID
|
||||
f.revisions[id], f.active = revision, revision
|
||||
return revision, nil
|
||||
}
|
||||
func (f *runtimeRepositoryFake) MarkIdentityRevisionFailed(_ context.Context, id string, expected int64, category, _, _ string) (identity.Revision, error) {
|
||||
revision := f.revisions[id]
|
||||
if revision.Version != expected {
|
||||
@@ -136,3 +145,20 @@ func TestRollbackValidatesAndAtomicallyReplacesActiveRuntime(t *testing.T) {
|
||||
t.Fatalf("rollback did not replace active runtime: revision=%#v current=%#v", rolledBack, manager.Current())
|
||||
}
|
||||
}
|
||||
|
||||
func TestActiveRevalidationSwapsOnlyAfterSuccessfulValidation(t *testing.T) {
|
||||
active := identity.Revision{ID: "active", State: identity.RevisionActive, Version: 4}
|
||||
repository := &runtimeRepositoryFake{revisions: map[string]identity.Revision{"active": active}, active: active}
|
||||
builder := &runtimeBuilderFake{}
|
||||
manager := NewManager(repository, builder)
|
||||
original := &Runtime{Revision: active}
|
||||
manager.current.Store(original)
|
||||
|
||||
revalidated, err := manager.Validate(context.Background(), active.ID, active.Version, "trace-new", "audit-new")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if revalidated.State != identity.RevisionActive || revalidated.Version != 5 || manager.Current() == original || manager.Current().Revision.LastAuditID != "audit-new" {
|
||||
t.Fatalf("active runtime was not safely revalidated: %#v", revalidated)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user