From b8a6e2f6f50ae595252bb473e623fdf5aa04e421 Mon Sep 17 00:00:00 2001 From: Mathias Date: Fri, 2 Oct 2026 17:20:38 +0200 Subject: [PATCH] test: second review -- the upload chat model outside the chain, room checked before spooling, a cut-off body is a 400, bidi controls in titles, the ensemble's deadline wiring, an honest test name (red) Co-Authored-By: Claude Sonnet 5.5 --- internal/uploads/intake_busy_test.go | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/internal/uploads/intake_busy_test.go b/internal/uploads/intake_busy_test.go index f895af5..6f12519 100644 --- a/internal/uploads/intake_busy_test.go +++ b/internal/uploads/intake_busy_test.go @@ -5,6 +5,7 @@ import ( "errors" "strings" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -29,3 +30,37 @@ func TestAccept_AFullQueueIsABusyRejectionNotAServerErrorAndLeavesNothingBehind( assert.Equal(t, domain.UploadErrBusy, r.st.failed["up-1"], "the row must not sit queued: that is the stuck spinner") assert.Empty(t, r.tmpFiles(t), "the audio is deleted") } + +// roomSubmitter is a Submitter that can say, before anything is spooled, that there is no room. +type roomSubmitter struct { + fakeSubmitter + room bool +} + +func (r *roomSubmitter) HasRoom(string) bool { return r.room } + +func TestAccept_ANoRoomQueueIsRefusedBeforeAnythingIsSpooledProbedOrStored(t *testing.T) { + // Checking only at Submit meant 200 MB was spooled and ffprobe run for every refused + // attempt, and a failed row was left behind each time (second adversarial review). + r := newRig(t) + full := &roomSubmitter{room: false} + in := uploads.NewIntake(r.st, r.pr, full, uploads.Limits{MaxBytes: 1024, MaxDuration: 90 * time.Minute}, r.tmp) + + _, err := in.Accept(context.Background(), "user-1", "t", strings.NewReader("data")) + + var rej *uploads.RejectError + require.True(t, errors.As(err, &rej)) + assert.Equal(t, uploads.ReasonBusy, rej.Reason) + assert.Empty(t, r.st.created, "no row for an upload that was never accepted") + assert.Empty(t, r.pr.paths, "ffprobe was never run on it") + assert.Empty(t, r.tmpFiles(t), "nothing was spooled") + assert.Empty(t, full.jobs) +} + +func TestAccept_ASubmitterThatCannotSayStillWorksAsBefore(t *testing.T) { + r := newRig(t) + + _, err := r.in.Accept(context.Background(), "user-1", "t", strings.NewReader("data")) + + require.NoError(t, err, "a Submitter without HasRoom is accepted: the check at Submit remains") +}