@@ -226,6 +226,97 @@ async def test_delete_conversation_async_returns_none():
226226 assert await _make_agent ().delete_conversation_async ("c" ) is None
227227
228228
229+ # ─── list_conversations_async ──────────────────────────────
230+
231+
232+ async def test_list_conversations_async_default_filters_by_agent_name ():
233+ """不传 metadata 时, 默认按 ``{"agentRuntimeName": self.name}`` 过滤."""
234+ instance = MagicMock ()
235+ instance .list_conversations_async = AsyncMock (return_value = [])
236+ factory = MagicMock (return_value = instance )
237+ with patch ("agentrun.super_agent.agent.SuperAgentDataAPI" , factory ):
238+ agent = SuperAgent (name = "my-agent" )
239+ result = await agent .list_conversations_async ()
240+ assert result == []
241+ assert instance .list_conversations_async .await_args .kwargs ["metadata" ] == {
242+ "agentRuntimeName" : "my-agent"
243+ }
244+
245+
246+ async def test_list_conversations_async_explicit_metadata_passthrough ():
247+ instance = MagicMock ()
248+ instance .list_conversations_async = AsyncMock (return_value = [])
249+ factory = MagicMock (return_value = instance )
250+ with patch ("agentrun.super_agent.agent.SuperAgentDataAPI" , factory ):
251+ agent = _make_agent ()
252+ await agent .list_conversations_async (metadata = {"foo" : "bar" })
253+ assert instance .list_conversations_async .await_args .kwargs ["metadata" ] == {
254+ "foo" : "bar"
255+ }
256+
257+
258+ async def test_list_conversations_async_empty_metadata_overrides_default ():
259+ """传入空 dict 明确表示「不按 agent 过滤」, SDK MUST 不再注入默认值."""
260+ instance = MagicMock ()
261+ instance .list_conversations_async = AsyncMock (return_value = [])
262+ factory = MagicMock (return_value = instance )
263+ with patch ("agentrun.super_agent.agent.SuperAgentDataAPI" , factory ):
264+ agent = _make_agent ()
265+ await agent .list_conversations_async (metadata = {})
266+ assert instance .list_conversations_async .await_args .kwargs ["metadata" ] == {}
267+
268+
269+ async def test_list_conversations_async_returns_conversation_info_list ():
270+ instance = MagicMock ()
271+ instance .list_conversations_async = AsyncMock (
272+ return_value = [
273+ {
274+ "conversationId" : "c1" ,
275+ "agentId" : "ag" ,
276+ "title" : "first" ,
277+ "createdAt" : 1 ,
278+ "updatedAt" : 2 ,
279+ "messages" : [{"role" : "user" , "content" : "hi" }],
280+ },
281+ {
282+ "conversationId" : "c2" ,
283+ "agentId" : "ag" ,
284+ "title" : "second" ,
285+ "messages" : [],
286+ },
287+ ]
288+ )
289+ factory = MagicMock (return_value = instance )
290+ with patch ("agentrun.super_agent.agent.SuperAgentDataAPI" , factory ):
291+ result = await _make_agent ().list_conversations_async ()
292+ assert [c .conversation_id for c in result ] == ["c1" , "c2" ]
293+ assert result [0 ].title == "first"
294+ assert len (result [0 ].messages ) == 1
295+ assert result [0 ].messages [0 ].content == "hi"
296+ assert result [1 ].title == "second"
297+
298+
299+ async def test_list_conversations_async_empty_list ():
300+ instance = MagicMock ()
301+ instance .list_conversations_async = AsyncMock (return_value = [])
302+ factory = MagicMock (return_value = instance )
303+ with patch ("agentrun.super_agent.agent.SuperAgentDataAPI" , factory ):
304+ assert await _make_agent ().list_conversations_async () == []
305+
306+
307+ async def test_list_conversations_async_item_missing_conversation_id_uses_empty_fallback ():
308+ """对单条会话里 ``conversationId`` 缺失的情况, fallback 保持空串 (不会用 agent name)."""
309+ instance = MagicMock ()
310+ instance .list_conversations_async = AsyncMock (
311+ return_value = [{"agentId" : "ag" }]
312+ )
313+ factory = MagicMock (return_value = instance )
314+ with patch ("agentrun.super_agent.agent.SuperAgentDataAPI" , factory ):
315+ result = await _make_agent ().list_conversations_async ()
316+ assert len (result ) == 1
317+ assert result [0 ].conversation_id == ""
318+
319+
229320# ─── sync methods → NotImplementedError ─────────────────────
230321
231322
@@ -237,6 +328,8 @@ def test_sync_methods_not_implemented():
237328 agent .get_conversation ("c" )
238329 with pytest .raises (NotImplementedError ):
239330 agent .delete_conversation ("c" )
331+ with pytest .raises (NotImplementedError ):
332+ agent .list_conversations ()
240333
241334
242335def test_invoke_async_signature_only_messages_and_conversation_id ():
0 commit comments