From 7282893877dcf36471755a70d6604d9fb45547e0 Mon Sep 17 00:00:00 2001 From: Mathias Date: Sun, 4 Oct 2026 22:40:35 +0200 Subject: [PATCH] test(transcribe): WithTimeout hands the engine the job's language, as on the production path (#61) The wrapper sits in front of both local engines; a fresh context there would send an auto upload as language=sv and un-cancel the job, and no test noticed. Found by the PR #62 review. Co-Authored-By: Claude Sonnet 5.5 --- internal/adapters/transcribe/timeout_test.go | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/adapters/transcribe/timeout_test.go b/internal/adapters/transcribe/timeout_test.go index fed4489..1ec6205 100644 --- a/internal/adapters/transcribe/timeout_test.go +++ b/internal/adapters/transcribe/timeout_test.go @@ -102,3 +102,32 @@ func TestEnsemble_AHungEngineIsASoftFailureAndTheOtherEnginesTextIsUsed(t *testi assert.Contains(t, got.Reconciliation.Reason, "timeout") assert.False(t, errors.Is(err, context.DeadlineExceeded)) } + +// WithTimeout sits in front of both local engines in production (cmd/tapir/uploads.go). It +// must hand the engine the job's context, not a fresh one: the language and the +// cancellation both travel on it (tapir#61). + +func TestWithTimeout_TheEngineStillReceivesTheLanguageOfTheJob(t *testing.T) { + for name, tt := range map[string]struct { + ctx context.Context + wantField bool + }{ + "auto leaves the field out": {domain.WithLanguage(context.Background(), domain.LangAuto), false}, + "swedish sends sv": {domain.WithLanguage(context.Background(), domain.LangSwedish), true}, + } { + t.Run(name, func(t *testing.T) { + var got seen + srv := serve(t, 200, verboseJSON, &got) + b := transcribe.WithTimeout(transcribe.NewGateway(srv.URL+"/v1", "k", "iguana/kb-whisper", srv.Client()), time.Minute) + + _, err := b.Transcribe(tt.ctx, wavFile(t, "RIFF-synthetic-pcm")) + + require.NoError(t, err) + lang, present := got.fields["language"] + assert.Equal(t, tt.wantField, present) + if tt.wantField { + assert.Equal(t, "sv", lang) + } + }) + } +}