Fix missed conversation replies

This commit is contained in:
jjbrunton committed 2026-08-09 16:56:25 +01:00
1 parent 70c156e1f7
commit dc3fc6373b
4 files changed
+68 -18

No files matched your search

+32 -3
View File
@@ -179,7 +179,7 @@ describe('conversation automation', () => {
const older = { ...incoming(1), username: 'older', roomId: 'room-older', url: '/room/older' };
chat.getCachedConversations.mockResolvedValue([newer, older]);
await service.processUnreadConversations();
await service.processPendingConversations();
expect(chat.refreshTopChats).toHaveBeenCalledWith(25);
expect(chat.sendChatMessage.mock.calls.map(([url]) => url)).toEqual(['/room/older', '/room/newer']);
@@ -190,7 +190,7 @@ describe('conversation automation', () => {
chat.getCachedConversations.mockResolvedValue([incoming(1)]);
expect(await service.hasActionableReplies()).toBe(true);
await service.processUnreadConversations();
await service.processPendingConversations();
expect(await service.hasActionableReplies()).toBe(false);
expect(service.getPriorityStatus()).toMatchObject({
@@ -215,6 +215,35 @@ describe('conversation automation', () => {
);
});
it('processes a durable inbound event even when Matrix reports the room as read', async () => {
const { service, chat, claims } = harness();
const conversation = { ...incoming(501), unread: false };
chat.getCachedConversations.mockResolvedValue([]);
await service.processPendingConversations();
chat.getCachedConversations.mockResolvedValue([conversation]);
expect(await service.hasActionableReplies()).toBe(true);
await service.processPendingConversations();
expect(claims.tryClaim).toHaveBeenCalledWith(
'room-alice',
'in-501',
'Would you be comfortable sharing a selfie?',
1_003,
);
expect(chat.sendChatMessage).toHaveBeenCalledOnce();
});
it('does not revive a historical read conversation on the first scan after startup', async () => {
const { service, chat, claims } = harness();
chat.getCachedConversations.mockResolvedValue([{ ...incoming(1), unread: false }]);
await service.processPendingConversations();
expect(claims.tryClaim).not.toHaveBeenCalled();
expect(chat.sendChatMessage).not.toHaveBeenCalled();
});
it('retries the same durable reply after an interrupted send', async () => {
const { service, chat, ai, claims } = harness();
chat.sendChatMessage.mockRejectedValueOnce(new Error('interrupted'));
@@ -269,7 +298,7 @@ describe('conversation automation', () => {
claims.listPending.mockReturnValue([pending] as never);
chat.getCachedConversations.mockResolvedValue([conversation]);
await service.processUnreadConversations();
await service.processPendingConversations();
expect(claims.markSent).toHaveBeenCalledWith('room-alice', 'in-1');
expect(chat.sendChatMessage).not.toHaveBeenCalled();