okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
a2f602398
main
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 ) { 11const result = await build ({ entryPoints :[ fileURLToPath ( new URL ( `../src/lib/ ${ file } ` , import . meta. url ))], bundle :true , format :'esm' , platform :'node' , write :false , loader :{ '.json' :'json' } }); 12return 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' , () => { 19const models = src ( 'src/components/NativeModels.tsx' ); 20assert . match ( models , / <strong>\{tr\("Read pictures"\)\}<\/strong> / ); 21for ( 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' ]) 22assert . ok ( ! models . includes ( gone ), ` ${ gone } is gone from the page` ); 23assert . 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 25assert . 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) 27assert . 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' , () => { 31const css = src ( 'src/styles/liquid.css' ); 32assert . match ( css , / :root \{ --st-check-ink: #ffffff; \} / ); 33assert . match ( css , / \[data-theme='dark'\] \{ --st-check-ink: var\(--st-accent-ink\); \} / ); 34assert . 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' , () => { 38const models = src ( 'src/components/NativeModels.tsx' ), css = src ( 'src/styles/app.css' ); 39const card = models . slice ( models . indexOf ( 'export function NativeProgress' )); 40for ( 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 ); 41assert . ok ( ! models . includes ( 'The buttons below wait until this finishes.' )); 42assert . match ( models , / <button type="button" className="native-progress__stop" [ \s\S ] * ?\}>\{tr\(stopping \? 'Stopping…' : 'Stop'\)\}<\/button> / , 'Stop is a text button' ); 43assert . match ( models , / aria-live="polite" / ); 44// only transform and opacity move 45const frames = [ ...css . matchAll ( / @keyframes ( native-ring | native-breathe | native-glide ) \{ [ ^ \n ] * \n / g )]. map ( m => m [ 0 ]); 46assert . equal ( frames . length , 3 ); 47for ( const fr of frames ) assert . doesNotMatch ( fr , / \b ( width | height | top | left | margin | padding ) \s * : / ); 48assert . 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' , () => { 52const ready = { visionPrepared :true , visionEnabled :true , visionDevice :'gpu' , images :'yes' }; 53assert . equal ( openingVision ( undefined ), 'yes' ); 54assert . equal ( openingVision ({ images :'off' , visionPrepared :false }), 'yes' , 'a version with no picture files opens on' ); 55assert . equal ( openingVision ({ visionEnabled :false , visionPrepared :false }), 'yes' , 'an old "off" saved while the files were missing opens on' ); 56assert . equal ( openingVision ({ visionEnabled :false , visionPrepared :true }), 'no' , 'off by hand, with the files there' ); 57assert . 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 59for ( const report of [ undefined , { images :'off' , visionPrepared :false }, { visionEnabled :false , visionPrepared :true }, ready , { visionEnabled :false , visionPrepared :false }]) 60for ( const picked of [ 'yes' , 'no' , 'cpu' ]) assert . equal ( shownVision ( picked , report ), picked ); 61assert . 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 63let last = steadyNoReader ( false , false , undefined , 'iq3_s' ); 64assert . equal ( last . value , false ); 65last = steadyNoReader ( true , true , last , 'iq3_s' ); 66assert . equal ( last . value , false , 'a job is running: the dropout is not shown' ); 67last = steadyNoReader ( true , false , last , 'iq3_s' ); 68assert . equal ( last . value , true , 'the job is over: the real answer shows' ); 69assert . equal ( steadyNoReader ( true , true , { id :'other' , value :false }, 'iq3_s' ). value , true , 'another version never inherits it' ); 70// the page uses all three 71const models = src ( 'src/components/NativeModels.tsx' ); 72assert . match ( models , / noReaderSeen\.current = steadyNoReader\( / ); 73assert . match ( models , / const known = visionPicks\.current\.get\(selectedSize\.id\), value = shownVision\(known, installed\); / ); 74assert . 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' ); 75assert . doesNotMatch ( models , / installed\.images, installed\.visionEnabled, installed\.visionDevice / , 'the host\'s picture fields no longer re-run the sync' ); 76assert . doesNotMatch ( models , / installed\?\.visionEnabled, installed\?\.visionDevice / ); 77// the host keeps the last known reader answer when its probe fails 78assert . match ( src ( 'server/native-control.mjs' ), / catch\{visionReader=snapshot\.visionReader===true;\} / ); 79// a locked box stays clearly on 80assert . 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' , () => { 84const css = src ( 'src/styles/annotation-fixes.css' ); 85const line = css . split ( '\n' ). find ( l => l . startsWith ( '.native-model-actions { display:flex;' )); 86assert . 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' , () => { 90const bar = src ( 'src/app/Sidebar.tsx' ), css = src ( 'src/styles/liquid.css' ); 91assert . ok ( bar . indexOf ( 'navsession__working' ) < bar . indexOf ( 'navsession__title' )); 92assert . match ( css , / \.navsession__arc \{ [ ^ } ] * stroke-linecap: round; [ ^ } ] * stroke-dasharray / ); 93assert . match ( css , / shape-rendering: geometricPrecision / ); 94assert . 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' , () => { 98const css = src ( 'src/styles/app.css' ); 99const rules = css . split ( '\n' ). filter ( l => l . startsWith ( '.live-status' )); 100assert . ok ( rules . length >= 4 ); 101for ( const r of rules ) assert . doesNotMatch ( r , / grid-template-columns / ); 102assert . match ( css , / \.live-status \{ display: flex; flex-wrap: wrap; / ); 103assert . match ( css , / \.live-status__time, \.live-status__tokens \{ flex: none; font-variant-numeric: tabular-nums; / ); 104assert . 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' , () => { 110assert . equal ( dirOf ( 'site/css/a.css' ), 'site/css' ); 111assert . equal ( dirOf ( 'a.css' ), '' ); 112assert . equal ( dirOf ( 'site\\css\\a.css' ), 'site/css' ); 113assert . equal ( rootOf ({ abs :'/w/pagoda/site/a.css' , path :'site/a.css' }), '/w/pagoda' ); 114assert . equal ( rootOf ({ abs :'C:\\w\\pagoda\\site\\a.css' , path :'site/a.css' }), 'C:/w/pagoda' ); 115assert . equal ( rootOf ( undefined ), '' ); 116// the file the answer names decides 117const files = [ f ( 'site/index.html' , { kind :'html' , order :1 }), f ( 'site/a.css' , { order :2 }), f ( 'notes/readme.md' , { kind :'markdown' , order :3 })]; 118assert . equal ( deliveryFolder ( files , 'Open site/index.html' ), 'site' ); 119assert . equal ( deliveryFolder ( files , 'See notes/readme.md' ), 'notes' ); 120// nothing previewable: the top-level folder with the most files 121const 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 })]; 122assert . equal ( deliveryFolder ( code , '' ), 'src' ); 123assert . equal ( deliveryFolder ([ f ( 'x.ts' , { order :1 })], '' ), '' , 'a file in the chat folder itself: the chat folder' ); 124assert . equal ( deliveryFolder ([], '' ), '' ); 125assert . equal ( deliveryFolder ( undefined , '' ), '' ); 126// 379 files 127const many = [ f ( 'site/index.html' , { kind :'html' , order :379 }), ...Array . from ({ length :378 }, ( _ , i ) => f ( `site/assets/p ${ i } .js` , { order :i + 1 }))]; 128assert . 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' , () => { 132assert . equal ( COMPACT_FILES_FROM , 6 ); 133const chat = src ( 'src/screens/Chat.tsx' ), parts = src ( 'src/components/Deliverables.tsx' ), css = src ( 'src/styles/liquid.css' ); 134assert . match ( chat , / m\.deliverables\.length >= COMPACT_FILES_FROM \? <FilesSummary files=\{m\.deliverables\} / ); 135assert . match ( chat , / <FileCard key=\{f\.path\} / , 'a short list is unchanged' ); 136const block = parts . slice ( parts . indexOf ( 'export function FilesSummary' ), parts . indexOf ( 'The saved skills an answer used' )); 137assert . 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' ); 138assert . match ( block , / className="fsum__open" aria-label=\{tr\("Open \{0\}", \[p\.name\]\)\} / , 'each folder button says which folder' ); 139assert . match ( block , / \{open \? <ul className="fsum__list" id=\{id\}> / , 'the list is closed until asked' ); 140assert . match ( block , / <button type="button" className="fsum__file" / , 'every row is a button' ); 141assert . match ( css , / \.fsum__list \{ [ ^ } ] * max-height: min\(320px, 50vh\); [ ^ } ] * overflow: auto; / , 'long lists scroll inside the block' ); 142assert . match ( css , / \.fsum__toggle:focus-visible / ); 143assert . 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' , () => { 147for ( const file of [ 'src/components/NativeModels.tsx' , 'src/components/GuidedSetup.tsx' , 'src/lib/plain-errors.ts' ]) assert . ok ( ! src ( file ). includes ( 'Leave 20%' ), file ); 148assert . match ( src ( 'src/components/NativeModels.tsx' ), / Leave room for my work / ); 149assert . match ( src ( 'src/components/GuidedSetup.tsx' ), / title: 'Leave room for my work', hint: 'Keeps 5-8 GB of memory free for other programs\.' / ); 150assert . match ( src ( 'src/lib/plain-errors.ts' ), / choose “Leave room for my work” / ); 151const cat = Object . fromEntries ( LANGS . map ( l => [ l , JSON . parse ( src ( `src/locales/gui- ${ l } .json` ))])); 152const keys = Object . keys ( cat . en ); 153assert . equal ( keys . length , 6 ); 154for ( const l of LANGS ) { 155assert . deepEqual ( Object . keys ( cat [ l ]), keys , l ); 156for ( const k of keys ) { 157assert . ok ( cat [ l ][ k ] && cat [ l ][ k ]. trim (), ` ${ l } ${ k } ` ); 158assert . deepEqual (( cat [ l ][ k ]. match ( / \{\d + \} / g ) ?? []). sort (), ( cat . en [ k ]. match ( / \{\d + \} / g ) ?? []). sort (), ` ${ l } ${ k } keeps its placeholders` ); 159if ( l !== 'en' ) assert . notEqual ( cat [ l ][ k ], cat . en [ k ], ` ${ l } ${ k } is translated` ); 160} 161} 162assert . equal ( cat . en . gf01 , 'Leave room for my work' ); 163assert . equal ( cat . en . gf02 , 'Keeps 5-8 GB of memory free for other programs.' ); 164});