import json from audita.core.schemas import parse_source_transcript_json, parse_transcript_json, transcript_to_json SERIATIM_TRANSCRIPT = """ { "metadata": { "application": "seriatim", "version": "dev", "input_reader": "json-files", "input_files": ["eric.json", "mike.json"], "preprocessing_modules": ["validate-raw", "normalize-speakers", "trim-text"], "postprocessing_modules": ["detect-overlaps", "resolve-overlaps", "backchannel"], "output_modules": ["json"] }, "segments": [ { "id": 1, "source": "eric.json", "source_segment_index": 0, "speaker": "Eric Rakestraw", "start": 1.25, "end": 3.5, "text": "Hello there.", "overlap_group_id": 1 }, { "id": 2, "source": "eric.json", "source_ref": "word-run:1:1:1", "derived_from": ["eric.json#0"], "speaker": "Eric Rakestraw", "start": 4.0, "end": 4.5, "text": "Resolved word run", "categories": ["backchannel"] } ], "overlap_groups": [ { "id": 1, "start": 1.25, "end": 4.0, "segments": ["eric.json#0", "mike.json#0"], "speakers": ["Eric Rakestraw", "Mike Brown"], "class": "unknown", "resolution": "unresolved" } ] } """ def test_parse_source_transcript_json_accepts_seriatim_transcript_object(): segments = parse_source_transcript_json(SERIATIM_TRANSCRIPT) assert len(segments) == 2 assert segments[0].id == 1 assert segments[0].speaker == "Eric Rakestraw" assert segments[0].start == 1.25 assert segments[0].end == 3.5 assert segments[0].text == "Hello there." assert segments[1].text == "Resolved word run" assert segments[0].categories is None assert segments[1].categories == ["backchannel"] def test_parse_transcript_json_accepts_seriatim_transcript_object_and_ignores_unused_fields(): segments = parse_transcript_json(SERIATIM_TRANSCRIPT) assert [segment.id for segment in segments] == [1, 2] assert [segment.text for segment in segments] == ["Hello there.", "Resolved word run"] assert segments[0].categories is None assert segments[1].categories == ["backchannel"] def test_transcript_to_json_emits_categories_only_when_present(): segments = parse_transcript_json(SERIATIM_TRANSCRIPT) payload = json.loads(transcript_to_json(segments)) assert "categories" not in payload[0] assert payload[1]["categories"] == ["backchannel"]