From 0232dbb90276fb273f58f4551e3e9520b07d28a4 Mon Sep 17 00:00:00 2001 From: OoO Date: Sat, 2 May 2026 16:13:43 +0800 Subject: [PATCH] test(openclaw): assert /menu returns full main menu keyboard --- tests/test_openclaw_bot_routes_webhook.py | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/test_openclaw_bot_routes_webhook.py b/tests/test_openclaw_bot_routes_webhook.py index d2a5836..bc33037 100644 --- a/tests/test_openclaw_bot_routes_webhook.py +++ b/tests/test_openclaw_bot_routes_webhook.py @@ -56,6 +56,43 @@ def test_openclaw_answer_variants_are_menu_wakeup(): assert bot._looks_like_wakeup_prompt("你好") is True +def test_menu_command_returns_full_main_menu_keyboard(monkeypatch): + from routes import openclaw_bot_routes as bot + from services.openclaw_bot import menu_keyboards + + captured = {} + + def fake_send_message(chat_id, text, reply_to=None, keyboard=None, parse_mode="Markdown", **_kwargs): + captured["chat_id"] = chat_id + captured["text"] = text + captured["keyboard"] = keyboard + captured["parse_mode"] = parse_mode + + monkeypatch.setattr(bot, "send_typing", lambda _chat_id: None) + monkeypatch.setattr(bot, "send_message", fake_send_message) + monkeypatch.setattr(bot, "BOT_USERNAME", "@KnownBot") + monkeypatch.setattr(bot, "_is_authorized", lambda _chat_type, _chat_id, _uid: True) + + app = _build_request_app() + payload = { + "update_id": 10002, + "message": { + "message_id": 56, + "chat": {"id": -200, "type": "supergroup"}, + "from": {"id": 777}, + "text": "/menu", + }, + } + + with app.test_request_context("/bot/telegram/webhook", method="POST", json=payload): + bot.telegram_webhook() + + assert captured["chat_id"] == -200 + assert captured["keyboard"] == menu_keyboards.main_menu_keyboard() + assert captured["parse_mode"] == "Markdown" + assert "OpenClaw(小O)" in captured["text"] + + def test_private_menu_command_is_allowed_when_no_whitelist_and_fallback_enabled(monkeypatch): from routes import openclaw_bot_routes as bot