Use shared audio discovery in inspection
This commit is contained in:
113
internal/app/audio_inspection_consistency_test.go
Normal file
113
internal/app/audio_inspection_consistency_test.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||
)
|
||||
|
||||
func TestAudioInspectionAgreesWithPreparation(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
files []string
|
||||
directory bool
|
||||
reject bool
|
||||
}{
|
||||
{name: "same basename", files: []string{"first/speaker.flac", "second/speaker.flac"}},
|
||||
{name: "explicit mixed", files: []string{"first/one.mp3", "second/two.unknown"}},
|
||||
{name: "directory mixed", files: []string{"audio/one.mp3", "audio/two.WAV"}, directory: true},
|
||||
{name: "repeated path", files: []string{"first/one.flac", "first/one.flac"}, reject: true},
|
||||
{name: "same stem", files: []string{"first/one.mp3", "second/one.wav"}, reject: true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
cfg := testConfig(t)
|
||||
root := filepath.Dir(cfg.SessionPath)
|
||||
for _, name := range tc.files {
|
||||
mustWriteFile(t, filepath.Join(root, name), "audio")
|
||||
}
|
||||
if tc.directory {
|
||||
cfg.Session.Inputs.AudioFiles = nil
|
||||
} else {
|
||||
cfg.Session.Inputs.AudioFiles = tc.files
|
||||
}
|
||||
check := inspectLocalAudioPresence(cfg)
|
||||
if (check.Err != nil) != tc.reject {
|
||||
t.Fatalf("inspection error: %v", check.Err)
|
||||
}
|
||||
entries, err := os.ReadDir(cfg.Pipeline.Workspace.Root)
|
||||
if err != nil || len(entries) != 0 {
|
||||
t.Fatalf("inspection changed workspace: %v %v", entries, err)
|
||||
}
|
||||
m := manifest.New(cfg.Session.SessionID, time.Now().UTC())
|
||||
var prepare stage.Stage
|
||||
for _, candidate := range stage.All() {
|
||||
if candidate.Name() == "prepare" {
|
||||
prepare = candidate
|
||||
break
|
||||
}
|
||||
}
|
||||
_, err = prepare.Run(context.Background(), &stage.Env{Config: cfg, ArtifactStore: artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)}, m)
|
||||
if (err != nil) != tc.reject {
|
||||
t.Fatalf("prepare error: %v", err)
|
||||
}
|
||||
if !tc.reject {
|
||||
count := 0
|
||||
for _, input := range m.Inputs {
|
||||
if input.Kind == "audio" {
|
||||
count++
|
||||
}
|
||||
}
|
||||
if count != len(check.Paths) {
|
||||
t.Fatalf("inspection paths %v, prepared %d", check.Paths, count)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteAudioInspectionAgreesWithPreparation(t *testing.T) {
|
||||
for _, collision := range []bool{false, true} {
|
||||
cfg := testConfig(t)
|
||||
cfg.Session.Inputs.AudioDir = ""
|
||||
cfg.Session.Inputs.AudioS3 = &config.SessionAudioS3Input{Prefix: "audio/"}
|
||||
cfg.Pipeline.Storage.S3 = &config.StorageS3Config{Bucket: "test", RootPrefix: "root"}
|
||||
prefix := artifacts.S3AudioPrefix(artifacts.S3SessionPrefix("root", cfg.Session.Campaign, cfg.Session.SessionID), "audio/")
|
||||
fake := &storage.FakeBackend{}
|
||||
fake.SeedObject(storage.FakeObject{Key: prefix + "one.flac", Data: []byte("one")})
|
||||
name := "two.mp3"
|
||||
if collision {
|
||||
name = "one.mp3"
|
||||
}
|
||||
fake.SeedObject(storage.FakeObject{Key: prefix + name, Data: []byte("two")})
|
||||
check := inspectRemoteAudioPresence(context.Background(), cfg, fake)
|
||||
if (check.Err != nil) != collision {
|
||||
t.Fatalf("inspection error: %v", check.Err)
|
||||
}
|
||||
if len(fake.Reads) != 0 {
|
||||
t.Fatal("inspection downloaded audio")
|
||||
}
|
||||
entries, err := os.ReadDir(cfg.Pipeline.Workspace.Root)
|
||||
if err != nil || len(entries) != 0 {
|
||||
t.Fatalf("inspection changed workspace: %v %v", entries, err)
|
||||
}
|
||||
m := manifest.New(cfg.Session.SessionID, time.Now().UTC())
|
||||
m.RunID = "20260515T031522Z-a1b2c3d4"
|
||||
for _, candidate := range stage.All() {
|
||||
if candidate.Name() == "prepare" {
|
||||
_, err = candidate.Run(context.Background(), &stage.Env{Config: cfg, ArtifactStore: artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root), ObjectStore: fake}, m)
|
||||
break
|
||||
}
|
||||
}
|
||||
if (err != nil) != collision {
|
||||
t.Fatalf("prepare error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user