okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c5755ed83
main
1/** Item 7: the tuner's stage names map onto the five steps shown, and the speeds it reports become the live readout. */ 2import test from 'node:test' ; 3import assert from 'node:assert/strict' ; 4import { readFile } from 'node:fs/promises' ; 5import { transform } from 'esbuild' ; 6 7const { code} = await transform ( await readFile ( new URL ( '../src/lib/tune-phase.ts' , import . meta. url ), 'utf8' ), { loader :'ts' , format :'esm' }); 8const { tunePhase, tuneSpeeds} = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 9 10test ( 'every stage the tuner reports lands on one of the five steps, in order' , () => { 11assert . deepEqual ([ 'start' , 'waiting' , undefined , null ]. map ( tunePhase ), [ 0 , 0 , 0 , 0 ], 'checking the PC, also while it waits for a quiet PC' ); 12assert . equal ( tunePhase ( 'base' ), 1 ); 13assert . deepEqual ([ 'plan' , 'rounds' , 'drift' , 'per_request' ]. map ( tunePhase ), [ 2 , 2 , 2 , 2 ]); 14assert . equal ( tunePhase ( 'confirm' ), 3 ); 15assert . equal ( tunePhase ( 'done' ), 4 ); 16assert . equal ( tunePhase ( 'something new' ), 0 , 'an unknown stage never breaks the page' ); 17}); 18 19test ( 'the speeds are what the tuner measured, base first, and nothing invented' , () => { 20assert . deepEqual ( tuneSpeeds ( undefined ), []); 21assert . deepEqual ( tuneSpeeds ({ stage :'rounds' }), []); 22const speeds = tuneSpeeds ({ stage :'rounds' , speeds :[{ label :'base' , tok_s :41.2 }, { label :'More experts in memory' , tok_s :46.8 }, { label :'bad' , tok_s :0 }, { label :'worse' , tok_s :'x' }] }); 23assert . deepEqual ( speeds , [{ label :'base' , tok_s :41.2 }, { label :'More experts in memory' , tok_s :46.8 }]); 24});