mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-22 10:32:00 +00:00
fix(model): clear stale endpoint credentials across switches
This commit is contained in:
parent
95a3affc2e
commit
c253b07380
9 changed files with 187 additions and 17 deletions
|
|
@ -16,7 +16,7 @@ from __future__ import annotations
|
|||
import yaml
|
||||
|
||||
from hermes_cli.auth import _update_config_for_provider
|
||||
from hermes_cli.config import get_config_path
|
||||
from hermes_cli.config import clear_model_endpoint_credentials, get_config_path
|
||||
|
||||
|
||||
def _read_model_cfg() -> dict:
|
||||
|
|
@ -49,6 +49,23 @@ def _seed_custom_provider_config(api_mode: str = "anthropic_messages") -> None:
|
|||
|
||||
|
||||
class TestUpdateConfigForProviderClearsStaleCustomFields:
|
||||
def test_clear_model_endpoint_credentials_removes_key_alias_and_mode(self):
|
||||
model_cfg = {
|
||||
"provider": "openrouter",
|
||||
"default": "anthropic/claude-sonnet-4.6",
|
||||
"api_key": "sk-stale",
|
||||
"api": "sk-legacy-stale",
|
||||
"api_mode": "anthropic_messages",
|
||||
}
|
||||
|
||||
returned = clear_model_endpoint_credentials(model_cfg)
|
||||
|
||||
assert returned is model_cfg
|
||||
assert "api_key" not in model_cfg
|
||||
assert "api" not in model_cfg
|
||||
assert "api_mode" not in model_cfg
|
||||
assert model_cfg["provider"] == "openrouter"
|
||||
|
||||
def test_switching_to_openrouter_clears_api_key_and_api_mode(self):
|
||||
_seed_custom_provider_config()
|
||||
|
||||
|
|
|
|||
|
|
@ -2327,9 +2327,10 @@ class TestWebServerEndpoints:
|
|||
# api_key follows the same lifecycle as base_url:
|
||||
# supplied → persisted.
|
||||
out = _apply_main_model_assignment(
|
||||
{}, "custom", "m", "http://x/v1", "sk-secret"
|
||||
{"api": "sk-legacy-old"}, "custom", "m", "http://x/v1", "sk-secret"
|
||||
)
|
||||
assert out["api_key"] == "sk-secret"
|
||||
assert "api" not in out
|
||||
|
||||
# same provider, no new key → existing key preserved (re-picking a model
|
||||
# on the same custom endpoint must not wipe the saved key).
|
||||
|
|
@ -2342,9 +2343,12 @@ class TestWebServerEndpoints:
|
|||
|
||||
# switching providers without a new key → stale key cleared.
|
||||
out = _apply_main_model_assignment(
|
||||
{"provider": "custom", "api_key": "sk-old"}, "openrouter", "m"
|
||||
{"provider": "custom", "api_key": "sk-old", "api_mode": "anthropic_messages"},
|
||||
"openrouter",
|
||||
"m",
|
||||
)
|
||||
assert out["api_key"] == ""
|
||||
assert "api_key" not in out
|
||||
assert "api_mode" not in out
|
||||
|
||||
def test_parse_model_ids_handles_openai_and_bare_shapes(self):
|
||||
"""Model discovery must tolerate the common /v1/models shapes and
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue