Skip to content

Commit 002699c

Browse files
committed
More missed instances of AgentAuthentication + nox format
1 parent 0e8ea30 commit 002699c

File tree

3 files changed

+48
-49
lines changed

3 files changed

+48
-49
lines changed

examples/google_adk/calendar_agent/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def main(host: str, port: int):
6464
defaultOutputModes=['text'],
6565
capabilities=AgentCapabilities(streaming=True),
6666
skills=[skill],
67-
authentication=AgentAuthentication(schemes=['public']),
6867
)
6968

7069
adk_agent = create_agent(

tests/client/test_client.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import json
2-
from unittest.mock import AsyncMock, MagicMock, patch
2+
33
from collections.abc import AsyncGenerator
4+
from typing import Any
5+
from unittest.mock import AsyncMock, MagicMock, patch
6+
47
import httpx
58
import pytest
69

10+
from httpx_sse import EventSource, ServerSentEvent
11+
712
from a2a.client import (
813
A2ACardResolver,
914
A2AClient,
@@ -12,31 +17,28 @@
1217
create_text_message_object,
1318
)
1419
from a2a.types import (
20+
A2ARequest,
21+
AgentCapabilities,
1522
AgentCard,
1623
AgentSkill,
17-
AgentCapabilities,
18-
AgentAuthentication,
19-
A2ARequest,
20-
Role,
21-
TaskQueryParams,
22-
TaskIdParams,
24+
CancelTaskRequest,
25+
CancelTaskResponse,
26+
CancelTaskSuccessResponse,
2327
GetTaskRequest,
2428
GetTaskResponse,
25-
SendMessageRequest,
29+
InvalidParamsError,
30+
JSONRPCErrorResponse,
2631
MessageSendParams,
32+
Role,
33+
SendMessageRequest,
2734
SendMessageResponse,
2835
SendMessageSuccessResponse,
29-
JSONRPCErrorResponse,
30-
InvalidParamsError,
31-
CancelTaskRequest,
32-
CancelTaskResponse,
33-
CancelTaskSuccessResponse,
3436
SendStreamingMessageRequest,
3537
SendStreamingMessageResponse,
38+
TaskIdParams,
3639
TaskNotCancelableError,
40+
TaskQueryParams,
3741
)
38-
from typing import Any
39-
from httpx_sse import ServerSentEvent, EventSource
4042

4143

4244
AGENT_CARD = AgentCard(
@@ -56,7 +58,6 @@
5658
examples=['hi', 'hello world'],
5759
)
5860
],
59-
authentication=AgentAuthentication(schemes=['public']),
6061
)
6162

6263
MINIMAL_TASK: dict[str, Any] = {
@@ -86,7 +87,7 @@ def mock_agent_card() -> MagicMock:
8687

8788
async def async_iterable_from_list(
8889
items: list[ServerSentEvent],
89-
) -> AsyncGenerator[ServerSentEvent, None]:
90+
) -> AsyncGenerator[ServerSentEvent]:
9091
"""Helper to create an async iterable from a list."""
9192
for item in items:
9293
yield item

tests/test_types.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
from a2a.types import (
88
A2AError,
99
A2ARequest,
10-
AgentAuthentication,
10+
APIKeySecurityScheme,
1111
AgentCapabilities,
1212
AgentCard,
1313
AgentProvider,
1414
AgentSkill,
1515
Artifact,
1616
CancelTaskRequest,
1717
CancelTaskResponse,
18+
CancelTaskSuccessResponse,
1819
ContentTypeNotSupportedError,
1920
DataPart,
2021
FileBase,
@@ -23,8 +24,11 @@
2324
FileWithUri,
2425
GetTaskPushNotificationConfigRequest,
2526
GetTaskPushNotificationConfigResponse,
27+
GetTaskPushNotificationConfigSuccessResponse,
2628
GetTaskRequest,
2729
GetTaskResponse,
30+
GetTaskSuccessResponse,
31+
In,
2832
InternalError,
2933
InvalidParamsError,
3034
InvalidRequestError,
@@ -35,18 +39,25 @@
3539
JSONRPCRequest,
3640
JSONRPCResponse,
3741
Message,
42+
MessageSendParams,
3843
MethodNotFoundError,
44+
OAuth2SecurityScheme,
3945
Part,
4046
PartBase,
4147
PushNotificationAuthenticationInfo,
4248
PushNotificationConfig,
4349
PushNotificationNotSupportedError,
50+
Role,
51+
SecurityScheme,
4452
SendMessageRequest,
4553
SendMessageResponse,
54+
SendMessageSuccessResponse,
4655
SendStreamingMessageRequest,
4756
SendStreamingMessageResponse,
57+
SendStreamingMessageSuccessResponse,
4858
SetTaskPushNotificationConfigRequest,
4959
SetTaskPushNotificationConfigResponse,
60+
SetTaskPushNotificationConfigSuccessResponse,
5061
Task,
5162
TaskArtifactUpdateEvent,
5263
TaskIdParams,
@@ -55,27 +66,20 @@
5566
TaskPushNotificationConfig,
5667
TaskQueryParams,
5768
TaskResubscriptionRequest,
58-
MessageSendParams,
5969
TaskState,
6070
TaskStatus,
6171
TaskStatusUpdateEvent,
6272
TextPart,
6373
UnsupportedOperationError,
64-
GetTaskSuccessResponse,
65-
SendStreamingMessageSuccessResponse,
66-
SendMessageSuccessResponse,
67-
CancelTaskSuccessResponse,
68-
Role,
69-
SetTaskPushNotificationConfigSuccessResponse,
70-
GetTaskPushNotificationConfigSuccessResponse,
7174
)
7275

