okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-split-int' into f-split-vision7c5e84612

main
3.4 KiB52 linesraw
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) {
11  const r = await build({ entryPoints: [src(file)], bundle: true, format: 'esm', platform: 'node', write: false, alias: { react: stub }, logLevel: 'silent' });
12  return 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', () => {
18  const 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 } });
19  assert.deepEqual(f.plan.steps.map(s => s.id), ['s1', '2']);
20  assert.equal(f.lever.why, 'The layout decides everything after it.');
21  assert.equal(f.a.step, 2); assert.equal(f.b.waiting, true);
22  assert.deepEqual(f.activity, { code: 'line', text: 'Step 2 of 5 in A: Draw the layout' });
23  assert.equal(T.isForkJob(f), true);
24  assert.equal(T.isForkJob({}), false);
25});
26
27test('an older job (an activity object, no plan) is not a fork job and keeps its activity', () => {
28  const f = T.forkFields({ phase: 'generating', activity: { code: 'reading-files', text: 'Reading' } });
29  assert.deepEqual(f.activity, { code: 'reading-files', text: 'Reading' });
30  assert.equal(T.isForkJob(f), false);
31  assert.equal(T.forkFields({ lever: null }).lever, null);
32});
33
34test('the folder answer: a path gives a name; nothing gives no folder', () => {
35  assert.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 });
36  assert.equal(F.readFolder({ path: '/home/me/site' }).name, 'site');
37  assert.equal(F.readFolder(null), null);
38  assert.equal(F.readFolder({ path: '' }), null);
39});
40
41test('the sample time-skip copy appears only when the host cannot be reached at all', async () => {
42  const { readFileSync } = await import('node:fs');
43  const store = readFileSync(src('lib/store.ts'), 'utf8');
44  const chat = readFileSync(src('screens/Chat.tsx'), 'utf8');
45  const panel = readFileSync(src('components/TimeSkipPanel.tsx'), 'utf8');
46  const route = store.slice(store.indexOf('const demoPrompt = '), store.indexOf('const imageTarget'));
47  assert.match(route, /connection === 'live'/);
48  assert.match(route, /connection === 'connecting'/);
49  assert.ok(route.indexOf('startTimeSkipDemo') > route.indexOf("'connecting'"), 'the sample run is the last resort, after live and connecting');
50  assert.match(chat, /hostLive \? tr\('This was a sample run/);
51  assert.match(panel, /run\.job \? 'Working on a copy of your files\.'/);
52});