test(01-06): harden matrix room-vs-chat regressions
- Seed invite tests with explicit next_chat_index progression instead of C1 assumptions - Separate Matrix room ids from logical chat ids in dispatcher coverage - Verify the full Matrix adapter suite against the tightened assertions
This commit is contained in:
parent
3e06a67e24
commit
9cdb6118e9
2 changed files with 25 additions and 14 deletions
|
|
@ -12,28 +12,30 @@ from sdk.mock import MockPlatformClient
|
|||
|
||||
async def test_matrix_dispatcher_registers_custom_handlers():
|
||||
runtime = build_runtime(platform=MockPlatformClient())
|
||||
current_chat_id = "C9"
|
||||
|
||||
start = IncomingCommand(user_id="u1", platform="matrix", chat_id="C1", command="start")
|
||||
start = IncomingCommand(user_id="u1", platform="matrix", chat_id=current_chat_id, command="start")
|
||||
await runtime.dispatcher.dispatch(start)
|
||||
|
||||
new = IncomingCommand(
|
||||
user_id="u1", platform="matrix", chat_id="C1", command="new", args=["Research"]
|
||||
user_id="u1", platform="matrix", chat_id=current_chat_id, command="new", args=["Research"]
|
||||
)
|
||||
result = await runtime.dispatcher.dispatch(new)
|
||||
assert any(isinstance(r, OutgoingMessage) and "Research" in r.text for r in result)
|
||||
|
||||
chats = await runtime.chat_mgr.list_active("u1")
|
||||
assert [c.chat_id for c in chats] == ["C1"]
|
||||
assert [c.surface_ref for c in chats] == [current_chat_id]
|
||||
|
||||
new2 = IncomingCommand(
|
||||
user_id="u1", platform="matrix", chat_id="C1", command="new", args=["Ops"]
|
||||
user_id="u1", platform="matrix", chat_id=current_chat_id, command="new", args=["Ops"]
|
||||
)
|
||||
await runtime.dispatcher.dispatch(new2)
|
||||
chats = await runtime.chat_mgr.list_active("u1")
|
||||
assert [c.chat_id for c in chats] == ["C1", "C2"]
|
||||
|
||||
skills = IncomingCommand(
|
||||
user_id="u1", platform="matrix", chat_id="C1", command="settings_skills"
|
||||
user_id="u1", platform="matrix", chat_id=current_chat_id, command="settings_skills"
|
||||
)
|
||||
result = await runtime.dispatcher.dispatch(skills)
|
||||
assert any(isinstance(r, OutgoingMessage) and "!skill on/off" in r.text for r in result)
|
||||
|
|
@ -56,15 +58,15 @@ async def test_new_chat_creates_real_matrix_room_when_client_available():
|
|||
room_invite=AsyncMock(),
|
||||
)
|
||||
runtime = build_runtime(platform=MockPlatformClient(), client=client)
|
||||
await set_user_meta(runtime.store, "u1", {"space_id": "!space:example", "next_chat_index": 1})
|
||||
await set_user_meta(runtime.store, "u1", {"space_id": "!space:example", "next_chat_index": 7})
|
||||
|
||||
start = IncomingCommand(user_id="u1", platform="matrix", chat_id="C1", command="start")
|
||||
start = IncomingCommand(user_id="u1", platform="matrix", chat_id="C3", command="start")
|
||||
await runtime.dispatcher.dispatch(start)
|
||||
|
||||
new = IncomingCommand(
|
||||
user_id="u1",
|
||||
platform="matrix",
|
||||
chat_id="C1",
|
||||
chat_id="C3",
|
||||
command="new",
|
||||
args=["Research"],
|
||||
)
|
||||
|
|
@ -75,12 +77,14 @@ async def test_new_chat_creates_real_matrix_room_when_client_available():
|
|||
put_call = client.room_put_state.call_args
|
||||
assert put_call.kwargs.get("room_id") == "!space:example" or put_call.args[0] == "!space:example"
|
||||
chats = await runtime.chat_mgr.list_active("u1")
|
||||
assert [c.chat_id for c in chats] == ["C7"]
|
||||
assert [c.surface_ref for c in chats] == ["!r2:example"]
|
||||
assert any(isinstance(r, OutgoingMessage) and "Research" in r.text for r in result)
|
||||
|
||||
|
||||
async def test_invite_event_creates_space_and_chat_room():
|
||||
runtime = build_runtime(platform=MockPlatformClient())
|
||||
await set_user_meta(runtime.store, "@alice:example.org", {"next_chat_index": 4})
|
||||
space_resp = SimpleNamespace(room_id="!space:example.org")
|
||||
chat_resp = SimpleNamespace(room_id="!chat1:example.org")
|
||||
client = SimpleNamespace(
|
||||
|
|
@ -111,10 +115,11 @@ async def test_invite_event_creates_space_and_chat_room():
|
|||
|
||||
room_meta = await get_room_meta(runtime.store, "!chat1:example.org")
|
||||
assert room_meta is not None
|
||||
assert room_meta["chat_id"] == "C1"
|
||||
assert room_meta["chat_id"] == "C4"
|
||||
assert room_meta["space_id"] == "!space:example.org"
|
||||
|
||||
assert await runtime.auth_mgr.is_authenticated("@alice:example.org") is True
|
||||
assert user_meta.get("next_chat_index") == 5
|
||||
client.room_send.assert_awaited_once()
|
||||
|
||||
|
||||
|
|
@ -155,11 +160,14 @@ async def test_bot_ignores_its_own_messages():
|
|||
|
||||
async def test_mat11_settings_returns_dashboard():
|
||||
runtime = build_runtime(platform=MockPlatformClient())
|
||||
current_chat_id = "C9"
|
||||
|
||||
start = IncomingCommand(user_id="u1", platform="matrix", chat_id="C1", command="start")
|
||||
start = IncomingCommand(user_id="u1", platform="matrix", chat_id=current_chat_id, command="start")
|
||||
await runtime.dispatcher.dispatch(start)
|
||||
|
||||
settings_cmd = IncomingCommand(user_id="u1", platform="matrix", chat_id="C1", command="settings")
|
||||
settings_cmd = IncomingCommand(
|
||||
user_id="u1", platform="matrix", chat_id=current_chat_id, command="settings"
|
||||
)
|
||||
result = await runtime.dispatcher.dispatch(settings_cmd)
|
||||
|
||||
assert len(result) >= 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue