diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index a5a26e7..b954dd6 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -231,7 +231,12 @@ no timing or production-size assumption is required. **Priority:** P3 -**Status:** For consideration +**Status:** Complete + +Prior audio records are indexed once by cleaned destination, retaining the first +audio match. Existing identity/hash/download checks remain unchanged. Verified +S3 reuse, missing-file replacement, unrelated kinds, and duplicate-record +precedence with `go test ./internal/stage ./internal/audio`. **Stage:** 17. diff --git a/internal/stage/prepare.go b/internal/stage/prepare.go index b7d833d..13b0613 100644 --- a/internal/stage/prepare.go +++ b/internal/stage/prepare.go @@ -433,15 +433,20 @@ func materializeS3AudioInputs(ctx context.Context, env *Env, m *manifest.Manifes return s3AudioMaterializationStats{}, fmt.Errorf("create work audio directory %q: %w", workAudioDir, err) } stats := s3AudioMaterializationStats{} + priorByPath := make(map[string]*manifest.InputRecord) + for i := range m.Inputs { + record := &m.Inputs[i] + if record.Kind != "audio" { + continue + } + key := filepath.Clean(record.Path) + if _, exists := priorByPath[key]; !exists { + priorByPath[key] = record + } + } for _, obj := range audioObjects { workPath := filepath.Join(workAudioDir, path.Base(obj.Key)) - var prior *manifest.InputRecord - for i := range m.Inputs { - if m.Inputs[i].Kind == "audio" && filepath.Clean(m.Inputs[i].Path) == filepath.Clean(workPath) { - prior = &m.Inputs[i] - break - } - } + prior := priorByPath[filepath.Clean(workPath)] result, err := audio.MaterializeS3Audio(ctx, audio.S3MaterializeRequest{ Reporter: env.Reporter, Store: env.ObjectStore, Object: obj, Bucket: strings.TrimSpace(env.Config.Pipeline.Storage.S3.Bucket), DestPath: workPath, Prior: prior, diff --git a/internal/stage/prepare_test.go b/internal/stage/prepare_test.go index c79efcd..bb2f61d 100644 --- a/internal/stage/prepare_test.go +++ b/internal/stage/prepare_test.go @@ -359,6 +359,12 @@ func TestPrepareStageS3AudioReusesPreparedCopy(t *testing.T) { t.Fatal(err) } m.RunID = "20260515T041522Z-a1b2c3d4" + prior := findManifestInput(t, m.Inputs, "audio") + duplicate := prior + duplicate.Checksum = strings.Repeat("0", 64) + // Selection ignores other kinds and retains the first matching audio record. + m.Inputs = append([]manifest.InputRecord{{Kind: "unrelated", Path: prior.Path}}, m.Inputs...) + m.Inputs = append(m.Inputs, duplicate) result, err := (prepareStage{}).Run(context.Background(), env, m) if err != nil { t.Fatal(err)