mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
Systematic prune per AGENTS.md test policy, one pass over every major test tree (gateway, hermes_cli, tools, agent, run_agent, plugins, cli, cron, tui_gateway, honcho/openviking, root-level): - DELETE: source-reading tests (read_text/getsource on prod files), change-detector tests (exact catalog counts, model-name snapshots, config version literals), mock-echo tests (assert a mock returns what it was told), assertion-free/trivial tests, near-duplicate parametrizations (boundaries + one representative kept), async/sync twin duplicates, cosmetic within-file variations. - KEEP (mandatory): security/redaction/approval guards, message-role alternation invariants, prompt-caching/deterministic-call-id invariants, issue-number regression tests (deduped), E2E tests. - 6 test files deleted outright (script-style/no-assert or fully redundant); conftest.py, fakes/, fixtures/ untouched. - tests/acp/conftest.py added: autouse fixture stubs the live models.dev/GitHub/Copilot/Anthropic inventory fetches that ACP server tests performed on every session create — test_server.py 147s → 3.4s, and the tests are now genuinely hermetic. - Sleep-based slowness shrunk where safe (codex_ttfb_watchdog, compression_concurrent_fork, etc.); no wall-clock assertion tightened. Verification: full hermetic suite via scripts/run_tests.sh — 2439 files, 31,130 tests passed, 0 failed, 0 flaky retries, 315s wall (baseline: 583s wall, 13,564s subprocess CPU).
71 lines
2.6 KiB
Python
71 lines
2.6 KiB
Python
"""Regression tests for the credential-pool provider-mismatch guard with
|
|
custom providers (Bernard's Fireworks report, June 2026).
|
|
|
|
Custom endpoints carry two naming conventions for the same provider: the
|
|
agent's ``provider`` attribute is the generic ``"custom"`` label while the
|
|
pool is keyed ``custom:<normalized-name>`` (``CUSTOM_POOL_PREFIX``). The
|
|
defensive guard in ``recover_with_credential_pool`` compared the two
|
|
literally, logged "Credential pool provider mismatch: pool=custom:<name>,
|
|
agent=custom", and skipped recovery — so 401/429 recovery (refresh,
|
|
rotation) never ran for ANY custom-provider user.
|
|
|
|
The fix accepts the pair only when the agent's current base_url resolves to
|
|
the same pool key, preserving the guard's original purpose (#33088/#33163:
|
|
never mutate the primary's pool while a fallback provider is active).
|
|
"""
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from agent.agent_runtime_helpers import recover_with_credential_pool
|
|
from agent.error_classifier import FailoverReason
|
|
|
|
|
|
FIREWORKS_URL = "https://api.fireworks.ai/inference/v1"
|
|
|
|
|
|
def _agent(provider, base_url, pool_provider):
|
|
agent = MagicMock()
|
|
agent.provider = provider
|
|
agent.base_url = base_url
|
|
pool = MagicMock()
|
|
pool.provider = pool_provider
|
|
agent._credential_pool = pool
|
|
return agent, pool
|
|
|
|
|
|
class TestCustomPoolMismatchGuard:
|
|
|
|
def test_unrelated_custom_pool_still_guarded(self):
|
|
"""agent=custom pointed at a DIFFERENT endpoint than the pool's
|
|
custom provider must still skip pool mutation."""
|
|
agent, pool = _agent(
|
|
"custom", "https://other-endpoint.example/v1", "custom:fireworks"
|
|
)
|
|
with patch(
|
|
"agent.credential_pool.get_custom_provider_pool_key",
|
|
return_value="custom:other",
|
|
):
|
|
recovered, _ = recover_with_credential_pool(
|
|
agent,
|
|
status_code=401,
|
|
has_retried_429=False,
|
|
classified_reason=FailoverReason.auth,
|
|
)
|
|
assert recovered is False
|
|
assert not pool.method_calls
|
|
|
|
def test_fallback_provider_still_guarded(self):
|
|
"""Original #33088/#33163 contract: when a fallback provider is
|
|
active (agent.provider != pool.provider, non-custom), the pool is
|
|
never mutated."""
|
|
agent, pool = _agent("openai-codex", "https://chatgpt.com/backend-api", "custom:fireworks")
|
|
recovered, _ = recover_with_credential_pool(
|
|
agent,
|
|
status_code=401,
|
|
has_retried_429=False,
|
|
classified_reason=FailoverReason.auth,
|
|
)
|
|
assert recovered is False
|
|
assert not pool.method_calls
|
|
|