fix(aux): bare-custom AuthError yields no custom endpoint instead of a stale env OPENAI_BASE_URL

This commit is contained in:
teknium1
2026-09-15 14:27:56 -07:00
committed by Teknium
parent a9fabe43c4
commit f55d4f6747
2 changed files with 18 additions and 0 deletions
+7
View File
@@ -2646,8 +2646,15 @@ def clear_runtime_main() -> None:
def _resolve_custom_runtime() -> Tuple[Optional[str], Optional[str], Optional[str]]:
"""Resolve the active custom/main endpoint like the main CLI (env OPENAI_BASE_URL or config-saved)."""
try:
from hermes_cli.auth import AuthError
from hermes_cli.runtime_provider import resolve_runtime_provider
runtime = resolve_runtime_provider(requested="custom")
except AuthError as exc:
# Bare 'custom' with nothing configured fails fast in the main resolver: there is no
# custom endpoint, so do NOT fall through to a stale env OPENAI_BASE_URL that the main
# resolver deliberately never consults.
logger.debug("Auxiliary client: no custom endpoint configured: %s", exc)
return None, None, None
except Exception as exc:
logger.debug("Auxiliary client: custom runtime resolution failed: %s", exc)
runtime = None
+11
View File
@@ -2667,6 +2667,17 @@ class TestAuxiliaryTaskExtraBody:
assert not any("OPENAI_BASE_URL is set" in rec.message for rec in caplog.records), \
"Should NOT warn when provider is 'custom'"
def test_bare_custom_auth_error_does_not_fall_back_to_env_base_url(self, monkeypatch):
"""Bare 'custom' with nothing configured: the main resolver raises AuthError; aux must
return no endpoint rather than route to a stale env OPENAI_BASE_URL with a placeholder key."""
from hermes_cli.auth import AuthError
from agent.auxiliary_client import _resolve_custom_runtime
monkeypatch.setenv("OPENAI_BASE_URL", "https://old-proxy.example/v1")
monkeypatch.delenv("OPENAI_API_KEY", raising=False)
with patch("hermes_cli.runtime_provider.resolve_runtime_provider",
side_effect=AuthError("no creds", provider="custom", code="missing_api_key")):
assert _resolve_custom_runtime() == (None, None, None)
# ---------------------------------------------------------------------------