|
34 | 34 | # Import dependencies with version checking |
35 | 35 | try: |
36 | 36 | from a2a.client.client import ClientConfig |
| 37 | + from a2a.client.client import Consumer |
37 | 38 | from a2a.client.client_factory import ClientFactory |
38 | 39 | from a2a.types import AgentCapabilities |
39 | 40 | from a2a.types import AgentCard |
@@ -246,6 +247,50 @@ async def test_ensure_factory_reuses_existing_client(self): |
246 | 247 | assert client == existing_client |
247 | 248 | assert agent._httpx_client_needs_cleanup is False |
248 | 249 |
|
| 250 | + @pytest.mark.asyncio |
| 251 | + async def test_ensure_httpx_client_updates_factory_with_new_client(self): |
| 252 | + """Test that _ensure_httpx_client updates factory with new client.""" |
| 253 | + agent = RemoteA2aAgent( |
| 254 | + name="test_agent", |
| 255 | + agent_card=create_test_agent_card(), |
| 256 | + a2a_client_factory=ClientFactory( |
| 257 | + ClientConfig(httpx_client=None), |
| 258 | + ), |
| 259 | + ) |
| 260 | + assert agent._a2a_client_factory._config.httpx_client is None |
| 261 | + |
| 262 | + client = await agent._ensure_httpx_client() |
| 263 | + |
| 264 | + assert client is not None |
| 265 | + assert agent._httpx_client == client |
| 266 | + assert agent._httpx_client_needs_cleanup is True |
| 267 | + assert agent._a2a_client_factory._config.httpx_client == client |
| 268 | + |
| 269 | + @pytest.mark.asyncio |
| 270 | + async def test_ensure_httpx_client_reregisters_transports_with_new_client( |
| 271 | + self, |
| 272 | + ): |
| 273 | + """Test that _ensure_httpx_client registers transports with new client.""" |
| 274 | + factory = ClientFactory( |
| 275 | + ClientConfig(httpx_client=None), |
| 276 | + ) |
| 277 | + factory.register("transport_label", lambda: "test") |
| 278 | + agent = RemoteA2aAgent( |
| 279 | + name="test_agent", |
| 280 | + agent_card=create_test_agent_card(), |
| 281 | + a2a_client_factory=factory, |
| 282 | + ) |
| 283 | + assert agent._a2a_client_factory._config.httpx_client is None |
| 284 | + assert "transport_label" in agent._a2a_client_factory._registry |
| 285 | + |
| 286 | + client = await agent._ensure_httpx_client() |
| 287 | + |
| 288 | + assert client is not None |
| 289 | + assert agent._httpx_client == client |
| 290 | + assert agent._httpx_client_needs_cleanup is True |
| 291 | + assert agent._a2a_client_factory._config.httpx_client == client |
| 292 | + assert "transport_label" in agent._a2a_client_factory._registry |
| 293 | + |
249 | 294 | @pytest.mark.asyncio |
250 | 295 | async def test_resolve_agent_card_from_url_success(self): |
251 | 296 | """Test successful agent card resolution from URL.""" |
|
0 commit comments