okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221apps/host: the owner's UI and the Node App Host0b3299a01

main
2.5 KiB47 linesraw
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', () => {
11  const 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  ];
18  const before = structuredClone(sessions);
19  assert.deepEqual(recentChats(sessions).map(chat => chat.id), ['latest', 'second', 'third', 'old-pinned']);
20  assert.deepEqual(sessions, before);
21  assert.deepEqual(recentChats([]), []);
22  assert.equal(recentChats([sessions[0]]).length, 1);
23});
24
25test('chat descriptions show the latest request and handle empty or long conversations', () => {
26  assert.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');
31  assert.equal(recentChatDescription({ messages: [] }), 'No messages yet');
32  assert.equal(recentChatDescription({ messages: [{ role: 'assistant', content: 'Welcome' }] }), 'Welcome');
33  const text = recentChatDescription({ messages: [{ role: 'user', content: 'a'.repeat(200) }] });
34  assert.ok(text.length <= 160);
35  assert.ok(text.endsWith('…'));
36});
37
38
39test('sidebar includes an older current chat plus the latest five, with stable activity slots', () => {
40  const sessions = Array.from({ length: 8 }, (_, i) => ({ id: String(i), updatedAt: `2026-10-${String(10-i).padStart(2, '0')}` }));
41  assert.deepEqual(recentChats(sessions, '7').map(s => s.id), ['0','1','2','3','4','7']);
42  assert.deepEqual(recentChats(sessions, '0').map(s => s.id), ['0','1','2','3','4','5']);
43  assert.deepEqual(recentChats(sessions, '3').map(s => s.id), ['0','1','2','3','4','5']);
44  assert.equal(recentChats(sessions, 'missing').length, 5);
45  sessions[7].archived = true;
46  assert.equal(recentChats(sessions, '7').some(s => s.id === '7'), false);
47});