Prepare references independently of audio
This commit is contained in:
@@ -287,21 +287,14 @@ func TestPipelineMaterializationPreservesNilEmptyAndExactIntegers(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateMissingAudioSource(t *testing.T) {
|
||||
func TestValidateAllowsMissingAudioSource(t *testing.T) {
|
||||
cfg := loadedValidConfig(t)
|
||||
cfg.Session.Inputs.AudioDir = ""
|
||||
cfg.Session.Inputs.AudioFiles = nil
|
||||
cfg.Session.Inputs.AudioS3 = nil
|
||||
|
||||
err := Validate(cfg)
|
||||
if err == nil {
|
||||
t.Fatal("expected validation error, got nil")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "audio_dir, at least one audio_files entry, or audio_s3") {
|
||||
t.Fatalf("error = %q, want audio source guidance", err.Error())
|
||||
}
|
||||
if !strings.Contains(err.Error(), "session config") {
|
||||
t.Fatalf("error = %q, want session config context", err.Error())
|
||||
if err := Validate(cfg); err != nil {
|
||||
t.Fatalf("configuration without audio should validate: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,10 +73,6 @@ func sessionConfigurationError(cfg *SessionConfig) (configkit.Path, error) {
|
||||
if hasAudioS3 && (hasAudioDir || hasAudioFiles) {
|
||||
return configkit.Keys("inputs", "audio_dir"), fmt.Errorf("session.inputs.audio_dir/audio_files and session.inputs.audio_s3 are mutually exclusive")
|
||||
}
|
||||
if !hasAudioDir && !hasAudioFiles && !hasAudioS3 {
|
||||
return configkit.Keys("inputs"), fmt.Errorf("session.inputs requires audio_dir, at least one audio_files entry, or audio_s3")
|
||||
}
|
||||
|
||||
return configkit.Keys(), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,23 @@ type prepareStage struct{}
|
||||
func (prepareStage) Name() string { return "prepare" }
|
||||
|
||||
func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*StageResult, error) {
|
||||
return prepareInputs(ctx, env, m, prepareNeedsAudio(env, m))
|
||||
}
|
||||
|
||||
// PrepareReferences materializes session references and history without acquiring audio.
|
||||
func PrepareReferences(ctx context.Context, env *Env, m *manifest.Manifest) (*StageResult, error) {
|
||||
return prepareInputs(ctx, env, m, false)
|
||||
}
|
||||
|
||||
func prepareNeedsAudio(env *Env, m *manifest.Manifest) bool {
|
||||
if env == nil || env.Config == nil || env.Config.Session == nil || env.ArtifactStore == nil || m == nil || env.Force {
|
||||
return true
|
||||
}
|
||||
paths := sessionPathsForEnv(env, m.SessionID)
|
||||
return !artifacts.SuppliedTranscriptCoverage(paths, m.SuppliedProducts)["transcribe"]
|
||||
}
|
||||
|
||||
func prepareInputs(ctx context.Context, env *Env, m *manifest.Manifest, acquireAudio bool) (*StageResult, error) {
|
||||
if env == nil || env.Config == nil {
|
||||
return nil, fmt.Errorf("prepare: stage environment config is required")
|
||||
}
|
||||
@@ -74,9 +91,16 @@ func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
}
|
||||
}
|
||||
|
||||
resolvedLocalAudio, useS3Audio, err := resolveAudioInputs(sessionDir, env.Config.Session.Inputs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare: resolve audio inputs: %w", err)
|
||||
var resolvedLocalAudio []audio.Source
|
||||
var useS3Audio bool
|
||||
if acquireAudio {
|
||||
resolvedLocalAudio, useS3Audio, err = resolveAudioInputs(sessionDir, env.Config.Session.Inputs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare: resolve audio inputs: %w", err)
|
||||
}
|
||||
if !useS3Audio && len(resolvedLocalAudio) == 0 {
|
||||
return nil, fmt.Errorf("prepare: audio input is required for transcription")
|
||||
}
|
||||
}
|
||||
|
||||
inputs := make([]manifest.InputRecord, 0, 9+len(resolvedLocalAudio))
|
||||
@@ -204,7 +228,7 @@ func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
return nil, fmt.Errorf("prepare: materialize s3 audio: %w", err)
|
||||
}
|
||||
audioStats = stats
|
||||
} else {
|
||||
} else if acquireAudio {
|
||||
if err := materializeLocalAudioInputs(env, paths, resolvedLocalAudio, registerInput); err != nil {
|
||||
return nil, fmt.Errorf("prepare: %w", err)
|
||||
}
|
||||
@@ -240,6 +264,7 @@ func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
"stage": "prepare",
|
||||
"inputs_count": len(inputs),
|
||||
"audio_files_resolved": countAudioInputs(inputs),
|
||||
"audio_prepared": acquireAudio,
|
||||
}
|
||||
if useS3Audio {
|
||||
metadata["audio_reused"] = audioStats.Reused
|
||||
|
||||
@@ -150,11 +150,13 @@ func currentPrepareSourceInputs(ctx context.Context, env *Env, m *manifest.Manif
|
||||
}
|
||||
expected = append(expected, partyInputs...)
|
||||
|
||||
audioInputs, err := currentPrepareAudioSourceInputs(ctx, env, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if prepareNeedsAudio(env, m) {
|
||||
audioInputs, err := currentPrepareAudioSourceInputs(ctx, env, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
expected = append(expected, audioInputs...)
|
||||
}
|
||||
expected = append(expected, audioInputs...)
|
||||
return expected, nil
|
||||
}
|
||||
|
||||
@@ -212,6 +214,9 @@ func currentPrepareAudioSourceInputs(ctx context.Context, env *Env, m *manifest.
|
||||
}
|
||||
return expected, nil
|
||||
}
|
||||
if len(local) == 0 {
|
||||
return nil, fmt.Errorf("audio input is required for transcription")
|
||||
}
|
||||
|
||||
expected := make([]prepareExpectedInput, 0, len(local))
|
||||
for _, source := range local {
|
||||
|
||||
64
internal/stage/prepare_supplied_test.go
Normal file
64
internal/stage/prepare_supplied_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package stage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
|
||||
func TestPrepareReferencesWithSuppliedTranscript(t *testing.T) {
|
||||
env, m := setupPrepareEnv(t)
|
||||
env.Config.Session.Inputs.AudioDir = ""
|
||||
paths := sessionPathsForEnv(env, m.SessionID)
|
||||
path := filepath.Join(paths.Root, filepath.FromSlash(artifacts.TranscriptPathFinalTrimmed))
|
||||
body := `{"segments":[]}`
|
||||
writeFile(t, path, body)
|
||||
checksum, err := artifacts.SHA256File(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := artifacts.ArtifactTranscriptFinalTrimmed
|
||||
m.SuppliedProducts = &manifest.SuppliedProductCollection{Version: manifest.SuppliedProductVersion, Products: map[string]manifest.SuppliedProduct{source: {Path: artifacts.TranscriptPathFinalTrimmed, Checksum: checksum, Size: int64(len(body))}}}
|
||||
m.Stages["transcribe"] = &manifest.StageRecord{Name: "transcribe", TranscribeSpeakers: map[string]manifest.TranscribeSpeakerRecord{"speaker": {Fingerprint: "prior"}}}
|
||||
m.Stages["analyze"] = &manifest.StageRecord{Name: "analyze", AnalyzeArtifacts: map[string]manifest.AnalyzeArtifactRecord{"prior": {Key: "prior"}}}
|
||||
result, err := (prepareStage{}).Run(context.Background(), env, m)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Metadata["audio_prepared"] != false || countAudioInputs(m.Inputs) != 0 {
|
||||
t.Fatalf("preparation %+v", result.Metadata)
|
||||
}
|
||||
if _, ok := m.SuppliedProducts.Products[source]; !ok {
|
||||
t.Fatal("supplied transcript lost")
|
||||
}
|
||||
if m.Stages["transcribe"].TranscribeSpeakers["speaker"].Fingerprint != "prior" || m.Stages["analyze"].AnalyzeArtifacts["prior"].Key != "prior" {
|
||||
t.Fatal("reference preparation changed unrelated checkpoints")
|
||||
}
|
||||
validation, err := (prepareStage{}).ValidateResume(context.Background(), env, m)
|
||||
if err != nil || !validation.Resumable {
|
||||
t.Fatalf("validation %+v %v", validation, err)
|
||||
}
|
||||
env.Force = true
|
||||
if _, err := (prepareStage{}).Run(context.Background(), env, m); err == nil {
|
||||
t.Fatal("forced transcription accepted absent audio")
|
||||
}
|
||||
env.Force = false
|
||||
if err := os.Remove(filepath.Join(filepath.Dir(env.Config.SessionPath), "speakers.yml")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := PrepareReferences(context.Background(), env, m); err == nil {
|
||||
t.Fatal("missing reference accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareWithoutSuppliedTranscriptRequiresAudio(t *testing.T) {
|
||||
env, m := setupPrepareEnv(t)
|
||||
env.Config.Session.Inputs.AudioDir = ""
|
||||
if _, err := (prepareStage{}).Run(context.Background(), env, m); err == nil {
|
||||
t.Fatal("missing audio accepted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user