@@ -134,13 +134,13 @@ async def test_on_get_task_not_found():
134134 params = TaskQueryParams (id = 'non_existent_task' )
135135
136136 from a2a .utils .errors import ServerError # Local import for ServerError
137-
137+ context = create_server_call_context ()
138138 with pytest .raises (ServerError ) as exc_info :
139- await request_handler .on_get_task (params , create_server_call_context () )
139+ await request_handler .on_get_task (params , context )
140140
141141 assert isinstance (exc_info .value .error , TaskNotFoundError )
142142 mock_task_store .get .assert_awaited_once_with (
143- 'non_existent_task' , create_server_call_context ()
143+ 'non_existent_task' , context
144144 )
145145
146146
@@ -156,16 +156,16 @@ async def test_on_cancel_task_task_not_found():
156156 params = TaskIdParams (id = 'task_not_found_for_cancel' )
157157
158158 from a2a .utils .errors import ServerError # Local import
159-
159+ context = create_server_call_context ()
160160 with pytest .raises (ServerError ) as exc_info :
161161 await request_handler .on_cancel_task (
162- params , create_server_call_context ()
162+ params , context
163163 )
164164
165165 assert isinstance (exc_info .value .error , TaskNotFoundError )
166166 mock_task_store .get .assert_awaited_once_with (
167167 'task_not_found_for_cancel' ,
168- create_server_call_context ()
168+ context
169169 )
170170
171171
@@ -200,18 +200,18 @@ async def test_on_cancel_task_queue_tap_returns_none():
200200 queue_manager = mock_queue_manager ,
201201 )
202202
203+ context = create_server_call_context ()
203204 with patch (
204205 'a2a.server.request_handlers.default_request_handler.ResultAggregator' ,
205206 return_value = mock_result_aggregator_instance ,
206207 ):
207208 params = TaskIdParams (id = 'tap_none_task' )
208209 result_task = await request_handler .on_cancel_task (
209- params , create_server_call_context ()
210+ params , context
210211 )
211212
212213 mock_task_store .get .assert_awaited_once_with (
213- 'tap_none_task' ,
214- create_server_call_context ()
214+ 'tap_none_task' , context
215215 )
216216 mock_queue_manager .tap .assert_awaited_once_with ('tap_none_task' )
217217 # agent_executor.cancel should be called with a new EventQueue if tap returned None
@@ -258,13 +258,14 @@ async def test_on_cancel_task_cancels_running_agent():
258258 mock_producer_task = AsyncMock (spec = asyncio .Task )
259259 request_handler ._running_agents [task_id ] = mock_producer_task
260260
261+ context = create_server_call_context ()
261262 with patch (
262263 'a2a.server.request_handlers.default_request_handler.ResultAggregator' ,
263264 return_value = mock_result_aggregator_instance ,
264265 ):
265266 params = TaskIdParams (id = task_id )
266267 await request_handler .on_cancel_task (
267- params , create_server_call_context ()
268+ params , context
268269 )
269270
270271 mock_producer_task .cancel .assert_called_once ()
@@ -1279,16 +1280,15 @@ async def test_set_task_push_notification_config_task_not_found():
12791280 ),
12801281 )
12811282 from a2a .utils .errors import ServerError # Local import
1282-
1283+ context = create_server_call_context ()
12831284 with pytest .raises (ServerError ) as exc_info :
12841285 await request_handler .on_set_task_push_notification_config (
1285- params , create_server_call_context ()
1286+ params , context
12861287 )
12871288
12881289 assert isinstance (exc_info .value .error , TaskNotFoundError )
12891290 mock_task_store .get .assert_awaited_once_with (
1290- 'non_existent_task' ,
1291- create_server_call_context ()
1291+ 'non_existent_task' , context
12921292 )
12931293 mock_push_store .set_info .assert_not_awaited ()
12941294
@@ -1326,15 +1326,15 @@ async def test_get_task_push_notification_config_task_not_found():
13261326 params = GetTaskPushNotificationConfigParams (id = 'non_existent_task' )
13271327 from a2a .utils .errors import ServerError # Local import
13281328
1329+ context = create_server_call_context ()
13291330 with pytest .raises (ServerError ) as exc_info :
13301331 await request_handler .on_get_task_push_notification_config (
1331- params , create_server_call_context ()
1332+ params , context
13321333 )
13331334
13341335 assert isinstance (exc_info .value .error , TaskNotFoundError )
13351336 mock_task_store .get .assert_awaited_once_with (
1336- 'non_existent_task' ,
1337- create_server_call_context ()
1337+ 'non_existent_task' , context
13381338 )
13391339 mock_push_store .get_info .assert_not_awaited ()
13401340
@@ -1357,18 +1357,17 @@ async def test_get_task_push_notification_config_info_not_found():
13571357 )
13581358 params = GetTaskPushNotificationConfigParams (id = 'non_existent_task' )
13591359 from a2a .utils .errors import ServerError # Local import
1360-
1360+ context = create_server_call_context ()
13611361 with pytest .raises (ServerError ) as exc_info :
13621362 await request_handler .on_get_task_push_notification_config (
1363- params , create_server_call_context ()
1363+ params , context
13641364 )
13651365
13661366 assert isinstance (
13671367 exc_info .value .error , InternalError
13681368 ) # Current code raises InternalError
13691369 mock_task_store .get .assert_awaited_once_with (
1370- 'non_existent_task' ,
1371- create_server_call_context ()
1370+ 'non_existent_task' , context
13721371 )
13731372 mock_push_store .get_info .assert_awaited_once_with ('non_existent_task' )
13741373
@@ -1392,8 +1391,9 @@ async def test_get_task_push_notification_config_info_with_config():
13921391 id = 'config_id' , url = 'http://1.example.com'
13931392 ),
13941393 )
1394+ context = create_server_call_context ()
13951395 await request_handler .on_set_task_push_notification_config (
1396- set_config_params , create_server_call_context ()
1396+ set_config_params , context
13971397 )
13981398
13991399 params = GetTaskPushNotificationConfigParams (
@@ -1402,7 +1402,7 @@ async def test_get_task_push_notification_config_info_with_config():
14021402
14031403 result : TaskPushNotificationConfig = (
14041404 await request_handler .on_get_task_push_notification_config (
1405- params , create_server_call_context ()
1405+ params , context
14061406 )
14071407 )
14081408
@@ -1467,18 +1467,17 @@ async def test_on_resubscribe_to_task_task_not_found():
14671467 params = TaskIdParams (id = 'resub_task_not_found' )
14681468
14691469 from a2a .utils .errors import ServerError # Local import
1470-
1470+ context = create_server_call_context ()
14711471 with pytest .raises (ServerError ) as exc_info :
14721472 # Need to consume the async generator to trigger the error
14731473 async for _ in request_handler .on_resubscribe_to_task (
1474- params , create_server_call_context ()
1474+ params , context
14751475 ):
14761476 pass
14771477
14781478 assert isinstance (exc_info .value .error , TaskNotFoundError )
14791479 mock_task_store .get .assert_awaited_once_with (
1480- 'resub_task_not_found' ,
1481- create_server_call_context ()
1480+ 'resub_task_not_found' , context
14821481 )
14831482
14841483
@@ -1501,18 +1500,18 @@ async def test_on_resubscribe_to_task_queue_not_found():
15011500
15021501 from a2a .utils .errors import ServerError # Local import
15031502
1503+ context = create_server_call_context ()
15041504 with pytest .raises (ServerError ) as exc_info :
15051505 async for _ in request_handler .on_resubscribe_to_task (
1506- params , create_server_call_context ()
1506+ params , context
15071507 ):
15081508 pass
15091509
15101510 assert isinstance (
15111511 exc_info .value .error , TaskNotFoundError
15121512 ) # Should be TaskNotFoundError as per spec
15131513 mock_task_store .get .assert_awaited_once_with (
1514- 'resub_queue_not_found' ,
1515- create_server_call_context ()
1514+ 'resub_queue_not_found' , context
15161515 )
15171516 mock_queue_manager .tap .assert_awaited_once_with ('resub_queue_not_found' )
15181517
@@ -1586,16 +1585,15 @@ async def test_list_task_push_notification_config_task_not_found():
15861585 )
15871586 params = ListTaskPushNotificationConfigParams (id = 'non_existent_task' )
15881587 from a2a .utils .errors import ServerError # Local import
1589-
1588+ context = create_server_call_context ()
15901589 with pytest .raises (ServerError ) as exc_info :
15911590 await request_handler .on_list_task_push_notification_config (
1592- params , create_server_call_context ()
1591+ params , context
15931592 )
15941593
15951594 assert isinstance (exc_info .value .error , TaskNotFoundError )
15961595 mock_task_store .get .assert_awaited_once_with (
1597- 'non_existent_task' ,
1598- create_server_call_context ()
1596+ 'non_existent_task' , context
15991597 )
16001598 mock_push_store .get_info .assert_not_awaited ()
16011599
@@ -1749,16 +1747,15 @@ async def test_delete_task_push_notification_config_task_not_found():
17491747 id = 'non_existent_task' , push_notification_config_id = 'config1'
17501748 )
17511749 from a2a .utils .errors import ServerError # Local import
1752-
1750+ context = create_server_call_context ()
17531751 with pytest .raises (ServerError ) as exc_info :
17541752 await request_handler .on_delete_task_push_notification_config (
1755- params , create_server_call_context ()
1753+ params , context
17561754 )
17571755
17581756 assert isinstance (exc_info .value .error , TaskNotFoundError )
17591757 mock_task_store .get .assert_awaited_once_with (
1760- 'non_existent_task' ,
1761- create_server_call_context ()
1758+ 'non_existent_task' , context
17621759 )
17631760 mock_push_store .get_info .assert_not_awaited ()
17641761
@@ -2003,10 +2000,10 @@ async def test_on_resubscribe_to_task_in_terminal_state(terminal_state):
20032000 params = TaskIdParams (id = task_id )
20042001
20052002 from a2a .utils .errors import ServerError
2006-
2003+ context = create_server_call_context ()
20072004 with pytest .raises (ServerError ) as exc_info :
20082005 async for _ in request_handler .on_resubscribe_to_task (
2009- params , create_server_call_context ()
2006+ params , context
20102007 ):
20112008 pass # pragma: no cover
20122009
@@ -2017,7 +2014,7 @@ async def test_on_resubscribe_to_task_in_terminal_state(terminal_state):
20172014 in exc_info .value .error .message
20182015 )
20192016 mock_task_store .get .assert_awaited_once_with (
2020- task_id , create_server_call_context ()
2017+ task_id , context
20212018 )
20222019
20232020
0 commit comments