Skip to content

Commit 64be5e4

Browse files
committed
Change References to hard-coded path
1 parent 0e1a509 commit 64be5e4

File tree

7 files changed

+52
-33
lines changed

7 files changed

+52
-33
lines changed

src/a2a/client/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
SendStreamingMessageResponse,
2727
SetTaskPushNotificationConfigRequest,
2828
SetTaskPushNotificationConfigResponse,
29+
WellKnownUris,
2930
)
3031
from a2a.utils.telemetry import SpanKind, trace_class
3132

@@ -40,7 +41,7 @@ def __init__(
4041
self,
4142
httpx_client: httpx.AsyncClient,
4243
base_url: str,
43-
agent_card_path: str = '/.well-known/agent.json',
44+
agent_card_path: str = WellKnownUris.AGENT_CARD_WELL_KNOWN_URI,
4445
):
4546
"""Initializes the A2ACardResolver.
4647
@@ -184,7 +185,7 @@ async def _apply_interceptors(
184185
async def get_client_from_agent_card_url(
185186
httpx_client: httpx.AsyncClient,
186187
base_url: str,
187-
agent_card_path: str = '/.well-known/agent.json',
188+
agent_card_path: str = WellKnownUris.AGENT_CARD_WELL_KNOWN_URI,
188189
http_kwargs: dict[str, Any] | None = None,
189190
) -> 'A2AClient':
190191
"""Fetches the public AgentCard and initializes an A2A client.

src/a2a/server/apps/jsonrpc/fastapi_app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
JSONRPCApplication,
1010
)
1111
from a2a.server.request_handlers.jsonrpc_handler import RequestHandler
12-
from a2a.types import AgentCard
12+
from a2a.types import AgentCard, WellKnownUris
1313

1414

