Skip to content

The agent that grows with you

fix(tui): keep a ${VAR} bare-custom endpoint as a ref in the new profile

kshitijk4poordd2db134920a
diff --git a/hermes_cli/web_routers/profiles.py b/hermes_cli/web_routers/profiles.py
index 2e9602929ac..9fd1a6d7a3c 100644
--- a/hermes_cli/web_routers/profiles.py
+++ b/hermes_cli/web_routers/profiles.py
@@ -136,8 +136,8 @@ def _write_profile_model(profile_dir: Path, provider: str, model: str, validate_
through ``get_secret``, which fails closed without a scope and reports the provider as
unconnected (UnscopedSecretError class, #114676).
- ``base_url`` is the endpoint a bare ``custom`` pick binds to (``switch_model`` has nothing else
- to resolve it from in a fresh profile); other providers ignore it."""
+ ``base_url`` is the endpoint a bare ``custom``/``local`` pick binds to (a fresh profile's config
+ names none); other providers ignore it."""
from hermes_cli.config import load_config, save_config
with _config_profile_scope(_scope_profile_name(validate_in or profile_dir)):
provider, model = _normalize_main_model_assignment(provider, model)
diff --git a/tests/tui_gateway/test_profiles_inherit_launch_model.py b/tests/tui_gateway/test_profiles_inherit_launch_model.py
index ffd8b964f19..ae1589dba5e 100644
--- a/tests/tui_gateway/test_profiles_inherit_launch_model.py
+++ b/tests/tui_gateway/test_profiles_inherit_launch_model.py
@@ -96,18 +96,21 @@ def test_inherit_launch_model_carries_a_custom_provider_gateway(
assert copied["api_key"] == "${FAKE_GW_TOKEN}"
-def test_inherit_launch_model_pins_a_bare_custom_endpoint(monkeypatch, tmp_path):
[email protected]("written", ["http://127.0.0.1:11434/v1", "${LAB_URL}"])
+def test_inherit_launch_model_pins_a_bare_custom_endpoint(monkeypatch, tmp_path, written):
home = tmp_path / ".hermes"
home.mkdir()
monkeypatch.setattr(Path, "home", lambda: tmp_path)
monkeypatch.setenv("HERMES_HOME", str(home))
for var in ("CUSTOM_BASE_URL", "OPENAI_BASE_URL"):
monkeypatch.delenv(var, raising=False)
- url = "http://127.0.0.1:11434/v1"
+ monkeypatch.setenv("LAB_URL", "http://127.0.0.1:11434/v1")
+ # Hermetic: the pin probes the endpoint's /models.
+ monkeypatch.setattr("hermes_cli.models.probe_api_models", lambda *a, **k: {"models": ["llama3"]})
atomic_config_write(
home / "config.yaml",
{
- "model": {"provider": "custom", "default": "llama3", "base_url": url},
+ "model": {"provider": "custom", "default": "llama3", "base_url": written},
"_config_version": DEFAULT_CONFIG["_config_version"],
},
)
@@ -122,7 +125,8 @@ def test_inherit_launch_model_pins_a_bare_custom_endpoint(monkeypatch, tmp_path)
assert srv._inherit_launch_model(profile) is True
model = read_user_config_raw(profile / "config.yaml")["model"]
- assert (model["provider"], model["default"], model["base_url"]) == ("custom", "llama3", url)
+ # The launch file's spelling travels: a ${VAR} URL stays a ref, never the launch value.
+ assert (model["provider"], model["default"], model["base_url"]) == ("custom", "llama3", written)
def test_inherit_launch_model_preserves_explicit_profile_selection(
diff --git a/tui_gateway/methods_profiles.py b/tui_gateway/methods_profiles.py
index 9e8328993e3..386f5c10702 100644
--- a/tui_gateway/methods_profiles.py
+++ b/tui_gateway/methods_profiles.py
@@ -529,10 +529,19 @@ def _inherit_launch_model(path) -> bool:
merge = _lazy("hermes_cli.profile_model_seed", "merge_endpoint_seed")
with _hermes_home_scope(path):
save_config(merge(read_user_config_raw(), seed))
- # A bare ``custom`` model is its endpoint: the pin validates it in the empty new profile, where
- # nothing else names that base_url.
+ # Bare ``custom``/``local`` carries its endpoint into validation (the new profile's config names
+ # none); other providers ignore it. Validation needs the expanded URL, the profile keeps the
+ # launch file's spelling so a ${VAR} URL stays a ref.
_pin_profile_model(path, str(model_cfg["provider"]), str(model_cfg["default"]),
str(model_cfg.get("base_url") or ""))
+ raw_url = ((read_user_config_raw() or {}).get("model") or {}).get("base_url")
+ if isinstance(raw_url, str) and "${" in raw_url:
+ from hermes_cli.config import save_config
+ with _hermes_home_scope(path):
+ cfg = read_user_config_raw() or {}
+ if isinstance(cfg.get("model"), dict) and cfg["model"].get("base_url") == model_cfg.get("base_url"):
+ cfg["model"]["base_url"] = raw_url
+ save_config(cfg)
return True