test: fix CI red — pool fixtures carry source, refresh assertion binds the failed key
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=<client.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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user