fix: support AI commands in media captions

This commit is contained in:
Azimkin
2026-09-14 14:35:48 +02:00
parent 40e7930e60
commit c6b93c9aa8
6 changed files with 62 additions and 10 deletions

View File

@@ -8,6 +8,32 @@ from app.commands import CommandDispatcher, CommandRegistry
class CommandDispatcherTests(unittest.IsolatedAsyncioTestCase):
async def test_command_in_media_caption_is_dispatched(self) -> None:
registry = CommandRegistry()
handler = AsyncMock()
registry.command("photo", "Caption command")(handler)
dispatcher = CommandDispatcher(registry)
message = SimpleNamespace(
text=None,
caption=".photo argument",
from_user=SimpleNamespace(id=123),
reply_text=AsyncMock(),
)
account = SimpleNamespace(me=SimpleNamespace(id=123), acl_store=None)
handled = await dispatcher.dispatch(
client=SimpleNamespace(),
message=message,
manager=SimpleNamespace(),
account=account,
)
self.assertTrue(handled)
handler.assert_awaited_once()
context = handler.await_args.args[0]
self.assertEqual(context.args, "argument")
self.assertEqual(context.raw_text, ".photo argument")
async def test_unknown_owner_command_is_silent(self) -> None:
dispatcher = CommandDispatcher(CommandRegistry())
message = SimpleNamespace(