feat(assistant): chat, note and poll cards drawn like the Collab tab

This commit is contained in:
Maurice
2026-10-22 15:50:51 +02:00
parent b4e188fbfc
commit 6e92c2777c
63 changed files with 5147 additions and 251 deletions
+62 -1
View File
@@ -16,7 +16,7 @@ import { countRows, findRow, updateRows } from '../../helpers/factories/rows';
import { FakeRealtimeService } from '../../helpers/fake-realtime';
import { createMcpHarness, parseToolResult, parseResourceResult, type McpHarness } from '../../helpers/mcp-harness';
import { bootTestApp } from '../../helpers/test-app';
import { resetTestDb } from '../../helpers/test-db';
import { resetTestDb, setCollabFeature } from '../../helpers/test-db';
import { createTestOrm, type TestOrm } from '../../helpers/test-orm';
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
@@ -825,3 +825,64 @@ describe('create_collab_note, as the Collab tab posts it', () => {
}
});
});
describe('Tool: list_collab_notes', () => {
interface ListedNote {
id: number;
title: string;
username: string;
pinned: number | null;
attachments: unknown[];
}
async function listNotes(userId: number, tripId: number) {
let listed: { isError?: unknown; data: unknown } = { data: null };
await withHarness(userId, async (h) => {
const result = await h.client.callTool({ name: 'list_collab_notes', arguments: { tripId } });
listed = { isError: result.isError, data: result.isError ? null : parseToolResult(result) };
});
return listed;
}
it('MCP-COLLAB-010: lists the notes of the trip, pinned first, with their author and files', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
createCollabNote(testDb, trip.id, user.id, { title: 'Ideas' });
const pinned = createCollabNote(testDb, trip.id, user.id, { title: 'Restaurants' });
await updateRows(orm, CollabNotes, { id: pinned.id }, { pinned: 1 });
const { isError, data } = await listNotes(user.id, trip.id);
expect(isError).not.toBe(true);
const notes = (data as { notes: ListedNote[] }).notes;
expect(notes.map((note) => note.title)).toEqual(['Restaurants', 'Ideas']);
expect(notes[0]).toMatchObject({ id: pinned.id, pinned: 1, username: user.username, attachments: [] });
});
it('MCP-COLLAB-011: refuses a trip the user is not part of, and reads nothing', async () => {
const { user } = createUser(testDb);
const { user: owner } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
createCollabNote(testDb, trip.id, owner.id, { title: 'Private' });
const { isError, data } = await listNotes(user.id, trip.id);
expect(isError).toBe(true);
expect(data).toBeNull();
});
it('MCP-COLLAB-012: is a read, offered only while the notes are switched on', async () => {
const { user } = createUser(testDb);
const names = async () => {
const h = await createMcpHarness({ realtime, userId: user.id, withResources: false });
try {
return (await h.client.listTools()).tools.map((tool) => [tool.name, tool.annotations?.readOnlyHint]);
} finally {
await h.cleanup();
}
};
expect(await names()).toContainEqual(['list_collab_notes', true]);
setCollabFeature(testDb, 'notes', false);
try {
expect((await names()).map(([name]) => name)).not.toContain('list_collab_notes');
} finally {
setCollabFeature(testDb, 'notes', true);
}
});
});