Skip to content

Commit d830036

Browse files
fix(compat): list push notification configs in the v0.3 REST client (a2aproject#1424)
# Description `CompatRestTransport.list_task_push_notification_configs` raised `NotImplementedError`, so a client using the HTTP+JSON binding could not list push notification configs on a v0.3 agent. The v0.3 REST binding defines the call as `GET /v1/tasks/{id}/pushNotificationConfigs`. This SDK's own v0.3 compat server (`REST03Adapter`) serves it, and the v0.3 JSON-RPC and gRPC client transports already implement it. This change sends the `GET` request and converts the `ListTaskPushNotificationConfigResponse` with the existing converters, as the v0.3 gRPC transport does. `delete_task_push_notification_config` keeps raising `NotImplementedError`, since the compat REST server does not mount a delete route. The unit test that asserted `NotImplementedError` now checks the request path and the parsed configs. Listing two configs against a server built with `create_rest_routes(..., enable_v0_3_compat=True)` also returns both of them now. - [x] Follow the [`CONTRIBUTING` Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md). - [x] Make your Pull Request title in the <https://www.conventionalcommits.org/> specification. - [x] Ensure the tests and linter pass (Run `bash scripts/format.sh` from the repository root to format) - [x] Appropriate docs were updated (if necessary) Fixes a2aproject#1423 Co-authored-by: mykytanetipa <mykytanetipa@google.com>
1 parent 5e0d415 commit d830036

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

‎src/a2a/compat/v0_3/rest_transport.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,20 @@ async def list_task_push_notification_configs(
260260
context: ClientCallContext | None = None,
261261
) -> ListTaskPushNotificationConfigsResponse:
262262
"""Lists push notification configurations for a specific task."""
263-
raise NotImplementedError(
264-
'list_task_push_notification_configs not supported in v0.3 REST'
263+
response_data = await self._execute_request(
264+
'GET',
265+
f'/v1/tasks/{request.task_id}/pushNotificationConfigs',
266+
context=context,
267+
)
268+
resp_proto = ParseDict(
269+
response_data,
270+
a2a_v0_3_pb2.ListTaskPushNotificationConfigResponse(),
271+
ignore_unknown_fields=True,
272+
)
273+
return conversions.to_core_list_task_push_notification_config_response(
274+
proto_utils.FromProto.list_task_push_notification_config_response(
275+
resp_proto
276+
)
265277
)
266278

267279
async def delete_task_push_notification_config(

‎tests/compat/v0_3/test_rest_transport.py‎

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,43 @@ async def test_compat_rest_transport_list_tasks(transport):
510510
async def test_compat_rest_transport_list_task_push_notification_configs(
511511
transport,
512512
):
513-
with pytest.raises(NotImplementedError):
514-
await transport.list_task_push_notification_configs(
515-
ListTaskPushNotificationConfigsRequest()
516-
)
513+
mock_execute_request = AsyncMock(
514+
return_value={
515+
'configs': [
516+
{
517+
'name': 'tasks/task-123/pushNotificationConfigs/push-1',
518+
'pushNotificationConfig': {
519+
'url': 'http://push-1',
520+
'id': 'push-1',
521+
},
522+
},
523+
{
524+
'name': 'tasks/task-123/pushNotificationConfigs/push-2',
525+
'pushNotificationConfig': {
526+
'url': 'http://push-2',
527+
'id': 'push-2',
528+
},
529+
},
530+
]
531+
}
532+
)
533+
transport._execute_request = mock_execute_request
534+
535+
response = await transport.list_task_push_notification_configs(
536+
ListTaskPushNotificationConfigsRequest(task_id='task-123')
537+
)
538+
539+
mock_execute_request.assert_awaited_once_with(
540+
'GET', '/v1/tasks/task-123/pushNotificationConfigs', context=None
541+
)
542+
assert list(response.configs) == [
543+
TaskPushNotificationConfig(
544+
id='push-1', task_id='task-123', url='http://push-1'
545+
),
546+
TaskPushNotificationConfig(
547+
id='push-2', task_id='task-123', url='http://push-2'
548+
),
549+
]
517550

518551

519552
@pytest.mark.asyncio

0 commit comments

Comments
 (0)