okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0b3299a01
main
1import test from 'node:test' ; 2import assert from 'node:assert/strict' ; 3import { readFile } from 'node:fs/promises' ; 4import { transform } from 'esbuild' ; 5 6const source = await readFile ( new URL ( '../src/lib/recent-chats.ts' , import . meta. url ), 'utf8' ); 7const { code} = await transform ( source , { loader :'ts' , format :'esm' }); 8const { recentChats, recentChatDescription} = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 9 10test ( 'recent chats use activity order, exclude archives, and leave the source list intact' , () => { 11const sessions = [ 12{ id :'old-pinned' , updatedAt :'2026-10-01' , pinned :true }, 13{ id :'second' , updatedAt :'2026-10-08' }, 14{ id :'archived' , updatedAt :'2026-10-11' , archived :true }, 15{ id :'latest' , updatedAt :'2026-10-10' }, 16{ id :'third' , updatedAt :'2026-10-07' }, 17]; 18const before = structuredClone ( sessions ); 19assert . deepEqual ( recentChats ( sessions ). map ( chat => chat . id ), [ 'latest' , 'second' , 'third' , 'old-pinned' ]); 20assert . deepEqual ( sessions , before ); 21assert . deepEqual ( recentChats ([]), []); 22assert . equal ( recentChats ([ sessions [ 0 ]]). length , 1 ); 23}); 24 25test ( 'chat descriptions show the latest request and handle empty or long conversations' , () => { 26assert . equal ( recentChatDescription ({ messages :[ 27{ role :'user' , content :'First request' }, 28{ role :'user' , content :' Plan\n our weekend ' }, 29{ role :'assistant' , content :'A long reply' }, 30] }), 'Plan our weekend' ); 31assert . equal ( recentChatDescription ({ messages :[] }), 'No messages yet' ); 32assert . equal ( recentChatDescription ({ messages :[{ role :'assistant' , content :'Welcome' }] }), 'Welcome' ); 33const text = recentChatDescription ({ messages :[{ role :'user' , content :'a' . repeat ( 200 ) }] }); 34assert . ok ( text . length <= 160 ); 35assert . ok ( text . endsWith ( '…' )); 36}); 37 38 39test ( 'sidebar includes an older current chat plus the latest five, with stable activity slots' , () => { 40const sessions = Array . from ({ length :8 }, ( _ , i ) => ({ id :String ( i ), updatedAt :`2026-10- ${ String ( 10 - i ). padStart ( 2 , '0' )} ` })); 41assert . deepEqual ( recentChats ( sessions , '7' ). map ( s => s . id ), [ '0' , '1' , '2' , '3' , '4' , '7' ]); 42assert . deepEqual ( recentChats ( sessions , '0' ). map ( s => s . id ), [ '0' , '1' , '2' , '3' , '4' , '5' ]); 43assert . deepEqual ( recentChats ( sessions , '3' ). map ( s => s . id ), [ '0' , '1' , '2' , '3' , '4' , '5' ]); 44assert . equal ( recentChats ( sessions , 'missing' ). length , 5 ); 45sessions [ 7 ]. archived = true ; 46assert . equal ( recentChats ( sessions , '7' ). some ( s => s . id === '7' ), false ); 47});