okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
8667a3dbf
main
1// QA report F05: a number typed into Response settings is checked against the field's own range. 2import test from 'node:test' ; 3import assert from 'node:assert/strict' ; 4import { readFile } from 'node:fs/promises' ; 5import { transform } from 'esbuild' ; 6async function loadTs ( path ) { 7const { code} = await transform ( await readFile ( new URL ( path , import . meta. url ), 'utf8' ), { loader :'ts' , format :'esm' }); 8return import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 9} 10const { checkWholeNumber, numberProblem} = await loadTs ( '../src/lib/number-field.ts' ); 11 12test ( 'Max output tokens: -1 and other numbers outside 0 to 1048576 are refused, whole numbers inside are taken' , () => { 13assert . deepEqual ( checkWholeNumber ( '-1' , 0 , 1048576 ), { ok :false , problem :'range' }); 14assert . deepEqual ( checkWholeNumber ( '1048577' , 0 , 1048576 ), { ok :false , problem :'range' }); 15assert . deepEqual ( checkWholeNumber ( '0' , 0 , 1048576 ), { ok :true , value :0 }); 16assert . deepEqual ( checkWholeNumber ( ' 4096 ' , 0 , 1048576 ), { ok :true , value :4096 }); 17assert . deepEqual ( checkWholeNumber ( '1048576' , 0 , 1048576 ), { ok :true , value :1048576 }); 18}); 19 20test ( 'Seed accepts -1 (random) and refuses what is not a whole number' , () => { 21assert . deepEqual ( checkWholeNumber ( '-1' , - 1 , 2147483647 ), { ok :true , value :- 1 }); 22assert . equal ( checkWholeNumber ( '-2' , - 1 , 2147483647 ). ok , false ); 23for ( const bad of [ '' , ' ' , '-' , '1.5' , '1e3' , 'abc' , '12abc' , '99999999999999999999' ]) assert . equal ( checkWholeNumber ( bad , - 1 , 2147483647 ). ok , false , JSON . stringify ( bad )); 24assert . deepEqual ( checkWholeNumber ( '' , 0 , 5 ), { ok :false , problem :'empty' }); 25}); 26 27test ( 'the sentence says what is wrong in plain words, with the range written the reader\'s way' , () => { 28const fmt = n => n . toLocaleString ( 'en' ); 29assert . equal ( numberProblem ( checkWholeNumber ( '7' , 0 , 10 ), 0 , 10 , fmt ), null ); 30assert . deepEqual ( numberProblem ( checkWholeNumber ( '' , 0 , 10 ), 0 , 10 , fmt ), { text :'Enter a number.' , args :[] }); 31assert . deepEqual ( numberProblem ( checkWholeNumber ( '-1' , 0 , 1048576 ), 0 , 1048576 , fmt ), { text :'Enter a whole number from {0} to {1}.' , args :[ '0' , '1,048,576' ] }); 32}); 33 34test ( 'the Response settings dialog uses it: wrong numbers show the sentence and the save stays off' , async () => { 35const source = ( await readFile ( new URL ( '../src/app/SamplingDrawer.tsx' , import . meta. url ), 'utf8' )). replace ( / \r\n / g , '\n' ); 36assert . match ( source , / checkWholeNumber\(text, field\.min, field\.max\) / ); 37assert . match ( source , / disabled=\{pending \|\| !dirty \|\| invalid\} / ); 38assert . match ( source , / if \(!dirty \|\| pending \|\| invalid\) / ); 39assert . match ( source , / aria-invalid=\{problem \? true : undefined\} / ); 40}); 41 42test ( 'F07: a page opened from another computer says why Add skill cannot work instead of waiting' , async () => { 43const pick = await loadTs ( '../src/lib/folder-pick.ts' ). catch (() => null ); 44const source = ( await readFile ( new URL ( '../src/lib/folder-pick.ts' , import . meta. url ), 'utf8' )); 45const fn = new Function ( ` ${ source . slice ( source . indexOf ( 'export function pageIsOnThisComputer' )). replace ( 'export function' , 'function' )} ; return pageIsOnThisComputer;` . replace ( / : string | : boolean / g , '' ))(); 46for ( const yes of [ 'localhost' , '127.0.0.1' , '127.1.2.3' , '[::1]' , '::1' ]) assert . equal ( fn ( yes ), true , yes ); 47for ( const no of [ '192.168.1.5' , 'strata.example.com' , 'my-pc.trycloudflare.com' ]) assert . equal ( fn ( no ), false , no ); 48const skills = ( await readFile ( new URL ( '../src/screens/Skills.tsx' , import . meta. url ), 'utf8' )); 49assert . match ( skills , / pageIsOnThisComputer\(window\.location\.hostname\) / ); 50void pick ; 51}); 52 53test ( 'F08: the message box stops at 30% of the window height (44 to 180 px) and scrolls inside' , async () => { 54const source = await readFile ( new URL ( '../src/lib/responsive.ts' , import . meta. url ), 'utf8' ); 55const composerCap = new Function ( ` ${ source . slice ( source . indexOf ( 'export function composerCap' )). replace ( 'export function' , 'function' ). replace ( / : number / g , '' )} ; return composerCap;` )(); 56assert . equal ( composerCap ( 400 ), 120 ); assert . equal ( composerCap ( 500 ), 150 ); assert . equal ( composerCap ( 720 ), 180 ); assert . equal ( composerCap ( 2000 ), 180 ); assert . equal ( composerCap ( 100 ), 44 ); 57const css = await readFile ( new URL ( '../src/styles/annotation-fixes.css' , import . meta. url ), 'utf8' ); 58assert . match ( css , / \.composer \.st-composer textarea \{ max-height: clamp\(44px, 30dvh, 180px\); overflow-y: auto; \} / ); 59assert . match ( await readFile ( new URL ( '../src/screens/Chat.tsx' , import . meta. url ), 'utf8' ), / composerCap\(window\.innerHeight\) / ); 60}); 61 62test ( 'O02: the screenshot Download button saves the picture and then says so' , async () => { 63const source = ( await readFile ( new URL ( '../src/components/SnapshotDialog.tsx' , import . meta. url ), 'utf8' )). replace ( / \r\n / g , '\n' ); 64assert . match ( source , / onClick=\{\(\) => saveSnapshotWithNotice\(data\)\}>\{tr\("Download"\)\} / ); 65assert . match ( source , / downloadSnapshot\(data\);\n\s + pushToast\('success' / ); 66assert . match ( source , / pushToast\('error', tr\('The screenshot was not saved'\) / ); 67}); 68 69test ( 'item 1: the desktop window leaves file drops to the page, and the drop box is animated' , async () => { 70const rust = await readFile ( new URL ( '../../desktop/src-tauri/src/main.rs' , import . meta. url ), 'utf8' ); 71assert . match ( rust , / #\[cfg\(windows\)\]\s + let builder = builder\.disable_drag_drop_handler\(\); / ); 72const css = await readFile ( new URL ( '../src/styles/app.css' , import . meta. url ), 'utf8' ); 73assert . match ( css , / \.dropzone \{ animation: dropzone-in / ); 74assert . match ( css , / prefers-reduced-motion: reduce\) \{ \.dropzone / ); 75});