Implemented an overlap detection module in the postprocessing chain

This commit is contained in:
2026-04-26 20:39:49 -05:00
parent f9ca80f2e8
commit e42a2326e8
8 changed files with 464 additions and 4 deletions

View File

@@ -137,6 +137,7 @@ func normalizeInputFiles(paths []string) ([]string, error) {
}
normalized := make([]string, 0, len(paths))
seen := make(map[string]struct{}, len(paths))
for _, path := range paths {
path = strings.TrimSpace(path)
if path == "" {
@@ -147,6 +148,10 @@ func normalizeInputFiles(paths []string) ([]string, error) {
if err := requireFile(clean, "--input-file"); err != nil {
return nil, err
}
if _, exists := seen[clean]; exists {
return nil, fmt.Errorf("duplicate --input-file %q", clean)
}
seen[clean] = struct{}{}
normalized = append(normalized, clean)
}
sort.Strings(normalized)

View File

@@ -3,6 +3,7 @@ package config
import (
"os"
"path/filepath"
"strings"
"testing"
)
@@ -24,6 +25,27 @@ func TestOmittingNormalizeSpeakersDoesNotRequireSpeakers(t *testing.T) {
}
}
func TestDuplicateInputFilesFailValidation(t *testing.T) {
dir := t.TempDir()
input := writeTempFile(t, dir, "input.json")
output := filepath.Join(dir, "merged.json")
_, err := NewMergeConfig(MergeOptions{
InputFiles: []string{input, input},
OutputFile: output,
InputReader: DefaultInputReader,
OutputModules: DefaultOutputModules,
PreprocessingModules: DefaultPreprocessingModules,
PostprocessingModules: DefaultPostprocessingModules,
})
if err == nil {
t.Fatal("expected duplicate input error")
}
if !strings.Contains(err.Error(), "duplicate --input-file") {
t.Fatalf("unexpected error: %v", err)
}
}
func writeTempFile(t *testing.T, dir string, name string) string {
t.Helper()