2121from a2a .server .context import ServerCallContext
2222from a2a .server .events import EventQueue , InMemoryQueueManager , QueueManager
2323from a2a .server .request_handlers import DefaultRequestHandler
24- from a2a .server .tasks .task_store import TasksPage
2524from a2a .server .tasks import (
2625 InMemoryPushNotificationConfigStore ,
2726 InMemoryTaskStore ,
3130 TaskStore ,
3231 TaskUpdater ,
3332)
33+ from a2a .server .tasks .task_store import TasksPage
3434from a2a .types import (
35+ Artifact ,
3536 DeleteTaskPushNotificationConfigParams ,
3637 GetTaskPushNotificationConfigParams ,
3738 InternalError ,
3839 InvalidParamsError ,
3940 ListTaskPushNotificationConfigParams ,
4041 ListTasksParams ,
41- ListTasksResult ,
4242 Message ,
4343 MessageSendConfiguration ,
4444 MessageSendParams ,
5656 TextPart ,
5757 UnsupportedOperationError ,
5858)
59- from a2a .utils import (
60- new_task ,
61- )
59+ from a2a .utils import new_agent_text_message , new_task
6260
6361
6462class DummyAgentExecutor (AgentExecutor ):
@@ -155,15 +153,25 @@ async def test_on_list_tasks_success():
155153 mock_page = MagicMock (spec = TasksPage )
156154 mock_page .tasks = [
157155 create_sample_task (task_id = 'task1' ),
158- create_sample_task (task_id = 'task2' ),
156+ create_sample_task (task_id = 'task2' ).model_copy (
157+ update = {
158+ 'artifacts' : [
159+ Artifact (
160+ artifact_id = 'artifact1' ,
161+ parts = [Part (root = TextPart (text = 'Hello world!' ))],
162+ name = 'conversion_result' ,
163+ )
164+ ]
165+ }
166+ ),
159167 ]
160168 mock_page .next_page_token = '123'
161169 mock_page .total_size = 2
162170 mock_task_store .list .return_value = mock_page
163171 request_handler = DefaultRequestHandler (
164172 agent_executor = DummyAgentExecutor (), task_store = mock_task_store
165173 )
166- params = ListTasksParams (page_size = 10 )
174+ params = ListTasksParams (include_artifacts = True , page_size = 10 )
167175 context = create_server_call_context ()
168176
169177 result = await request_handler .on_list_tasks (params , context )
@@ -175,6 +183,68 @@ async def test_on_list_tasks_success():
175183 assert result .page_size == params .page_size
176184
177185
186+ @pytest .mark .asyncio
187+ async def test_on_list_tasks_excludes_artifacts ():
188+ """Test on_list_tasks excludes artifacts from returned tasks."""
189+ mock_task_store = AsyncMock (spec = TaskStore )
190+ mock_page = MagicMock (spec = TasksPage )
191+ mock_page .tasks = [
192+ create_sample_task (task_id = 'task1' ),
193+ create_sample_task (task_id = 'task2' ).model_copy (
194+ update = {
195+ 'artifacts' : [
196+ Artifact (
197+ artifact_id = 'artifact1' ,
198+ parts = [Part (root = TextPart (text = 'Hello world!' ))],
199+ name = 'conversion_result' ,
200+ )
201+ ]
202+ }
203+ ),
204+ ]
205+ mock_page .next_page_token = '123'
206+ mock_page .total_size = 2
207+ mock_task_store .list .return_value = mock_page
208+ request_handler = DefaultRequestHandler (
209+ agent_executor = DummyAgentExecutor (), task_store = mock_task_store
210+ )
211+ params = ListTasksParams (include_artifacts = False , page_size = 10 )
212+ context = create_server_call_context ()
213+
214+ result = await request_handler .on_list_tasks (params , context )
215+
216+ assert result .tasks [1 ].artifacts == None
217+
218+
219+ @pytest .mark .asyncio
220+ async def test_on_list_tasks_applies_history_length ():
221+ """Test on_list_tasks applies history length filter."""
222+ mock_task_store = AsyncMock (spec = TaskStore )
223+ mock_page = MagicMock (spec = TasksPage )
224+ history = [
225+ new_agent_text_message ('Hello 1!' ),
226+ new_agent_text_message ('Hello 2!' ),
227+ ]
228+ mock_page .tasks = [
229+ create_sample_task (task_id = 'task1' ),
230+ create_sample_task (task_id = 'task2' ).model_copy (
231+ update = {'history' : history }
232+ ),
233+ ]
234+ mock_page .next_page_token = '123'
235+ mock_page .total_size = 2
236+ mock_task_store .list .return_value = mock_page
237+ request_handler = DefaultRequestHandler (
238+ agent_executor = DummyAgentExecutor (), task_store = mock_task_store
239+ )
240+ params = ListTasksParams (history_length = 1 , page_size = 10 )
241+ context = create_server_call_context ()
242+
243+ result = await request_handler .on_list_tasks (params , context )
244+
245+ assert result .tasks [1 ].history == [history [1 ]]
246+
247+
178248@pytest .mark .asyncio
179249async def test_on_cancel_task_task_not_found ():
180250 """Test on_cancel_task when the task is not found."""
0 commit comments