Add output validation against a defined JSON schema

This commit is contained in:
2026-04-27 21:27:19 -05:00
parent 8a95dba276
commit 6cb739be55
14 changed files with 638 additions and 30 deletions

View File

@@ -102,6 +102,9 @@ func TestMergeWritesMergedOutputAndReport(t *testing.T) {
if !equalStrings(gotModules, wantModules) {
t.Fatalf("report event order mismatch:\ngot %v\nwant %v", gotModules, wantModules)
}
if !hasReportEvent(rpt, "postprocessing", "validate-output", "validated 3 output segment(s)") {
t.Fatal("expected validate-output report event")
}
}
func TestMergeTieBreakOrder(t *testing.T) {
@@ -153,6 +156,28 @@ func TestMergeTieBreakOrder(t *testing.T) {
}
}
func TestMergeValidateOutputBeforeAssignIDsFails(t *testing.T) {
dir := t.TempDir()
input := writeJSONFile(t, dir, "input.json", `{
"segments": [
{"start": 1, "end": 2, "text": "hello"}
]
}`)
output := filepath.Join(dir, "merged.json")
err := executeMerge(
"--input-file", input,
"--output-file", output,
"--postprocessing-modules", "validate-output,assign-ids",
)
if err == nil {
t.Fatal("expected validation error")
}
if !strings.Contains(err.Error(), "validate-output: segment 0 has id 0; want 1") {
t.Fatalf("unexpected error: %v", err)
}
}
func TestMergeDetectsOverlapGroups(t *testing.T) {
dir := t.TempDir()
inputA := writeJSONFile(t, dir, "a.json", `{