test(01-05): cover matrix confirm flow round trip

- assert room_id is preserved on !yes and !no callbacks
- exercise send_outgoing to confirm and cancel with user+room scope
This commit is contained in:
Mikhail Putilovskij 2026-04-03 12:27:42 +03:00
parent 35695e043f
commit 716dec5dfd
3 changed files with 160 additions and 16 deletions

View file

@ -19,7 +19,8 @@ async def test_mat09_yes_reads_pending_confirm():
await set_pending_confirm(
store,
"C1",
"@alice:example.org",
"!confirm:example.org",
{
"action_id": "delete_file",
"description": "Удалить файл config.yaml",
@ -31,16 +32,16 @@ async def test_mat09_yes_reads_pending_confirm():
event = IncomingCallback(
user_id="@alice:example.org",
platform="matrix",
chat_id="C1",
chat_id="C7",
action="confirm",
payload={"source": "command", "command": "yes"},
payload={"source": "command", "command": "yes", "room_id": "!confirm:example.org"},
)
result = await handler(event, auth_mgr, platform, chat_mgr, settings_mgr)
assert len(result) == 1
assert isinstance(result[0], OutgoingMessage)
assert "Удалить файл config.yaml" in result[0].text
assert await get_pending_confirm(store, "C1") is None
assert await get_pending_confirm(store, "@alice:example.org", "!confirm:example.org") is None
async def test_no_clears_pending_confirm():
@ -52,7 +53,8 @@ async def test_no_clears_pending_confirm():
await set_pending_confirm(
store,
"C1",
"@alice:example.org",
"!confirm:example.org",
{
"action_id": "delete_file",
"description": "Удалить файл",
@ -64,15 +66,15 @@ async def test_no_clears_pending_confirm():
event = IncomingCallback(
user_id="@alice:example.org",
platform="matrix",
chat_id="C1",
chat_id="C7",
action="cancel",
payload={"source": "command", "command": "no"},
payload={"source": "command", "command": "no", "room_id": "!confirm:example.org"},
)
result = await handler(event, auth_mgr, platform, chat_mgr, settings_mgr)
assert len(result) == 1
assert "отменено" in result[0].text.lower()
assert await get_pending_confirm(store, "C1") is None
assert await get_pending_confirm(store, "@alice:example.org", "!confirm:example.org") is None
async def test_yes_without_pending_returns_no_pending():
@ -94,3 +96,35 @@ async def test_yes_without_pending_returns_no_pending():
assert len(result) == 1
assert "Нет ожидающих" in result[0].text
async def test_yes_falls_back_to_legacy_chat_key_without_room_payload():
store = InMemoryStore()
platform = MockPlatformClient()
chat_mgr = ChatManager(platform, store)
auth_mgr = AuthManager(platform, store)
settings_mgr = SettingsManager(platform, store)
await set_pending_confirm(
store,
"legacy-chat",
{
"action_id": "delete_file",
"description": "Legacy confirm",
"payload": {},
},
)
handler = make_handle_confirm(store)
event = IncomingCallback(
user_id="@alice:example.org",
platform="matrix",
chat_id="legacy-chat",
action="confirm",
payload={"source": "command", "command": "yes"},
)
result = await handler(event, auth_mgr, platform, chat_mgr, settings_mgr)
assert len(result) == 1
assert "Legacy confirm" in result[0].text
assert await get_pending_confirm(store, "legacy-chat") is None