Add Phase 2 fixtures and compatibility tests
This commit is contained in:
@@ -1097,38 +1097,107 @@ func TestRunProcessFailedRunsRetained(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunProcessSuccessfulRunRetention(t *testing.T) {
|
||||
func TestRunProcessCLIAndNormalizationAgree(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
transcriptJSON := `[{"id": 1, "speaker": "Alice", "start": 0.0, "end": 1.0, "text": "Hello"}]`
|
||||
transcriptJSON := `[
|
||||
{"id": 1, "speaker": "Alice", "start": 0.0, "end": 1.0, "text": "Hello"},
|
||||
{"id": 2, "speaker": "Alice", "start": 1.5, "end": 2.5, "text": "world"}
|
||||
]`
|
||||
|
||||
transcriptPath := filepath.Join(t.TempDir(), "transcript.json")
|
||||
glossaryPath := fixturePath("tiny_glossary.yaml")
|
||||
workDir := filepath.Join(t.TempDir(), "work")
|
||||
|
||||
if err := os.WriteFile(transcriptPath, []byte(transcriptJSON), 0644); err != nil {
|
||||
t.Fatalf("failed to create test transcript: %v", err)
|
||||
}
|
||||
|
||||
// Test with "never" retention - successful runs should be removed
|
||||
exitCode := Run([]string{
|
||||
"process",
|
||||
transcriptPath,
|
||||
"--glossary",
|
||||
glossaryPath,
|
||||
"--work-dir",
|
||||
workDir,
|
||||
"--work-dir-retention",
|
||||
"never",
|
||||
}, &stdout, &stderr)
|
||||
exitCode := Run([]string{"process", transcriptPath, "--glossary", glossaryPath}, &stdout, &stderr)
|
||||
if exitCode != 0 {
|
||||
t.Fatalf("expected exit code 0, got %d with stderr %q", exitCode, stderr.String())
|
||||
}
|
||||
|
||||
// With "never" retention, successful runs should be removed
|
||||
runDirs, err := os.ReadDir(workDir)
|
||||
if err == nil && len(runDirs) > 0 {
|
||||
t.Fatalf("expected successful run to be removed with 'never' retention, found %d directories", len(runDirs))
|
||||
// Parse CLI output
|
||||
var cliOutput schema.Transcript
|
||||
if err := schema.ParseTranscriptJSON(stdout.Bytes()); err != nil {
|
||||
t.Fatalf("failed to parse CLI output: %v", err)
|
||||
}
|
||||
|
||||
// Parse source transcript
|
||||
var sourceTranscript schema.SourceTranscript
|
||||
if err := schema.ParseSourceTranscriptJSON([]byte(transcriptJSON)); err != nil {
|
||||
t.Fatalf("failed to parse source transcript: %v", err)
|
||||
}
|
||||
|
||||
// Convert to canonical format
|
||||
canonical := &schema.Transcript{
|
||||
Segments: make([]schema.Segment, len(sourceTranscript.Segments)),
|
||||
}
|
||||
for i, s := range sourceTranscript.Segments {
|
||||
id := i + 1
|
||||
if s.ID != nil {
|
||||
id = *s.ID
|
||||
}
|
||||
canonical.Segments[i] = schema.Segment{
|
||||
ID: id,
|
||||
Speaker: s.Speaker,
|
||||
Start: s.Start,
|
||||
End: s.End,
|
||||
Text: s.Text,
|
||||
Categories: s.Categories,
|
||||
}
|
||||
}
|
||||
|
||||
// Apply normalization using pure package
|
||||
normalizer := normalization.NewNormalizer(normalization.NormalizationConfig{
|
||||
MaxSegmentGap: 2.0,
|
||||
EllipsisGap: 1.0,
|
||||
MaxSegmentDuration: 60.0,
|
||||
MaxSegmentTokens: 100,
|
||||
})
|
||||
|
||||
packageOutput, _ := normalizer.Normalize(canonical)
|
||||
|
||||
// Compare CLI and package outputs
|
||||
assertTranscriptsEqual(t, &cliOutput, packageOutput)
|
||||
}
|
||||
|
||||
func assertTranscriptsEqual(t *testing.T, actual, expected *schema.Transcript) {
|
||||
t.Helper()
|
||||
|
||||
if len(actual.Segments) != len(expected.Segments) {
|
||||
t.Errorf("segment count mismatch: expected %d, got %d", len(expected.Segments), len(actual.Segments))
|
||||
return
|
||||
}
|
||||
|
||||
for i := range actual.Segments {
|
||||
a := actual.Segments[i]
|
||||
e := expected.Segments[i]
|
||||
|
||||
if a.ID != e.ID {
|
||||
t.Errorf("segment %d: ID mismatch: expected %d, got %d", i, e.ID, a.ID)
|
||||
}
|
||||
if a.Speaker != e.Speaker {
|
||||
t.Errorf("segment %d: speaker mismatch: expected %q, got %q", i, e.Speaker, a.Speaker)
|
||||
}
|
||||
if a.Start != e.Start {
|
||||
t.Errorf("segment %d: start mismatch: expected %f, got %f", i, e.Start, a.Start)
|
||||
}
|
||||
if a.End != e.End {
|
||||
t.Errorf("segment %d: end mismatch: expected %f, got %f", i, e.End, a.End)
|
||||
}
|
||||
if a.Text != e.Text {
|
||||
t.Errorf("segment %d: text mismatch: expected %q, got %q", i, e.Text, a.Text)
|
||||
}
|
||||
if len(a.Categories) != len(e.Categories) {
|
||||
t.Errorf("segment %d: categories count mismatch: expected %d, got %d", i, len(e.Categories), len(a.Categories))
|
||||
continue
|
||||
}
|
||||
for j, cat := range a.Categories {
|
||||
if j >= len(e.Categories) || cat != e.Categories[j] {
|
||||
t.Errorf("segment %d: category %d mismatch: expected %q, got %q", i, j, e.Categories[j], cat)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user