The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(cli): regression tests pinning auth-first ordering skips registry sweep
kshitij8f52040dd086
diff --git a/tests/hermes_cli/test_api_key_providers.py b/tests/hermes_cli/test_api_key_providers.pyindex 775b5ae84e3..619cc74c45a 100644--- a/tests/hermes_cli/test_api_key_providers.py+++ b/tests/hermes_cli/test_api_key_providers.py@@ -562,7 +562,103 @@ class TestHasAnyProviderConfigured:from hermes_cli.main import _has_any_provider_configuredassert _has_any_provider_configured() is True+ @staticmethod+ def _clear_provider_env(monkeypatch):+ """Clear every provider env var so early checks can't short-circuit."""+ from hermes_cli.auth import PROVIDER_REGISTRY+ _all_vars = {"OPENROUTER_API_KEY", "OPENAI_API_KEY", "ANTHROPIC_API_KEY",+ "ANTHROPIC_TOKEN", "OPENAI_BASE_URL"}+ for pconfig in PROVIDER_REGISTRY.values():+ if pconfig.auth_type == "api_key":+ _all_vars.update(pconfig.api_key_env_vars)+ for var in _all_vars:+ monkeypatch.delenv(var, raising=False)++ def _setup_home(self, monkeypatch, tmp_path):+ from hermes_cli import config as config_module+ hermes_home = tmp_path / ".hermes"+ hermes_home.mkdir()+ monkeypatch.setattr(config_module, "get_env_path", lambda: hermes_home / ".env")+ monkeypatch.setattr(config_module, "get_hermes_home", lambda: hermes_home)+ monkeypatch.setenv("HERMES_HOME", str(hermes_home))+ self._clear_provider_env(monkeypatch)+ return hermes_home++ def test_config_provider_skips_registry_sweep(self, monkeypatch, tmp_path):+ """model.provider in config.yaml must short-circuit BEFORE the slow+ provider-registry sweep (gh subprocess etc.) is ever invoked.++ Regression test for the auth-first ordering: get_auth_status is+ booby-trapped to fail loudly if the sweep runs. The sweep wraps its+ loop in ``except Exception``, so we also record every call — any+ recorded call proves the sweep ran even if the raise was swallowed.+ """+ import yaml+ hermes_home = self._setup_home(monkeypatch, tmp_path)+ (hermes_home / "config.yaml").write_text(yaml.dump({+ "model": {"default": "anthropic/claude-opus-4.6", "provider": "openrouter"},+ }))+ sweep_calls = []++ def _trap(provider_id):+ sweep_calls.append(provider_id)+ raise AssertionError("sweep must be skipped")++ monkeypatch.setattr("hermes_cli.auth.get_auth_status", _trap)+ from hermes_cli.main import _has_any_provider_configured+ assert _has_any_provider_configured() is True+ assert sweep_calls == [], (+ f"provider registry sweep ran before config short-circuit: {sweep_calls}"+ )++ def test_config_base_url_api_key_skips_registry_sweep(self, monkeypatch, tmp_path):+ """Custom endpoint (base_url/api_key in config, no provider) must also+ short-circuit before the registry sweep."""+ import yaml+ hermes_home = self._setup_home(monkeypatch, tmp_path)+ (hermes_home / "config.yaml").write_text(yaml.dump({+ "model": {+ "default": "local/custom-model",+ "base_url": "http://localhost:8000/v1",+ "api_key": "sk-local-test",+ },+ }))+ sweep_calls = []++ def _trap(provider_id):+ sweep_calls.append(provider_id)+ raise AssertionError("sweep must be skipped")+ monkeypatch.setattr("hermes_cli.auth.get_auth_status", _trap)+ from hermes_cli.main import _has_any_provider_configured+ assert _has_any_provider_configured() is True+ assert sweep_calls == [], (+ f"provider registry sweep ran before config short-circuit: {sweep_calls}"+ )++ def test_auth_json_skips_registry_sweep(self, monkeypatch, tmp_path):+ """auth.json with a logged-in active provider must short-circuit before+ the registry sweep. get_auth_status may be called ONLY for the active+ provider from auth.json — any other provider id means the sweep ran.+ """+ import json+ hermes_home = self._setup_home(monkeypatch, tmp_path)+ (hermes_home / "auth.json").write_text(json.dumps({+ "active_provider": "nous",+ }))+ calls = []++ def _guarded_status(provider_id):+ calls.append(provider_id)+ assert provider_id == "nous", "sweep must be skipped"+ return {"logged_in": True}++ monkeypatch.setattr("hermes_cli.auth.get_auth_status", _guarded_status)+ from hermes_cli.main import _has_any_provider_configured+ assert _has_any_provider_configured() is True+ assert calls == ["nous"], (+ f"provider registry sweep ran before auth.json short-circuit: {calls}"+ )# =============================================================================