lab5: исправления по ревью

Concurrent complete no longer deletes the shared verified source; admission is atomic and covers pending presign rows; relay reconciles queued jobs lost to dead-lettering; failed staging is protected until failed_retention; timestamps normalized to UTC; reprocess prefers the durable original and keeps job->attachment lock order; heartbeat errors no longer burn attempts; confirm timeout enforced; pinned images and sanitized health responses.
This commit is contained in:
Vladislav Kunetskiy
2026-10-30 23:13:44 +03:00
parent 4bdcac3dfa
commit 9d7a0acb5a
40 changed files with 592 additions and 521 deletions
@@ -64,7 +64,7 @@ func (s *PipelineSuite) TestCreateClaimCompleteAndIdempotentRedelivery() {
draft, job := s.attachmentDraft(chat, alice, 1)
repo := s.store.Pipeline()
created, err := repo.CreateQueued(s.T().Context(), draft, job)
created, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{})
s.Require().NoError(err)
s.Equal(domain.AttachmentQueued, created.Status)
s.Equal(1, created.PipelineVersion)
@@ -114,7 +114,7 @@ func (s *PipelineSuite) TestLeaseExpiryIsBoundedByMaxAttempts() {
job.MaxAttempts = 1
repo := s.store.Pipeline()
_, err := repo.CreateQueued(s.T().Context(), draft, job)
_, 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", time.Millisecond)
@@ -133,3 +133,74 @@ func (s *PipelineSuite) TestLeaseExpiryIsBoundedByMaxAttempts() {
s.NotNil(dead.LastErrorCode)
s.Equal("retry_exhausted", *dead.LastErrorCode)
}
func (s *PipelineSuite) TestAdmissionCountsPendingPresignAndIsAtomic() {
alice := s.createUser("alice")
chat := s.createChat(alice)
repo := s.store.Pipeline()
draft, _ := s.attachmentDraft(chat, alice, 1)
draft.ObjectKey = "staging/presign/" + chat.ID.String() + "/" + draft.ID.String()
draft.StagingKey = draft.ObjectKey
draft.Status = domain.AttachmentPending
limits := domain.AdmissionLimits{PerUser: 1, Total: 10}
_, err := repo.CreatePresign(s.T().Context(), draft, limits)
s.Require().NoError(err)
second, _ := s.attachmentDraft(chat, alice, 1)
second.ObjectKey = "staging/presign/" + chat.ID.String() + "/" + second.ID.String()
second.StagingKey = second.ObjectKey
second.Status = domain.AttachmentPending
_, err = repo.CreatePresign(s.T().Context(), second, limits)
s.Require().ErrorIs(err, domain.ErrRateLimited)
}
func (s *PipelineSuite) TestReconcileQueuedJobsRepublishesLostIntent() {
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)
claimed, err := repo.ClaimOutbox(s.T().Context(), "relay", time.Minute, 10)
s.Require().NoError(err)
s.Require().Len(claimed, 1)
s.Require().NoError(repo.MarkPublished(s.T().Context(), []int64{claimed[0].ID}))
reconciled, err := repo.ReconcileQueuedJobs(s.T().Context(), 0, 10)
s.Require().NoError(err)
s.Equal(1, reconciled)
pending, err := repo.ClaimOutbox(s.T().Context(), "relay", time.Minute, 10)
s.Require().NoError(err)
s.Require().Len(pending, 1)
s.Equal("reconcile", pending[0].Kind)
s.Equal(job.ID, pending[0].JobID)
}
func (s *PipelineSuite) TestFailedStagingStaysReferencedUntilRetention() {
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", time.Minute)
s.Require().NoError(err)
s.Equal(domain.ClaimAcquired, claim.Outcome)
ok, err := repo.FailJob(s.T().Context(), job.ID, 1, "lease", "invalid_image")
s.Require().NoError(err)
s.True(ok)
keys, err := repo.ListReferencedKeys(s.T().Context(), "", 100)
s.Require().NoError(err)
s.Contains(keys, draft.StagingKey)
}