async def test_citation_extraction_and_events(self, mock_agent):
        """Test citation extraction and event emission during streaming."""
        # Set up the streaming response with citations
        response_chunks = [
            "Response ",
            "with citation ",
            "[abc123] ",
            "and another ",
            "citation [def456]."
        ]
        mock_agent.llm_provider.setup_stream(response_chunks)

        # Process the streamed response
        messages = [{"role": "user", "content": "Tell me about citations"}]
        result = await mock_agent.process_streamed_response(messages)

        # Verify the full response
        assert result == "Response with citation [abc123] and another citation [def456]."

        # Verify citation events
        citation_events = [e for e in mock_agent.events if e["type"] == "citation"]
        assert len(citation_events) == 2

        # Check first citation event - update values to match actual positions
        assert citation_events[0]["data"]["citation_id"] == "abc123"
        assert citation_events[0]["data"]["start"] == 23  # Corrected position
        assert citation_events[0]["data"]["end"] == 31  # Corrected position

        # Check second citation event - update values to match actual positions
        assert citation_events[1]["data"]["citation_id"] == "def456"
        assert citation_events[1]["data"]["start"] == 53  # Updated to actual position
        assert citation_events[1]["data"]["end"] == 61  # Updated to actual position
Test citation extraction and event emission during streaming.
py/tests/unit/agent/test_streaming_agent.py