Merge pull request #1287 from NousResearch/hermes/hermes-cc060dd9

fix(gateway): avoid slash-command crash with GatewayConfig
This commit is contained in:
Teknium 2026-03-14 04:13:56 -07:00 committed by GitHub
commit 02752c83b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 79 additions and 3 deletions

View file

@ -6,6 +6,7 @@ from gateway.config import (
Platform,
PlatformConfig,
SessionResetPolicy,
load_gateway_config,
)
@ -89,15 +90,49 @@ class TestGatewayConfigRoundtrip:
platforms={
Platform.TELEGRAM: PlatformConfig(
enabled=True,
token="tok",
token="tok_123",
home_channel=HomeChannel(Platform.TELEGRAM, "123", "Home"),
),
},
reset_triggers=["/new"],
quick_commands={"limits": {"type": "exec", "command": "echo ok"}},
)
d = config.to_dict()
restored = GatewayConfig.from_dict(d)
assert Platform.TELEGRAM in restored.platforms
assert restored.platforms[Platform.TELEGRAM].token == "tok"
assert restored.platforms[Platform.TELEGRAM].token == "tok_123"
assert restored.reset_triggers == ["/new"]
assert restored.quick_commands == {"limits": {"type": "exec", "command": "echo ok"}}
class TestLoadGatewayConfig:
def test_bridges_quick_commands_from_config_yaml(self, tmp_path, monkeypatch):
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
config_path = hermes_home / "config.yaml"
config_path.write_text(
"quick_commands:\n"
" limits:\n"
" type: exec\n"
" command: echo ok\n",
encoding="utf-8",
)
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
config = load_gateway_config()
assert config.quick_commands == {"limits": {"type": "exec", "command": "echo ok"}}
def test_invalid_quick_commands_in_config_yaml_are_ignored(self, tmp_path, monkeypatch):
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
config_path = hermes_home / "config.yaml"
config_path.write_text("quick_commands: not-a-mapping\n", encoding="utf-8")
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
config = load_gateway_config()
assert config.quick_commands == {}

View file

@ -146,3 +146,20 @@ class TestGatewayQuickCommands:
result = await runner._handle_message(event)
assert result is not None
assert "timed out" in result.lower()
@pytest.mark.asyncio
async def test_gateway_config_object_supports_quick_commands(self):
from gateway.config import GatewayConfig
from gateway.run import GatewayRunner
runner = GatewayRunner.__new__(GatewayRunner)
runner.config = GatewayConfig(
quick_commands={"limits": {"type": "exec", "command": "echo ok"}}
)
runner._running_agents = {}
runner._pending_messages = {}
runner._is_user_authorized = MagicMock(return_value=True)
event = self._make_event("limits")
result = await runner._handle_message(event)
assert result == "ok"