fix(telegram): register Dream menu commands with Telegram-safe aliases

Use dream_log and dream_restore in Telegram's bot command menu so command registration succeeds, while still accepting the original dream-log and dream-restore forms in chat. Keep the internal command routing unchanged and add coverage for the alias normalization path.
This commit is contained in:
Xubin Ren
2026-04-04 10:31:26 +00:00
parent 549e5ea8e2
commit 7b852506ff
2 changed files with 38 additions and 5 deletions
+23 -2
View File
@@ -189,8 +189,8 @@ async def test_start_creates_separate_pools_with_proxy(monkeypatch) -> None:
assert callable(app.updater.start_polling_kwargs["error_callback"])
assert any(cmd.command == "status" for cmd in app.bot.commands)
assert any(cmd.command == "dream" for cmd in app.bot.commands)
assert any(cmd.command == "dream-log" for cmd in app.bot.commands)
assert any(cmd.command == "dream-restore" for cmd in app.bot.commands)
assert any(cmd.command == "dream_log" for cmd in app.bot.commands)
assert any(cmd.command == "dream_restore" for cmd in app.bot.commands)
@pytest.mark.asyncio
@@ -1009,6 +1009,27 @@ async def test_forward_command_preserves_dream_log_args_and_strips_bot_suffix()
assert handled[0]["content"] == "/dream-log deadbeef"
@pytest.mark.asyncio
async def test_forward_command_normalizes_telegram_safe_dream_aliases() -> None:
channel = TelegramChannel(
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"], group_policy="open"),
MessageBus(),
)
channel._app = _FakeApp(lambda: None)
handled = []
async def capture_handle(**kwargs) -> None:
handled.append(kwargs)
channel._handle_message = capture_handle
update = _make_telegram_update(text="/dream_restore@nanobot_test deadbeef", reply_to_message=None)
await channel._forward_command(update, None)
assert len(handled) == 1
assert handled[0]["content"] == "/dream-restore deadbeef"
@pytest.mark.asyncio
async def test_on_help_includes_restart_command() -> None:
channel = TelegramChannel(