This commit is contained in:
@@ -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")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user