fix(snapshot): 阻止旧策略作业重放冒充新验收口径
build / build (push) Successful in 1m6s

This commit is contained in:
姚章浩
2026-10-28 08:05:39 +08:00
parent 76f687b52d
commit 3dc854de4b
3 changed files with 28 additions and 0 deletions
@@ -64,6 +64,9 @@ func CaptureLibrary(ctx context.Context, freeze *libraryfreeze.Coordinator, arch
if err != nil {
return libraryfreeze.Result{}, errors.New("captured library archive no longer verifies")
}
if saved.ValidationPolicy != librarysnapshot.ArtifactAcceptancePolicy {
return libraryfreeze.Result{}, errors.New("library capture validation policy conflicts with existing job")
}
if saved.Scope != req.Scope || saved.TenantID != req.Identity.TenantID || saved.KnowledgeBaseID != req.Identity.KnowledgeBaseID || saved.Compatibility != req.Compatibility || !saved.CreatedAt.Equal(req.CreatedAt) {
return libraryfreeze.Result{}, errors.New("library capture request conflicts with existing job")
}
@@ -133,6 +133,24 @@ func TestLibraryCaptureMaintenanceOwnsArchiveAndRestoresOnFailure(t *testing.T)
if got, err := CaptureLibrary(context.Background(), freeze, archive, db, search, &libraryCandidateReader{}, ready, req); err == nil || got.State == "succeeded" {
t.Fatal("missing archive returned a successful candidate")
}
// Simulate a durable successful job created before the policy marker.
// Replaying it must not silently upgrade its validation contract.
saved.ValidationPolicy = ""
legacyID, err := archive.Seal(saved)
if err != nil {
t.Fatal(err)
}
req.JobID = "legacy-capture-job"
if _, err := freeze.RunPrepared(context.Background(), req.JobID, func(context.Context) error { return nil }, func(context.Context) (string, error) { return legacyID, nil }); err != nil {
t.Fatal(err)
}
stops, previousChecks := writer.stops, checks
if got, err := CaptureLibrary(context.Background(), freeze, archive, db, search, &libraryCandidateReader{}, ready, req); err == nil || got.State == "succeeded" || got.SnapshotID != "" {
t.Fatal("legacy policy replay silently upgraded to artifact acceptance")
}
if writer.stops != stops || checks != previousChecks {
t.Fatal("policy conflict touched current source")
}
})
}
}