76+
7377
# --- Helper Data ---
7478

75-
MINIMAL_AGENT_AUTH: dict[str, Any] = {'schemes': ['Bearer']}
76-
FULL_AGENT_AUTH: dict[str, Any] = {
77-
'schemes': ['Bearer', 'Basic'],
78-
'credentials': 'user:pass',
79+
MINIMAL_AGENT_SECURITY_SCHEME: dict[str, Any] = {
80+
'type': 'apiKey',
81+
'in': 'header',
82+
'name': 'X-API-KEY',
7983
}
8084

8185
MINIMAL_AGENT_SKILL: dict[str, Any] = {
@@ -95,7 +99,6 @@
9599
}
96100

97101
MINIMAL_AGENT_CARD: dict[str, Any] = {
98-
'authentication': MINIMAL_AGENT_AUTH,
99102
'capabilities': {}, # AgentCapabilities is required but can be empty
100103
'defaultInputModes': ['text/plain'],
101104
'defaultOutputModes': ['application/json'],
@@ -175,26 +178,23 @@
175178
# --- Test Functions ---
176179

177180

178-
def test_agent_authentication_valid():
179-
auth = AgentAuthentication(**MINIMAL_AGENT_AUTH)
180-
assert auth.schemes == ['Bearer']
181-
assert auth.credentials is None
182-
183-
auth_full = AgentAuthentication(**FULL_AGENT_AUTH)
184-
assert auth_full.schemes == ['Bearer', 'Basic']
185-
assert auth_full.credentials == 'user:pass'
181+
def test_security_scheme_valid():
182+
scheme = SecurityScheme.model_validate(MINIMAL_AGENT_SECURITY_SCHEME)
183+
assert isinstance(scheme.root, APIKeySecurityScheme)
184+
assert scheme.root.type == 'apiKey'
185+
assert scheme.root.in_ == In.header
186+
assert scheme.root.name == 'X-API-KEY'
186187

187188

188-
def test_agent_authentication_invalid():
189+
def test_security_scheme_invalid():
189190
with pytest.raises(ValidationError):
190-
AgentAuthentication(
191-
credentials='only_creds'
192-
) # Missing schemes # type: ignore
191+
APIKeySecurityScheme(
192+
name='my_api_key',
193+
) # Missing "in" # type: ignore
193194

194-
AgentAuthentication(
195-
schemes=['Bearer'],
196-
extra_field='extra', # type: ignore
197-
) # Extra field
195+
OAuth2SecurityScheme(
196+
description='OAuth2 scheme missing flows',
197+
) # Missing "flows"
198198

199199

200200
def test_agent_capabilities():
@@ -251,7 +251,6 @@ def test_agent_card_valid():
251251
card = AgentCard(**MINIMAL_AGENT_CARD)
252252
assert card.name == 'TestAgent'
253253
assert card.version == '1.0'
254-
assert card.authentication.schemes == ['Bearer']
255254
assert len(card.skills) == 1
256255
assert card.skills[0].id == 'skill-123'
257256
assert card.provider is None # Optional

0 commit comments

Comments
 (0)