host tests: explicitly enter the right room in scripted-command test#4681
host tests: explicitly enter the right room in scripted-command test#4681
Conversation
The matrix-service / room.ts fix from #4621 worked — diagnostic from the next CI flake confirmed _messageCache and matrixRoom on the test's mock_room_1 are fully populated (eventsCount: 10, messagesCount: 2, hasRoomState: true, memberIds includes aibot). But the panel was rendering mock_room_0 (the beforeEach createAndJoinRoom room) instead. Why mock_room_0 qualifies as an AI session room: mock-matrix createRoom auto-invites and joins @AIBot:localhost for any room id that doesn't match the auth-realm prefix. So the beforeEach room and the schedule-meeting room are both in aiSessionRooms, and a stale sessionStorage["currentRoomId"] from a prior test (e.g. OpenAiAssistantRoomCommand racing schedule-meeting and persisting the beforeEach roomId) lands enterRoomInitially on the wrong one. Fix: don't rely on enterRoomInitially's heuristic. Open the panel, then explicitly call aiAssistantPanelService.enterRoom(roomId) with the roomId we sent messages to, and waitFor a settled marker scoped to that specific room (`[data-room-id="${roomId}"][data-room-settled]`) so we fail loudly if the room ever fails to render rather than asserting on whichever Room happened to be in the DOM. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Preview deploymentsHost Test Results 1 files ±0 1 suites ±0 2h 2m 47s ⏱️ - 1m 51s Results for commit 3470548. ± Comparison against earlier commit c1d9927. Realm Server Test Results 1 files ±0 1 suites ±0 17m 48s ⏱️ -9s Results for commit 3470548. ± Comparison against earlier commit c1d9927. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a flaky host acceptance test by removing reliance on the AI assistant panel’s “initial room selection” heuristic and instead explicitly entering the Matrix room that the test sends messages to.
Changes:
- After opening the AI assistant panel, explicitly call
ai-assistant-panel-service.enterRoom(roomId)for the room created by the schedule-meeting flow. - Tighten the test synchronization by waiting for a settled marker scoped to the expected room (
[data-room-id="${roomId}"][data-room-settled]) rather than any room.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The DBAdapter interface gained a notify() method (PR #4672, cs-pg-notify- browser-guard) the same week tests/indexing-event-sink-test.ts was added (CS-10930). Each PR was rebased on a main that didn't see the other, so the merge of both leaves two DBAdapter literals in this test missing the new required method, breaking lint:types in CI for any branch that merges current main. Add async notify() {} to both mock literals (line 18 and line 362). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Acceptance | Commands tests: a scripted command can create a card, update it and show itflaked again on PR #4659 (CI run) — but the diagnostic landed in #4621 made the cause unambiguous.The matrix-service /
room.tsfix from #4621 is working. The roomResource for the test'smock_room_1is fully populated:The problem: the panel rendered the wrong room.
Why mock_room_0 wins the race
tests/helpers/mock-matrix/_server-state.tscreateRoomauto-invites + joins@aibot:localhostfor any roomId that doesn't match the auth-realm prefix. So thebeforeEachcreateAndJoinRoomroom (mock_room_0) qualifies as an AI session room just like the schedule-meeting room (mock_room_1) does.aiSessionRoomscontains both.enterRoomInitially(ai-assistant-panel-service.ts) prefers a persisted roomId fromsessionStorage["currentRoomId"]overlatestRoom. An earlier test in the same module (OpenAiAssistantRoomCommand opens the AI assistant room) clicks[data-test-open-ai-assistant-room-button]while the schedule-meeting click handler is still creatingmock_room_1in the background. IfgetRoomIds().pop()resolves beforemock_room_1exists, it returnsmock_room_0and that gets persisted — andmock_room_0exists fresh in every test (counter resets), so the find succeeds.Fix
Don't rely on the heuristic. Open the panel, then explicitly call
aiAssistantPanelService.enterRoom(roomId)with the roomId we know we sent messages to, andwaitFora settled marker scoped to that specific room ([data-room-id="${roomId}"][data-room-settled]) so the test fails loudly if the right room never renders, instead of asserting on whichever Room happened to be in the DOM.The diagnostic landed in #4621 stays in place — any future flake from a different cause is still fully attributable.
Test plan
OpenAiAssistantRoomCommand opens the AI assistant room) — that one still uses its own pattern and is untouched🤖 Generated with Claude Code