1515
logger = logging.getLogger(__name__)
@@ -52,7 +52,7 @@ def __init__(
5252
def add_routes_to_app(
5353
self,
5454
app: FastAPI,
55-
agent_card_url: str = '/.well-known/agent.json',
55+
agent_card_url: str = WellKnownUris.AGENT_CARD_WELL_KNOWN_URI,
5656
rpc_url: str = '/',
5757
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
5858
) -> None:
@@ -83,7 +83,7 @@ async def get_extended_agent_card(request: Request) -> Response:
8383

8484
def build(
8585
self,
86-
agent_card_url: str = '/.well-known/agent.json',
86+
agent_card_url: str = WellKnownUris.AGENT_CARD_WELL_KNOWN_URI,
8787
rpc_url: str = '/',
8888
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
8989
**kwargs: Any,

src/a2a/server/apps/jsonrpc/jsonrpc_app.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
SetTaskPushNotificationConfigRequest,
4242
TaskResubscriptionRequest,
4343
UnsupportedOperationError,
44+
WellKnownUris,
4445
)
4546
from a2a.utils.errors import MethodNotImplementedError
4647

@@ -299,24 +300,32 @@ async def _process_non_streaming_request(
299300
request_obj, context
300301
)
301302
case SetTaskPushNotificationConfigRequest():
302-
handler_result = await self.handler.set_push_notification_config(
303-
request_obj,
304-
context,
303+
handler_result = (
304+
await self.handler.set_push_notification_config(
305+
request_obj,
306+
context,
307+
)
305308
)
306309
case GetTaskPushNotificationConfigRequest():
307-
handler_result = await self.handler.get_push_notification_config(
308-
request_obj,
309-
context,
310+
handler_result = (
311+
await self.handler.get_push_notification_config(
312+
request_obj,
313+
context,
314+
)
310315
)
311316
case ListTaskPushNotificationConfigRequest():
312-
handler_result = await self.handler.list_push_notification_config(
313-
request_obj,
314-
context,
317+
handler_result = (
318+
await self.handler.list_push_notification_config(
319+
request_obj,
320+
context,
321+
)
315322
)
316323
case DeleteTaskPushNotificationConfigRequest():
317-
handler_result = await self.handler.delete_push_notification_config(
318-
request_obj,
319-
context,
324+
handler_result = (
325+
await self.handler.delete_push_notification_config(
326+
request_obj,
327+
context,
328+
)
320329
)
321330
case _:
322331
logger.error(
@@ -424,7 +433,7 @@ async def _handle_get_authenticated_extended_agent_card(
424433
@abstractmethod
425434
def build(
426435
self,
427-
agent_card_url: str = '/.well-known/agent.json',
436+
agent_card_url: str = WellKnownUris.AGENT_CARD_WELL_KNOWN_URI,
428437
rpc_url: str = '/',
429438
**kwargs: Any,
430439
) -> FastAPI | Starlette:

src/a2a/server/apps/jsonrpc/starlette_app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
JSONRPCApplication,
1111
)
1212
from a2a.server.request_handlers.jsonrpc_handler import RequestHandler
13-
from a2a.types import AgentCard
13+
from a2a.types import AgentCard, WellKnownUris
1414

1515

1616
logger = logging.getLogger(__name__)
@@ -52,7 +52,7 @@ def __init__(
5252

5353
def routes(
5454
self,
55-
agent_card_url: str = '/.well-known/agent.json',
55+
agent_card_url: str = WellKnownUris.AGENT_CARD_WELL_KNOWN_URI,
5656
rpc_url: str = '/',
5757
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
5858
) -> list[Route]:
@@ -95,7 +95,7 @@ def routes(
9595
def add_routes_to_app(
9696
self,
9797
app: Starlette,
98-
agent_card_url: str = '/.well-known/agent.json',
98+
agent_card_url: str = WellKnownUris.AGENT_CARD_WELL_KNOWN_URI,
9999
rpc_url: str = '/',
100100
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
101101
) -> None:
@@ -116,7 +116,7 @@ def add_routes_to_app(
116116

117117
def build(
118118
self,
119-
agent_card_url: str = '/.well-known/agent.json',
119+
agent_card_url: str = WellKnownUris.AGENT_CARD_WELL_KNOWN_URI,
120120
rpc_url: str = '/',
121121
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
122122
**kwargs: Any,

tests/client/test_client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
TaskNotCancelableError,
4747
TaskPushNotificationConfig,
4848
TaskQueryParams,
49+
WellKnownUris,
4950
)
5051

5152

@@ -127,8 +128,7 @@ async def async_iterable_from_list(
127128

128129
class TestA2ACardResolver:
129130
BASE_URL = 'http://example.com'
130-
AGENT_CARD_PATH = '/.well-known/agent.json'
131-
FULL_AGENT_CARD_URL = f'{BASE_URL}{AGENT_CARD_PATH}'
131+
FULL_AGENT_CARD_URL = f'{BASE_URL}{WellKnownUris.AGENT_CARD_WELL_KNOWN_URI}'
132132
EXTENDED_AGENT_CARD_PATH = (
133133
'/agent/authenticatedExtendedCard' # Default path
134134
)
@@ -153,20 +153,26 @@ async def test_init_parameters_stored_correctly(
153153
httpx_client=mock_httpx_client,
154154
base_url=base_url,
155155
)
156-
assert resolver_default_path.agent_card_path == '.well-known/agent.json'
156+
assert (
157+
resolver_default_path.agent_card_path
158+
== WellKnownUris.AGENT_CARD_WELL_KNOWN_URI.lstrip('/')
159+
)
157160

158161
@pytest.mark.asyncio
159162
async def test_init_strips_slashes(self, mock_httpx_client: AsyncMock):
160163
resolver = A2ACardResolver(
161164
httpx_client=mock_httpx_client,
162165
base_url='http://example.com/', # With trailing slash
163-
agent_card_path='/.well-known/agent.json/', # With leading/trailing slash
166+
agent_card_path=f'{WellKnownUris.AGENT_CARD_WELL_KNOWN_URI}/', # With leading/trailing slash
164167
)
165168
assert (
166169
resolver.base_url == 'http://example.com'
167170
) # Trailing slash stripped
168171
# constructor lstrips agent_card_path, but keeps trailing if provided
169-
assert resolver.agent_card_path == '.well-known/agent.json/'
172+
assert (
173+
resolver.agent_card_path
174+
== WellKnownUris.AGENT_CARD_WELL_KNOWN_URI.lstrip('/') + '/'
175+
)
170176

171177
@pytest.mark.asyncio
172178
async def test_get_agent_card_success_public_only(

tests/server/apps/jsonrpc/test_serialization.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from unittest import mock
22

33
import pytest
4+
5+
from pydantic import ValidationError
46
from starlette.testclient import TestClient
57

68
from a2a.server.apps import A2AFastAPIApplication, A2AStarletteApplication
@@ -10,8 +12,8 @@
1012
AgentCard,
1113
In,
1214
SecurityScheme,
15+
WellKnownUris,
1316
)
14-
from pydantic import ValidationError
1517

1618

1719
@pytest.fixture
@@ -52,7 +54,7 @@ def test_starlette_agent_card_with_api_key_scheme_alias(
5254
app_instance = A2AStarletteApplication(agent_card_with_api_key, handler)
5355
client = TestClient(app_instance.build())
5456

55-
response = client.get('/.well-known/agent.json')
57+
response = client.get(WellKnownUris.AGENT_CARD_WELL_KNOWN_URI)
5658
assert response.status_code == 200
5759
response_data = response.json()
5860

@@ -84,7 +86,7 @@ def test_fastapi_agent_card_with_api_key_scheme_alias(
8486
app_instance = A2AFastAPIApplication(agent_card_with_api_key, handler)
8587
client = TestClient(app_instance.build())
8688

87-
response = client.get('/.well-known/agent.json')
89+
response = client.get(WellKnownUris.AGENT_CARD_WELL_KNOWN_URI)
8890
assert response.status_code == 200
8991
response_data = response.json()
9092

tests/server/test_integration.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
TaskStatus,
4444
TextPart,
4545
UnsupportedOperationError,
46+
WellKnownUris,
4647
)
4748
from a2a.utils.errors import MethodNotImplementedError
4849

@@ -147,7 +148,7 @@ def client(app: A2AStarletteApplication, **kwargs):
147148

148149
def test_agent_card_endpoint(client: TestClient, agent_card: AgentCard):
149150
"""Test the agent card endpoint returns expected data."""
150-
response = client.get('/.well-known/agent.json')
151+
response = client.get(WellKnownUris.AGENT_CARD_WELL_KNOWN_URI)
151152
assert response.status_code == 200
152153
data = response.json()
153154
assert data['name'] == agent_card.name
@@ -315,7 +316,7 @@ def custom_handler(request):
315316
assert response.json() == {'message': 'Hello'}
316317

317318
# Ensure default routes still work
318-
response = client.get('/.well-known/agent.json')
319+
response = client.get(WellKnownUris.AGENT_CARD_WELL_KNOWN_URI)
319320
assert response.status_code == 200
320321
data = response.json()
321322
assert data['name'] == agent_card.name
@@ -339,7 +340,7 @@ def custom_handler(request):
339340
assert response.json() == {'message': 'Hello'}
340341

341342
# Ensure default routes still work
342-
response = client.get('/.well-known/agent.json')
343+
response = client.get(WellKnownUris.AGENT_CARD_WELL_KNOWN_URI)
343344
assert response.status_code == 200
344345
data = response.json()
345346
assert data['name'] == agent_card.name

0 commit comments

Comments
 (0)