4444 TextPart ,
4545 UnsupportedOperationError ,
4646)
47+ from a2a .utils import (
48+ AGENT_CARD_WELL_KNOWN_PATH ,
49+ PREV_AGENT_CARD_WELL_KNOWN_PATH ,
50+ )
4751from a2a .utils .errors import MethodNotImplementedError
4852
4953
@@ -147,7 +151,7 @@ def client(app: A2AStarletteApplication, **kwargs):
147151
148152def test_agent_card_endpoint (client : TestClient , agent_card : AgentCard ):
149153 """Test the agent card endpoint returns expected data."""
150- response = client .get ('/.well-known/agent.json' )
154+ response = client .get (AGENT_CARD_WELL_KNOWN_PATH )
151155 assert response .status_code == 200
152156 data = response .json ()
153157 assert data ['name' ] == agent_card .name
@@ -169,6 +173,36 @@ def test_authenticated_extended_agent_card_endpoint_not_supported(
169173 assert response .status_code == 404 # Starlette's default for no route
170174
171175
176+ def test_agent_card_default_endpoint_has_deprecated_route (
177+ agent_card : AgentCard , handler : mock .AsyncMock
178+ ):
179+ """Test agent card deprecated route is available for default route."""
180+ app_instance = A2AStarletteApplication (agent_card , handler )
181+ client = TestClient (app_instance .build ())
182+ response = client .get (AGENT_CARD_WELL_KNOWN_PATH )
183+ assert response .status_code == 200
184+ data = response .json ()
185+ assert data ['name' ] == agent_card .name
186+ response = client .get (PREV_AGENT_CARD_WELL_KNOWN_PATH )
187+ assert response .status_code == 200
188+ data = response .json ()
189+ assert data ['name' ] == agent_card .name
190+
191+
192+ def test_agent_card_custom_endpoint_has_no_deprecated_route (
193+ agent_card : AgentCard , handler : mock .AsyncMock
194+ ):
195+ """Test agent card deprecated route is not available for custom route."""
196+ app_instance = A2AStarletteApplication (agent_card , handler )
197+ client = TestClient (app_instance .build (agent_card_url = '/my-agent' ))
198+ response = client .get ('/my-agent' )
199+ assert response .status_code == 200
200+ data = response .json ()
201+ assert data ['name' ] == agent_card .name
202+ response = client .get (PREV_AGENT_CARD_WELL_KNOWN_PATH )
203+ assert response .status_code == 404
204+
205+
172206def test_authenticated_extended_agent_card_endpoint_not_supported_fastapi (
173207 agent_card : AgentCard , handler : mock .AsyncMock
174208):
@@ -253,9 +287,7 @@ def test_starlette_rpc_endpoint_custom_url(
253287 """Test the RPC endpoint with a custom URL."""
254288 # Provide a valid Task object as the return value
255289 task_status = TaskStatus (** MINIMAL_TASK_STATUS )
256- task = Task (
257- id = 'task1' , context_id = 'ctx1' , state = 'completed' , status = task_status
258- )
290+ task = Task (id = 'task1' , context_id = 'ctx1' , status = task_status )
259291 handler .on_get_task .return_value = task
260292 client = TestClient (app .build (rpc_url = '/api/rpc' ))
261293 response = client .post (
@@ -278,9 +310,7 @@ def test_fastapi_rpc_endpoint_custom_url(
278310 """Test the RPC endpoint with a custom URL."""
279311 # Provide a valid Task object as the return value
280312 task_status = TaskStatus (** MINIMAL_TASK_STATUS )
281- task = Task (
282- id = 'task1' , context_id = 'ctx1' , state = 'completed' , status = task_status
283- )
313+ task = Task (id = 'task1' , context_id = 'ctx1' , status = task_status )
284314 handler .on_get_task .return_value = task
285315 client = TestClient (app .build (rpc_url = '/api/rpc' ))
286316 response = client .post (
@@ -315,7 +345,7 @@ def custom_handler(request):
315345 assert response .json () == {'message' : 'Hello' }
316346
317347 # Ensure default routes still work
318- response = client .get ('/.well-known/agent.json' )
348+ response = client .get (AGENT_CARD_WELL_KNOWN_PATH )
319349 assert response .status_code == 200
320350 data = response .json ()
321351 assert data ['name' ] == agent_card .name
@@ -339,11 +369,40 @@ def custom_handler(request):
339369 assert response .json () == {'message' : 'Hello' }
340370
341371 # Ensure default routes still work
342- response = client .get ('/.well-known/agent.json' )
372+ response = client .get (AGENT_CARD_WELL_KNOWN_PATH )
343373 assert response .status_code == 200
344374 data = response .json ()
345375 assert data ['name' ] == agent_card .name
346376
377+ # check if deprecated agent card path route is available with default well-known path
378+ response = client .get (PREV_AGENT_CARD_WELL_KNOWN_PATH )
379+ assert response .status_code == 200
380+ data = response .json ()
381+ assert data ['name' ] == agent_card .name
382+
383+
384+ def test_fastapi_build_custom_agent_card_path (
385+ app : A2AFastAPIApplication , agent_card : AgentCard
386+ ):
387+ """Test building the app with a custom agent card path."""
388+
389+ test_app = app .build (agent_card_url = '/agent-card' )
390+ client = TestClient (test_app )
391+
392+ # Ensure custom card path works
393+ response = client .get ('/agent-card' )
394+ assert response .status_code == 200
395+ data = response .json ()
396+ assert data ['name' ] == agent_card .name
397+
398+ # Ensure default agent card location is not available
399+ response = client .get (AGENT_CARD_WELL_KNOWN_PATH )
400+ assert response .status_code == 404
401+
402+ # check if deprecated agent card path route is not available
403+ response = client .get (PREV_AGENT_CARD_WELL_KNOWN_PATH )
404+ assert response .status_code == 404
405+
347406
348407# === REQUEST METHODS TESTS ===
349408
@@ -395,9 +454,7 @@ def test_cancel_task(client: TestClient, handler: mock.AsyncMock):
395454 # Setup mock response
396455 task_status = TaskStatus (** MINIMAL_TASK_STATUS )
397456 task_status .state = TaskState .canceled # 'cancelled' #
398- task = Task (
399- id = 'task1' , context_id = 'ctx1' , state = 'cancelled' , status = task_status
400- )
457+ task = Task (id = 'task1' , context_id = 'ctx1' , status = task_status )
401458 handler .on_cancel_task .return_value = task
402459
403460 # Send request
@@ -425,9 +482,7 @@ def test_get_task(client: TestClient, handler: mock.AsyncMock):
425482 """Test getting a task."""
426483 # Setup mock response
427484 task_status = TaskStatus (** MINIMAL_TASK_STATUS )
428- task = Task (
429- id = 'task1' , context_id = 'ctx1' , state = 'completed' , status = task_status
430- )
485+ task = Task (id = 'task1' , context_id = 'ctx1' , status = task_status )
431486 handler .on_get_task .return_value = task # JSONRPCResponse(root=task)
432487
433488 # Send request
0 commit comments