char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
2.3 KiB69 linesraw
1import { MessageRole, MessageType } from '$lib/enums';
2import { DatabaseService } from '$lib/services/database.service';
3import type { ExportedConversation } from '$lib/types/database';
4import { afterEach, describe, expect, it } from 'vitest';
5
6function makeSession(id: string): ExportedConversation {
7	return {
8		conv: { currNode: `${id}-msg`, id, lastModified: 0, name: `Chat ${id}` },
9		messages: [
10			{
11				children: [],
12				content: `hello from ${id}`,
13				convId: id,
14				id: `${id}-msg`,
15				parent: null,
16				role: MessageRole.USER,
17				timestamp: 0,
18				type: MessageType.TEXT
19			}
20		]
21	} as unknown as ExportedConversation;
22}
23
24afterEach(async () => {
25	const conversations = await DatabaseService.getAllConversations();
26
27	await DatabaseService.bulkDeleteConversations(conversations.map((conv) => conv.id));
28});
29
30/**
31 * An import leaves a conversation already in the database untouched, so the
32 * caller needs to know what was written to report it instead of echoing the
33 * selection back at the user.
34 */
35describe('DatabaseService.importConversations', () => {
36	it('reports the conversations it wrote', async () => {
37		const { imported, skipped } = await DatabaseService.importConversations([
38			makeSession('a'),
39			makeSession('b')
40		]);
41
42		expect(imported.map((conv) => conv.id)).toEqual(['a', 'b']);
43		expect(skipped).toEqual([]);
44		expect(await DatabaseService.getConversationMessages('a')).toHaveLength(1);
45	});
46
47	it('reports an existing conversation as skipped and leaves it untouched', async () => {
48		await DatabaseService.importConversations([makeSession('a')]);
49		await DatabaseService.updateConversation('a', { name: 'Renamed locally' });
50
51		const { imported, skipped } = await DatabaseService.importConversations([makeSession('a')]);
52
53		expect(imported).toEqual([]);
54		expect(skipped.map((conv) => conv.id)).toEqual(['a']);
55		expect((await DatabaseService.getConversation('a'))?.name).toBe('Renamed locally');
56	});
57
58	it('imports the new conversations of a partially known selection', async () => {
59		await DatabaseService.importConversations([makeSession('a')]);
60
61		const { imported, skipped } = await DatabaseService.importConversations([
62			makeSession('a'),
63			makeSession('b')
64		]);
65
66		expect(imported.map((conv) => conv.id)).toEqual(['b']);
67		expect(skipped.map((conv) => conv.id)).toEqual(['a']);
68	});
69});