Skip to content

The agent that grows with you

fix(webapp): validate the endpoint the Local / custom wizard submits, not the saved route

Tekniumbdfd425a320b
diff --git a/hermes_cli/web_server_config.py b/hermes_cli/web_server_config.py
index 4c4b453f32f..250354599bb 100644
--- a/hermes_cli/web_server_config.py
+++ b/hermes_cli/web_server_config.py
@@ -497,9 +497,13 @@ def _validated_main_model_selection(
# An explicit endpoint must not resolve through the named custom providers: the legacy
# bare-``custom`` recovery in ``resolve_custom_provider`` would bind the FIRST named entry.
explicit_endpoint = _is_explicit_custom_endpoint(provider, base_url)
+ # The submitted endpoint is seeded as a current bare-``custom`` route so the credential step
+ # keeps it: arriving from another provider it re-resolves ``custom`` from config and would
+ # validate the saved ``model.base_url`` (and its key) instead of the endpoint being saved.
result = switch_model(
raw_input=model, explicit_provider=provider, is_global=True,
- current_provider=str(model_cfg.get("provider") or ""), current_model=str(model_cfg.get("default") or ""),
+ current_provider="custom" if explicit_endpoint else str(model_cfg.get("provider") or ""),
+ current_model=str(model_cfg.get("default") or ""),
current_base_url=base_url if is_bare_custom else str(model_cfg.get("base_url") or ""),
current_api_key=api_key if is_bare_custom else "",
user_providers=cfg.get("providers") if isinstance(cfg.get("providers"), dict) else {},
diff --git a/tests/hermes_cli/test_model_set_explicit_custom_endpoint.py b/tests/hermes_cli/test_model_set_explicit_custom_endpoint.py
index 86d8ba73147..cff6e54a659 100644
--- a/tests/hermes_cli/test_model_set_explicit_custom_endpoint.py
+++ b/tests/hermes_cli/test_model_set_explicit_custom_endpoint.py
@@ -79,3 +79,28 @@ def test_bare_custom_without_url_still_recovers_the_named_provider(isolated_home
_base_url, result = _prepare_main_assignment(load_config(), "custom", "model-a", "", "")
assert (result.target_provider, result.base_url) == ("custom:provider-a", OLD_URL)
+
+
[email protected]("api_key", ["key-b", ""])
+def test_wizard_validation_probes_the_submitted_endpoint_not_the_saved_one(isolated_home, monkeypatch, api_key):
+ """The active named provider's loopback URL sits in ``model.base_url``: validation must probe
+ the submitted endpoint with the submitted key, never the saved route it is about to replace."""
+ from hermes_cli import models_validate
+ from hermes_cli.web_server_config import _apply_model_assignment_sync
+
+ cfg = {"model": {"provider": "custom:provider-a", "default": "model-a", "base_url": OLD_URL,
+ "api_key": "key-a"}, **LAYOUTS["custom_providers_list"]}
+ (isolated_home / "config.yaml").write_text(json.dumps(cfg), encoding="utf-8")
+ probes = []
+
+ def record(model, provider, *, api_key=None, base_url=None, **_kw):
+ probes.append((base_url, api_key))
+ return {"accepted": True, "persist": True, "recognized": True, "message": ""}
+
+ monkeypatch.setattr(models_validate, "validate_requested_model", record)
+ _apply_model_assignment_sync("main", "custom", "model-b", "", NEW_URL, api_key)
+
+ assert probes, "the submitted endpoint was never validated"
+ assert all(url == NEW_URL for url, _ in probes), probes
+ assert all((key or "") in {api_key, "no-key-required"} and key != "key-a" for _, key in probes), probes
+ assert _read(isolated_home)["model"]["base_url"] == NEW_URL