okami.mom/strata

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

Niko1221rc1 merge gui-fb2 (35d4781f1): two files conflicted (apps/host/server/native-control.mjs, apps/host/src/components/NativeModels.tsx), resolved at token level; images/visionPrepared take both the DeepSeek tower check and picturesMissinga2f602398

main
12.1 KiB164 linesraw
1/** GUI feedback round 2 (11-02), items 1 to 8: the owner's own words are in C:\Users\AI-Server\Desktop\gui-feedback2.md. */
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { readFileSync as read } from 'node:fs';
5import { openingVision, shownVision, steadyNoReader } from '../src/lib/pictures-choice.ts';
6import { build } from 'esbuild';
7import { fileURLToPath } from 'node:url';
8
9const src = name => read(new URL(`../${name}`, import.meta.url), 'utf8');
10async function bundle(file) {
11  const result = await build({ entryPoints: [fileURLToPath(new URL(`../src/lib/${file}`, import.meta.url))], bundle: true, format: 'esm', platform: 'node', write: false, loader: { '.json': 'json' } });
12  return import(`data:text/javascript;base64,${Buffer.from(result.outputFiles[0].text).toString('base64')}`);
13}
14globalThis.window ??= globalThis; globalThis.localStorage ??= { getItem: () => null, setItem: () => {} };
15const { COMPACT_FILES_FROM, deliveryFolder, dirOf, rootOf } = await bundle('deliverables.ts');
16const LANGS = ['en', 'zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr'];
17
18test('1: Read pictures is a plain checkmark: no explanation, no download button; Load does the rest', () => {
19  const models = src('src/components/NativeModels.tsx');
20  assert.match(models, /<strong>\{tr\("Read pictures"\)\}<\/strong>/);
21  for (const gone of ['Understand photos, screenshots and charts', 'Turn it off to save memory', 'On by default', 'Download picture-reading files', 'Picture reading needs a few more files'])
22    assert.ok(!models.includes(gone), `${gone} is gone from the page`);
23  assert.doesNotMatch(models, /native-vision-missing/);
24  // a failed or offline picture download is still said, in one line under the checkbox, once the model is loaded without them
25  assert.match(models, /vision !== 'no' && !noReader && !active && loadedSelected\?\.picturesNote \? <p className="small muted native-vision-note" role="status">/);
26  // Load still takes the picture step itself (the host side is pinned in load-pictures.test.mjs)
27  assert.match(models, /picturesByLoad/);
28});
29
30test('2: the tick of a checkbox is white in light mode and keeps the dark ink in dark mode', () => {
31  const css = src('src/styles/liquid.css');
32  assert.match(css, /:root \{ --st-check-ink: #ffffff; \}/);
33  assert.match(css, /\[data-theme='dark'\] \{ --st-check-ink: var\(--st-accent-ink\); \}/);
34  assert.match(css, /input\[type='checkbox'\]:checked::after,\s*\.native-image-reading input\[type='checkbox'\]::after,\s*\.native-gpu-options input\[type='checkbox'\]::after \{\s*border-color: var\(--st-check-ink\);/);
35});
36
37test('3: the progress card names the step and nothing else', () => {
38  const models = src('src/components/NativeModels.tsx'), css = src('src/styles/app.css');
39  const card = models.slice(models.indexOf('export function NativeProgress'));
40  for (const gone of ['The buttons below wait until this finishes.', 'Still working for {0}', 'native-wait-note', 'section-toolbar']) assert.ok(!models.includes(gone) || !card.includes(gone), gone);
41  assert.ok(!models.includes('The buttons below wait until this finishes.'));
42  assert.match(models, /<button type="button" className="native-progress__stop"[\s\S]*?\}>\{tr\(stopping \? 'Stopping…' : 'Stop'\)\}<\/button>/, 'Stop is a text button');
43  assert.match(models, /aria-live="polite"/);
44  // only transform and opacity move
45  const frames = [...css.matchAll(/@keyframes (native-ring|native-breathe|native-glide) \{[^\n]*\n/g)].map(m => m[0]);
46  assert.equal(frames.length, 3);
47  for (const fr of frames) assert.doesNotMatch(fr, /\b(width|height|top|left|margin|padding)\s*:/);
48  assert.match(css, /\.native-progress__bar\[data-indeterminate\] > i \{[^}]*animation: native-glide/);
49});
50
51test('4: what the box shows is the person\'s choice; the host\'s reports only open it', () => {
52  const ready = { visionPrepared: true, visionEnabled: true, visionDevice: 'gpu', images: 'yes' };
53  assert.equal(openingVision(undefined), 'yes');
54  assert.equal(openingVision({ images: 'off', visionPrepared: false }), 'yes', 'a version with no picture files opens on');
55  assert.equal(openingVision({ visionEnabled: false, visionPrepared: false }), 'yes', 'an old "off" saved while the files were missing opens on');
56  assert.equal(openingVision({ visionEnabled: false, visionPrepared: true }), 'no', 'off by hand, with the files there');
57  assert.equal(openingVision(ready), 'gpu');
58  // the report changes while Load runs (the run file gets its picture section, the choice is saved, the instance appears): the choice stays
59  for (const report of [undefined, { images: 'off', visionPrepared: false }, { visionEnabled: false, visionPrepared: true }, ready, { visionEnabled: false, visionPrepared: false }])
60    for (const picked of ['yes', 'no', 'cpu']) assert.equal(shownVision(picked, report), picked);
61  assert.equal(shownVision(undefined, ready), 'gpu');
62  // the probe for the engine's picture reader can drop out while a job runs: the answer from before the job is kept
63  let last = steadyNoReader(false, false, undefined, 'iq3_s');
64  assert.equal(last.value, false);
65  last = steadyNoReader(true, true, last, 'iq3_s');
66  assert.equal(last.value, false, 'a job is running: the dropout is not shown');
67  last = steadyNoReader(true, false, last, 'iq3_s');
68  assert.equal(last.value, true, 'the job is over: the real answer shows');
69  assert.equal(steadyNoReader(true, true, { id: 'other', value: false }, 'iq3_s').value, true, 'another version never inherits it');
70  // the page uses all three
71  const models = src('src/components/NativeModels.tsx');
72  assert.match(models, /noReaderSeen\.current = steadyNoReader\(/);
73  assert.match(models, /const known = visionPicks\.current\.get\(selectedSize\.id\), value = shownVision\(known, installed\);/);
74  assert.match(models, /if \(known === undefined\)\s*visionPicks\.current\.set\(selectedSize\.id, value\);/, 'the first value is remembered: later reports of the host never change it');
75  assert.doesNotMatch(models, /installed\.images, installed\.visionEnabled, installed\.visionDevice/, 'the host\'s picture fields no longer re-run the sync');
76  assert.doesNotMatch(models, /installed\?\.visionEnabled, installed\?\.visionDevice/);
77  // the host keeps the last known reader answer when its probe fails
78  assert.match(src('server/native-control.mjs'), /catch\{visionReader=snapshot\.visionReader===true;\}/);
79  // a locked box stays clearly on
80  assert.match(src('src/styles/liquid.css'), /\.native-image-reading input\[type='checkbox'\]:disabled:checked \{\s*opacity: 0\.8;/);
81});
82
83test('5: no separator under Read pictures', () => {
84  const css = src('src/styles/annotation-fixes.css');
85  const line = css.split('\n').find(l => l.startsWith('.native-model-actions { display:flex;'));
86  assert.ok(line && !/border-top/.test(line), line);
87});
88
89test('6: the running-chat ring is before the name, an SVG circle, and turns with the existing keyframes', () => {
90  const bar = src('src/app/Sidebar.tsx'), css = src('src/styles/liquid.css');
91  assert.ok(bar.indexOf('navsession__working') < bar.indexOf('navsession__title'));
92  assert.match(css, /\.navsession__arc \{[^}]*stroke-linecap: round;[^}]*stroke-dasharray/);
93  assert.match(css, /shape-rendering: geometricPrecision/);
94  assert.doesNotMatch(css, /\.navsession__working \{[^}]*position: absolute/, 'in the row\'s flow, not in the right gutter');
95});
96
97test('7: the chat\'s time and token count have no fixed widths', () => {
98  const css = src('src/styles/app.css');
99  const rules = css.split('\n').filter(l => l.startsWith('.live-status'));
100  assert.ok(rules.length >= 4);
101  for (const r of rules) assert.doesNotMatch(r, /grid-template-columns/);
102  assert.match(css, /\.live-status \{ display: flex; flex-wrap: wrap;/);
103  assert.match(css, /\.live-status__time, \.live-status__tokens \{ flex: none; font-variant-numeric: tabular-nums;/);
104  assert.match(css, /\.live-status__verb \{ flex: 0 1 24ch; min-width: 0;/, 'the word is the one that gives way');
105});
106
107const f = (path, extra = {}) => ({ path, abs: `/w/${path}`, name: path.split('/').at(-1), kind: 'code', status: 'created', size: 10, lines: 3, added: 3, removed: 0, ...extra });
108
109test('8: where a run delivered to, from its files', () => {
110  assert.equal(dirOf('site/css/a.css'), 'site/css');
111  assert.equal(dirOf('a.css'), '');
112  assert.equal(dirOf('site\\css\\a.css'), 'site/css');
113  assert.equal(rootOf({ abs: '/w/pagoda/site/a.css', path: 'site/a.css' }), '/w/pagoda');
114  assert.equal(rootOf({ abs: 'C:\\w\\pagoda\\site\\a.css', path: 'site/a.css' }), 'C:/w/pagoda');
115  assert.equal(rootOf(undefined), '');
116  // the file the answer names decides
117  const files = [f('site/index.html', { kind: 'html', order: 1 }), f('site/a.css', { order: 2 }), f('notes/readme.md', { kind: 'markdown', order: 3 })];
118  assert.equal(deliveryFolder(files, 'Open site/index.html'), 'site');
119  assert.equal(deliveryFolder(files, 'See notes/readme.md'), 'notes');
120  // nothing previewable: the top-level folder with the most files
121  const code = [f('src/a.ts', { order: 1 }), f('src/b.ts', { order: 2 }), f('src/c.ts', { order: 3 }), f('docs/x.ts', { order: 4 })];
122  assert.equal(deliveryFolder(code, ''), 'src');
123  assert.equal(deliveryFolder([f('x.ts', { order: 1 })], ''), '', 'a file in the chat folder itself: the chat folder');
124  assert.equal(deliveryFolder([], ''), '');
125  assert.equal(deliveryFolder(undefined, ''), '');
126  // 379 files
127  const many = [f('site/index.html', { kind: 'html', order: 379 }), ...Array.from({ length: 378 }, (_, i) => f(`site/assets/p${i}.js`, { order: i + 1 }))];
128  assert.equal(deliveryFolder(many, 'I stopped here.'), 'site');
129});
130
131test('8: a few files keep their cards; many are one compact block with an accessible, keyboard-usable count', () => {
132  assert.equal(COMPACT_FILES_FROM, 6);
133  const chat = src('src/screens/Chat.tsx'), parts = src('src/components/Deliverables.tsx'), css = src('src/styles/liquid.css');
134  assert.match(chat, /m\.deliverables\.length >= COMPACT_FILES_FROM \? <FilesSummary files=\{m\.deliverables\}/);
135  assert.match(chat, /<FileCard key=\{f\.path\}/, 'a short list is unchanged');
136  const block = parts.slice(parts.indexOf('export function FilesSummary'), parts.indexOf('The saved skills an answer used'));
137  assert.match(block, /<button type="button" className="fsum__toggle" aria-expanded=\{open\} aria-controls=\{id\}/, 'a real button: Enter and Space work, the state is announced');
138  assert.match(block, /className="fsum__open" aria-label=\{tr\("Open \{0\}", \[p\.name\]\)\}/, 'each folder button says which folder');
139  assert.match(block, /\{open \? <ul className="fsum__list" id=\{id\}>/, 'the list is closed until asked');
140  assert.match(block, /<button type="button" className="fsum__file"/, 'every row is a button');
141  assert.match(css, /\.fsum__list \{[^}]*max-height: min\(320px, 50vh\);[^}]*overflow: auto;/, 'long lists scroll inside the block');
142  assert.match(css, /\.fsum__toggle:focus-visible/);
143  assert.match(css, /prefers-reduced-motion: reduce\) \{\s*\.fsum__chev/);
144});
145
146test('"Leave room for my work" everywhere the old name was, and the new words in nine languages', () => {
147  for (const file of ['src/components/NativeModels.tsx', 'src/components/GuidedSetup.tsx', 'src/lib/plain-errors.ts']) assert.ok(!src(file).includes('Leave 20%'), file);
148  assert.match(src('src/components/NativeModels.tsx'), /Leave room for my work/);
149  assert.match(src('src/components/GuidedSetup.tsx'), /title: 'Leave room for my work', hint: 'Keeps 5-8 GB of memory free for other programs\.'/);
150  assert.match(src('src/lib/plain-errors.ts'), /choose “Leave room for my work”/);
151  const cat = Object.fromEntries(LANGS.map(l => [l, JSON.parse(src(`src/locales/gui-${l}.json`))]));
152  const keys = Object.keys(cat.en);
153  assert.equal(keys.length, 6);
154  for (const l of LANGS) {
155    assert.deepEqual(Object.keys(cat[l]), keys, l);
156    for (const k of keys) {
157      assert.ok(cat[l][k] && cat[l][k].trim(), `${l} ${k}`);
158      assert.deepEqual((cat[l][k].match(/\{\d+\}/g) ?? []).sort(), (cat.en[k].match(/\{\d+\}/g) ?? []).sort(), `${l} ${k} keeps its placeholders`);
159      if (l !== 'en') assert.notEqual(cat[l][k], cat.en[k], `${l} ${k} is translated`);
160    }
161  }
162  assert.equal(cat.en.gf01, 'Leave room for my work');
163  assert.equal(cat.en.gf02, 'Keeps 5-8 GB of memory free for other programs.');
164});