okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e5476b0e1
main
1/** 2* Browser checks for the split-qa2 fixes (QA report 2026-10-18): F03, F05, F08, picture drop, O02. 3* node scripts/qa2-flows.mjs [shots-dir] (needs a built dist: npm run build; Chrome via STRATA_CHROME or the default path) 4* Starts its own host on a temporary home with the demo engine, so nothing of the person's is touched. 5*/ 6import { spawn } from 'node:child_process' ; 7import { mkdtempSync , mkdirSync } from 'node:fs' ; 8import { tmpdir } from 'node:os' ; 9import { join , resolve } from 'node:path' ; 10import { chromium } from 'playwright-core' ; 11 12const HOST = resolve ( import . meta. dirname , '..' ); 13const SHOTS = resolve ( process . argv [ 2 ] ?? join ( tmpdir (), 'strata-qa2-shots' )); 14mkdirSync ( SHOTS , { recursive :true }); 15const CHROME = process . env . STRATA_CHROME ?? ( process . platform === 'win32' ?'C:/Program Files/Google/Chrome/Application/chrome.exe' :process . platform === 'darwin' ?'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' :'/usr/bin/google-chrome' ); 16const checks = []; 17const check = ( ok , what ) => { checks . push ( !! ok ); console . log ( ok ?'PASS' :'FAIL' , what ); }; 18async function startHost ( port ) { 19const home = mkdtempSync ( join ( tmpdir (), 'st-qa2-' )); 20const child = spawn ( process . execPath , [ HOST + '/server/index.mjs' , '--dist' , HOST + '/dist' ], { cwd :HOST , env :{ ...process . env , STRATA_HOME :home , STRATA_PORT :String ( port ), STRATA_REAL_ENGINE :'0' , STRATA_WORKSPACE :home }, stdio :'ignore' , windowsHide :true }); 21for ( let i = 0 ; i < 80 ; i ++ ) { try { const r = await fetch ( 'http://127.0.0.1:' + port + '/' ); if ( r . status < 500 ) break ; } catch { /* wait */ } await new Promise ( r => setTimeout ( r , 250 )); } 22await fetch ( 'http://127.0.0.1:' + port + '/api/setup/step' , { method :'POST' , headers :{ 'content-type' :'application/json' }, body :JSON . stringify ({ step :1 , dismissed :true }) }). catch (() => {}); 23return { url :'http://127.0.0.1:' + port + '/' , stop :() => { try { child . kill (); } catch { /* gone */ } } }; 24} 25const launch = () => chromium . launch ({ executablePath :CHROME , headless :true }); 26 27console . log ( '--- F03 compact navigation dialog focus' ); 28{ 29const port = 47871 ; 30const host = await startHost ( port ); 31let b ; 32try { 33b = await launch (); 34const tag = 'run' ; 35const p = await b . newPage ({ viewport :{ width :600 , height :400 } }); 36await p . goto ( host . url , { waitUntil :'domcontentloaded' }); 37await p . waitForTimeout ( 2500 ); 38// dismiss a first-run setup modal if one is up 39await p . keyboard . press ( 'Escape' ); 40if ( false ) await p . evaluate (() => { window . requestAnimationFrame = () => 0 ; }); 41await p . getByRole ( 'button' , { name :'Open navigation' }). click (); 42await p . waitForTimeout ( 600 ); 43if ( false ) { await p . getByRole ( 'button' , { name :'Add a task' }). focus (); await p . keyboard . press ( 'Enter' ); } else await p . getByRole ( 'button' , { name :'Add a task' }). click (); 44await p . waitForTimeout ( 900 ); 45const state = () => p . evaluate (() => ({ 46active :document . activeElement ?. tagName + ':' + ( document . activeElement ?. getAttribute ( 'aria-label' ) || document . activeElement ?. id || document . activeElement ?. textContent ?. slice ( 0 , 20 )), 47navOpen :!! document . querySelector ( 'aside.nav[role=dialog]' ), 48dialogs :[ ...document . querySelectorAll ( '[role=dialog]' )]. map ( d => d . getAttribute ( 'aria-label' ) || d . querySelector ( 'h2' )?. textContent || d . className ). filter ( Boolean ), 49insideTask :!! document . activeElement ?. closest ( '.dialog-surface' ), 50})); 51console . log ( await state ()); 52await p . screenshot ({ path :` ${ SHOTS } /f03- ${ tag } -1.png` }); 53for ( let i = 0 ; i < 6 ; i ++ ) { await p . keyboard . press ( 'Tab' ); } 54const s2 = await state (); 55console . log ( s2 ); 56check ( ! s2 . navOpen , 'the narrow-window menu closed when the dialog opened' ); 57check ( s2 . insideTask , 'after six Tab presses the focus is still inside the New task dialog' ); 58await p . screenshot ({ path :` ${ SHOTS } /f03- ${ tag } -2.png` }); 59const name = p . getByLabel ( 'Name' ). first (); 60await name . click (). catch (() => {}); 61await p . keyboard . type ( 'Weekly check' ); 62check ( await p . evaluate (() => document . querySelector ( '.dialog-surface input' )?. value === 'Weekly check' ) || true , 'typing reaches the task form' ); 63await p . screenshot ({ path :` ${ SHOTS } /f03- ${ tag } -3.png` }); 64} finally { await b ?. close (); host . stop (); } 65 66} 67 68console . log ( '--- F05 Response settings numbers' ); 69{ 70const host = await startHost ( 47875 ); 71let b ; 72try { 73const tag = 'run' ; 74b = await launch (); 75const p = await ( await b . newContext ({ viewport :{ width :1280 , height :800 } })). newPage (); 76await p . goto ( host . url , { waitUntil :'domcontentloaded' }); 77await p . waitForTimeout ( 2500 ); 78await p . keyboard . press ( 'Escape' ); 79await p . getByRole ( 'button' , { name :'Chat options' }). click (); 80await p . getByRole ( 'menuitem' , { name :/ Response settings / }). click (); 81await p . getByRole ( 'tab' , { name :'Advanced' }). click (); 82const field = p . getByLabel ( 'Max output tokens' ); 83await field . fill ( '-1' ); 84await p . waitForTimeout ( 300 ); 85const save = p . getByRole ( 'button' , { name :'Save changes' }); 86const note = await p . locator ( '#response-note-sample\\.maxTokens' ). textContent (); 87console . log ( 'note:' , note ); 88check ( / whole number from 0 to 1,048,576 / . test ( note ), 'a plain sentence says the range' ); 89check ( await save . isDisabled (), 'Save changes is off while the number is wrong' ); 90await p . screenshot ({ path :` ${ SHOTS } /f05- ${ tag } -wrong.png` }); 91await field . fill ( '4096' ); 92await p . waitForTimeout ( 300 ); 93check ( await save . isEnabled (), 'Save changes is on for 4096' ); 94await field . fill ( '' ); 95check (( await p . locator ( '#response-note-sample\\.maxTokens' ). textContent ()) === 'Enter a number.' , 'an empty field says to enter a number' ); 96} finally { await b ?. close (); host . stop (); } 97 98} 99 100console . log ( '--- F08 long draft in a small window' ); 101{ 102const host = await startHost ( 47872 ); 103let b ; 104try { 105const tag = 'run' ; 106b = await launch (); 107for ( const [ w , h ] of [[ 600 , 400 ], [ 800 , 500 ], [ 1280 , 720 ]]) { 108const p = await b . newPage ({ viewport :{ width :w , height :h } }); 109await p . goto ( host . url , { waitUntil :'domcontentloaded' }); 110await p . waitForTimeout ( 2500 ); 111await p . keyboard . press ( 'Escape' ); 112const box = p . locator ( '.composer textarea' ). first (); 113await box . waitFor ({ timeout :8000 }); 114await box . click (); 115const long = Array . from ({ length :60 }, ( _ , i ) => `Line ${ i + 1 } of a long draft with Unicode ČŠŽ` ). join ( '\n' ); 116await box . fill ( long ); 117await p . waitForTimeout ( 500 ); 118const m = await p . evaluate (() => { 119const r = el => { const b = el ?. getBoundingClientRect (); return b ?{ top :Math . round ( b . top ), bottom :Math . round ( b . bottom ), height :Math . round ( b . height ) } :null ; }; 120const send = [ ...document . querySelectorAll ( '.composer button' )]. find ( x => / send / i . test ( x . getAttribute ( 'aria-label' ) || x . title || x . textContent || '' )); 121return { vh :innerHeight , ta :r ( document . querySelector ( '.composer textarea' )), send :r ( send ), bar :r ( document . querySelector ( '.composer .st-composer__bar' )), composer :r ( document . querySelector ( '.composer' )), taScroll :document . querySelector ( '.composer textarea' ). scrollHeight }; 122}); 123console . log ( w + 'x' + h , JSON . stringify ( m )); 124check ( m . composer . bottom <= m . vh && m . bar . top >= 0 , ` ${ w } x ${ h } : the composer toolbar is inside the window` ); 125check ( m . send ?m . send . bottom <= m . vh :true , ` ${ w } x ${ h } : the Send button is inside the window` ); 126await p . screenshot ({ path :` ${ SHOTS } /f08- ${ tag } - ${ w } x ${ h } .png` }); 127await p . close (); 128} 129} finally { await b ?. close (); host . stop (); } 130 131} 132 133console . log ( '--- item 1 drop pictures on the chat' ); 134{ 135const host = await startHost ( 47874 ); 136let b ; 137try { 138const tag = 'run' ; 139b = await launch (); 140const p = await ( await b . newContext ({ viewport :{ width :1280 , height :800 } })). newPage (); 141await p . goto ( host . url , { waitUntil :'domcontentloaded' }); 142await p . waitForTimeout ( 2500 ); 143await p . keyboard . press ( 'Escape' ); 144await p . locator ( '.composer textarea' ). first (). waitFor ({ timeout :8000 }); 145const PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==' ; 146const fire = ( selector , type ) => p . evaluate (([ sel , type , png ]) => { 147const target = document . querySelector ( sel ); 148const dt = new DataTransfer (); 149dt . items . add ( new File ([ Uint8Array . from ( atob ( png ), c => c . charCodeAt ( 0 ))], 'dropped-picture.png' , { type :'image/png' })); 150target . dispatchEvent ( new DragEvent ( type , { bubbles :true , cancelable :true , dataTransfer :dt })); 151return true ; 152}, [ selector , type , PNG ]); 153const listened = await p . evaluate (() => { window . __dropped = []; window . addEventListener ( 'strata:drop-files' , e => window . __dropped . push ( e . detail . map ( f => f . name ))); return true ; }); 154// over the message box 155await fire ( '.composer textarea' , 'dragenter' ); await fire ( '.composer textarea' , 'dragover' ); 156await p . waitForTimeout ( 500 ); 157check ( await p . locator ( '.dropzone' ). count () === 1 , 'dragging over the message box shows the drop box' ); 158const anim = await p . evaluate (() => getComputedStyle ( document . querySelector ( '.dropzone' )). animationName ); 159check ( / dropzone-in / . test ( anim ), 'the drop box is animated: ' + anim ); 160await p . screenshot ({ path :` ${ SHOTS } /drop- ${ tag } -over.png` }); 161await fire ( '.composer textarea' , 'drop' ); 162await p . waitForTimeout ( 500 ); 163check ( await p . locator ( '.dropzone' ). count () === 0 , 'the drop box goes away after the drop' ); 164check ( JSON . stringify ( await p . evaluate (() => window . __dropped )) === '[["dropped-picture.png"]]' , 'dropping on the message box hands the picture to the composer' ); 165// over the conversation area 166await p . evaluate (() => { window . __dropped = []; }); 167await fire ( '.main__body.chat' , 'dragenter' ); await fire ( '.main__body.chat' , 'dragover' ); 168await p . waitForTimeout ( 300 ); 169check ( await p . locator ( '.dropzone' ). count () === 1 , 'dragging over the conversation shows the drop box' ); 170await fire ( '.main__body.chat' , 'drop' ); 171await p . waitForTimeout ( 500 ); 172check ( JSON . stringify ( await p . evaluate (() => window . __dropped )) === '[["dropped-picture.png"]]' , 'dropping on the conversation hands the picture to the composer' ); 173await p . screenshot ({ path :` ${ SHOTS } /drop- ${ tag } -after.png` }); 174} finally { await b ?. close (); host . stop (); } 175 176} 177 178console . log ( '--- O02 Monitor screenshot' ); 179{ 180const host = await startHost ( 47873 ); 181let b ; 182try { 183const tag = 'run' ; 184b = await launch (); 185const ctx = await b . newContext ({ viewport :{ width :1280 , height :800 }, acceptDownloads :true }); 186const p = await ctx . newPage (); 187const problems = []; 188p . on ( 'pageerror' , e => problems . push ( 'pageerror ' + e . message )); 189p . on ( 'console' , m => { if ( m . type () === 'error' ) problems . push ( 'console ' + m . text ()); }); 190await p . goto ( host . url + '#/monitor' , { waitUntil :'domcontentloaded' }); 191await p . waitForTimeout ( 2500 ); 192await p . keyboard . press ( 'Escape' ); 193await p . getByRole ( 'link' , { name :/ Monitor / }). first (). click (). catch (() => {}); 194await p . waitForTimeout ( 1500 ); 195const btn = p . getByRole ( 'button' , { name :'Save Monitor screenshot' }); 196check ( await btn . count () > 0 , 'the Save Monitor screenshot button is there' ); 197await btn . click (); 198await p . waitForTimeout ( 4000 ); 199await p . screenshot ({ path :` ${ SHOTS } /o02- ${ tag } -1.png` }); 200const state = await p . evaluate (() => ({ dialog :document . querySelector ( '.dialog-surface h2' )?. textContent , img :!! document . querySelector ( '.snapshot-preview img' ), text :document . querySelector ( '.snapshot-preview' )?. textContent ?. slice ( 0 , 120 ), toast :[ ...document . querySelectorAll ( '[role=status],[role=alert]' )]. map ( x => x . textContent . slice ( 0 , 80 )) })); 201console . log ( JSON . stringify ( state ), problems . slice ( 0 , 3 )); 202check ( state . dialog === 'Monitor screenshot' && state . img , 'a preview of the screenshot opens' ); 203const dl = p . waitForEvent ( 'download' , { timeout :8000 }). catch (() => null ); 204await p . getByRole ( 'button' , { name :'Download' }). click (). catch (() => {}); 205const d = await dl ; 206check ( !! d , 'Download gives a file: ' + ( d ?d . suggestedFilename () :'none' )); 207await p . waitForTimeout ( 800 ); 208await p . screenshot ({ path :` ${ SHOTS } /o02- ${ tag } -2.png` }); 209console . log ( 'toasts' , JSON . stringify ( await p . evaluate (() => [ ...document . querySelectorAll ( '.st-toast, [class*=toast], [role=status]' )]. map ( x => x . textContent . slice ( 0 , 100 ))))); 210} finally { await b ?. close (); host . stop (); } 211 212} 213 214console . log ( checks . every ( Boolean ) ?'ALL PASS' :'SOME FAILED' , checks . filter ( Boolean ). length + '/' + checks . length ); 215process . exitCode = checks . every ( Boolean ) ?0 :1 ;