From a7e2cc43c020f904d0f4e26ec2eaea73d4405e4d Mon Sep 17 00:00:00 2001 From: Mathias Date: Fri, 2 Oct 2026 16:45:25 +0200 Subject: [PATCH] test(cmd): the built worker refuses audio longer than the configured maximum (review F2) Co-Authored-By: Claude Sonnet 5.5 --- cmd/tapir/uploads_worker_limit_test.go | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 cmd/tapir/uploads_worker_limit_test.go diff --git a/cmd/tapir/uploads_worker_limit_test.go b/cmd/tapir/uploads_worker_limit_test.go new file mode 100644 index 0000000..1be8f32 --- /dev/null +++ b/cmd/tapir/uploads_worker_limit_test.go @@ -0,0 +1,39 @@ +package main + +import ( + "context" + "os" + "path/filepath" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "git.d-ma.be/mathias/tapir/internal/domain" + "git.d-ma.be/mathias/tapir/internal/uploads" +) + +// The worker buildUploads returns enforces the configured maximum on what was really +// converted (adversarial review F2). A stub ffmpeg writes a sparse 100-minute WAV however +// short the file claimed to be; the gateway is never reached because the job fails first. + +func TestBuildUploads_TheWorkerRefusesAudioLongerThanTheConfiguredMaximum(t *testing.T) { + dir := t.TempDir() + stub := filepath.Join(dir, "ffmpeg") + require.NoError(t, os.WriteFile(stub, []byte("#!/bin/sh\nfor a; do last=\"$a\"; done\ntruncate -s 192000044 \"$last\"\n"), 0o700)) + cfg := uploadCfg(t, true) + cfg.FFmpegBin = stub + cfg.UploadMaxDuration = 90 * time.Minute + cfg.TranscribeTimeout = time.Minute + st := &fakeUploadsStore{} + _, w, err := buildUploads(context.Background(), cfg, st, quietLog()) + require.NoError(t, err) + src := filepath.Join(cfg.UploadTmpDir, "upload-x") + require.NoError(t, os.WriteFile(src, []byte("audio"), 0o600)) + + w.Process(context.Background(), uploads.Job{UserID: "u", UploadID: "id", Path: src, Duration: 10 * time.Second}) + + assert.Equal(t, []domain.UploadErrorKind{domain.UploadErrTooLong}, st.failedKinds, + "a file that claimed 10 s but converted to 100 minutes must fail, not be sent to an engine") +}