@@ -2004,3 +2004,48 @@ def test_capture_files_closed_on_finish(self):
20042004
20052005 assert socket ._raw_file .closed
20062006 assert socket ._gated_file .closed
2007+
2008+
2009+ class TestProcessAudioDgRemapWiring :
2010+ """Tests for the remap callback wiring in process_audio_dg (streaming.py)."""
2011+
2012+ def test_remap_callback_wraps_stream_transcript (self ):
2013+ """When vad_gate is provided, stream_transcript should receive remapped segments."""
2014+ gate = VADStreamingGate (sample_rate = 16000 , channels = 1 , mode = 'active' , uid = 'test' , session_id = 'test' )
2015+ # Build mapper state: 5s of audio sent, then silence gap, then 3s at wall=15s
2016+ gate .dg_wall_mapper .on_audio_sent (5.0 , 0.0 )
2017+ gate .dg_wall_mapper .on_silence_skipped ()
2018+ gate .dg_wall_mapper .on_audio_sent (3.0 , 15.0 )
2019+
2020+ received_segments = []
2021+ original_transcript = lambda segs : received_segments .extend (segs )
2022+
2023+ # Simulate the wiring from process_audio_dg lines 330-335
2024+ _original = original_transcript
2025+
2026+ def wrapped_transcript (segments ):
2027+ gate .remap_segments (segments )
2028+ _original (segments )
2029+
2030+ segments = [{'start' : 6.0 , 'end' : 7.0 , 'text' : 'hello' , 'speaker' : 'SPEAKER_0' }]
2031+ wrapped_transcript (segments )
2032+
2033+ # After remap: dg=6.0 is in second checkpoint range (dg=5.0 -> wall=15.0)
2034+ # So wall = 15.0 + (6.0 - 5.0) = 16.0
2035+ assert len (received_segments ) == 1
2036+ assert abs (received_segments [0 ]['start' ] - 16.0 ) < 0.01
2037+ assert abs (received_segments [0 ]['end' ] - 17.0 ) < 0.01
2038+ assert received_segments [0 ]['text' ] == 'hello'
2039+
2040+ def test_no_remap_when_gate_is_none (self ):
2041+ """Without vad_gate, stream_transcript should receive unmodified segments."""
2042+ received_segments = []
2043+ original_transcript = lambda segs : received_segments .extend (segs )
2044+
2045+ # No gate — call directly (no wrapping)
2046+ segments = [{'start' : 6.0 , 'end' : 7.0 , 'text' : 'hello' , 'speaker' : 'SPEAKER_0' }]
2047+ original_transcript (segments )
2048+
2049+ assert len (received_segments ) == 1
2050+ assert received_segments [0 ]['start' ] == 6.0
2051+ assert received_segments [0 ]['end' ] == 7.0
0 commit comments