Prepare references independently of audio
This commit is contained in:
@@ -133,7 +133,7 @@ remote state with an unsafe legacy identity must be migrated before use.
|
||||
campaign supplies its default file; an explicit CLI selection replaces it
|
||||
for the invocation and supplies the derived players input. `players_file` and
|
||||
session `party_file` are unsupported configuration keys.
|
||||
- Exactly one audio mode must be configured in session input:
|
||||
- When audio is needed, configure one audio mode in session input:
|
||||
- local (`audio_dir` or `audio_files`), or
|
||||
- S3 (`audio_s3.prefix`).
|
||||
|
||||
@@ -680,6 +680,8 @@ own the contract; see the [maintained examples](../examples/README.md).
|
||||
|
||||
Audio rules:
|
||||
|
||||
- Audio selection may be omitted when remaining work does not require it;
|
||||
uncovered or forced transcription requires audio.
|
||||
- configure local mode (`audio_dir` or `audio_files`) or S3 mode (`audio_s3.prefix`), not both.
|
||||
- `audio_s3` requires `pipeline.storage.backend: s3` and a configured S3 bucket.
|
||||
- Explicit `audio_files` take precedence over `audio_dir`. Paths are resolved relative
|
||||
|
||||
@@ -8,7 +8,7 @@ Materialize canonical current-session inputs before processing stages.
|
||||
|
||||
- resolved campaign, session, and pipeline configuration
|
||||
- the stable speakers input, inline autocorrection rules, canonical party, and optional glossary selections
|
||||
- one resolved local or S3 audio source
|
||||
- a local or S3 audio source when transcription needs audio
|
||||
- previous-session input requirements from selected targets and their configured prerequisites
|
||||
|
||||
## Outputs
|
||||
@@ -21,7 +21,7 @@ Materialize canonical current-session inputs before processing stages.
|
||||
- `inputs/glossaries/{party,campaign,setting,spells,combined}.yml`
|
||||
- `inputs/players.yml`
|
||||
- `inputs/party.yml`
|
||||
- prepared recordings in `audio/`
|
||||
- prepared recordings in `audio/` when audio is acquired
|
||||
- optional `inputs/previous/manifest.json`
|
||||
- optional `inputs/previous/artifacts/**`
|
||||
- deterministic `manifest.inputs` entries (checksums + provenance)
|
||||
@@ -29,6 +29,10 @@ Materialize canonical current-session inputs before processing stages.
|
||||
## Key Behavior
|
||||
|
||||
- validates required config/store state and resolves selected vocabulary before audio work.
|
||||
- prepares references and history without acquiring audio when a validated
|
||||
supplied transcript satisfies transcription. Forced or uncovered transcription
|
||||
requires an audio selection. Preparation metadata records whether audio was
|
||||
prepared, and reference-only preparation preserves supplied-product records.
|
||||
- derives the party glossary and resolves the remaining named collections through
|
||||
`internal/glossary`; writes four individual shared envelopes and a combined
|
||||
envelope with checksums, sizes, and provenance. The combined record declares
|
||||
@@ -82,7 +86,8 @@ The fingerprint deliberately does not read or rehash large audio. Prepared
|
||||
input checksums remain the content provenance. Before reusing success, prepare
|
||||
validates every durable prepared copy and compares current stable-input bytes,
|
||||
effective campaign/session, canonical party, derived-player and resolved glossary
|
||||
bytes, local audio membership/checksums, or S3 key/size/entity-tag identity with that provenance.
|
||||
bytes, and, when audio was needed, local audio membership/checksums or S3
|
||||
key/size/entity-tag identity with that provenance.
|
||||
Source relocation with equivalent effective documents, names, and bytes remains
|
||||
reusable; changed or unavailable evidence causes a normal prepare rerun.
|
||||
Confirmed mismatches and sources that cannot be verified have distinct reasons;
|
||||
|
||||
@@ -239,7 +239,7 @@ Validation: `go test ./internal/app ./internal/stage`.
|
||||
|
||||
## Stage 6: Separate reference preparation from audio acquisition
|
||||
|
||||
Status: Pending
|
||||
Status: Complete
|
||||
|
||||
Read `config/validate_core.go`, `stage/prepare*.go`, and preparation semantic
|
||||
evidence. Preserve ConfigKit's completed-configuration boundary.
|
||||
|
||||
@@ -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