The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): expand ${VAR} env refs in platform adapter config
Konstantin Khlopkov06cafaa7b3d8
diff --git a/gateway/config_loader.py b/gateway/config_loader.pyindex 46fe00fc66c..2c97082b9fb 100644--- a/gateway/config_loader.py+++ b/gateway/config_loader.py@@ -393,6 +393,14 @@ def read_yaml_layers(home: Path) -> dict:with open(config_yaml_path, encoding="utf-8") as f:yaml_cfg = yaml.safe_load(f) or {}+ from hermes_cli.config import _expand_env_vars++ # ${VAR} / ${env:VAR} expansion — the same primitive the CLI loader applies, so platform+ # adapter settings (webhook secret, api_server key, teams credentials) arrive resolved+ # instead of as literal refs. User layer first: the managed overlay is expanded by+ # apply_managed_overlay itself and must not be re-resolved (config_effective._effective order).+ yaml_cfg = _expand_env_vars(yaml_cfg)+# Managed scope: overlay administrator-pinned values (this loader bypasses# hermes_cli.config.load_config, so managed quick_commands / stt would otherwise be ignored).from hermes_cli import managed_scopediff --git a/tests/gateway/test_config.py b/tests/gateway/test_config.pyindex 43777d62440..923aaa89623 100644--- a/tests/gateway/test_config.py+++ b/tests/gateway/test_config.py@@ -255,7 +255,79 @@ class TestGatewayConfigRoundtrip:class TestLoadGatewayConfig:+ def test_platforms_env_refs_expanded_for_adapters(self, tmp_path, monkeypatch):+ """``${VAR}`` refs under ``platforms:`` reach the adapter config expanded — the gateway+ YAML layer expands them the same way the CLI loader does (webhook secret used as the+ HMAC key; api_server caller-auth key)."""+ hermes_home = tmp_path / ".hermes"+ hermes_home.mkdir()+ (hermes_home / "config.yaml").write_text(+ "platforms:\n"+ " webhook:\n"+ " enabled: true\n"+ " port: 8089\n"+ " secret: ${WEBHOOK_SECRET}\n"+ " api_server:\n"+ " enabled: true\n"+ " key: ${env:API_SERVER_KEY}\n",+ encoding="utf-8",+ )++ monkeypatch.setenv("HERMES_HOME", str(hermes_home))+ monkeypatch.setenv("WEBHOOK_SECRET", "whsec-expanded")+ monkeypatch.setenv("API_SERVER_KEY", "server-key-expanded")++ config = load_gateway_config()++ assert config.platforms[Platform.WEBHOOK].extra["secret"] == "whsec-expanded"+ assert (+ config.platforms[Platform.API_SERVER].extra["key"] == "server-key-expanded"+ )++ def test_platforms_env_ref_unresolved_stays_literal(self, tmp_path, monkeypatch):+ """An unset env var keeps the literal placeholder (loader is fail-open; the adapter's+ startup validation is what reports a bad secret)."""+ hermes_home = tmp_path / ".hermes"+ hermes_home.mkdir()+ (hermes_home / "config.yaml").write_text(+ "platforms:\n"+ " webhook:\n"+ " enabled: true\n"+ " secret: ${WEBHOOK_SECRET_UNSET_FOR_TEST}\n",+ encoding="utf-8",+ )++ monkeypatch.setenv("HERMES_HOME", str(hermes_home))+ monkeypatch.delenv("WEBHOOK_SECRET_UNSET_FOR_TEST", raising=False)++ config = load_gateway_config()++ assert (+ config.platforms[Platform.WEBHOOK].extra["secret"]+ == "${WEBHOOK_SECRET_UNSET_FOR_TEST}"+ )++ def test_platforms_plain_values_untouched_by_expansion(self, tmp_path, monkeypatch):+ """Configs without ``${VAR}`` refs load byte-identically through the same path."""+ hermes_home = tmp_path / ".hermes"+ hermes_home.mkdir()+ (hermes_home / "config.yaml").write_text(+ "platforms:\n"+ " webhook:\n"+ " enabled: true\n"+ " port: 8089\n"+ " secret: plain-secret-value\n",+ encoding="utf-8",+ )+ monkeypatch.setenv("HERMES_HOME", str(hermes_home))++ config = load_gateway_config()++ assert (+ config.platforms[Platform.WEBHOOK].extra["secret"] == "plain-secret-value"+ )+ assert config.platforms[Platform.WEBHOOK].extra["port"] == 8089def test_slack_ignored_channels_config_sets_env_bridge(self, tmp_path, monkeypatch):hermes_home = tmp_path / ".hermes"