feat: label AI-generated conversation messages

This commit is contained in:
jjbrunton committed 2026-08-08 23:23:26 +01:00
1 parent 3beb8aada2
commit 5ad7f1bf77
10 files changed
+69 -11

No files matched your search

+16 -9
View File
@@ -3,6 +3,7 @@ import type { AddressInfo } from 'node:net';
import { afterEach, describe, expect, it, vi } from 'vitest';
import type { WebContext } from '../../src/web/context.js';
import { createConversationsRouter } from '../../src/web/routes/conversations.js';
import { buildConversationState, conversationMessageFingerprint } from '../../src/services/conversation-state.js';
const servers: Array<ReturnType<express.Express['listen']>> = [];
@@ -234,13 +235,14 @@ describe('conversations route', () => {
lastMessageSnippet: 'Hello',
isFromUs: false,
unread: false,
messages: [{
sender: 'alice',
text: 'Hello',
timestamp: 1_786_000_000_000,
isSelf: false,
}],
messages: [
{ sender: 'me', text: 'Automated hello', timestamp: 1_785_999_900_000, isSelf: true },
{ sender: 'alice', text: 'Hello', timestamp: 1_786_000_000_000, isSelf: false },
],
};
const savedState = buildConversationState(conversation.messages);
savedState.automation.turnsUsed = 1;
savedState.automation.aiMessageFingerprints = [conversationMessageFingerprint('Automated hello')];
const refreshTopChats = vi.fn();
const loadConversationDetails = vi.fn();
const context = {
@@ -249,6 +251,7 @@ describe('conversations route', () => {
messages: { getLatestByRecipient: vi.fn().mockReturnValue(undefined) },
},
services: {
conversationState: { get: vi.fn().mockReturnValue(savedState), save: vi.fn() },
chat: {
getSyncStatus: vi.fn().mockReturnValue({
syncing: false,
@@ -270,11 +273,13 @@ describe('conversations route', () => {
const body = await response.json();
expect(body.username).toBe('alice');
expect(body.automation).toEqual({
turnsUsed: 0,
remainingTurns: 3,
turnsUsed: 1,
remainingTurns: 2,
status: 'active',
handoffReason: null,
});
expect(body.messages[0]).toMatchObject({ text: 'Automated hello', isAi: true });
expect(body.messages[1].isAi).toBeUndefined();
expect(refreshTopChats).not.toHaveBeenCalled();
expect(loadConversationDetails).not.toHaveBeenCalled();
});
@@ -310,10 +315,12 @@ describe('conversations route', () => {
const response = await request(app, '/api/conversations/room-alice');
expect(response.status).toBe(200);
expect((await response.json()).triggeringPost).toEqual({
const body = await response.json();
expect(body.triggeringPost).toEqual({
id: 'post-exact', subreddit: 'example', title: 'Exact source post',
url: roomOrigin.postUrl, imageUrl: roomOrigin.postImageUrl, sentAt: 9,
});
expect(body.messages[0]).toMatchObject({ text: 'Hello', isAi: true });
expect(context.repos.messages.getLatestByRecipient).not.toHaveBeenCalled();
});