Skip to content

Commit b313e2a

Browse files
committed
test: add unittests for jsonrpc apps
Signed-off-by: Shingo OKAWA <[email protected]>
1 parent 35c742a commit b313e2a

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

src/a2a/types.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,9 @@ class Artifact(BaseModel):
13661366

13671367

13681368
class DeleteTaskPushNotificationConfigResponse(
1369-
RootModel[JSONRPCErrorResponse | DeleteTaskPushNotificationConfigSuccessResponse]
1369+
RootModel[
1370+
JSONRPCErrorResponse | DeleteTaskPushNotificationConfigSuccessResponse
1371+
]
13701372
):
13711373
root: JSONRPCErrorResponse | DeleteTaskPushNotificationConfigSuccessResponse
13721374
"""
@@ -1375,7 +1377,9 @@ class DeleteTaskPushNotificationConfigResponse(
13751377

13761378

13771379
class GetTaskPushNotificationConfigResponse(
1378-
RootModel[JSONRPCErrorResponse | GetTaskPushNotificationConfigSuccessResponse]
1380+
RootModel[
1381+
JSONRPCErrorResponse | GetTaskPushNotificationConfigSuccessResponse
1382+
]
13791383
):
13801384
root: JSONRPCErrorResponse | GetTaskPushNotificationConfigSuccessResponse
13811385
"""
@@ -1384,7 +1388,9 @@ class GetTaskPushNotificationConfigResponse(
13841388

13851389

13861390
class ListTaskPushNotificationConfigResponse(
1387-
RootModel[JSONRPCErrorResponse | ListTaskPushNotificationConfigSuccessResponse]
1391+
RootModel[
1392+
JSONRPCErrorResponse | ListTaskPushNotificationConfigSuccessResponse
1393+
]
13881394
):
13891395
root: JSONRPCErrorResponse | ListTaskPushNotificationConfigSuccessResponse
13901396
"""
@@ -1539,7 +1545,9 @@ class SendStreamingMessageRequest(BaseModel):
15391545

15401546

15411547
class SetTaskPushNotificationConfigResponse(
1542-
RootModel[JSONRPCErrorResponse | SetTaskPushNotificationConfigSuccessResponse]
1548+
RootModel[
1549+
JSONRPCErrorResponse | SetTaskPushNotificationConfigSuccessResponse
1550+
]
15431551
):
15441552
root: JSONRPCErrorResponse | SetTaskPushNotificationConfigSuccessResponse
15451553
"""
@@ -1846,7 +1854,9 @@ class SendStreamingMessageSuccessResponse(BaseModel):
18461854
"""
18471855

18481856

1849-
class CancelTaskResponse(RootModel[JSONRPCErrorResponse | CancelTaskSuccessResponse]):
1857+
class CancelTaskResponse(
1858+
RootModel[JSONRPCErrorResponse | CancelTaskSuccessResponse]
1859+
):
18501860
root: JSONRPCErrorResponse | CancelTaskSuccessResponse
18511861
"""
18521862
JSON-RPC response for the 'tasks/cancel' method.
@@ -1885,7 +1895,9 @@ class JSONRPCResponse(
18851895
"""
18861896

18871897

1888-
class SendMessageResponse(RootModel[JSONRPCErrorResponse | SendMessageSuccessResponse]):
1898+
class SendMessageResponse(
1899+
RootModel[JSONRPCErrorResponse | SendMessageSuccessResponse]
1900+
):
18891901
root: JSONRPCErrorResponse | SendMessageSuccessResponse
18901902
"""
18911903
JSON-RPC response model for the 'message/send' method.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from unittest.mock import MagicMock
2+
3+
import pytest
4+
5+
from a2a.server.apps.jsonrpc.jsonrpc_app import JSONRPCApplicationBuilder
6+
from a2a.server.apps.jsonrpc.fastapi_app import A2AFastAPIApplication
7+
from a2a.server.request_handlers.request_handler import RequestHandler
8+
from a2a.types import AgentCard
9+
10+
11+
def test_builder_protocol():
12+
"""
13+
Tests that `A2AFastAPIApplication` matches the `JSONRPCApplicationBuilder` protocol.
14+
15+
This ensures that `A2AFastAPIApplication` can be used interchangeably where
16+
`JSONRPCApplicationBuilder` is expected.
17+
"""
18+
agent_card = MagicMock(spec=AgentCard)
19+
agent_card.url = 'http://mockurl.com'
20+
agent_card.supportsAuthenticatedExtendedCard = False
21+
http_handler = MagicMock(spec=RequestHandler)
22+
application = A2AFastAPIApplication(agent_card, http_handler)
23+
assert isinstance(application, JSONRPCApplicationBuilder)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from unittest.mock import MagicMock
2+
3+
import pytest
4+
5+
from a2a.server.apps.jsonrpc.jsonrpc_app import JSONRPCApplicationBuilder
6+
from a2a.server.apps.jsonrpc.starlette_app import A2AStarletteApplication
7+
from a2a.server.request_handlers.request_handler import RequestHandler
8+
from a2a.types import AgentCard
9+
10+
11+
def test_builder_protocol():
12+
"""
13+
Tests that `A2AStarletteApplication` matches the `JSONRPCApplicationBuilder` protocol.
14+
15+
This ensures that `A2AStarletteApplication` can be used interchangeably where
16+
`JSONRPCApplicationBuilder` is expected.
17+
"""
18+
agent_card = MagicMock(spec=AgentCard)
19+
agent_card.url = 'http://mockurl.com'
20+
agent_card.supportsAuthenticatedExtendedCard = False
21+
http_handler = MagicMock(spec=RequestHandler)
22+
application = A2AStarletteApplication(agent_card, http_handler)
23+
assert isinstance(application, JSONRPCApplicationBuilder)

0 commit comments

Comments
 (0)