async def test_text_fragments_with_spaces(self):
        """Test aggregating text fragments with various spacing patterns"""
        processor = AssistantTranscriptProcessor()

        # Track received updates
        received_updates = []

        @processor.event_handler("on_transcript_update")
        async def handle_update(proc, frame: TranscriptionUpdateFrame):
            received_updates.append(frame)

        # Test the specific pattern shared
        frames_to_send = [
            BotStartedSpeakingFrame(),
            SleepFrame(sleep=0.1),
            TTSTextFrame(text="Hello"),
            TTSTextFrame(text=" there"),
            TTSTextFrame(text="!"),
            TTSTextFrame(text=" How"),
            TTSTextFrame(text="'s"),
            TTSTextFrame(text=" it"),
            TTSTextFrame(text=" going"),
            TTSTextFrame(text="?"),
            BotStoppedSpeakingFrame(),
        ]

        expected_down_frames = [
            BotStartedSpeakingFrame,
            BotStoppedSpeakingFrame,
            TTSTextFrame,
            TTSTextFrame,
            TTSTextFrame,
            TTSTextFrame,
            TTSTextFrame,
            TTSTextFrame,
            TTSTextFrame,
            TTSTextFrame,
            TranscriptionUpdateFrame,
        ]

        # Run test
        received_frames, _ = await run_test(
            processor,
            frames_to_send=frames_to_send,
            expected_down_frames=expected_down_frames,
        )

        # Verify result
        self.assertEqual(len(received_updates), 1)
        message = received_updates[0].messages[0]
        self.assertEqual(message.role, "assistant")
        # Should be properly joined without extra spaces
        self.assertEqual(message.content, "Hello there! How's it going?")
Test aggregating text fragments with various spacing patterns
tests/test_transcript_processor.py