hermes-agent/tests/hermes_cli/test_aux_picker_inventory.py
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.9 KiB
Python

"""Auxiliary-task pickers share one provider-inventory substrate.
Every aux picker (``hermes model`` → Configure auxiliary models, the
``hermes tools`` vision picker, and any future one) must route through
``hermes_cli.inventory.build_aux_picker_rows()`` so it shows the same
provider universe as ``/model``.
Two independent contributor PRs fixed the same two call sites for exactly
this reason:
- #52642 (@deepjia) — user ``providers:`` / ``custom_providers:`` entries
were invisible because the aux picker never forwarded them.
- #66624 (@Drexuxux) — providers with a fully rate-limited credential pool
were hidden because the aux picker never forwarded ``for_picker``.
Both were per-call-site kwarg patches, so the next aux picker would have
reintroduced the gap. These tests pin the *shared substrate* behaviour and
guard the seam itself, not the kwargs at any one site.
"""
from pathlib import Path
from unittest.mock import patch
import pytest
import yaml
CONFIG = {
"model": {"provider": "openrouter", "default": "anthropic/claude-opus-4.6"},
"model_catalog": {"excluded_providers": ["copilot"]},
"providers": {
"my-llm": {
"name": "My LLM",
"base_url": "https://myllm.example.com/v1",
"key_env": "MYLLM_KEY",
"discover_models": False,
"models": {"big-model": {}, "small-model": {}},
}
},
"custom_providers": [
{
"name": "Legacy Box",
"base_url": "https://legacy.example.com/v1",
"key_env": "LEGACY_KEY",
"model": "legacy-1",
"discover_models": False,
}
],
}
@pytest.fixture
def configured_home(tmp_path, monkeypatch):
"""A HERMES_HOME with one ``providers:`` entry and one legacy
``custom_providers:`` entry, both credentialled via env."""
home = tmp_path / ".hermes"
home.mkdir()
(home / "config.yaml").write_text(yaml.safe_dump(CONFIG))
monkeypatch.setattr(Path, "home", lambda: tmp_path)
monkeypatch.setenv("HERMES_HOME", str(home))
monkeypatch.setenv("OPENROUTER_API_KEY", "sk-or-test")
monkeypatch.setenv("MYLLM_KEY", "sk-mine")
monkeypatch.setenv("LEGACY_KEY", "sk-legacy")
return home
# ─── The substrate contract ─────────────────────────────────────────────
def test_aux_picker_surfaces_user_defined_providers(configured_home):
"""Both config schemas for a user's own endpoint reach an aux picker.
This is #52642's bug: the aux picker built its own kwargs and passed
neither ``user_providers`` nor ``custom_providers``, so a user who had
configured their own endpoint could not route any auxiliary task to it.
"""
from hermes_cli.inventory import build_aux_picker_rows
slugs = {r["slug"] for r in build_aux_picker_rows()}
assert "my-llm" in slugs, (
"a keyed providers: entry must be selectable for auxiliary tasks"
)
assert "custom:legacy-box" in slugs, (
"a legacy custom_providers: entry must be selectable for auxiliary tasks"
)
def test_aux_picker_requests_exhausted_pool_visibility(configured_home):
"""#66624: a provider whose credential pool is entirely rate-limited
must stay visible. Rate limits are per-model and the aux picker writes a
config the user runs later, once the cooldown has cleared."""
from hermes_cli import inventory
seen = {}
def _capture(**kwargs):
seen.update(kwargs)
return []
with patch("hermes_cli.model_switch.list_authenticated_providers", _capture):
inventory.build_aux_picker_rows()
assert seen.get("for_picker") is True
# ─── Shared rendering ───────────────────────────────────────────────────
# ─── Seam guard ─────────────────────────────────────────────────────────
def test_aux_pickers_route_through_the_shared_substrate(configured_home):
"""Neither aux picker may call ``list_authenticated_providers`` directly.
This is the regression that produced #52642 and #66624 as two separate
contributor PRs against the same two call sites: a picker calling the
low-level function re-derives its own kwargs and drops whichever slice
of user config the author didn't think about. Both pickers must reach
the provider list only through ``build_aux_picker_rows``.
"""
import hermes_cli.main as main
import hermes_cli.tools_config as tools_config
direct_calls = []
substrate_calls = []
def _direct(**kwargs):
direct_calls.append(kwargs)
return []
def _substrate(**kwargs):
substrate_calls.append(kwargs)
return []
# Abort each picker at its first prompt, right after it has asked for its
# provider list. The vision picker returns early on empty rows; the
# aux-task picker still renders auto/custom/back, so cancel its menu.
with (
patch("hermes_cli.model_switch.list_authenticated_providers", _direct),
patch("hermes_cli.inventory.build_aux_picker_rows", _substrate),
patch("hermes_cli.main._prompt_provider_choice", return_value=None),
):
main._aux_select_for_task("compression")
tools_config._configure_vision_provider_model({}, {})
assert len(substrate_calls) == 2, (
"both the aux-task picker and the vision picker must source providers "
f"from build_aux_picker_rows (got {len(substrate_calls)} calls)"
)
assert direct_calls == [], (
"aux pickers must not call list_authenticated_providers directly — "
"route through hermes_cli.inventory.build_aux_picker_rows so custom "
"providers, exclusions, and picker visibility stay consistent"
)