Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/a2a/client/transports/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@
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,
)
from a2a.types.a2a_pb2 import (
AgentCard,
CancelTaskRequest,
DeleteTaskPushNotificationConfigRequest,
GetExtendedAgentCardRequest,
GetTaskPushNotificationConfigRequest,
GetTaskRequest,
ListTaskPushNotificationConfigsRequest,
ListTaskPushNotificationConfigsResponse,
ListTasksRequest,
ListTasksResponse,
SendMessageRequest,
SendMessageResponse,
StreamResponse,
SubscribeToTaskRequest,
Task,
TaskPushNotificationConfig,
)
from a2a.utils.errors import A2A_REASON_TO_ERROR, MethodNotFoundError

Check notice on line 39 in src/a2a/client/transports/rest.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Copy/pasted code

see src/a2a/client/transports/jsonrpc.py (17-39)
from a2a.utils.proto_utils import parse_lenient
from a2a.utils.telemetry import SpanKind, trace_class

Expand Down Expand Up @@ -299,14 +300,24 @@
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,
Expand Down
81 changes: 81 additions & 0 deletions tests/client/transports/test_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Loading