The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(profiles): copy launch ${VAR} refs into new profiles, not their values
John Paul Solivac3e78fcb4ed8
diff --git a/tests/tui_gateway/test_profiles_create_env_refs.py b/tests/tui_gateway/test_profiles_create_env_refs.pynew file mode 100644index 00000000000..1b4c6e5a7a9--- /dev/null+++ b/tests/tui_gateway/test_profiles_create_env_refs.py@@ -0,0 +1,42 @@+"""A bot created from the launch profile gets its ``${VAR}`` refs, never their resolved values.++``${VAR}`` refs in ``config.yaml`` resolve against each profile's own ``.env``; copying the+launch profile's LOADED (expanded) config into a new profile wrote the launch secrets into the+new ``config.yaml`` as plaintext, where rotating the key in the bot's ``.env`` no longer applies.+"""++from __future__ import annotations++from pathlib import Path++import tui_gateway.server as server++_SECRETS = {"FAKE_TTS_KEY": "tts-FAKE-111", "FAKE_STT_KEY": "stt-FAKE-222", "FAKE_MCP_TOKEN": "mcp-FAKE-333"}+++def _ok(method: str, params: dict) -> dict:+ resp = server._methods[method](1, params)+ assert "error" not in resp, resp.get("error")+ return resp["result"]+++def test_new_bot_config_keeps_launch_env_refs_not_their_values(tmp_path, monkeypatch):+ home = tmp_path / ".hermes"+ home.mkdir()+ monkeypatch.setattr(Path, "home", lambda: tmp_path)+ monkeypatch.setenv("HERMES_HOME", str(home))+ for name, value in _SECRETS.items():+ monkeypatch.setenv(name, value)+ (home / "config.yaml").write_text(+ "tts:\n provider: elevenlabs\n elevenlabs:\n api_key: ${FAKE_TTS_KEY}\n"+ "stt:\n provider: openai\n openai:\n api_key: ${FAKE_STT_KEY}\n"+ "mcp_servers:\n tracker:\n command: tracker-mcp\n env:\n TRACKER_TOKEN: ${FAKE_MCP_TOKEN}\n",+ encoding="utf-8")++ # The Desktop "New bot" flow: create, then enable a launch-catalog MCP server in the editor.+ _ok("profiles.create", {"name": "scout", "no_alias": True, "no_skills": True})+ _ok("profiles.configure", {"name": "scout", "enabled_mcp_servers": ["tracker"]})++ written = (home / "profiles" / "scout" / "config.yaml").read_text(encoding="utf-8")+ assert {ref: f"${{{ref}}}" in written for ref in _SECRETS} == dict.fromkeys(_SECRETS, True)+ assert [value for value in _SECRETS.values() if value in written] == []diff --git a/tests/tui_gateway/test_profiles_inherit_launch_model.py b/tests/tui_gateway/test_profiles_inherit_launch_model.pyindex 85ca71acfb7..ca3c4d11c37 100644--- a/tests/tui_gateway/test_profiles_inherit_launch_model.py+++ b/tests/tui_gateway/test_profiles_inherit_launch_model.py@@ -17,9 +17,10 @@ def test_inherit_launch_model_carries_a_custom_provider_gateway(monkeypatch, tmphome = tmp_path / ".hermes"home.mkdir()monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setenv("FAKE_GW_TOKEN", "gw-FAKE-111")(home / "config.yaml").write_text("model:\n provider: my-gateway\n default: my-finetune\n"- "providers:\n my-gateway:\n api: https://llm.internal.example.com/v1\n key_env: GW_KEY\n"+ "providers:\n my-gateway:\n api: https://llm.internal.example.com/v1\n key_env: GW_KEY\n api_key: ${FAKE_GW_TOKEN}\n"" unrelated:\n api: https://other.example.com/v1\n")profile = home / "profiles" / "scout"profile.mkdir(parents=True)@@ -29,3 +30,5 @@ def test_inherit_launch_model_carries_a_custom_provider_gateway(monkeypatch, tmpcfg = yaml.safe_load((profile / "config.yaml").read_text())assert (cfg["model"]["provider"], cfg["model"]["default"]) == ("my-gateway", "my-finetune")assert set(cfg["providers"]) == {"my-gateway"}+ # The gateway travels as the launch file wrote it: the ref, never the launch secret.+ assert cfg["providers"]["my-gateway"]["api_key"] == "${FAKE_GW_TOKEN}"diff --git a/tui_gateway/methods_profiles.py b/tui_gateway/methods_profiles.pyindex fee24a421df..d7fce74e65b 100644--- a/tui_gateway/methods_profiles.py+++ b/tui_gateway/methods_profiles.py@@ -474,8 +474,10 @@ def _mirror_voice_sections(path) -> bool:"""Copy stt/tts/voice sections from the launch profile (a fresh profile has only ``model``,so voice fell back to defaults); True if written."""try:- from hermes_cli.config import load_config_readonly, read_user_config_raw, save_config- src_cfg = load_config_readonly() or {}+ from hermes_cli.config import read_user_config_raw, save_config+ # Launch file RAW too: the loaded config has ${VAR} refs expanded, and the new profile+ # must get the ref (resolved against its own .env), never the launch profile's secret.+ src_cfg = read_user_config_raw()sections = {k: src_cfg[k] for k in ("stt", "tts", "voice") if src_cfg.get(k)}if not sections:return False@@ -509,7 +511,8 @@ def _inherit_launch_model(path) -> bool:# A custom `providers:` gateway travels with the model it backs (same seed as the CLI path). It is# written BEFORE the pin: the pin validates the pick inside the new profile, and an empty profile# rejects a provider it has not been told about ("Unknown provider").- custom = _lazy("hermes_cli.profiles", "launch_model_seed")(launch_cfg).get("providers")+ # Seeded from the RAW launch file so a ${VAR} api_key travels as the ref, not its value.+ custom = _lazy("hermes_cli.profiles", "launch_model_seed")(read_user_config_raw()).get("providers")if custom:from hermes_cli.config import load_config, save_configwith _hermes_home_scope(path):@@ -689,7 +692,8 @@ def _configure_cfg_sections(profile_dir, params, applied) -> None:want_mcp = isinstance(params.get("enabled_mcp_servers"), list)launch_mcp = {}if want_mcp: # launch catalog read BEFORE the home override flips config resolution- load_launch = _lazy("hermes_cli.config", "load_config_readonly")+ # RAW: a copied entry keeps its ${VAR} refs instead of the launch profile's expanded secrets.+ load_launch = _lazy("hermes_cli.config", "read_user_config_raw")launch_mcp = _try(lambda: (load_launch() or {}).get("mcp_servers"), {})launch_mcp = launch_mcp if isinstance(launch_mcp, dict) else {}with _hermes_home_scope(profile_dir):