mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 05:37:20 +08:00
fix(backend): unable to export conversation (#12577)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -1295,7 +1295,7 @@ class LiveStatusAppConversationService(AppConversationServiceBase):
|
||||
# Get all events for this conversation
|
||||
i = 0
|
||||
async for event in page_iterator(
|
||||
self.event_service.search_events, conversation_id__eq=conversation_id
|
||||
self.event_service.search_events, conversation_id=conversation_id
|
||||
):
|
||||
event_filename = f'event_{i:06d}_{event.id}.json'
|
||||
event_path = os.path.join(temp_dir, event_filename)
|
||||
|
||||
@@ -1165,6 +1165,50 @@ class TestLiveStatusAppConversationService:
|
||||
)
|
||||
self.mock_event_service.search_events.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_export_conversation_calls_search_events_with_correct_parameter_name(
|
||||
self,
|
||||
):
|
||||
"""Test that export_conversation calls search_events with 'conversation_id' parameter, not 'conversation_id__eq'.
|
||||
|
||||
This test verifies the fix for a bug where page_iterator was called with
|
||||
conversation_id__eq instead of conversation_id, causing a TypeError since
|
||||
the search_events method expects conversation_id as its parameter name.
|
||||
"""
|
||||
# Arrange
|
||||
conversation_id = uuid4()
|
||||
|
||||
# Mock conversation info
|
||||
mock_conversation_info = Mock(spec=AppConversationInfo)
|
||||
mock_conversation_info.id = conversation_id
|
||||
mock_conversation_info.model_dump_json = Mock(return_value='{}')
|
||||
|
||||
self.mock_app_conversation_info_service.get_app_conversation_info = AsyncMock(
|
||||
return_value=mock_conversation_info
|
||||
)
|
||||
|
||||
# Mock empty event page to simplify test
|
||||
mock_event_page = Mock()
|
||||
mock_event_page.items = []
|
||||
mock_event_page.next_page_id = None
|
||||
|
||||
self.mock_event_service.search_events = AsyncMock(return_value=mock_event_page)
|
||||
|
||||
# Act
|
||||
await self.service.export_conversation(conversation_id)
|
||||
|
||||
# Assert - Verify search_events was called with 'conversation_id', not 'conversation_id__eq'
|
||||
self.mock_event_service.search_events.assert_called()
|
||||
call_kwargs = self.mock_event_service.search_events.call_args[1]
|
||||
|
||||
assert 'conversation_id' in call_kwargs, (
|
||||
"search_events should be called with 'conversation_id' parameter"
|
||||
)
|
||||
assert 'conversation_id__eq' not in call_kwargs, (
|
||||
"search_events should NOT be called with 'conversation_id__eq' parameter"
|
||||
)
|
||||
assert call_kwargs['conversation_id'] == conversation_id
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_export_conversation_large_pagination(self):
|
||||
"""Test download with multiple pages of events."""
|
||||
|
||||
Reference in New Issue
Block a user