feat: upload audio, get a private Swedish transcript, discuss it (#33, ADR-033) #39
@@ -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")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user