char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
92d1bb0c9
char/aliceai-t5-moe
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 { 7return { 8conv :{ currNode :` ${ id } -msg` , id, lastModified :0 , name :`Chat ${ id } ` }, 9messages :[ 10{ 11children :[], 12content :`hello from ${ id } ` , 13convId :id , 14id :` ${ id } -msg` , 15parent :null , 16role :MessageRole . USER , 17timestamp :0 , 18type :MessageType . TEXT 19} 20] 21} as unknown as ExportedConversation ; 22} 23 24afterEach ( async () => { 25const conversations = await DatabaseService . getAllConversations (); 26 27await 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' , () => { 36it ( 'reports the conversations it wrote' , async () => { 37const { imported, skipped} = await DatabaseService . importConversations ([ 38makeSession ( 'a' ), 39makeSession ( 'b' ) 40]); 41 42expect ( imported . map (( conv ) => conv . id )). toEqual ([ 'a' , 'b' ]); 43expect ( skipped ). toEqual ([]); 44expect ( await DatabaseService . getConversationMessages ( 'a' )). toHaveLength ( 1 ); 45}); 46 47it ( 'reports an existing conversation as skipped and leaves it untouched' , async () => { 48await DatabaseService . importConversations ([ makeSession ( 'a' )]); 49await DatabaseService . updateConversation ( 'a' , { name :'Renamed locally' }); 50 51const { imported, skipped} = await DatabaseService . importConversations ([ makeSession ( 'a' )]); 52 53expect ( imported ). toEqual ([]); 54expect ( skipped . map (( conv ) => conv . id )). toEqual ([ 'a' ]); 55expect (( await DatabaseService . getConversation ( 'a' ))?. name ). toBe ( 'Renamed locally' ); 56}); 57 58it ( 'imports the new conversations of a partially known selection' , async () => { 59await DatabaseService . importConversations ([ makeSession ( 'a' )]); 60 61const { imported, skipped} = await DatabaseService . importConversations ([ 62makeSession ( 'a' ), 63makeSession ( 'b' ) 64]); 65 66expect ( imported . map (( conv ) => conv . id )). toEqual ([ 'b' ]); 67expect ( skipped . map (( conv ) => conv . id )). toEqual ([ 'a' ]); 68}); 69});