fix(gateway): honor key_env in auth-failure fallback resolution

This commit is contained in:
QuenVix
2026-05-23 09:11:22 +03:00
committed by Teknium
parent 99671a8634
commit d21ac579e9
2 changed files with 51 additions and 1 deletions

View File

@@ -218,3 +218,46 @@ fallback_providers:
assert runtime_kwargs["provider"] == "openrouter"
assert runtime_kwargs["api_key"] == "sk-openrouter"
def test_gateway_auth_fallback_resolves_key_env_for_custom_provider(tmp_path, monkeypatch):
"""Auth-failure fallback should honor key_env/api_key_env custom-endpoint hints."""
config = tmp_path / "config.yaml"
config.write_text(
"""
fallback_providers:
- provider: custom
model: fallback-model
base_url: https://fallback.example/v1
key_env: MY_FALLBACK_KEY
""".lstrip(),
encoding="utf-8",
)
monkeypatch.setattr(gateway_run, "_hermes_home", tmp_path)
monkeypatch.setenv("MY_FALLBACK_KEY", "env-secret")
def fake_resolve_runtime_provider(*, requested=None, explicit_base_url=None, explicit_api_key=None):
assert requested == "custom"
assert explicit_base_url == "https://fallback.example/v1"
assert explicit_api_key == "env-secret"
return {
"api_key": explicit_api_key,
"base_url": explicit_base_url,
"provider": "custom",
"api_mode": "chat_completions",
"command": None,
"args": [],
"credential_pool": None,
}
import hermes_cli.runtime_provider as runtime_provider
monkeypatch.setattr(runtime_provider, "resolve_runtime_provider", fake_resolve_runtime_provider)
runtime_kwargs = gateway_run._try_resolve_fallback_provider()
assert runtime_kwargs is not None
assert runtime_kwargs["provider"] == "custom"
assert runtime_kwargs["api_key"] == "env-secret"
assert runtime_kwargs["base_url"] == "https://fallback.example/v1"
assert runtime_kwargs["model"] == "fallback-model"