Upload a recording (audio, or video with the camera off), get a private Swedish transcript, and chat about it. - ADR-033: RLS-scoped private transcript store; ffprobe/ffmpeg intake; gateway transcription (iguana kb-whisper, berget fallback); in-process single-replica worker; chat over the transcript (local models only). - ADR-034: optional two-engine mode (pianissimo + kb-whisper) reconciled by a LOCAL model; off unless TAPIR_RECONCILE_BASE_MODEL is set. - ADR-035: real progress (phases, running/quiet/lost), phase logging, every judged spot stored, merged segments. - Hardening from four adversarial reviews: errors logged and stored as kinds never text; per-engine deadlines; converted-length check; bounded queue; client hang-ups are not errors; strict local-alias check. - Dockerfile: static ffmpeg/ffprobe 7.0.2 pinned by sha256 (#34). Built and inspected by hand; CI does not build the image on a PR, so its first CI build is this merge. Uploads stay OFF until TAPIR_UPLOADS_ENABLED is set in the deployment. Closes #33, #34, #42, #43, #44. Co-authored-by: Mathias <mthbqv@gmail.com>
79 lines
2.9 KiB
Go
79 lines
2.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// The wiring of the per-engine deadline: a gateway whose primary model never answers
|
|
// must still reach the fallback model inside the job's own deadline (adversarial review
|
|
// F4). The fake gateway answers per model from the multipart `model` field.
|
|
|
|
func TestBuildTranscriber_AWedgedPrimaryReachesTheFallbackBeforeTheJobDeadline(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseMultipartForm(1 << 20)
|
|
if r.FormValue("model") == "iguana/kb-whisper" {
|
|
<-r.Context().Done() // wedged: never answers
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_, _ = w.Write([]byte(`{"text":"hej","duration":1,"segments":[{"start":0,"end":1,"text":"hej"}]}`))
|
|
}))
|
|
defer srv.Close()
|
|
cfg := uploadCfg(t, true)
|
|
cfg.GatewayURL = srv.URL
|
|
cfg.TranscribeModel = "iguana/kb-whisper"
|
|
cfg.TranscribeFallbackModel = "berget/kb-whisper"
|
|
cfg.TranscribeEngineTimeout = 150 * time.Millisecond
|
|
wav := filepath.Join(t.TempDir(), "a.wav")
|
|
require.NoError(t, os.WriteFile(wav, []byte("RIFF....WAVEfmt "), 0o600))
|
|
job, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
|
defer cancel()
|
|
|
|
got, err := buildTranscriber(cfg).Transcribe(job, wav)
|
|
|
|
require.NoError(t, err, "the wedged primary used the whole job and the fallback never ran")
|
|
assert.Equal(t, "berget/kb-whisper", got.Endpoint)
|
|
}
|
|
|
|
func TestBuildTranscriber_AWedgedBaseEngineIsASoftFailureInTheEnsemble(t *testing.T) {
|
|
// The same deadline must guard the ensemble's BASE engine, not only the chain's primary
|
|
// (second adversarial review: the wiring was tested for the chain alone).
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseMultipartForm(1 << 20)
|
|
if r.FormValue("model") == "iguana/pianissimo" {
|
|
<-r.Context().Done()
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_, _ = w.Write([]byte(`{"text":"hej","duration":1,"segments":[{"start":0,"end":1,"text":"hej"}]}`))
|
|
}))
|
|
defer srv.Close()
|
|
cfg := uploadCfg(t, true)
|
|
cfg.GatewayURL = srv.URL
|
|
cfg.TranscribeModel = "iguana/kb-whisper"
|
|
cfg.ReconcileBaseModel = "iguana/pianissimo"
|
|
cfg.ReconcileModel = "iguana/gemma4-31b"
|
|
cfg.TranscribeEngineTimeout = 150 * time.Millisecond
|
|
wav := filepath.Join(t.TempDir(), "a.wav")
|
|
require.NoError(t, os.WriteFile(wav, []byte("RIFF....WAVEfmt "), 0o600))
|
|
job, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
|
defer cancel()
|
|
|
|
got, err := buildTranscriber(cfg).Transcribe(job, wav)
|
|
|
|
require.NoError(t, err, "a wedged base engine must not use up the job")
|
|
assert.Equal(t, "hej", got.Text)
|
|
require.NotNil(t, got.Reconciliation)
|
|
assert.Equal(t, "single_engine", string(got.Reconciliation.Status))
|
|
assert.Contains(t, got.Reconciliation.Reason, "timeout")
|
|
}
|