ReconcileLibraryJobs 不再把 completed capture queue 当成不存在,保留待核对 pending 封存作业;failed/cancelled/missing 仍按真实队列状态处置。管理员核对 入口只允许精确的启动误判形态,并要求 completed queue、export succeeded、 唯一 test_sealed 版本、来源身份与完整归档复核。新增 library_job_repairs 不可变审计表,在同一事务内 CAS 保存原 state/stage/error/recovery/finished_at 及本次 actor/原因/证据后修复;真实失败/取消不开放。 验证:真实隔离 PostgreSQL 启动收敛 RED/GREEN、启动→handler 纵向 pending 与 系统误判 failed、审计保留/幂等、负例;真实 Go 全量与 make verify 17 项通过。
This commit is contained in:
@@ -99,6 +99,30 @@ func (f *fakeLibraryStore) ReconcileLibraryCaptureTerminal(_ context.Context, jo
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (f *fakeLibraryStore) ReconcileMisclassifiedLibraryCapture(_ context.Context, jobID, scope, queueJobID, snapshotID, expectedStage, expectedError, expectedRecovery string, expectedFinished *time.Time, _ string, _ string, _ string, _ map[string]any, _ time.Time) (bool, error) {
|
||||
if f.reconcileDenied {
|
||||
return false, nil
|
||||
}
|
||||
for index := range f.jobs {
|
||||
j := &f.jobs[index]
|
||||
if j.ID != jobID || j.Scope != scope || j.Kind != governance.LibraryJobSeal || j.QueueJobID != queueJobID ||
|
||||
j.State != governance.LibraryJobFailed || j.Stage != expectedStage || j.Error != expectedError ||
|
||||
j.Recovery != expectedRecovery || j.SnapshotID != "" || (j.FinishedAt == nil) != (expectedFinished == nil) ||
|
||||
(j.FinishedAt != nil && expectedFinished != nil && !j.FinishedAt.Equal(*expectedFinished)) {
|
||||
return false, nil
|
||||
}
|
||||
j.State = governance.LibraryJobSucceeded
|
||||
j.SnapshotID = snapshotID
|
||||
j.Stage = "export"
|
||||
f.lastState = governance.LibraryJobSucceeded
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
var _ libraryCaptureReconciler = (*fakeLibraryStore)(nil)
|
||||
|
||||
func runReconcile(t *testing.T, config Config, jobID string) *httptest.ResponseRecorder {
|
||||
t.Helper()
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/library/jobs/"+jobID+"/reconcile-capture", nil)
|
||||
@@ -271,3 +295,67 @@ func TestLibraryCaptureReconcileConditionalWriteRejectsConcurrentState(t *testin
|
||||
t.Fatalf("code=%d advanced=%q body=%s", rec.Code, store.lastState, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibraryCaptureReconcileRepairsExactLegacyMisclassification(t *testing.T) {
|
||||
store, config, job, _ := reconcileFixture(t)
|
||||
finished := time.Now().UTC()
|
||||
job.State = governance.LibraryJobFailed
|
||||
job.Stage = ""
|
||||
job.Error = legacyOrphanError
|
||||
job.Recovery = legacyOrphanRecovery
|
||||
job.FinishedAt = &finished
|
||||
store.jobs[0] = job
|
||||
rec := runReconcile(t, config, job.ID)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("code=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var body map[string]any
|
||||
_ = json.Unmarshal(rec.Body.Bytes(), &body)
|
||||
if body["misclassification_repaired"] != true || store.lastState != governance.LibraryJobSucceeded {
|
||||
t.Fatalf("body=%v advanced=%q", body, store.lastState)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibraryCaptureReconcileRejectsOtherFailedError(t *testing.T) {
|
||||
store, config, job, _ := reconcileFixture(t)
|
||||
finished := time.Now().UTC()
|
||||
job.State = governance.LibraryJobFailed
|
||||
job.Stage = ""
|
||||
job.Error = "capture export failed"
|
||||
job.Recovery = legacyOrphanRecovery
|
||||
job.FinishedAt = &finished
|
||||
store.jobs[0] = job
|
||||
rec := runReconcile(t, config, job.ID)
|
||||
if rec.Code != http.StatusConflict || store.lastState != "" {
|
||||
t.Fatalf("code=%d advanced=%q body=%s", rec.Code, store.lastState, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibraryCaptureReconcileRejectsRealFailureAndCancel(t *testing.T) {
|
||||
for _, state := range []governance.LibraryJobState{governance.LibraryJobFailed, governance.LibraryJobCancelled} {
|
||||
store, config, job, _ := reconcileFixture(t)
|
||||
job.State = state
|
||||
job.Error = "real failure"
|
||||
store.jobs[0] = job
|
||||
rec := runReconcile(t, config, job.ID)
|
||||
if rec.Code != http.StatusConflict || store.lastState != "" {
|
||||
t.Fatalf("state=%s code=%d advanced=%q", state, rec.Code, store.lastState)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibraryCaptureReconcileMisclassificationCASRejectsChange(t *testing.T) {
|
||||
store, config, job, _ := reconcileFixture(t)
|
||||
finished := time.Now().UTC()
|
||||
job.State = governance.LibraryJobFailed
|
||||
job.Stage = ""
|
||||
job.Error = legacyOrphanError
|
||||
job.Recovery = legacyOrphanRecovery
|
||||
job.FinishedAt = &finished
|
||||
store.jobs[0] = job
|
||||
store.reconcileDenied = true
|
||||
rec := runReconcile(t, config, job.ID)
|
||||
if rec.Code != http.StatusConflict || store.lastState != "" {
|
||||
t.Fatalf("code=%d advanced=%q", rec.Code, store.lastState)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user