okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
a1cc285fa
main
1#!/usr/bin/env node 2/** 3* Reading-measure check. 4* 5* node scripts/measure.mjs 6* 7* Long-form reading wants 45–75 characters per line, and ~66 is the classic 8* target. This asserts the transcript stays inside that band at every content 9* font size the settings offer, in both normal and focus mode — the property 10* most likely to silently regress when a width or a padding changes. 11* 12* Note: `--st-measure` is expressed in `ch`, but `ch` is the width of the "0" 13* glyph, which is narrower than average running text in GT Walsheim. Measured 14* characters therefore run ~1.2× the ch value, which is why the assertion is on 15* the rendered result rather than on the token. 16* 17* Requires the dev server. Exits non-zero if any size falls outside 45–75. 18*/ 19import { chromium } from 'playwright-core' ; 20import { existsSync } from 'node:fs' ; 21import { join } from 'node:path' ; 22import { homedir } from 'node:os' ; 23import { requireChromium } from './browser.mjs' ; 24 25const BASE = process . env . STRATA_URL ?? 'http://localhost:5199' ; 26const MIN = 45 ; 27const MAX = 75 ; 28 29const executablePath = requireChromium (); 30 31if ( ! executablePath ) { 32console . error ( 'No cached Chromium found.' ); 33process . exit ( 2 ); 34} 35 36const browser = await chromium . launch ({ executablePath, args :[ '--no-sandbox' ] }); 37const page = await browser . newPage ({ viewport :{ width :1512 , height :1110 } }); 38const errors = []; 39page . on ( 'pageerror' , ( e ) => errors . push ( e . message )); 40 41/** Characters per line of assistant prose, measured from the rendered element. */ 42const measure = async () => { 43await page . locator ( '.st-msg--assistant .st-bubble p' ). first (). scrollIntoViewIfNeeded (); 44return page . evaluate (() => { 45const para = document . querySelector ( '.st-msg--assistant .st-bubble p' ); 46if ( ! para ) return null ; 47const fs = getComputedStyle ( para ). fontSize ; 48const span = document . createElement ( 'span' ); 49span . style . cssText = `position:absolute;visibility:hidden;white-space:nowrap;font:400 ${ fs } var(--st-font)` ; 50span . textContent = 'abcdefghijklmnopqrstuvwxyz' . repeat ( 8 ); 51document . body . appendChild ( span ); 52const avg = span . getBoundingClientRect (). width / 208 ; 53span . remove (); 54return { chars :Math . round ( para . getBoundingClientRect (). width / avg ), fontSize :fs }; 55}); 56}; 57 58async function setSize ( px ) { 59await page . goto ( ` ${ BASE } /#/settings` , { waitUntil :'domcontentloaded' }); 60await page . waitForSelector ( '.st-slider' , { timeout :8000 }); 61// React tracks the previous value of a controlled input, so assigning .value 62// directly is ignored. Go through the native setter, then dispatch. 63await page . evaluate (( value ) => { 64const el = document . querySelector ( '.st-slider' ); 65const setter = Object . getOwnPropertyDescriptor ( HTMLInputElement . prototype , 'value' ). set ; 66setter . call ( el , String ( value )); 67el . dispatchEvent ( new Event ( 'input' , { bubbles :true })); 68}, px ); 69await page . waitForTimeout ( 250 ); 70// Confirm the setting actually took, so this check can never pass vacuously. 71const applied = await page . evaluate (() => 72getComputedStyle ( document . documentElement ). getPropertyValue ( '--st-content-fs' ). trim (), 73); 74if ( applied !== ` ${ px } px` ) { 75throw new Error ( `text size did not apply: asked for ${ px } px, --st-content-fs is " ${ applied } "` ); 76} 77} 78 79async function prepareConversation () { 80await page . goto ( ` ${ BASE } /#/chat` , { waitUntil :'domcontentloaded' }); 81await page . waitForTimeout ( 1300 ); 82await page . click ( 'button.nav-new' ); 83await page . waitForTimeout ( 300 ); 84await page . fill ( 'textarea' , 'read the readme' ); 85await page . keyboard . press ( 'Enter' ); 86await page . waitForTimeout ( 6500 ); 87} 88 89const rows = []; 90await prepareConversation (); 91 92for ( const size of [ 10 , 16 , 22 ]) { 93await setSize ( size ); 94await page . goto ( ` ${ BASE } /#/chat` , { waitUntil :'domcontentloaded' }); 95await page . waitForTimeout ( 1000 ); 96rows . push ([ ` ${ size } px · normal` , await measure ()]); 97 98await page . keyboard . press ( 'Meta+Shift+F' ); 99await page . waitForTimeout ( 700 ); 100rows . push ([ ` ${ size } px · focus` , await measure ()]); 101await page . keyboard . press ( 'Escape' ); 102await page . waitForTimeout ( 400 ); 103} 104 105await browser . close (); 106 107let failures = 0 ; 108console . log ( 'reading measure (target 45–75 characters per line)\n' ); 109for ( const [ label , m ] of rows ) { 110if ( ! m ) { 111console . log ( ` ${ label . padEnd ( 16 )} no prose found` ); 112failures += 1 ; 113continue ; 114} 115const ok = m . chars >= MIN && m . chars <= MAX ; 116if ( ! ok ) failures += 1 ; 117console . log ( ` ${ label . padEnd ( 16 )} ${ String ( m . chars ). padStart ( 3 )} chars/line at ${ m . fontSize } ${ ok ? 'PASS' : 'FAIL' } ` ); 118} 119if ( errors . length ) { 120failures += errors . length ; 121console . log ( `\n page errors: ${ errors . join ( '; ' )} ` ); 122} 123console . log ( failures ?`\nreading measure: ${ failures } failure(s)` :'\nreading measure: every size inside the comfortable band' ); 124process . exit ( failures ?1 :0 );