From 07ddfaa2d6f93ffe386eab6895e61c24f7cfb674 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 7 Sep 2026 03:21:09 -0700 Subject: [PATCH] =?UTF-8?q?test:=20fix=20CI=20red=20=E2=80=94=20pool=20fix?= =?UTF-8?q?tures=20carry=20source,=20refresh=20assertion=20binds=20the=20f?= =?UTF-8?q?ailed=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two test-only corrections for the failures on run 34105317301: - tests/agent/test_anthropic_adapter.py::TestResolveAnthropicToken: the new skip_borrowed branch reads ``entry.source``. ``PooledCredential.source`` is a required dataclass field that ``from_dict`` always materializes (defaults to SOURCE_MANUAL) and ``_available_entries`` returns only PooledCredential, so a production entry can never lack it. The three SimpleNamespace doubles were the incomplete side; build them via ``PooledCredential.from_dict`` instead of duck-typing production with getattr. - tests/agent/test_auxiliary_client.py::test_stale_anthropic_fallback_refreshes_and_retries: the PR itself now passes ``failed_api_key=`` into ``_refresh_provider_credentials`` so an unrelated borrowed login never owns the refresh; the assertion still expected the bare ``("anthropic")`` call. Give the stale client an explicit api_key and assert the request-bound call. Main's auxiliary changes since the PR base (ebe4e7bb44, b40998bc3c..cb1a42d33b) did not move this call. --- tests/agent/test_anthropic_adapter.py | 16 ++++++++++------ tests/agent/test_auxiliary_client.py | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/agent/test_anthropic_adapter.py b/tests/agent/test_anthropic_adapter.py index 3ded294a6c..7ed804baa7 100644 --- a/tests/agent/test_anthropic_adapter.py +++ b/tests/agent/test_anthropic_adapter.py @@ -12,6 +12,7 @@ from agent.prompt_caching import apply_anthropic_cache_control from agent.anthropic_adapter import build_anthropic_client, build_anthropic_bedrock_client, build_anthropic_kwargs from agent.anthropic_credentials import _is_oauth_token, _refresh_oauth_token, _write_claude_code_credentials, is_claude_code_token_valid, read_claude_code_credentials, resolve_anthropic_token, run_oauth_setup_token from agent.anthropic_endpoints import _is_azure_anthropic_endpoint +from agent.credential_pool import PooledCredential from agent.anthropic_message_convert import _to_plain_data, convert_messages_to_anthropic, convert_tools_to_anthropic, normalize_model_name from agent.transports import get_transport @@ -272,10 +273,9 @@ class TestResolveAnthropicToken: # returns nothing, mirroring a Hermes-PKCE-only setup. monkeypatch.setattr("agent.anthropic_credentials.read_claude_code_credentials", lambda: None) - pool_entry = SimpleNamespace( - auth_type="oauth", - access_token="pool-oauth-token", - ) + pool_entry = PooledCredential.from_dict("anthropic", { + "auth_type": "oauth", "access_token": "pool-oauth-token", + }) pool = SimpleNamespace( _available_entries=lambda **_kwargs: ([pool_entry], []), ) @@ -330,7 +330,9 @@ class TestResolveAnthropicToken: monkeypatch.setattr("agent.anthropic_credentials.Path.home", lambda: tmp_path) monkeypatch.setattr("agent.anthropic_credentials.read_claude_code_credentials", lambda: None) - api_key_entry = SimpleNamespace(auth_type="api_key", access_token="sk-pool-apikey") + api_key_entry = PooledCredential.from_dict("anthropic", { + "auth_type": "api_key", "access_token": "sk-pool-apikey", + }) pool = SimpleNamespace( _available_entries=lambda **_kwargs: ([api_key_entry], []), ) @@ -351,7 +353,9 @@ class TestResolveAnthropicToken: monkeypatch.setattr("agent.anthropic_credentials.read_claude_code_credentials", lambda: None) captured = {} - pool_entry = SimpleNamespace(auth_type="oauth", access_token="pool-oauth-token") + pool_entry = PooledCredential.from_dict("anthropic", { + "auth_type": "oauth", "access_token": "pool-oauth-token", + }) def _available_entries(**kwargs): captured.update(kwargs) diff --git a/tests/agent/test_auxiliary_client.py b/tests/agent/test_auxiliary_client.py index c88f247363..44afecdb57 100644 --- a/tests/agent/test_auxiliary_client.py +++ b/tests/agent/test_auxiliary_client.py @@ -1724,6 +1724,7 @@ class TestStaleFallbackCandidateSkip: stale_fb = MagicMock() stale_fb.base_url = "https://api.anthropic.com" + stale_fb.api_key = "expired-anthropic-token" stale_fb.chat.completions.create.side_effect = _AuxAuth401("Invalid bearer token") fresh_fb = MagicMock() @@ -1752,7 +1753,7 @@ class TestStaleFallbackCandidateSkip: ) assert result.choices[0].message.content == "fresh-fallback" - mock_refresh.assert_called_once_with("anthropic") + mock_refresh.assert_called_once_with("anthropic", failed_api_key=stale_fb.api_key) assert stale_fb.chat.completions.create.call_count == 1 assert fresh_fb.chat.completions.create.call_count == 1