okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
7c5e84612
main
1/** Round 8, item 11: the fork design's events (notes-split-agent8.md) are read into the job; the folder chip reads the host's answer. */ 2import test from 'node:test' ; 3import assert from 'node:assert/strict' ; 4import { build } from 'esbuild' ; 5import { fileURLToPath } from 'node:url' ; 6 7const src = f => fileURLToPath ( new URL ( `../src/ ${ f } ` , import . meta. url )); 8const stub = fileURLToPath ( new URL ( './helpers/react-stub.mjs' , import . meta. url )); 9globalThis . window ??= globalThis ; globalThis . localStorage ??= { getItem :() => null , setItem :() => {} }; globalThis . navigator ??= { language :'en' }; 10async function load ( file ) { 11const r = await build ({ entryPoints :[ src ( file )], bundle :true , format :'esm' , platform :'node' , write :false , alias :{ react :stub }, logLevel :'silent' }); 12return import ( `data:text/javascript;base64, ${ Buffer . from ( r . outputFiles [ 0 ]. text ). toString ( 'base64' )} ` ); 13} 14const T = await load ( 'lib/time-skip.ts' ); 15const F = await load ( 'lib/chat-folder.ts' ); 16 17test ( 'an event carries the plan, the lever with its why, both lanes and one friendly line' , () => { 18const f = T . forkFields ({ phase :'running' , activity :'Step 2 of 5 in A: Draw the layout' , plan :{ steps :[{ id :'s1' , text :'Look' }, { text :'Draw' }, 5 ] }, lever :{ step :3 , total :5 , text :'Styles' , why :'The layout decides everything after it.' , defaulted :false }, a :{ state :'running' , step :2 , total :5 , text :'Draw' , line :'Step 2 of 5' , waiting :false }, b :{ state :'waiting' , waiting :true } }); 19assert . deepEqual ( f . plan . steps . map ( s => s . id ), [ 's1' , '2' ]); 20assert . equal ( f . lever . why , 'The layout decides everything after it.' ); 21assert . equal ( f . a . step , 2 ); assert . equal ( f . b . waiting , true ); 22assert . deepEqual ( f . activity , { code :'line' , text :'Step 2 of 5 in A: Draw the layout' }); 23assert . equal ( T . isForkJob ( f ), true ); 24assert . equal ( T . isForkJob ({}), false ); 25}); 26 27test ( 'an older job (an activity object, no plan) is not a fork job and keeps its activity' , () => { 28const f = T . forkFields ({ phase :'generating' , activity :{ code :'reading-files' , text :'Reading' } }); 29assert . deepEqual ( f . activity , { code :'reading-files' , text :'Reading' }); 30assert . equal ( T . isForkJob ( f ), false ); 31assert . equal ( T . forkFields ({ lever :null }). lever , null ); 32}); 33 34test ( 'the folder answer: a path gives a name; nothing gives no folder' , () => { 35assert . deepEqual ( F . readFolder ({ path :'C:\Users\me\pagoda-site' , name :'pagoda-site' , exists :true }), { path :'C:\Users\me\pagoda-site' , name :'pagoda-site' , exists :true }); 36assert . equal ( F . readFolder ({ path :'/home/me/site' }). name , 'site' ); 37assert . equal ( F . readFolder ( null ), null ); 38assert . equal ( F . readFolder ({ path :'' }), null ); 39}); 40 41test ( 'the sample time-skip copy appears only when the host cannot be reached at all' , async () => { 42const { readFileSync} = await import ( 'node:fs' ); 43const store = readFileSync ( src ( 'lib/store.ts' ), 'utf8' ); 44const chat = readFileSync ( src ( 'screens/Chat.tsx' ), 'utf8' ); 45const panel = readFileSync ( src ( 'components/TimeSkipPanel.tsx' ), 'utf8' ); 46const route = store . slice ( store . indexOf ( 'const demoPrompt = ' ), store . indexOf ( 'const imageTarget' )); 47assert . match ( route , / connection === 'live' / ); 48assert . match ( route , / connection === 'connecting' / ); 49assert . ok ( route . indexOf ( 'startTimeSkipDemo' ) > route . indexOf ( "'connecting'" ), 'the sample run is the last resort, after live and connecting' ); 50assert . match ( chat , / hostLive \? tr\('This was a sample run / ); 51assert . match ( panel , / run\.job \? 'Working on a copy of your files\.' / ); 52});