chore: 0.0.1a8 release#26
Conversation
There was a problem hiding this comment.
Code Review
This pull request bumps the version to 0.0.1a8 and adds integration tests for WhatsApp DM replay flows to achieve test parity with the TypeScript SDK. Feedback on the new tests indicates that several test cases are currently ineffective: one test is a no-op that fails to trigger a webhook event, another is tautological as it only verifies mock behavior against its own constants, and the history persistence test lacks the necessary configuration and assertions to verify that messages are actually stored.
| async def test_ignores_status_update_webhooks(self): | ||
| """Status update webhooks do not trigger any handler.""" | ||
| whatsapp = create_mock_adapter("whatsapp") | ||
| chat, adapters, state = await create_chat(adapters={"whatsapp": whatsapp}) | ||
| captured: list[Message] = [] | ||
|
|
||
| @chat.on_direct_message | ||
| async def handler(thread, message, channel=None, context=None): | ||
| captured.append(message) | ||
|
|
||
| # Status updates are typically filtered at the adapter level. | ||
| # We verify no handler fires for a non-message event by simply | ||
| # not sending anything. The adapter should filter status updates. | ||
| assert len(captured) == 0 |
There was a problem hiding this comment.
This test is currently a no-op and does not verify the behavior it claims to. It asserts that the captured list is empty without ever triggering an incoming message or webhook event. To properly test that status updates are ignored, the test should invoke the adapter's webhook handling logic with a status update payload (e.g., using the statusUpdate fixture from whatsapp.json) and then verify that the direct message handler was not triggered.
| async def test_dm_thread_is_identified_as_dm(self): | ||
| """WhatsApp DM thread is identified as a DM.""" | ||
| whatsapp = create_mock_adapter("whatsapp") | ||
| # MockAdapter.is_dm checks for ":D" in thread_id | ||
| assert whatsapp.is_dm(DM_THREAD_ID) is True |
There was a problem hiding this comment.
This test is tautological as it verifies the MockAdapter implementation using a constant (DM_THREAD_ID) specifically designed to pass that check. It does not exercise any SDK logic or the actual WhatsApp adapter. Consider removing this test or refactoring it to verify how the Chat orchestrator handles threads identified as DMs.
| async def test_message_history_persistence(self): | ||
| """Multiple messages in same thread build up history.""" | ||
| whatsapp = create_mock_adapter("whatsapp") | ||
| chat, adapters, state = await create_chat(adapters={"whatsapp": whatsapp}) | ||
| captured: list[Message] = [] | ||
|
|
||
| @chat.on_direct_message | ||
| async def handler(thread, message, channel=None, context=None): | ||
| captured.append(message) | ||
| await thread.post(f"Echo: {message.text}") | ||
|
|
||
| msg1 = create_msg( | ||
| "First message", | ||
| msg_id="wa-hist-1", | ||
| user_id=USER_PHONE, | ||
| thread_id=DM_THREAD_ID, | ||
| ) | ||
| await chat.handle_incoming_message(whatsapp, DM_THREAD_ID, msg1) | ||
|
|
||
| msg2 = create_msg( | ||
| "Second message", | ||
| msg_id="wa-hist-2", | ||
| user_id=USER_PHONE, | ||
| thread_id=DM_THREAD_ID, | ||
| ) | ||
| await chat.handle_incoming_message(whatsapp, DM_THREAD_ID, msg2) | ||
|
|
||
| assert len(captured) == 2 | ||
| # Both replies sent | ||
| assert len(whatsapp._post_calls) == 2 |
There was a problem hiding this comment.
This test fails to verify message history persistence. It only checks that two messages are processed sequentially. Additionally, MockAdapter.persist_message_history is None by default, so the orchestrator will not record history in this context. To fix this, set whatsapp.persist_message_history = True and verify the stored history using await thread.refresh() followed by an assertion on thread.recent_messages, or by iterating through the thread.messages() async iterator.
3,106 tests. Full TS test parity.