Skip to content

Commit 14e799c

Browse files
fix(compat): serve DELETE for v0.3 REST push notification configs (a2aproject#1442)
# Description `REST03Adapter` mounts `GET`/`POST /v1/tasks/{id}/pushNotificationConfigs` and `GET /v1/tasks/{id}/pushNotificationConfigs/{push_id}`, but no `DELETE`. The v0.3 binding defines `DELETE /v1/tasks/{id}/pushNotificationConfigs/{configId}` (spec section 3.5.6, and the `google.api.http` option on `DeleteTaskPushNotificationConfig` in `a2a_v0_3.proto`), and the v0.3 JSON-RPC and gRPC adapters already serve the call. Without the route the request falls through to the v1.0 `/{tenant}` mount with tenant `v1`, so a v0.3 client gets a 400 with reason `VERSION_NOT_SUPPORTED` ("A2A version '0.3' is not supported by this handler. Expected version '1.0'."). To reproduce on main: serve a `DefaultRequestHandler` through `create_rest_routes(..., enable_v0_3_compat=True)`, create a push config over v0.3 REST, then send `DELETE /v1/tasks/{task_id}/pushNotificationConfigs/{config_id}`. It returns 400. The same delete over v0.3 JSON-RPC (`tasks/pushNotificationConfig/delete`) and gRPC (`DeleteTaskPushNotificationConfig`) succeeds. This change adds `REST03Handler.delete_push_notification`, which builds a v0.3 `DeleteTaskPushNotificationConfigRequest` from the path and calls the v1.0 handler through `RequestHandler03`, and mounts it. It returns `{}`, the JSON form of `google.protobuf.Empty`, as the v1.0 REST dispatcher does. `CompatRestTransport.delete_task_push_notification_config` raised `NotImplementedError`, which a2aproject#1424 left in place because the server had no route. It now sends the same `DELETE`, so the v0.3 REST client can delete a config too (added after review). Tests: `test_delete_push_notification` (handler) and `test_delete_push_notification_config_v03` (route) fail on main and pass with this change. After review: `test_compat_rest_transport_delete_task_push_notification_config` now checks the request the client sends instead of expecting `NotImplementedError`, `test_compat_rest_client_deletes_push_notification_config` sends the delete from the client through the real v0.3 REST routes, and `test_delete_push_notification_config_v03_unknown_task_returns_404` covers `TaskNotFoundError`. The client tests fail with the old client code. - `uv run pytest tests/compat/v0_3/ -k "delete_push_notification or deletes_push_notification"`: 8 failed with the three compat source files from main, 8 passed with this change - `uv run pytest --cov=a2a --cov-fail-under=88` after merging current main: 2576 passed, 207 skipped, 4 xfailed, 1 xpassed; coverage 93.57%. In one of three runs `test_scenario_auth_required_side_channel[blocking-legacy]` failed and then passed on rerun; it does not touch this code. - `tests/integration/cross_version/client_server/test_client_server.py` (against `a2a-sdk` 0.3.24): 4 passed - `uv run ruff check` and `uv run ruff format --check`: clean; `uv run ty check`: no errors (3 warnings, all in files this PR does not touch) Worth checking: v0.3 routes are registered before the `/{tenant}` mount, so a v1.0 tenant literally named `v1` deleting at this path now reaches the v0.3 handler. That is already true for the existing v0.3 GET on the same path. Deleting an unknown config id returns 200 `{}`, as it does on the other transports. - [x] Follow the CONTRIBUTING Guide. - [x] Make your Pull Request title in the conventionalcommits.org specification. - [x] Ensure the tests and linter pass - [ ] Appropriate docs were updated (if necessary) Fixes a2aproject#1441 --------- Co-authored-by: YusefSyed <211442445+YusefSyed@users.noreply.github.com> Co-authored-by: Mateusz Iwaniuk <45974414+Iwaniukooo11@users.noreply.github.com>
1 parent 2ccef0d commit 14e799c

6 files changed

Lines changed: 139 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ def routes(self) -> dict[tuple[str, str], Callable[[Request], Any]]:
148148
): functools.partial(
149149
self._handle_request, self.handler.get_push_notification
150150
),
151+
(
152+
'/v1/tasks/{id}/pushNotificationConfigs/{push_id}',
153+
'DELETE',
154+
): functools.partial(
155+
self._handle_request, self.handler.delete_push_notification
156+
),
151157
(
152158
'/v1/tasks/{id}/pushNotificationConfigs',
153159
'POST',

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,36 @@ async def get_push_notification(
194194
)
195195
return MessageToDict(pb2_v03_config)
196196

197+
@validate_version(constants.PROTOCOL_VERSION_0_3)
198+
async def delete_push_notification(
199+
self,
200+
request: Request,
201+
context: ServerCallContext,
202+
) -> dict[str, Any]:
203+
"""Handles the 'tasks/pushNotificationConfig/delete' REST method.
204+
205+
Args:
206+
request: The incoming `Request` object.
207+
context: Context provided by the server.
208+
209+
Returns:
210+
An empty `dict`, the JSON form of `google.protobuf.Empty`.
211+
"""
212+
task_id = request.path_params['id']
213+
push_id = request.path_params['push_id']
214+
215+
rpc_req = types_v03.DeleteTaskPushNotificationConfigRequest(
216+
id='',
217+
params=types_v03.DeleteTaskPushNotificationConfigParams(
218+
id=task_id, push_notification_config_id=push_id
219+
),
220+
)
221+
222+
await self.handler03.on_delete_task_push_notification_config(
223+
rpc_req, context
224+
)
225+
return {}
226+
197227
@validate_version(constants.PROTOCOL_VERSION_0_3)
198228
async def set_push_notification(
199229
self,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@ async def delete_task_push_notification_config(
285285
context: ClientCallContext | None = None,
286286
) -> None:
287287
"""Deletes the push notification configuration for a specific task."""
288-
raise NotImplementedError(
289-
'delete_task_push_notification_config not supported in v0.3 REST'
288+
await self._execute_request(
289+
'DELETE',
290+
f'/v1/tasks/{request.task_id}/pushNotificationConfigs/{request.id}',
291+
context=context,
290292
)
291293

292294
async def subscribe(

‎tests/compat/v0_3/test_rest_handler.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,26 @@ async def test_list_push_notifications(
371371
assert called_req.params.id == 'task-1'
372372

373373

374+
@pytest.mark.anyio
375+
async def test_delete_push_notification(
376+
rest_handler, mock_request, mock_context
377+
):
378+
mock_request.path_params = {'id': 'task-1', 'push_id': 'push-1'}
379+
rest_handler.handler03.on_delete_task_push_notification_config.return_value = None
380+
381+
result = await rest_handler.delete_push_notification(
382+
mock_request, mock_context
383+
)
384+
385+
assert result == {}
386+
rest_handler.handler03.on_delete_task_push_notification_config.assert_called_once()
387+
called_req = rest_handler.handler03.on_delete_task_push_notification_config.call_args[
388+
0
389+
][0]
390+
assert called_req.params.id == 'task-1'
391+
assert called_req.params.push_notification_config_id == 'push-1'
392+
393+
374394
# Add our new translation method test
375395
@pytest.mark.anyio
376396
async def test_on_get_extended_agent_card_success(

‎tests/compat/v0_3/test_rest_routes_compat.py‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
from a2a.compat.v0_3 import a2a_v0_3_pb2, rest_adapter
1010
from a2a.compat.v0_3.rest_adapter import REST03Adapter
11+
from a2a.compat.v0_3.rest_transport import CompatRestTransport
1112
from a2a.server.request_handlers.request_handler import RequestHandler
1213
from a2a.server.routes import create_agent_card_routes
1314
from a2a.server.routes.rest_routes import create_rest_routes
1415
from a2a.types.a2a_pb2 import (
1516
AgentCard,
17+
DeleteTaskPushNotificationConfigRequest,
1618
Message as Message10,
1719
Part as Part10,
1820
Role as Role10,
@@ -228,6 +230,69 @@ async def test_invalid_utf8_body_v03_is_bad_request(
228230
assert response.json()['error']['status'] == 'INVALID_ARGUMENT'
229231

230232

233+
@pytest.mark.anyio
234+
async def test_delete_push_notification_config_v03(
235+
client: AsyncClient, request_handler: MagicMock
236+
) -> None:
237+
request_handler.on_delete_task_push_notification_config.return_value = None
238+
239+
response = await client.delete(
240+
'/v1/tasks/test_task_id/pushNotificationConfigs/push-1'
241+
)
242+
243+
assert response.status_code == 200
244+
assert response.json() == {}
245+
request_handler.on_delete_task_push_notification_config.assert_awaited_once()
246+
params = request_handler.on_delete_task_push_notification_config.call_args[
247+
0
248+
][0]
249+
assert params == DeleteTaskPushNotificationConfigRequest(
250+
task_id='test_task_id', id='push-1'
251+
)
252+
253+
254+
@pytest.mark.anyio
255+
async def test_delete_push_notification_config_v03_unknown_task_returns_404(
256+
client: AsyncClient, request_handler: MagicMock
257+
) -> None:
258+
request_handler.on_delete_task_push_notification_config.side_effect = (
259+
TaskNotFoundError
260+
)
261+
262+
response = await client.delete(
263+
'/v1/tasks/unknown/pushNotificationConfigs/push-1'
264+
)
265+
266+
assert response.status_code == 404
267+
assert response.json()['error']['status'] == 'NOT_FOUND'
268+
269+
270+
@pytest.mark.anyio
271+
async def test_compat_rest_client_deletes_push_notification_config(
272+
client: AsyncClient, request_handler: MagicMock
273+
) -> None:
274+
request_handler.on_delete_task_push_notification_config.return_value = None
275+
transport = CompatRestTransport(
276+
httpx_client=client,
277+
agent_card=AgentCard(),
278+
url='http://testapp',
279+
)
280+
281+
await transport.delete_task_push_notification_config(
282+
DeleteTaskPushNotificationConfigRequest(
283+
task_id='test_task_id', id='push-1'
284+
)
285+
)
286+
287+
request_handler.on_delete_task_push_notification_config.assert_awaited_once()
288+
params = request_handler.on_delete_task_push_notification_config.call_args[
289+
0
290+
][0]
291+
assert params == DeleteTaskPushNotificationConfigRequest(
292+
task_id='test_task_id', id='push-1'
293+
)
294+
295+
231296
@pytest.mark.anyio
232297
async def test_list_tasks_not_in_v03_adapter_routes(
233298
request_handler: RequestHandler,

‎tests/compat/v0_3/test_rest_transport.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,21 @@ async def test_compat_rest_transport_list_task_push_notification_configs(
605605
async def test_compat_rest_transport_delete_task_push_notification_config(
606606
transport,
607607
):
608-
with pytest.raises(NotImplementedError):
609-
await transport.delete_task_push_notification_config(
610-
DeleteTaskPushNotificationConfigRequest()
608+
mock_execute_request = AsyncMock(return_value={})
609+
transport._execute_request = mock_execute_request
610+
611+
response = await transport.delete_task_push_notification_config(
612+
DeleteTaskPushNotificationConfigRequest(
613+
task_id='task-123', id='push-123'
611614
)
615+
)
616+
617+
mock_execute_request.assert_awaited_once_with(
618+
'DELETE',
619+
'/v1/tasks/task-123/pushNotificationConfigs/push-123',
620+
context=None,
621+
)
622+
assert response is None
612623

613624

614625
@pytest.mark.asyncio

0 commit comments

Comments
 (0)