async def test_auto_generate_title_with_llm():
    """Test auto-generating a title using LLM."""
    # Mock dependencies
    file_store = InMemoryFileStore()

    # Create test conversation with a user message
    conversation_id = 'test-conversation'
    user_id = 'test-user'

    # Create a mock event
    user_message = MessageAction(
        content='Help me write a Python script to analyze data'
    )
    user_message._source = EventSource.USER
    user_message._id = 1
    user_message._timestamp = datetime.now(timezone.utc).isoformat()

    # Mock the EventStream class
    with patch(
        'openhands.utils.conversation_summary.EventStream'
    ) as mock_event_stream_cls:
        # Configure the mock event stream to return our test message
        mock_event_stream = MagicMock(spec=EventStream)
        mock_event_stream.get_events.return_value = [user_message]
        mock_event_stream_cls.return_value = mock_event_stream

        # Mock the LLM response
        with patch('openhands.utils.conversation_summary.LLM') as mock_llm_cls:
            mock_llm = mock_llm_cls.return_value
            mock_response = MagicMock()
            mock_response.choices = [MagicMock()]
            mock_response.choices[0].message.content = 'Python Data Analysis Script'
            mock_llm.completion.return_value = mock_response

            # Create test settings with LLM config
            settings = Settings(
                llm_model='test-model',
                llm_api_key='test-key',
                llm_base_url='test-url',
            )

            # Call the auto_generate_title function directly
            title = await auto_generate_title(
                conversation_id, user_id, file_store, settings
            )

            # Verify the result
            assert title == 'Python Data Analysis Script'

            # Verify EventStream was created with the correct parameters
            mock_event_stream_cls.assert_called_once_with(
                conversation_id, file_store, user_id
            )

            # Verify LLM was called with appropriate parameters
            mock_llm_cls.assert_called_once_with(
                LLMConfig(
                    model='test-model',
                    api_key='test-key',
                    base_url='test-url',
                )
            )
            mock_llm.completion.assert_called_once()
Test auto-generating a title using LLM.
tests/unit/test_auto_generate_title.py