This commit is contained in:
Junassi 2026-04-24 17:24:22 -05:00 committed by GitHub
commit 2ca09ccf8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 3 deletions

View file

@ -3818,11 +3818,11 @@ class GatewayRunner:
target = qcmd.get("target", "").strip()
if target:
target = target if target.startswith("/") else f"/{target}"
target_command = target.lstrip("/")
user_args = event.get_command_args().strip()
event.text = f"{target} {user_args}".strip()
command = target_command
# Fall through to normal command dispatch below
# Re-dispatch so aliased built-ins follow the same
# command path as if the user had typed the target.
return await self._handle_message(event)
else:
return f"Quick command '/{command}' has no target defined."
else:

View file

@ -4,6 +4,10 @@ from unittest.mock import MagicMock, patch, AsyncMock
from rich.text import Text
import pytest
from gateway.config import Platform
from gateway.platforms.base import MessageEvent, MessageType
from gateway.session import SessionSource
# ── CLI tests ──────────────────────────────────────────────────────────────
@ -205,3 +209,38 @@ class TestGatewayQuickCommands:
event = self._make_event("limits")
result = await runner._handle_message(event)
assert result == "ok"
@pytest.mark.asyncio
async def test_alias_command_re_dispatches_to_builtin_handler(self):
from gateway.run import GatewayRunner
runner = GatewayRunner.__new__(GatewayRunner)
runner.config = {"quick_commands": {"shortcut": {"type": "alias", "target": "/help"}}}
runner._running_agents = {}
runner._running_agents_ts = {}
runner._busy_ack_ts = {}
runner._pending_messages = {}
runner._pending_approvals = {}
runner._is_user_authorized = MagicMock(return_value=True)
runner._handle_help_command = AsyncMock(side_effect=lambda ev: ev.text)
runner._handle_message_with_agent = AsyncMock(return_value="agent")
runner.hooks = MagicMock()
runner.hooks.emit = AsyncMock()
event = MessageEvent(
text="/shortcut extra args",
message_type=MessageType.TEXT,
source=SessionSource(
platform=Platform.TELEGRAM,
user_id="test_user",
user_name="Test User",
chat_id="123",
chat_type="dm",
),
)
result = await runner._handle_message(event)
assert result == "/help extra args"
runner._handle_help_command.assert_awaited_once()
runner._handle_message_with_agent.assert_not_awaited()