nousresearch--hermes-agent
b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
86 行
3.9 KiB
Python
86 行
3.9 KiB
Python
"""Regression: _try_anthropic() must fall back to the legacy token resolver
|
|
when the credential pool is present but has no usable entry.
|
|
|
|
Root cause (observed 2026-07-05): the pooled Anthropic OAuth entry expired and
|
|
its refresh_token was stale, so `_select_pool_entry("anthropic")` returned
|
|
`(True, None)` — pool exists, no selectable entry. The old `_try_anthropic`
|
|
hard-failed on that branch (`return None, None`), even though a perfectly
|
|
valid `ANTHROPIC_TOKEN` / credentials-file token was available. This wedged
|
|
every auxiliary task routed to Anthropic (goal judge → "no auxiliary client
|
|
configured"), while the MAIN session stayed healthy because it resolves the
|
|
env token directly.
|
|
|
|
openrouter (test_try_openrouter_pool_exhausted_falls_back_to_env) and codex
|
|
(TestBuildCodexClient.test_pool_without_selected_entry_falls_back_to_auth_store)
|
|
already fall through to their standalone credential on `(True, None)`. This
|
|
test pins the same invariant for anthropic so the three paths stay symmetric:
|
|
a temporarily dead pool entry must never hard-fail when a valid standalone
|
|
credential exists.
|
|
"""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
|
class TestAnthropicPoolExhaustedFallsBackToEnv:
|
|
def test_pool_present_no_entry_falls_back_to_resolve_token(self, monkeypatch):
|
|
"""pool=(True, None) but a valid env token exists → client is built."""
|
|
monkeypatch.setenv("ANTHROPIC_TOKEN", "«redacted:sk-…»-oauth-token")
|
|
with patch(
|
|
"agent.auxiliary_client._select_pool_entry", return_value=(True, None)
|
|
), patch(
|
|
"agent.anthropic_adapter.build_anthropic_client"
|
|
) as mock_build:
|
|
mock_build.return_value = MagicMock()
|
|
from agent.auxiliary_client import _try_anthropic, AnthropicAuxiliaryClient
|
|
|
|
client, model = _try_anthropic()
|
|
|
|
assert client is not None, (
|
|
"_try_anthropic must fall back to resolve_anthropic_token() when the "
|
|
"pool is present but has no usable entry (parity with openrouter/codex)"
|
|
)
|
|
assert isinstance(client, AnthropicAuxiliaryClient)
|
|
# Default aux model when none configured.
|
|
assert model == "claude-haiku-4-5-20251001"
|
|
# Must have used the env/legacy token, not a pooled entry.
|
|
assert mock_build.call_args.args[0] == "«redacted:sk-…»-oauth-token"
|
|
|
|
def test_pool_present_no_entry_and_no_token_still_returns_none(self, monkeypatch):
|
|
"""No pooled entry AND no resolvable token → clean (None, None), no crash."""
|
|
monkeypatch.delenv("ANTHROPIC_TOKEN", raising=False)
|
|
monkeypatch.delenv("ANTHROPIC_API_KEY", raising=False)
|
|
monkeypatch.delenv("CLAUDE_CODE_OAUTH_TOKEN", raising=False)
|
|
with patch(
|
|
"agent.auxiliary_client._select_pool_entry", return_value=(True, None)
|
|
), patch(
|
|
"agent.anthropic_adapter.resolve_anthropic_token", return_value=None
|
|
):
|
|
from agent.auxiliary_client import _try_anthropic
|
|
|
|
client, model = _try_anthropic()
|
|
|
|
assert client is None
|
|
assert model is None
|
|
|
|
def test_base_url_defaults_when_pool_present_but_no_entry(self, monkeypatch):
|
|
"""Falling through with pool_present=True must not crash on base_url
|
|
resolution (previously guarded by `if pool_present`)."""
|
|
monkeypatch.setenv("ANTHROPIC_TOKEN", "«redacted:sk-…»-oauth-token")
|
|
captured = {}
|
|
|
|
def _fake_build(token, base_url):
|
|
captured["base_url"] = base_url
|
|
return MagicMock()
|
|
|
|
with patch(
|
|
"agent.auxiliary_client._select_pool_entry", return_value=(True, None)
|
|
), patch(
|
|
"agent.anthropic_adapter.build_anthropic_client", side_effect=_fake_build
|
|
):
|
|
from agent.auxiliary_client import _try_anthropic
|
|
|
|
client, _model = _try_anthropic()
|
|
|
|
assert client is not None
|
|
assert captured["base_url"] == "https://api.anthropic.com"
|