feat(matrix): land QA follow-ups and refresh docs
- harden Matrix onboarding/chat lifecycle after manual QA - refresh README and Matrix docs to match current behavior - add local ignores for runtime artifacts and include current planning/report docs Closes #7 Closes #9 Closes #14
This commit is contained in:
parent
7fce4c9b3e
commit
6ced154124
35 changed files with 8380 additions and 67 deletions
|
|
@ -3,9 +3,10 @@ from __future__ import annotations
|
|||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from nio.api import RoomVisibility
|
||||
from nio.responses import RoomCreateError
|
||||
|
||||
from adapter.matrix.handlers.chat import make_handle_archive, make_handle_new_chat
|
||||
from adapter.matrix.handlers.chat import make_handle_archive, make_handle_new_chat, make_handle_rename
|
||||
from adapter.matrix.store import set_user_meta
|
||||
from core.auth import AuthManager
|
||||
from core.chat import ChatManager
|
||||
|
|
@ -44,7 +45,14 @@ async def test_mat04_new_chat_calls_room_put_state_with_space_id():
|
|||
)
|
||||
result = await handler(event, auth_mgr, platform, chat_mgr, settings_mgr)
|
||||
|
||||
client.room_create.assert_awaited_once_with(
|
||||
name="Test",
|
||||
visibility=RoomVisibility.private,
|
||||
is_direct=False,
|
||||
invite=["@alice:example.org"],
|
||||
)
|
||||
client.room_put_state.assert_awaited_once()
|
||||
client.room_invite.assert_not_awaited()
|
||||
kwargs = client.room_put_state.call_args.kwargs
|
||||
assert kwargs.get("room_id") == "!space:ex"
|
||||
assert kwargs.get("event_type") == "m.space.child"
|
||||
|
|
@ -79,7 +87,8 @@ async def test_mat05_new_chat_without_space_id_returns_error():
|
|||
async def test_mat10_archive_calls_chat_mgr_archive():
|
||||
platform, store, chat_mgr, auth_mgr, settings_mgr = await _setup()
|
||||
|
||||
handler = make_handle_archive(None, store)
|
||||
client = SimpleNamespace(room_leave=AsyncMock())
|
||||
handler = make_handle_archive(client, store)
|
||||
event = IncomingCommand(
|
||||
user_id="@alice:example.org",
|
||||
platform="matrix",
|
||||
|
|
@ -98,6 +107,61 @@ async def test_mat10_archive_calls_chat_mgr_archive():
|
|||
|
||||
assert len(result) == 1
|
||||
assert "архивирован" in result[0].text
|
||||
client.room_leave.assert_awaited_once_with("!room:ex")
|
||||
chats = await chat_mgr.list_active("@alice:example.org")
|
||||
assert chats == []
|
||||
|
||||
|
||||
async def test_mat11_rename_updates_matrix_room_name_via_state_event():
|
||||
platform, store, chat_mgr, auth_mgr, settings_mgr = await _setup()
|
||||
await chat_mgr.get_or_create(
|
||||
user_id="@alice:example.org",
|
||||
chat_id="C1",
|
||||
platform="matrix",
|
||||
surface_ref="!room:ex",
|
||||
name="Old",
|
||||
)
|
||||
|
||||
client = SimpleNamespace(room_put_state=AsyncMock())
|
||||
handler = make_handle_rename(client, store)
|
||||
event = IncomingCommand(
|
||||
user_id="@alice:example.org",
|
||||
platform="matrix",
|
||||
chat_id="C1",
|
||||
command="rename",
|
||||
args=["New", "Name"],
|
||||
)
|
||||
|
||||
result = await handler(event, auth_mgr, platform, chat_mgr, settings_mgr)
|
||||
|
||||
client.room_put_state.assert_awaited_once_with(
|
||||
room_id="!room:ex",
|
||||
event_type="m.room.name",
|
||||
content={"name": "New Name"},
|
||||
state_key="",
|
||||
)
|
||||
assert len(result) == 1
|
||||
assert "Переименован" in result[0].text
|
||||
|
||||
|
||||
async def test_mat11b_rename_from_unregistered_room_returns_error_message():
|
||||
platform, store, chat_mgr, auth_mgr, settings_mgr = await _setup()
|
||||
|
||||
client = SimpleNamespace(room_put_state=AsyncMock())
|
||||
handler = make_handle_rename(client, store)
|
||||
event = IncomingCommand(
|
||||
user_id="@alice:example.org",
|
||||
platform="matrix",
|
||||
chat_id="unregistered:!old:example.org",
|
||||
command="rename",
|
||||
args=["New"],
|
||||
)
|
||||
|
||||
result = await handler(event, auth_mgr, platform, chat_mgr, settings_mgr)
|
||||
|
||||
client.room_put_state.assert_not_awaited()
|
||||
assert len(result) == 1
|
||||
assert "не найден" in result[0].text.lower() or "примите приглашение" in result[0].text.lower()
|
||||
|
||||
|
||||
async def test_mat12_room_create_error_returns_user_message():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue