okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
5d9f47922
main
1// Screenshots of the served web page (serve/web) in its new states, against the mock server (no model): 2// WEBTEST_MODULES=<folder with node_modules/puppeteer-core> node tools/webtest/shots.mjs <out folder> [name-substring] 3import { startMock } from "./mock.mjs" ; 4import { launch , openPage , say , idle , sleep , shot } from "./lib.mjs" ; 5 6const out = process . argv [ 2 ] || "shots" ; 7const only = process . argv [ 3 ]; 8const mock = await startMock (); 9const browser = await launch (); 10const turn = ( role , text , extra = {}) => ({ role, text, time :Date . now (), ...extra }); 11const fence = ( lang , code ) => "```" + lang + "\n" + code + "\n```\n" ; 12const on = ( extra = {}) => ({ sampling :{ chatList :true , chatEdit :true , ...extra } }); 13const day = 86400000 ; 14 15const LONG = "Here is a short plan.\n\n1. Read the notes the user attached.\n2. Write the summary in plain words.\n3. List the open questions.\n\n" + 16"The summary is **short** on purpose: three sentences, no jargon, and one next step.\n\n| Step | Who | When |\n|---|---|---|\n| Read | You | Today |\n| Summary | Me | Now |\n" ; 17const CHAT = [ turn ( "user" , "Can you plan how to summarise my notes?" ), turn ( "assistant" , LONG , { meta :"212 tokens · 41.3 tok/s" }), 18turn ( "user" , "Make it shorter, please." ), turn ( "assistant" , "Sure. Read the notes, write three sentences, list what is still open." , { meta :"24 tokens · 40.8 tok/s" })]; 19 20// the saved-chats list with chats from different days (put into the page's own store, then the page is reloaded) 21async function seedChats ( page ) { 22await page . evaluate ( async ( base , d ) => { 23const mk = ( id , title , days , text ) => ({ id, title, time :Date . now () - days * d , messages :[{ role :"user" , text, time :1 }, { role :"assistant" , text :"Sure." , time :2 }] }); 24for ( const c of [ mk ( "s1" , "" , 0.1 , "Plan my week" ), mk ( "s2" , "Garden plan" , 0.2 , "Which tomatoes grow in shade?" ), mk ( "s3" , "" , 1.5 , "Translate this letter" ), 25mk ( "s4" , "Branch of Recipe ideas" , 3 , "Recipe ideas" ), mk ( "s5" , "" , 12 , "Explain compound interest" ), mk ( "s6" , "" , 50 , "Old question about the printer" )]) { 26chatStore . put ( StrataHistory . cleanChat ( c )); 27} 28}, null , day ); 29await sleep ( 300 ); 30await page . reload ({ waitUntil :"networkidle0" }); 31} 32 33const shots = [ 34[ "01-wide-window" , async () => { 35const p = await openPage ( browser , mock , { width :2560 , height :1300 , seed :{ chat :CHAT , ...on () } }); 36await seedChats ( p ); 37return p ; 38}], 39[ "02-saved-chats-list" , async () => { 40const p = await openPage ( browser , mock , { width :1280 , height :800 , seed :{ chat :CHAT , ...on () } }); 41await seedChats ( p ); 42return p ; 43}], 44[ "03-rewind-choice" , async () => { 45const p = await openPage ( browser , mock , { width :1280 , height :800 , seed :{ chat :CHAT , ...on () } }); 46await p . evaluate (() => { const i = 2 ; openRewind ( i ); }); 47await sleep ( 200 ); 48return p ; 49}], 50[ "04-undo-bar" , async () => { 51const p = await openPage ( browser , mock , { width :1280 , height :800 , seed :{ chat :CHAT , ...on () } }); 52await p . evaluate (() => { openRewind ( 2 ); }); 53await p . $eval ( ".history-panel .st-btn--primary" , ( b ) => b . click ()); 54await sleep ( 200 ); 55return p ; 56}], 57[ "05-edit-answer" , async () => { 58const p = await openPage ( browser , mock , { width :1280 , height :800 , seed :{ chat :CHAT , ...on () } }); 59await p . evaluate (() => { editAnswerAt ( 3 ); }); 60await sleep ( 200 ); 61return p ; 62}], 63[ "06-branch-from-here" , async () => { 64const p = await openPage ( browser , mock , { width :1280 , height :800 , seed :{ chat :CHAT , ...on () } }); 65await p . evaluate (() => { openRewind ( 2 ); }); 66await p . evaluate (() => [ ...document . querySelectorAll ( ".history-panel .st-btn" )]. find (( b ) => b . textContent === "Branch from here" ). click ()); 67await sleep ( 300 ); 68return p ; 69}], 70[ "07-math" , async () => { 71const p = await openPage ( browser , mock , { width :1100 , height :760 , seed :{ sampling :{ math :true } } }); 72await say ( p , "#math show me" ); await idle ( p ); await sleep ( 900 ); 73return p ; 74}], 75[ "08-math-dark" , async () => { 76const p = await openPage ( browser , mock , { width :1100 , height :760 , dark :true , seed :{ sampling :{ math :true } } }); 77await say ( p , "#math show me" ); await idle ( p ); await sleep ( 900 ); 78return p ; 79}], 80[ "09-svg-preview" , async () => { 81const p = await openPage ( browser , mock , { width :1100 , height :760 }); 82await say ( p , "#svg draw a circle" ); await idle ( p ); await sleep ( 200 ); 83await p . click ( "[data-preview-toggle]" ); await sleep ( 400 ); 84return p ; 85}], 86[ "10-html-preview-and-scripts" , async () => { 87const p = await openPage ( browser , mock , { width :1100 , height :760 }); 88await say ( p , "#html make a page" ); await idle ( p ); await sleep ( 200 ); 89await p . click ( "[data-preview-toggle]" ); await sleep ( 300 ); 90await p . click ( "[data-preview-scripts]" ); await sleep ( 500 ); 91return p ; 92}], 93[ "11-narrow-chat" , async () => { 94const p = await openPage ( browser , mock , { width :390 , height :780 , seed :{ chat :CHAT , ...on () } }); 95await sleep ( 200 ); 96return p ; 97}], 98[ "12-narrow-saved-chats-open" , async () => { 99const p = await openPage ( browser , mock , { width :390 , height :780 , seed :{ chat :CHAT , ...on () } }); 100await seedChats ( p ); 101await p . click ( "#sidebar-toggle" ); await sleep ( 300 ); 102return p ; 103}], 104[ "13-narrow-header-320" , async () => openPage ( browser , mock , { width :320 , height :640 , seed :{ chat :CHAT } })], 105[ "14-chat-settings" , async () => { 106const p = await openPage ( browser , mock , { width :1280 , height :900 , seed :{ chat :CHAT } }); 107await p . click ( "#sampling-btn" ); await sleep ( 500 ); 108await p . $eval ( ".st-drawer__body" , ( e ) => { e . scrollTop = e . scrollHeight ; }); 109await sleep ( 200 ); 110return p ; 111}], 112[ "15-send-while-answering" , async () => { 113const p = await openPage ( browser , mock , { width :1100 , height :760 , seed :on ({ whileBusy :"queue" }) }); 114await say ( p , "#hold start a long answer" ); 115await p . waitForFunction (() => busy !== null ); 116await sleep ( 500 ); 117await say ( p , "And then summarise it for me" ); 118await sleep ( 300 ); 119return p ; 120}], 121[ "16-load-unload" , async () => { 122mock . state . loaded = false ; 123const p = await openPage ( browser , mock , { width :1100 , height :520 }); 124await sleep ( 1500 ); 125return p ; 126}], 127[ "18-german-chat" , async () => { 128const p = await openPage ( browser , mock , { width :1280 , height :800 , query :"?lang=de" , seed :{ chat :CHAT , ...on () } }); 129await p . evaluate (() => { openRewind ( 2 ); }); 130await sleep ( 200 ); 131return p ; 132}], 133[ "19-german-chat-settings" , async () => { 134const p = await openPage ( browser , mock , { width :1280 , height :900 , query :"?lang=de" , seed :{ chat :CHAT } }); 135await p . click ( "#sampling-btn" ); await sleep ( 500 ); 136await p . $eval ( ".st-drawer__body" , ( e ) => { e . scrollTop = e . scrollHeight ; }); 137await sleep ( 200 ); 138return p ; 139}], 140[ "20-dark-saved-chats" , async () => { 141const p = await openPage ( browser , mock , { width :1280 , height :800 , dark :true , seed :{ chat :CHAT , ...on () } }); 142await seedChats ( p ); 143return p ; 144}], 145[ "17-narrow-wide-mid-900" , async () => openPage ( browser , mock , { width :900 , height :700 , seed :{ chat :CHAT , ...on () } })], 146]; 147 148try { 149for ( const [ name , make ] of shots ) { 150if ( only && ! name . includes ( only )) continue ; 151mock . state . loaded = true ; 152const page = await make (); 153await sleep ( 300 ); 154console . log ( await shot ( page , out , name ), page . errors . length ?"ERRORS " + page . errors . join ( " | " ) :"" ); 155await page . close (); 156} 157} finally { 158await browser . close (); 159await mock . stop (); 160}