lab5: закрытие второго ревью

Validate the PNG raster itself: exact Adam7/non-interlaced row layout, scanline filter bytes, palette/PLTE rules, bounded streaming without keeping the raster. Settle an attachment as failed when a newer pipeline fails before any version was published, while keeping a ready serving version intact. Reject unsupported pipeline versions in jobctl before changing state.
This commit is contained in:
Vladislav Kunetskiy
2026-10-31 01:06:43 +03:00
parent b965350cc9
commit 8c0a455aa5
14 changed files with 478 additions and 112 deletions
@@ -998,7 +998,15 @@ func failJobTx(
return fmt.Errorf("mark job failed: %w", mapError(err))
}
if job.PipelineVersion == attachment.PipelineVersion {
// A failed job settles the attachment when its version is the serving one,
// or when it is a newer version attempted before any version was
// published (reprocess from queued/processing/failed). A newer version
// failing while an older ready version is serving must not disturb the
// published version: it stays ready and downloadable.
settlesAttachment := job.PipelineVersion == attachment.PipelineVersion ||
(job.PipelineVersion > attachment.PipelineVersion && attachment.Status != domain.AttachmentReady)
if settlesAttachment {
_, err = tx.Exec(ctx, `
UPDATE attachments
SET status = 'failed',
@@ -221,6 +221,86 @@ func (s *PipelineSuite) TestReprocessReadyUsesObjectSource() {
s.Equal(draft.ObjectKey, created.SourceKey)
}
// A reprocess failure before any version was published must settle the
// attachment as failed instead of leaving it queued with no active jobs.
func (s *PipelineSuite) TestReprocessFailureSettlesUnpublishedAttachment() {
alice := s.createUser("alice")
chat := s.createChat(alice)
repo := s.store.Pipeline()
draft, job := s.attachmentDraft(chat, alice, 1)
_, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{})
s.Require().NoError(err)
reprocessID, err := uuid.NewV7()
s.Require().NoError(err)
reprocess, err := repo.Reprocess(s.T().Context(), draft.ID, 2, 5, reprocessID)
s.Require().NoError(err)
claim, err := repo.ClaimJob(s.T().Context(), domain.NewJobMessage(reprocess), "lease-2", time.Minute)
s.Require().NoError(err)
s.Equal(domain.ClaimAcquired, claim.Outcome)
failed, err := repo.FailJob(s.T().Context(), reprocess.ID, 1, "lease-2", "invalid_image")
s.Require().NoError(err)
s.True(failed)
current, err := repo.GetForOwner(s.T().Context(), alice.ID, draft.ID)
s.Require().NoError(err)
s.Equal(domain.AttachmentFailed, current.Status)
s.Require().NotNil(current.ErrorCode)
s.Equal("invalid_image", *current.ErrorCode)
}
// A reprocess failure while an older ready version is serving must keep that
// version ready and downloadable; only the new job fails.
func (s *PipelineSuite) TestReprocessFailureKeepsReadyServingVersion() {
alice := s.createUser("alice")
chat := s.createChat(alice)
repo := s.store.Pipeline()
draft, job := s.attachmentDraft(chat, alice, 1)
_, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{})
s.Require().NoError(err)
claim, err := repo.ClaimJob(s.T().Context(), domain.NewJobMessage(job), "lease-1", time.Minute)
s.Require().NoError(err)
s.Equal(domain.ClaimAcquired, claim.Outcome)
variants := []domain.Variant{
{
Name: domain.VariantThumbnail, ContentType: "image/jpeg", SizeBytes: 11,
Width: 256, Height: 160, SHA256: strings.Repeat("b", 64),
ObjectKey: domain.VariantObjectKey(chat.ID, draft.ID, 1, domain.VariantThumbnail),
},
}
ok, err := repo.CompleteJob(s.T().Context(), job.ID, 1, "lease-1", variants)
s.Require().NoError(err)
s.True(ok)
reprocessID, err := uuid.NewV7()
s.Require().NoError(err)
reprocess, err := repo.Reprocess(s.T().Context(), draft.ID, 2, 5, reprocessID)
s.Require().NoError(err)
claim, err = repo.ClaimJob(s.T().Context(), domain.NewJobMessage(reprocess), "lease-2", time.Minute)
s.Require().NoError(err)
s.Equal(domain.ClaimAcquired, claim.Outcome)
failed, err := repo.FailJob(s.T().Context(), reprocess.ID, 1, "lease-2", "invalid_image")
s.Require().NoError(err)
s.True(failed)
current, err := repo.GetForOwner(s.T().Context(), alice.ID, draft.ID)
s.Require().NoError(err)
s.Equal(domain.AttachmentReady, current.Status)
s.Equal(1, current.PipelineVersion)
s.Nil(current.ErrorCode)
}
func (s *PipelineSuite) TestReconcileQueuedJobsRepublishesLostIntent() {
alice := s.createUser("alice")
chat := s.createChat(alice)