Add normalize report diagnostics
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/report"
|
||||
"gitea.maximumdirect.net/eric/seriatim/schema"
|
||||
)
|
||||
|
||||
@@ -292,8 +294,139 @@ func TestNormalizeSelectedOutputSchemaIsHonored(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeReportFileWrittenAndContainsObjectInputShape(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
input := writeJSONFile(t, dir, "input.json", `{"segments":[{"start":1,"end":2,"speaker":"A","text":"one"}]}`)
|
||||
output := filepath.Join(dir, "normalized.json")
|
||||
reportPath := filepath.Join(dir, "report.json")
|
||||
|
||||
err := executeNormalize(
|
||||
"--input-file", input,
|
||||
"--output-file", output,
|
||||
"--report-file", reportPath,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("normalize failed: %v", err)
|
||||
}
|
||||
|
||||
var rpt report.Report
|
||||
readJSON(t, reportPath, &rpt)
|
||||
audit := extractNormalizeAudit(t, rpt)
|
||||
if audit.InputShape != "object_with_segments" {
|
||||
t.Fatalf("input shape = %q, want object_with_segments", audit.InputShape)
|
||||
}
|
||||
if audit.InputSegmentCount != 1 {
|
||||
t.Fatalf("input segment count = %d, want 1", audit.InputSegmentCount)
|
||||
}
|
||||
if audit.OutputSchema != config.OutputSchemaIntermediate {
|
||||
t.Fatalf("output schema = %q, want %q", audit.OutputSchema, config.OutputSchemaIntermediate)
|
||||
}
|
||||
if len(audit.OutputModules) != 1 || audit.OutputModules[0] != "json" {
|
||||
t.Fatalf("output modules = %v, want [json]", audit.OutputModules)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeReportIncludesBareArrayShape(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
input := writeJSONFile(t, dir, "input.json", `[{"start":1,"end":2,"speaker":"A","text":"one"}]`)
|
||||
output := filepath.Join(dir, "normalized.json")
|
||||
reportPath := filepath.Join(dir, "report.json")
|
||||
|
||||
err := executeNormalize(
|
||||
"--input-file", input,
|
||||
"--output-file", output,
|
||||
"--report-file", reportPath,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("normalize failed: %v", err)
|
||||
}
|
||||
|
||||
var rpt report.Report
|
||||
readJSON(t, reportPath, &rpt)
|
||||
audit := extractNormalizeAudit(t, rpt)
|
||||
if audit.InputShape != "bare_segments_array" {
|
||||
t.Fatalf("input shape = %q, want bare_segments_array", audit.InputShape)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeReportEmptyInputEmitsWarning(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
input := writeJSONFile(t, dir, "input.json", `{"segments":[]}`)
|
||||
output := filepath.Join(dir, "normalized.json")
|
||||
reportPath := filepath.Join(dir, "report.json")
|
||||
|
||||
err := executeNormalize(
|
||||
"--input-file", input,
|
||||
"--output-file", output,
|
||||
"--report-file", reportPath,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("normalize failed: %v", err)
|
||||
}
|
||||
|
||||
var rpt report.Report
|
||||
readJSON(t, reportPath, &rpt)
|
||||
found := false
|
||||
for _, event := range rpt.Events {
|
||||
if event.Stage == "normalize" && event.Module == "normalize" && event.Severity == report.SeverityWarning &&
|
||||
strings.Contains(event.Message, "zero segments") {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected empty transcript warning event, got %#v", rpt.Events)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeReportWriteFailureReturnsClearError(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
input := writeJSONFile(t, dir, "input.json", `{"segments":[{"start":1,"end":2,"speaker":"A","text":"one"}]}`)
|
||||
output := filepath.Join(dir, "normalized.json")
|
||||
|
||||
err := executeNormalize(
|
||||
"--input-file", input,
|
||||
"--output-file", output,
|
||||
"--report-file", dir,
|
||||
)
|
||||
if err == nil {
|
||||
t.Fatal("expected report write failure")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "write --report-file") {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func executeNormalize(args ...string) error {
|
||||
cmd := NewRootCommand()
|
||||
cmd.SetArgs(append([]string{"normalize"}, args...))
|
||||
return cmd.Execute()
|
||||
}
|
||||
|
||||
type normalizeAudit struct {
|
||||
Command string `json:"command"`
|
||||
InputFile string `json:"input_file"`
|
||||
OutputFile string `json:"output_file"`
|
||||
InputShape string `json:"input_shape"`
|
||||
InputSegmentCount int `json:"input_segment_count"`
|
||||
OutputSchema string `json:"output_schema"`
|
||||
OutputModules []string `json:"output_modules"`
|
||||
IDsReassigned bool `json:"ids_reassigned"`
|
||||
SortingChangedInput bool `json:"sorting_changed_input_order"`
|
||||
SegmentsWithCategories int `json:"segments_with_categories"`
|
||||
}
|
||||
|
||||
func extractNormalizeAudit(t *testing.T, rpt report.Report) normalizeAudit {
|
||||
t.Helper()
|
||||
for _, event := range rpt.Events {
|
||||
if event.Stage == "normalize" && event.Module == "normalize-audit" {
|
||||
var audit normalizeAudit
|
||||
if err := json.Unmarshal([]byte(event.Message), &audit); err != nil {
|
||||
t.Fatalf("decode normalize audit: %v", err)
|
||||
}
|
||||
return audit
|
||||
}
|
||||
}
|
||||
t.Fatalf("missing normalize-audit event: %#v", rpt.Events)
|
||||
return normalizeAudit{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user