fix(library): 收口 B1-R1/B2-R1/B5-R1 并让恢复链经过正式队列终态
B1-R1: 演练写集改为受限 restore-drill(V2 信封/contract 1/schema 摘要,零对象、零索引、零本地映射,来源身份必填)。B2-R1: verify 作业先建不可变 operation 并携带 operation_id,同 job recover 的网关 claim 同时携带原 operation 与 recovery 身份。B5-R1: 前端按 scope 世代与动作序号丢弃迟到响应,不污染新 scope 或父级旧回调。harness 的 recovery 改由生产 jobs.Worker.RunOnce 消费并读回 jobs 终态;原失败窗口作业保持 failed,不改写历史。
This commit is contained in:
@@ -97,11 +97,25 @@ func libraryVerifyEnqueue(w http.ResponseWriter, r *http.Request, config Config)
|
||||
return
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
// 验证作业必须有和同步/恢复同一套不可变 operation:worker 的 owned attempt 从
|
||||
// job.operation_id 取身份,恢复派发闸口和对象网关都按它核验。没有 operation 的
|
||||
// verify 作业在真实恢复时会被 fail closed(审核 B2-R1)。
|
||||
intent, intentErr := ensureLibraryIntent(r.Context(), store, request.Scope, governance.LibraryJobVerify,
|
||||
"", digest, identity.Username, "", now)
|
||||
if intentErr != nil {
|
||||
if isIntentConflict(intentErr) {
|
||||
writeJSON(w, http.StatusConflict, map[string]any{"code": "library_verify_conflict",
|
||||
"error": "同一幂等键对应了不同的请求"})
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "cannot create library verify operation"})
|
||||
return
|
||||
}
|
||||
job, reused, err := store.CreateLibraryDispatch(r.Context(), governance.LibraryJob{
|
||||
ID: fmt.Sprintf("libverify-%s-%d", request.Scope, now.UnixNano()), Scope: request.Scope,
|
||||
Kind: governance.LibraryJobVerify,
|
||||
IdempotencyKey: "library.verify:" + request.Scope + ":" + now.Format("20060102T150405.000000000"),
|
||||
RequestDigest: digest, Actor: identity.Username,
|
||||
IdempotencyKey: intent.JobKey,
|
||||
RequestDigest: digest, OperationID: intent.Operation.ID, Actor: identity.Username,
|
||||
}, governance.VerifyStages(), false, now)
|
||||
if errors.Is(err, governance.ErrLibraryJobActive) {
|
||||
writeJSON(w, http.StatusConflict, map[string]any{"code": "library_write_active",
|
||||
|
||||
@@ -99,6 +99,14 @@ func TestLibraryVerifyEnqueuesVerifyJobWithCanaryStages(t *testing.T) {
|
||||
if !strings.HasPrefix(store.lastJob.ID, "libverify-internal-") {
|
||||
t.Fatalf("job id=%q", store.lastJob.ID)
|
||||
}
|
||||
// B2-R1:verify 作业必须带不可变 operation,worker 的 owned attempt / 恢复派发
|
||||
// 身份都从它取;没有 operation 的作业在真实恢复时会被 fail closed。
|
||||
if store.lastJob.OperationID == "" || store.lastJob.OperationID != store.lastOperation.ID {
|
||||
t.Fatalf("verify job must carry its operation: job=%#v op=%#v", store.lastJob, store.lastOperation)
|
||||
}
|
||||
if store.lastOperation.Kind != governance.LibraryJobVerify || store.lastOperation.Scope != "internal" {
|
||||
t.Fatalf("verify operation identity=%#v", store.lastOperation)
|
||||
}
|
||||
// 阶段必须包含 canary:没有"写 canary 证明校验有效"这一步,验证就只是自证。
|
||||
want := governance.VerifyStages()
|
||||
if len(want) != 5 || want[2] != "canary" || want[3] != "restore" || want[4] != "finalize" {
|
||||
|
||||
Reference in New Issue
Block a user