diff --git a/src/a2a/client/transports/rest.py b/src/a2a/client/transports/rest.py index 54caca2b4..82a72f650 100644 --- a/src/a2a/client/transports/rest.py +++ b/src/a2a/client/transports/rest.py @@ -14,6 +14,7 @@ from a2a.client.transports.base import ClientTransport from a2a.client.transports.http_helpers import ( get_http_args, + handle_http_exceptions, send_http_request, send_http_stream_request, ) @@ -299,14 +300,24 @@ async def delete_task_push_notification_config( if 'tenant' in params: del params['tenant'] - await self._execute_request( - 'DELETE', + path = self._get_path( f'/tasks/{_quote_id(request.task_id)}' f'/pushNotificationConfigs/{_quote_id(request.id)}', request.tenant, - context=context, + ) + http_request = self.httpx_client.build_request( + 'DELETE', + f'{self.url}{path}', params=params, + **get_http_args(context), ) + if self.httpx_client.is_closed: + raise A2AClientError('HTTP client is closed') + # The body is not read: servers confirm the deletion with `{}`, + # with 204 No Content, or with a 200 that has no body. + with handle_http_exceptions(self._handle_http_error): + response = await self.httpx_client.send(http_request) + response.raise_for_status() async def subscribe( self, diff --git a/tests/client/transports/test_rest_client.py b/tests/client/transports/test_rest_client.py index 7189769ba..a75aafc3c 100644 --- a/tests/client/transports/test_rest_client.py +++ b/tests/client/transports/test_rest_client.py @@ -549,6 +549,87 @@ async def test_delete_task_push_notification_config_success( in call_args[0][1] ) + @pytest.mark.asyncio + @pytest.mark.parametrize( + ('status_code', 'content'), + [(200, b'{}'), (204, b''), (200, b'')], + ids=['json_object', 'no_content', 'empty_200'], + ) + async def test_delete_task_push_notification_config_ignores_body( + self, mock_agent_card: MagicMock, status_code: int, content: bytes + ): + """Servers confirm a deletion with `{}`, 204, or a 200 with no body.""" + transport = httpx.MockTransport( + lambda request: httpx.Response(status_code, content=content) + ) + async with httpx.AsyncClient(transport=transport) as http_client: + client = RestTransport( + httpx_client=http_client, + agent_card=mock_agent_card, + url='http://agent.example.com/api', + ) + await client.delete_task_push_notification_config( + DeleteTaskPushNotificationConfigRequest( + task_id='task-1', id='config-1' + ) + ) + + @pytest.mark.asyncio + async def test_delete_task_push_notification_config_maps_errors( + self, mock_agent_card: MagicMock + ): + """An error response still raises the mapped A2A error.""" + body = { + 'error': { + 'code': 404, + 'status': 'NOT_FOUND', + 'message': 'Task task-1 not found', + 'details': [ + { + '@type': 'type.googleapis.com/google.rpc.ErrorInfo', + 'reason': 'TASK_NOT_FOUND', + 'domain': 'a2a-protocol.org', + } + ], + } + } + transport = httpx.MockTransport( + lambda request: httpx.Response(404, json=body) + ) + async with httpx.AsyncClient(transport=transport) as http_client: + client = RestTransport( + httpx_client=http_client, + agent_card=mock_agent_card, + url='http://agent.example.com/api', + ) + with pytest.raises(TaskNotFoundError): + await client.delete_task_push_notification_config( + DeleteTaskPushNotificationConfigRequest( + task_id='task-1', id='config-1' + ) + ) + + @pytest.mark.asyncio + async def test_delete_task_push_notification_config_closed_client( + self, mock_httpx_client: AsyncMock, mock_agent_card: MagicMock + ): + """A closed HTTP client raises before anything is sent.""" + mock_httpx_client.is_closed = True + client = RestTransport( + httpx_client=mock_httpx_client, + agent_card=mock_agent_card, + url='http://agent.example.com/api', + ) + + with pytest.raises(A2AClientError, match='HTTP client is closed'): + await client.delete_task_push_notification_config( + DeleteTaskPushNotificationConfigRequest( + task_id='task-1', id='config-1' + ) + ) + + mock_httpx_client.send.assert_not_called() + class TestRestTransportTenant: """Tests for tenant path prepending in RestTransport."""