Skip to content

Commit b43bf9f

Browse files
committed
fix tests
1 parent ce5a6e1 commit b43bf9f

File tree

5 files changed

+49
-42
lines changed

5 files changed

+49
-42
lines changed

.vscode/launch.json

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
"PYTHONPATH": "${workspaceFolder}"
1313
},
1414
"cwd": "${workspaceFolder}/examples/helloworld",
15-
"args": ["--host", "localhost", "--port", "9999"]
15+
"args": [
16+
"--host",
17+
"localhost",
18+
"--port",
19+
"9999"
20+
]
1621
},
1722
{
1823
"name": "Debug Currency Agent",
@@ -25,7 +30,24 @@
2530
"PYTHONPATH": "${workspaceFolder}"
2631
},
2732
"cwd": "${workspaceFolder}/examples/langgraph",
28-
"args": ["--host", "localhost", "--port", "10000"]
33+
"args": [
34+
"--host",
35+
"localhost",
36+
"--port",
37+
"10000"
38+
]
39+
},
40+
{
41+
"name": "Pytest All",
42+
"type": "debugpy",
43+
"request": "launch",
44+
"module": "pytest",
45+
"args": [
46+
"-v",
47+
"-s"
48+
],
49+
"console": "integratedTerminal",
50+
"justMyCode": true // Or false if you need to step into library code
2951
}
3052
]
31-
}
53+
}

src/a2a/client/auth/credentials.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,30 @@ async def get_credentials(
2222

2323
class InMemoryContextCredentialStore(CredentialService):
2424
"""
25-
A simple in-memory store for context-keyed credentials.
25+
A simple in-memory store for session-keyed credentials.
2626
27-
This class uses the 'contextId' from the ClientCallContext state to
28-
store and retrieve credentials, providing a simple, user-specific
29-
credential mechanism without requiring a full user authentication system.
27+
This class uses the 'sessionId' from the ClientCallContext state to
28+
store and retrieve credentials...
3029
"""
3130

3231
def __init__(self):
33-
# {context_id: {scheme_name: credential}}
32+
# {session_id: {scheme_name: credential}}
3433
self._store: dict[str, dict[str, str]] = {}
3534

3635
async def get_credentials(
3736
self,
3837
security_scheme_name: str,
3938
context: ClientCallContext | None,
4039
) -> str | None:
41-
if not context or 'contextId' not in context.state:
40+
if not context or 'sessionId' not in context.state:
4241
return None
43-
context_id = context.state['contextId']
44-
return self._store.get(context_id, {}).get(security_scheme_name)
42+
session_id = context.state['sessionId']
43+
return self._store.get(session_id, {}).get(security_scheme_name)
4544

46-
async def set_credentials(
47-
self, context_id: str, security_scheme_name: str, credential: str
45+
async def set_credential(
46+
self, session_id: str, security_scheme_name: str, credential: str
4847
):
4948
"""Method to populate the store."""
50-
if context_id not in self._store:
51-
self._store[context_id] = {}
52-
self._store[context_id][security_scheme_name] = credential
49+
if session_id not in self._store:
50+
self._store[session_id] = {}
51+
self._store[session_id][security_scheme_name] = credential

src/a2a/client/auth/interceptor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
from a2a.client.auth.credentials import CredentialService
77
from a2a.client.middleware import ClientCallContext, ClientCallInterceptor
8-
from a2a.types import AgentCard, APIKeySecurityScheme, HTTPAuthSecurityScheme, In, OAuth2SecurityScheme, OpenIdConnectSecurityScheme
8+
from a2a.types import (AgentCard, APIKeySecurityScheme, HTTPAuthSecurityScheme,
9+
In, OAuth2SecurityScheme, OpenIdConnectSecurityScheme)
910

1011
logger = logging.getLogger(__name__)
1112

src/a2a/client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ async def send_message_streaming(
270270
self.httpx_client,
271271
'POST',
272272
self.url,
273-
json=payload
273+
json=payload,
274274
**modified_kwargs,
275275
) as event_source:
276276
try:

tests/client/test_auth_middleware.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,15 @@
66
import pytest
77
import respx
88

9-
from a2a.client import (
10-
A2AClient,
11-
ClientCallContext,
12-
ClientCallInterceptor,
13-
)
14-
from a2a.client.auth import (
15-
AuthInterceptor,
16-
CredentialService,
17-
InMemoryContextCredentialStore,
18-
)
19-
from a2a.types import (
20-
AgentCard,
21-
AgentCapabilities,
22-
APIKeySecurityScheme,
23-
AuthorizationCodeOAuthFlow,
24-
HTTPAuthSecurityScheme,
25-
In,
26-
OAuth2SecurityScheme,
27-
OAuthFlows,
28-
OpenIdConnectSecurityScheme,
29-
SecurityScheme,
30-
SendMessageRequest,
31-
)
9+
from a2a.client import A2AClient, ClientCallContext, ClientCallInterceptor
10+
from a2a.client.auth import (AuthInterceptor, CredentialService,
11+
InMemoryContextCredentialStore)
12+
from a2a.types import (AgentCapabilities, AgentCard, APIKeySecurityScheme,
13+
AuthorizationCodeOAuthFlow, HTTPAuthSecurityScheme, In,
14+
OAuth2SecurityScheme, OAuthFlows,
15+
OpenIdConnectSecurityScheme, SecurityScheme,
16+
SendMessageRequest)
17+
3218

3319
# A simple mock interceptor for testing basic middleware functionality
3420
class HeaderInterceptor(ClientCallInterceptor):
@@ -60,7 +46,6 @@ async def test_client_with_simple_interceptor():
6046
# Arrange
6147
test_url = "http://fake-agent.com/rpc"
6248
header_interceptor = HeaderInterceptor("X-Test-Header", "Test-Value-123")
63-
6449
async with httpx.AsyncClient() as http_client:
6550
client = A2AClient(
6651
httpx_client=http_client,

0 commit comments

Comments
 (0)