Implemented substring matching for speakers.yml

This commit is contained in:
2026-04-26 19:20:00 -05:00
parent fe00600762
commit 99d0c425d6
4 changed files with 308 additions and 74 deletions

View File

@@ -24,11 +24,11 @@ func TestMergeWritesMergedOutputAndReport(t *testing.T) {
{"start": 5, "end": 6, "text": "first b"}
]
}`)
speakers := writeYAMLFile(t, dir, "speakers.yml", `inputs:
a.json:
speaker: Alice
b.json:
speaker: Bob
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["a.json"]
- speaker: Bob
match: ["b.json"]
`)
output := filepath.Join(dir, "merged.json")
reportPath := filepath.Join(dir, "report.json")
@@ -112,11 +112,11 @@ func TestMergeTieBreakOrder(t *testing.T) {
{"start": 1, "end": 2, "text": "b-same-time"}
]
}`)
speakers := writeYAMLFile(t, dir, "speakers.yml", `inputs:
a.json:
speaker: Alice
b.json:
speaker: Bob
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["a.json"]
- speaker: Bob
match: ["b.json"]
`)
output := filepath.Join(dir, "merged.json")
@@ -148,12 +148,43 @@ func TestMergeTieBreakOrder(t *testing.T) {
}
}
func TestSpeakerMatchingUsesFirstMatchingRuleCaseInsensitive(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "2026-04-19-Adam_Rakestraw.json", `{
"segments": [
{"start": 1, "end": 2, "text": "hello"}
]
}`)
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: First Match
match: ["adam"]
- speaker: Later Match
match: ["Adam_Rakestraw"]
`)
output := filepath.Join(dir, "merged.json")
err := executeMerge(
"--input-file", input,
"--speakers", speakers,
"--output-file", output,
)
if err != nil {
t.Fatalf("merge failed: %v", err)
}
var transcript model.FinalTranscript
readJSON(t, output, &transcript)
if got, want := transcript.Segments[0].Speaker, "First Match"; got != want {
t.Fatalf("speaker = %q, want %q", got, want)
}
}
func TestUnknownModulesFailDuringValidation(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "input.json", `{"segments":[]}`)
speakers := writeYAMLFile(t, dir, "speakers.yml", `inputs:
input.json:
speaker: Alice
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["input.json"]
`)
output := filepath.Join(dir, "merged.json")
@@ -224,9 +255,9 @@ func TestInvalidPreprocessingOrderFails(t *testing.T) {
func TestMissingInputFileFailsBeforePipelineExecution(t *testing.T) {
dir := t.TempDir()
speakers := writeYAMLFile(t, dir, "speakers.yml", `inputs:
missing.json:
speaker: Alice
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["missing.json"]
`)
output := filepath.Join(dir, "merged.json")
@@ -263,9 +294,9 @@ func TestNormalizeSpeakersRequiresSpeakersFile(t *testing.T) {
func TestAutocorrectRequiresAutocorrectFile(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "input.json", `{"segments":[]}`)
speakers := writeYAMLFile(t, dir, "speakers.yml", `inputs:
input.json:
speaker: Alice
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["input.json"]
`)
output := filepath.Join(dir, "merged.json")
@@ -287,11 +318,11 @@ func TestOutputJSONIsByteStable(t *testing.T) {
dir := t.TempDir()
inputA := writeJSONFile(t, dir, "a.json", `{"segments":[{"start":2,"end":3,"text":"a"}]}`)
inputB := writeJSONFile(t, dir, "b.json", `{"segments":[{"start":1,"end":2,"text":"b"}]}`)
speakers := writeYAMLFile(t, dir, "speakers.yml", `inputs:
a.json:
speaker: Alice
b.json:
speaker: Bob
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["a.json"]
- speaker: Bob
match: ["b.json"]
`)
outputA := filepath.Join(dir, "merged-a.json")
outputB := filepath.Join(dir, "merged-b.json")
@@ -327,9 +358,9 @@ func TestOutputJSONIsByteStable(t *testing.T) {
func TestMissingSpeakerMappingFails(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "input.json", `{"segments":[]}`)
speakers := writeYAMLFile(t, dir, "speakers.yml", `inputs:
other.json:
speaker: Alice
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["other.json"]
`)
output := filepath.Join(dir, "merged.json")
@@ -341,7 +372,7 @@ func TestMissingSpeakerMappingFails(t *testing.T) {
if err == nil {
t.Fatal("expected error")
}
if !strings.Contains(err.Error(), `speaker map has no entry for input basename "input.json"`) {
if !strings.Contains(err.Error(), `speaker map has no match for input basename "input.json"`) {
t.Fatalf("unexpected error: %v", err)
}
}
@@ -349,9 +380,9 @@ func TestMissingSpeakerMappingFails(t *testing.T) {
func TestMalformedJSONFails(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "input.json", `{"segments":[`)
speakers := writeYAMLFile(t, dir, "speakers.yml", `inputs:
input.json:
speaker: Alice
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["input.json"]
`)
output := filepath.Join(dir, "merged.json")
@@ -371,9 +402,9 @@ func TestMalformedJSONFails(t *testing.T) {
func TestMissingTopLevelSegmentsFails(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "input.json", `{}`)
speakers := writeYAMLFile(t, dir, "speakers.yml", `inputs:
input.json:
speaker: Alice
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["input.json"]
`)
output := filepath.Join(dir, "merged.json")
@@ -422,9 +453,9 @@ func TestInvalidSegmentFieldsFailWithSourceAndIndex(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "input.json", test.json)
speakers := writeYAMLFile(t, dir, "speakers.yml", `inputs:
input.json:
speaker: Alice
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["input.json"]
`)
output := filepath.Join(dir, "merged.json")
@@ -468,9 +499,9 @@ func TestInvalidTimingFails(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "input.json", test.json)
speakers := writeYAMLFile(t, dir, "speakers.yml", `inputs:
input.json:
speaker: Alice
speakers := writeYAMLFile(t, dir, "speakers.yml", `match:
- speaker: Alice
match: ["input.json"]
`)
output := filepath.Join(dir, "merged.json")