Files
hermes-agent/tests/acp/test_named_provider_catalogs.py
T
Teknium 39975613b1 test: prune wave 2 + speed fixes — 28,106 → 19,757 test functions, suite wall 315s → 294s
Second, deeper pass over tools/gateway/hermes_cli plus first pass over
the trees wave 1 missed (acp, acp_adapter, skills, computer_use, docker,
dashboard, conformance, monitoring, secret_sources, hermes_state,
providers). Same rubric as wave 1 (AGENTS.md test policy); security,
alternation/caching invariants, issue-number regressions, and E2E kept.

Real test-quality fixes found and rooted out along the way:
- tests/tools/test_command_guards.py made real auxiliary-LLM HTTPS calls
  (DEFAULT_CONFIG smart-approval leaked in) — pinned approval
  mode=manual via autouse fixture: 17.4s → 0.4s.
- test_model_switch_custom_providers.py / test_user_providers_model_switch.py
  silently probed live provider catalogs (~2s/test) — stubbed
  cached_provider_model_ids/provider_model_ids/fetch_api_models.
- test_telegram_noise_filter.py: 15-platform copy-paste matrix over
  shared gateway.run logic → 3 representative platforms (55s → 3.9s).
- test_gateway_shutdown.py: stop()'s 5s interrupt-deadline loop spun on
  MagicMock agents — interrupt.side_effect now clears _running_agents
  (22s → 1.0s).
- test_gateway_inactivity_timeout.py poll-harness timings shrunk 3-5x
  (24s → 1.1s); test_mcp_stability.py backoff/SIGTERM-grace sleeps
  patched (15.4s → 2.5s); test_async_delegation.py negative-drain wait
  5s → 0.5s.
- test_telegram_init_deadline.py: loop-block margin restored to 1.0s
  with rationale comment — the watchdog-dump assertion needs the loop
  blocked well past deadline+grace under parallel load (flaked once in
  the 40-worker verification run at a 0.2s margin).

Verification: full hermetic suite via scripts/run_tests.sh —
2,438 files, 21,718 tests passed, 0 failed, 293.9s wall.
Suite totals vs original baseline: 46,820 → 19,757 test functions
(−57.8%), wall 583.5s → 293.9s (−50%), subprocess CPU 13,564s → 11,623s.
2026-07-29 13:39:40 -07:00

159 lines
5.6 KiB
Python

"""Tests for named user-defined provider entries in the ACP model selector.
Named endpoints from the ``providers:`` mapping (and legacy
``custom_providers:`` list) are invisible to canonical provider enumeration,
so ``_build_model_state`` must append them explicitly for ACP clients to
offer them — the TUI ``/model`` picker already renders these entries
(#47039 implemented named endpoints for the TUI surface only).
"""
from types import SimpleNamespace
from unittest.mock import patch
import pytest
from acp_adapter.server import HermesACPAgent, _named_custom_provider_catalogs
from acp_adapter.session import SessionManager
from acp.schema import SessionModelState
MANTLE_URL = "https://bedrock-mantle.us-east-1.api.aws/openai/v1"
def _cfg(providers=None, custom_providers=None):
cfg = {}
if providers is not None:
cfg["providers"] = providers
if custom_providers is not None:
cfg["custom_providers"] = custom_providers
return cfg
class TestNamedCustomProviderCatalogs:
def test_live_discovery_extends_declared_models(self, monkeypatch):
monkeypatch.setenv("SOME_KEY", "k")
cfg = _cfg(
providers={
"relay": {
"name": "Relay",
"base_url": "https://relay.example/v1",
"key_env": "SOME_KEY",
"default_model": "model-a",
}
}
)
with patch("hermes_cli.config.load_config", return_value=cfg), patch(
"hermes_cli.models.fetch_api_models",
return_value=["model-a", "model-b"],
):
catalogs = _named_custom_provider_catalogs()
assert len(catalogs) == 1
slug, label, models = catalogs[0]
assert slug == "custom:relay"
assert [m for m, _ in models] == ["model-a", "model-b"]
def test_disabled_provider_skipped(self, monkeypatch):
monkeypatch.setenv("SOME_KEY", "k")
cfg = _cfg(
providers={
"off": {
"name": "Disabled Endpoint",
"base_url": "https://off.example/v1",
"key_env": "SOME_KEY",
"default_model": "m",
"enabled": False,
}
}
)
with patch("hermes_cli.config.load_config", return_value=cfg), patch(
"hermes_cli.models.fetch_api_models", return_value=None
):
assert _named_custom_provider_catalogs() == []
def test_no_credential_and_no_declared_models_skipped(self, monkeypatch):
monkeypatch.delenv("MISSING_KEY", raising=False)
cfg = _cfg(
providers={
"bare": {
"name": "Bare",
"base_url": "https://bare.example/v1",
"key_env": "MISSING_KEY",
}
}
)
with patch("hermes_cli.config.load_config", return_value=cfg), patch(
"hermes_cli.models.fetch_api_models", return_value=None
):
assert _named_custom_provider_catalogs() == []
def test_legacy_custom_providers_list_included(self, monkeypatch):
monkeypatch.setenv("SOME_KEY", "k")
cfg = _cfg(
custom_providers=[
{
"name": "Legacy Endpoint",
"base_url": "https://legacy.example/v1",
"key_env": "SOME_KEY",
"model": "legacy-model",
}
]
)
with patch("hermes_cli.config.load_config", return_value=cfg), patch(
"hermes_cli.models.fetch_api_models", return_value=None
):
catalogs = _named_custom_provider_catalogs()
assert catalogs == [
("custom:legacy-endpoint", "Legacy Endpoint", [("legacy-model", "")])
]
class TestModelStateIncludesNamedProviders:
@pytest.mark.asyncio
async def test_named_provider_models_appear_in_model_state(self):
manager = SessionManager(
agent_factory=lambda: SimpleNamespace(
model="gpt-5.4", provider="openai-codex"
)
)
acp_agent = HermesACPAgent(session_manager=manager)
with patch(
"hermes_cli.models.curated_models_for_provider",
return_value=[("gpt-5.4", "recommended")],
), patch(
"acp_adapter.server._named_custom_provider_catalogs",
return_value=[
(
"custom:bedrock-mantle",
"AWS Bedrock Mantle",
[("openai.gpt-5.5", "")],
)
],
):
resp = await acp_agent.new_session(cwd="/tmp")
assert isinstance(resp.models, SessionModelState)
ids = [m.model_id for m in resp.models.available_models]
# Current provider's models come first, named endpoints after.
assert ids[0] == "openai-codex:gpt-5.4"
assert "custom:bedrock-mantle:openai.gpt-5.5" in ids
named = next(
m
for m in resp.models.available_models
if m.model_id == "custom:bedrock-mantle:openai.gpt-5.5"
)
assert "AWS Bedrock Mantle" in (named.description or "")
def test_selector_choice_id_round_trips_through_parse_model_input(self):
"""The encoded choice id must resolve back to the named provider."""
from hermes_cli.models import parse_model_input
choice_id = "custom:bedrock-mantle:openai.gpt-5.5"
provider, model = parse_model_input(choice_id, "bedrock")
assert provider == "custom:bedrock-mantle"
assert model == "openai.gpt-5.5"