okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
99866a47a
main
1/** A streamed token changes one message. The others must not render again, or a long chat does work (and makes garbage) for every 2* token in proportion to its whole history: measured 0.7 s of main-thread time for a 10-turn reply on a new chat and 1.9 s after ten 3* replies, peak heap 95 MB instead of 50 MB (scripts/chat-growth.mjs). Source guards: the DOM is not available in this suite. */ 4import test from 'node:test' ; 5import assert from 'node:assert/strict' ; 6import { readFileSync } from 'node:fs' ; 7import { resolve } from 'node:path' ; 8 9const chat = readFileSync ( resolve ( import . meta. dirname , '../src/screens/Chat.tsx' ), 'utf8' ); 10 11test ( 'the message row is a memoised component' , () => { 12assert . match ( chat , / import \{ [ ^ } ] * \bmemo\b [ ^ } ] * \} from 'react' / ); 13assert . match ( chat , / const Message = memo\(MessageView\) / ); 14}); 15 16test ( 'the list passes handlers whose identity never changes' , () => { 17assert . match ( chat , / const messageHandlers = useMemo\(\(\) => \(\{ [ \s\S ] * ?\}\), \[\]\) / ); 18for ( const name of [ 'onEditPrompt' , 'onPreview' , 'onOpenTimeSkip' , 'onOpenLink' ]) 19assert . match ( chat , new RegExp ( ` ${ name } =\{messageHandlers\. ${ name } \}` ), name ); 20assert . doesNotMatch ( chat , / onEditPrompt=\{editPrompt\} / ); 21}); 22 23const store = readFileSync ( resolve ( import . meta. dirname , '../src/lib/store.ts' ), 'utf8' ); 24 25test ( 'streamed text and reasoning are applied in groups, and everything else applies what is waiting first' , () => { 26assert . match ( store , / const queueText = \(kind: 'reasoning' \| 'delta', text: string\) / ); 27assert . match ( store , / waitingTimer \?\?= setTimeout\(flushWaiting, 90\) / ); 28// the order of frames the person sees is the order written: a frame of any other kind flushes first 29assert . match ( store , / if \(type === 'delta' \|\| type === 'reasoning'\) \{ queueText\(type, String\(frame\.text \?\? ''\)\); return; \}\s * flushWaiting\(\); / ); 30// a failure or the end of the turn never leaves text behind 31assert . match ( store , / \} catch \(err\) \{\s * flushWaiting\(\); / ); 32assert . match ( store , / \} finally \{\s * flushWaiting\(\); / ); 33});