okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
a2f602398
main
1/** Owner round 7: live numbers in chat, a steady status line, the subagents counts on the title row, plain Privacy, a round arrow instead of "Latest". */ 2import test from 'node:test' ; 3import assert from 'node:assert/strict' ; 4import { readFile } from 'node:fs/promises' ; 5import { build } from 'esbuild' ; 6import { fileURLToPath } from 'node:url' ; 7 8const src = f => fileURLToPath ( new URL ( `../src/ ${ f } ` , import . meta. url )); 9const read = f => readFile ( src ( f ), 'utf8' ); 10async function load ( file ) { 11const result = await build ({ entryPoints :[ src ( `lib/ ${ file } ` )], bundle :true , format :'esm' , platform :'node' , write :false , alias :{ react :fileURLToPath ( new URL ( './helpers/react-stub.mjs' , import . meta. url )) }, logLevel :'silent' , loader :{ '.json' :'json' } }); 12return import ( `data:text/javascript;base64, ${ Buffer . from ( result . outputFiles [ 0 ]. text ). toString ( 'base64' )} ` ); 13} 14globalThis . window ??= globalThis ; globalThis . localStorage ??= { getItem :() => null , setItem :() => {} }; 15globalThis . navigator ??= { language :'en' }; 16const { tweenValue, easeOutCubic} = await load ( 'tween.ts' ); 17const { chatMetrics} = await load ( 'chat-metrics.ts' ); 18 19test ( 'item 5: a number travels between two readings in a short ease-out, never past them' , () => { 20assert . equal ( tweenValue ( 40 , 50 , 0 , 600 ), 40 ); 21assert . equal ( tweenValue ( 40 , 50 , 600 , 600 ), 50 ); 22assert . ok ( tweenValue ( 40 , 50 , 150 , 600 ) > 40 && tweenValue ( 40 , 50 , 150 , 600 ) < 50 ); 23assert . ok ( tweenValue ( 50 , 40 , 150 , 600 ) < 50 && tweenValue ( 50 , 40 , 150 , 600 ) > 40 , 'down as well as up' ); 24assert . equal ( tweenValue ( NaN , 7 , 100 , 600 ), 7 ); assert . equal ( tweenValue ( 1 , 2 , 0 , 0 ), 2 ); 25assert . ok ( easeOutCubic ( 0.5 ) > 0.5 , 'fast at first, settling at the end' ); 26}); 27 28const reply = ( extra = {}) => ({ role :'assistant' , at :new Date ( 1_000_000 ). toISOString (), content :'x' , ...extra }); 29test ( 'item 5: during a goal the chat follows the Monitor even though the engine names another session' , () => { 30const session = { id :'chat-a' , statsAvailable :true , tokensIn :5000 , tokensOut :400 , messages :[{ role :'user' , content :'goal' }, reply ({ inputTokens :5000 , tokens :400 , tps :41 , contextMax :65536 , durationMs :9000 , reasoningMs :3000 }), reply ({ streaming :true , tokens :120 , inputTokens :5200 , reasoningStartedAt :1_070_000 })] }; 31const monitor = { phase :'generating' , outputTps :47.4 , context :{ sessionId :'harness-xyz' , usedTokens :9100 , maxTokens :65536 } }; 32const m = chatMetrics ( session , monitor , 65536 , 1_100_000 ); 33assert . equal ( m . speed , 47.4 , 'the live speed comes from the Monitor' ); 34assert . equal ( m . used , 9100 , 'and so does the context in use' ); 35assert . equal ( m . llmMs , 9000 + 100_000 , 'a reply being written counts its running time' ); 36assert . equal ( m . thinkMs , 3000 + 30_000 ); 37assert . equal ( m . writeMs , 9000 + 100_000 - 33_000 ); 38assert . equal ( m . total , 5000 + 400 + 120 + 5200 ); 39// an idle engine does not move a finished chat's numbers 40const idle = chatMetrics ({ ...session , messages :session . messages . slice ( 0 , 2 ) }, { phase :'idle' , outputTps :0 , context :{ sessionId :'harness-xyz' , usedTokens :1 , maxTokens :2 } }, 65536 , 1_100_000 ); 41assert . equal ( idle . speed , 41 ); assert . notEqual ( idle . used , 1 ); 42}); 43 44test ( 'item 10 / GUI-FB2 item 7: the status line is a wrapping flex row with no fixed widths, so a long time or count never runs into its neighbour' , async () => { 45const css = await read ( 'styles/app.css' ), line = await read ( 'components/StatusLine.tsx' ); 46assert . match ( css , / \.live-status \{ display: flex; flex-wrap: wrap; / ); 47assert . doesNotMatch ( css , / \.live-status \{ [ ^ } ] * grid-template-columns / ); 48assert . doesNotMatch ( css , / \.live-status [ ^ { ] * \{ [ ^ } ] * \b6ch\b / , 'no fixed column for the time' ); 49assert . match ( css , / \.live-status__verb \{ flex: 0 1 24ch; min-width: 0; / , 'the word gives way first' ); 50assert . match ( css , / \.live-status__time, \.live-status__tokens \{ flex: none; font-variant-numeric: tabular-nums / ); 51assert . match ( line , / live-status__verb / ); assert . match ( line , / live-status__time / ); assert . match ( line , / live-status__tokens / ); 52}); 53 54test ( 'items 15, 16, 17: counts on the Subagents title row, Privacy as plain text, a round arrow' , async () => { 55const bar = await read ( 'components/ChatToolbar.tsx' ), pop = await read ( 'components/Popover.tsx' ), privacy = await read ( 'components/PrivacyNotes.tsx' ), chat = await read ( 'screens/Chat.tsx' ); 56assert . match ( bar , / title=\{tr\(session\?\.agents\?\.length \? "Subagents" : "No subagents recorded"\)\} detail=\{ / ); assert . ok ( ! /subagents-overview-summary / . test ( bar ), 'no second line of counts' ); 57assert . match ( pop , / telepop__detail / ); 58assert . ok ( ! /Icon / . test ( privacy ), 'no icons in Privacy' ); 59assert . ok ( ! />\{tr\("Latest"\)\}< / . test ( chat ) && ( chat . match ( / aria-label=\{tr\("Scroll to the latest message"\)\} / g ) ?? []). length === 2 , 'the Latest button is a round arrow' ); 60});