okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
74e25e165
main
1/** The chat footer's "tok/s · last reply" is the answer-writing speed: the engine's output tokens over the time spent decoding them. */ 2import test , { mock } from 'node:test' ; 3import assert from 'node:assert/strict' ; 4import { TurnProjector } from '../server/agent/events.mjs' ; 5 6const chunk = ( attemptId , c ) => ({ type :'assistant-stream' , frame :{ type :'chunk' , attemptId, chunk :c } }); 7 8/** One model request: `pieces` chunks `gap` ms apart of the given kind, then the engine's usage; tool runs and the wait for the prompt take their own time. */ 9test ( 'writing a big tool call counts as decoding time: 600 tokens over 10 s is 60 tok/s, not hundreds' , () => { 10mock . timers . enable ({ apis :[ 'Date' ], now :1_000_000 }); 11try { 12const p = new TurnProjector ({ startedAt :Date . now () }); 13// the model reads a 30 s prompt first: no chunk yet 14mock . timers . tick ( 30_000 ); 15// it writes a file as a tool call: 100 chunks, 100 ms apart, 600 output tokens in the engine's count 16for ( let i = 0 ; i < 100 ; i ++ ) { 17p . consume ( chunk ( 'a1' , { type :'tool-call-delta' , id :'call-1' , name :'write' , argumentsDelta :'x' . repeat ( 24 ) })); 18mock . timers . tick ( 100 ); 19} 20p . consume ( chunk ( 'a1' , { type :'usage' , usage :{ inputTokens :5000 , outputTokens :600 } })); 21// a short closing sentence 22p . consume ( chunk ( 'a2' , { type :'text-delta' , text :'Done.' })); 23p . consume ({ type :'event' , event :{ seq :9 , time :9 , type :'turn/end' , data :{ reason :{ kind :'completed' } } } }); 24p . ended = { kind :'completed' }; 25const done = p . finish ({ model :'m' , contextMax :32768 }). find ( f => f . type === 'done' ); 26assert . ok ( done . tps >= 55 && done . tps <= 65 , ` ${ done . tps } tok/s` ); 27assert . equal ( done . tokensOut , 600 , "the engine's own count" ); 28} finally { mock . timers . reset (); } 29}); 30 31test ( 'text and reasoning keep their speed, and tool-run time is not decoding time' , () => { 32mock . timers . enable ({ apis :[ 'Date' ], now :2_000_000 }); 33try { 34const p = new TurnProjector ({ startedAt :Date . now () }); 35for ( let i = 0 ; i < 50 ; i ++ ) { p . consume ( chunk ( 'a1' , { type :'reasoning-delta' , text :'think ' })); mock . timers . tick ( 20 ); } 36for ( let i = 0 ; i < 50 ; i ++ ) { p . consume ( chunk ( 'a1' , { type :'text-delta' , text :'word ' })); mock . timers . tick ( 20 ); } 37p . consume ( chunk ( 'a1' , { type :'usage' , usage :{ inputTokens :100 , outputTokens :100 } })); 38mock . timers . tick ( 60_000 ); // a slow command runs: not decoding 39p . ended = { kind :'completed' }; 40const done = p . finish ({}). find ( f => f . type === 'done' ); 41assert . ok ( done . tps >= 45 && done . tps <= 55 , ` ${ done . tps } tok/s` ); 42} finally { mock . timers . reset (); } 43});