Simplify the CLI interface and update documentation accordingly

This commit is contained in:
2026-04-26 19:47:47 -05:00
parent 3928e0c4a7
commit f9ca80f2e8
5 changed files with 92 additions and 62 deletions

View File

@@ -90,6 +90,7 @@ func TestMergeWritesMergedOutputAndReport(t *testing.T) {
"placeholder-merger",
"detect-overlaps",
"resolve-overlaps",
"autocorrect",
"assign-ids",
"validate-output",
"json",
@@ -274,43 +275,37 @@ func TestMissingInputFileFailsBeforePipelineExecution(t *testing.T) {
}
}
func TestNormalizeSpeakersRequiresSpeakersFile(t *testing.T) {
func TestDefaultMergeWorksWithoutSpeakersOrAutocorrect(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "input.json", `{"segments":[]}`)
input := writeJSONFile(t, dir, "input.json", `{"segments":[{"start":1,"end":2,"text":"Frank"}]}`)
output := filepath.Join(dir, "merged.json")
reportPath := filepath.Join(dir, "report.json")
err := executeMerge(
"--input-file", input,
"--output-file", output,
"--report-file", reportPath,
)
if err == nil {
t.Fatal("expected error")
if err != nil {
t.Fatalf("merge failed: %v", err)
}
if !strings.Contains(err.Error(), "--speakers is required") {
t.Fatalf("unexpected error: %v", err)
}
}
func TestAutocorrectRequiresAutocorrectFile(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "input.json", `{"segments":[]}`)
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["input.json"]
`)
output := filepath.Join(dir, "merged.json")
err := executeMerge(
"--input-file", input,
"--speakers", speakers,
"--output-file", output,
"--postprocessing-modules", "detect-overlaps,resolve-overlaps,autocorrect,assign-ids,validate-output",
)
if err == nil {
t.Fatal("expected error")
var transcript model.FinalTranscript
readJSON(t, output, &transcript)
if got, want := transcript.Segments[0].Speaker, "input.json"; got != want {
t.Fatalf("speaker = %q, want %q", got, want)
}
if !strings.Contains(err.Error(), "--autocorrect is required") {
t.Fatalf("unexpected error: %v", err)
if got, want := transcript.Segments[0].Text, "Frank"; got != want {
t.Fatalf("text = %q, want %q", got, want)
}
var rpt report.Report
readJSON(t, reportPath, &rpt)
if !hasReportEvent(rpt, "preprocessing", "normalize-speakers", "using input basenames") {
t.Fatal("expected normalize-speakers fallback report event")
}
if !hasReportEvent(rpt, "postprocessing", "autocorrect", "skipped autocorrect") {
t.Fatal("expected autocorrect skip report event")
}
}
@@ -402,6 +397,28 @@ func TestPostprocessingAutocorrectUpdatesOutputAndReport(t *testing.T) {
}
}
func TestInvalidAutocorrectFileFailsWhenProvided(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "input.json", `{"segments":[{"start":1,"end":2,"text":"Frank"}]}`)
output := filepath.Join(dir, "merged.json")
autocorrect := writeYAMLFile(t, dir, "autocorrect.yml", `autocorrect:
- target: ""
match: ["Frank"]
`)
err := executeMerge(
"--input-file", input,
"--autocorrect", autocorrect,
"--output-file", output,
)
if err == nil {
t.Fatal("expected error")
}
if !strings.Contains(err.Error(), "must include target") {
t.Fatalf("unexpected error: %v", err)
}
}
func TestOutputJSONIsByteStable(t *testing.T) {
dir := t.TempDir()
inputA := writeJSONFile(t, dir, "a.json", `{"segments":[{"start":2,"end":3,"text":"a"}]}`)
@@ -658,6 +675,15 @@ func equalStrings(left []string, right []string) bool {
return true
}
func hasReportEvent(rpt report.Report, stage string, module string, messageSubstring string) bool {
for _, event := range rpt.Events {
if event.Stage == stage && event.Module == module && strings.Contains(event.Message, messageSubstring) {
return true
}
}
return false
}
func assertSegment(t *testing.T, segment model.Segment, id int, source string, sourceIndex int, speaker string, start float64, end float64, text string) {
t.Helper()