Verify mixed audio retries and transport

This commit is contained in:
2026-12-02 03:19:22 +00:00
parent 3b16bf2790
commit 9e2fc7313e
5 changed files with 96 additions and 6 deletions

View File

@@ -305,6 +305,8 @@ func TestPrepareStageS3AudioDownloadAndMaterialization(t *testing.T) {
t.Fatalf("expected file %q: %v", p, err)
}
}
mustReadFileEquals(t, aliceWork, "alice")
mustReadFileEquals(t, bobWork, "bob")
if got := result.Metadata["audio_reused"]; got != 0 {
t.Fatalf("audio_reused = %#v, want 0", got)
}

View File

@@ -559,3 +559,89 @@ func TestTranscribeAudioDiscoveryValidatesSelectedInputs(t *testing.T) {
}
}
}
func TestMixedAudioPreparationRetryAndReconciliation(t *testing.T) {
env, m := setupTranscribeEnv(t, nil)
root := filepath.Dir(env.Config.SessionPath)
files := []string{"first/a.flac", "second/a.flac", "b.mp3", "c.flac", "z.unknown"}
for _, name := range files {
writeFile(t, filepath.Join(root, name), "bytes-"+name)
}
env.Config.Session.Inputs.AudioFiles = files
one := 1
env.Config.Pipeline.WhisperX.Concurrency = &one
if _, err := (prepareStage{}).Run(context.Background(), env, m); err != nil {
t.Fatal(err)
}
paths := sessionPathsForEnv(env, m.SessionID)
prepared, err := buildTranscribeJobs(m, paths)
if err != nil {
t.Fatal(err)
}
if len(prepared) != len(files) || prepared[0].audioPath == prepared[1].audioPath {
t.Fatalf("jobs %#v", prepared)
}
for _, input := range m.Inputs {
if input.Kind == "audio" {
data, err := os.ReadFile(input.Path)
if err != nil {
t.Fatal(err)
}
if !strings.HasPrefix(string(data), "bytes-") {
t.Fatalf("unexpected bytes for %s: %q", input.Path, data)
}
}
}
backendErr := errors.New("unsupported or malformed audio")
env.WhisperX = &whisperx.FakeClient{TranscribeFn: func(_ context.Context, req whisperx.TranscribeRequest) (whisperx.TranscribeResult, error) {
if req.SpeakerID == "z" {
return whisperx.TranscribeResult{}, backendErr
}
if err := writeJSONFile(req.OutputRawTranscriptPath, map[string]any{"speaker": req.SpeakerID}); err != nil {
return whisperx.TranscribeResult{}, err
}
return whisperx.TranscribeResult{OutputRawTranscriptPath: req.OutputRawTranscriptPath}, nil
}}
if _, err := (transcribeStage{}).Run(context.Background(), env, m); !errors.Is(err, backendErr) {
t.Fatalf("backend failure: %v", err)
}
durable, err := env.ManifestStore.Load(context.Background(), paths.ManifestPath)
if err != nil {
t.Fatal(err)
}
if len(durable.Stages["transcribe"].TranscribeSpeakers) != 4 {
t.Fatalf("checkpoints: %#v", durable.Stages["transcribe"].TranscribeSpeakers)
}
retry := &whisperx.FakeClient{}
env.WhisperX = retry
if _, err := (transcribeStage{}).Run(context.Background(), env, durable); err != nil {
t.Fatal(err)
}
requests := retry.RequestsSnapshot()
if len(requests) != 1 || requests[0].SpeakerID != "z" {
t.Fatalf("retry requests: %#v", requests)
}
durable, err = env.ManifestStore.Load(context.Background(), paths.ManifestPath)
if err != nil {
t.Fatal(err)
}
var changed string
for _, job := range prepared {
if job.speakerID == "b" {
changed = job.audioPath
}
}
if changed == "" {
t.Fatal("missing b speaker")
}
writeFile(t, changed, "changed audio")
retry = &whisperx.FakeClient{}
env.WhisperX = retry
if _, err := (transcribeStage{}).Run(context.Background(), env, durable); err != nil {
t.Fatal(err)
}
requests = retry.RequestsSnapshot()
if len(requests) != 1 || requests[0].SpeakerID != "b" {
t.Fatalf("changed requests: %#v", requests)
}
}