okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
1631a9fde
main
1import test from 'node:test' ; 2import assert from 'node:assert/strict' ; 3import { readFile } from 'node:fs/promises' ; 4import { build } from 'esbuild' ; 5 6const bundled = await build ({ entryPoints :[ 'src/lib/loop.ts' ], bundle :true , write :false , format :'esm' , platform :'node' , loader :{ '.json' :'json' } }); 7const { parseLoop, loopEvery, LOOP_MIN_MS } = await import ( `data:text/javascript;base64, ${ Buffer . from ( bundled . outputFiles [ 0 ]. text ). toString ( 'base64' )} ` ); 8 9test ( '/loop reads how often, then what to do' , () => { 10assert . deepEqual ( parseLoop ( '/loop 10m check the build' ), { kind :'start' , everyMs :600000 , prompt :'check the build' }); 11assert . deepEqual ( parseLoop ( '/loop 2h summarise my inbox notes' ), { kind :'start' , everyMs :7200000 , prompt :'summarise my inbox notes' }); 12assert . deepEqual ( parseLoop ( '/loop every 5 minutes say hi' ), { kind :'start' , everyMs :300000 , prompt :'say hi' }); 13assert . equal ( parseLoop ( 'hello /loop' ), null , 'only a message that starts with /loop is a loop' ); 14assert . equal ( parseLoop ( '/looping' ), null ); 15}); 16 17test ( '/loop with no time, a tiny time or a huge time is explained in plain words, never run' , () => { 18assert . equal ( parseLoop ( '/loop check the build' ). kind , 'help' ); 19assert . match ( parseLoop ( '/loop check the build' ). problem , / how often / ); 20assert . match ( parseLoop ( '/loop 10s ping' ). problem , / 1 minute / ); 21assert . match ( parseLoop ( '/loop 48h ping' ). problem , / 24 hours / ); 22assert . equal ( LOOP_MIN_MS , 60000 ); 23}); 24 25test ( '/loop, /loop stop and the words for how often' , () => { 26assert . deepEqual ( parseLoop ( '/loop' ), { kind :'status' }); 27assert . deepEqual ( parseLoop ( '/loop stop' ), { kind :'stop' }); 28assert . deepEqual ( parseLoop ( '/loop OFF' ), { kind :'stop' }); 29assert . equal ( loopEvery ( 60000 ), 'every minute' ); 30assert . equal ( loopEvery ( 600000 ), 'every 10 minutes' ); 31assert . equal ( loopEvery ( 3600000 ), 'every hour' ); 32assert . equal ( loopEvery ( 7200000 ), 'every 2 hours' ); 33}); 34 35test ( 'the slash menu lists /time-skip, /goal and /loop with plain descriptions, and /loop no longer just opens Tasks' , async () => { 36const chat = await readFile ( 'src/screens/Chat.tsx' , 'utf8' ); 37for ( const [ label , words ] of [[ '/time-skip' , 'Try a change on a copy' ], [ '/goal' , 'keep working until it is done' ], [ '/loop' , 'every few minutes' ]]) { 38const line = chat . split ( '\n' ). find ( l => l . includes ( `label: ' ${ label } '` )); 39assert . ok ( line , ` ${ label } is in the menu` ); 40assert . ok ( line . includes ( words ), ` ${ label } has a plain description` ); 41} 42const commands = await readFile ( 'src/lib/commands.ts' , 'utf8' ); 43assert . ok ( ! /slash: \['loop'\] / . test ( commands ), 'the old /loop alias that only opened Tasks is gone' ); 44}); 45 46test ( 'the store sends /loop to the loop and /time-skip to a real job when a local model is ready' , async () => { 47const store = await readFile ( 'src/lib/store.ts' , 'utf8' ); 48assert . match ( store , / parseLoop\(text\.trim\(\)\) / ); 49assert . match ( store , / startTimeSkipReal\(demoPrompt\) / ); 50assert . match ( store , / nativeState\(\)\?\.instances\.some\(i => i\.status === 'ready'\) / ); 51assert . match ( store , / !m\.timeSkipId && !m\.local / , 'notes from the app and trial turns are not sent back to the model' ); 52}); 53 54test ( 'the new slash-command, Time-skip and Tools words are translated in every language, with their slots' , async () => { 55const i18n = await build ({ stdin :{ contents :"export * from './src/lib/i18n';" , resolveDir :process . cwd () }, bundle :true , write :false , format :'esm' , platform :'node' , loader :{ '.json' :'json' } }); 56const { tr, setTranslationLanguage, loadCatalog} = await import ( `data:text/javascript;base64, ${ Buffer . from ( i18n . outputFiles [ 0 ]. text ). toString ( 'base64' )} ` ); 57for ( const l of [ 'zh' , 'ja' , 'de' , 'es' , 'ru' , 'pt' , 'ko' , 'fr' ]) await loadCatalog ( l ); // the non-English catalogs load on first use (src/lib/i18n.ts loadCatalog); load them before the first tr() 58const cases = [ 59[ 'Keep the update' , 'de' , 'Aktualisierung behalten' ], 60[ 'Put the original back' , 'ja' , '元に戻す' ], 61[ 'Repeat a message every few minutes while this chat is open' , 'es' , 'Repite un mensaje cada pocos minutos mientras este chat esté abierto' ], 62[ 'Search the web' , 'zh' , '搜索网络' ], 63]; 64for ( const [ text , lang , want ] of cases ) { setTranslationLanguage ( lang ); assert . equal ( tr ( text ), want , ` ${ lang } : ${ text } ` ); } 65setTranslationLanguage ( 'de' ); 66assert . equal ( tr ( 'Revision {0}' , [ 2 ]), 'Überarbeitung 2' ); 67assert . equal ( tr ( 'every {0} minutes' , [ 10 ]), 'alle 10 Minuten' ); 68assert . equal ( tr ( 'Time-skip stopped. The model rejected the credentials. Your files were not changed.' ), 'Time-skip wurde gestoppt. The model rejected the credentials. Deine Dateien wurden nicht geändert.' ); 69setTranslationLanguage ( 'en' ); 70assert . equal ( tr ( 'Keep the update' ), 'Keep the update' ); 71});