Files
Strata/app/host/scripts/measure.mjs
T
Niko1221 4058aa782b Layout move for 0.2.16: the top level becomes app/, engine/, terminal/, docs/, tools/ and .github/
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
  changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
  Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
  repository paths inside tests.

engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.

No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
2026-11-17 13:19:21 +01:00

125 lines
4.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* Reading-measure check.
*
* node scripts/measure.mjs
*
* Long-form reading wants 45–75 characters per line, and ~66 is the classic
* target. This asserts the transcript stays inside that band at every content
* font size the settings offer, in both normal and focus mode — the property
* most likely to silently regress when a width or a padding changes.
*
* Note: `--st-measure` is expressed in `ch`, but `ch` is the width of the "0"
* glyph, which is narrower than average running text in GT Walsheim. Measured
* characters therefore run ~1.2× the ch value, which is why the assertion is on
* the rendered result rather than on the token.
*
* Requires the dev server. Exits non-zero if any size falls outside 45–75.
*/
import { chromium } from 'playwright-core';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { homedir } from 'node:os';
import { requireChromium } from './browser.mjs';
const BASE = process.env.STRATA_URL ?? 'http://localhost:5199';
const MIN = 45;
const MAX = 75;
const executablePath = requireChromium();
if (!executablePath) {
console.error('No cached Chromium found.');
process.exit(2);
}
const browser = await chromium.launch({ executablePath, args: ['--no-sandbox'] });
const page = await browser.newPage({ viewport: { width: 1512, height: 1110 } });
const errors = [];
page.on('pageerror', (e) => errors.push(e.message));
/** Characters per line of assistant prose, measured from the rendered element. */
const measure = async () => {
await page.locator('.st-msg--assistant .st-bubble p').first().scrollIntoViewIfNeeded();
return page.evaluate(() => {
const para = document.querySelector('.st-msg--assistant .st-bubble p');
if (!para) return null;
const fs = getComputedStyle(para).fontSize;
const span = document.createElement('span');
span.style.cssText = `position:absolute;visibility:hidden;white-space:nowrap;font:400 ${fs} var(--st-font)`;
span.textContent = 'abcdefghijklmnopqrstuvwxyz'.repeat(8);
document.body.appendChild(span);
const avg = span.getBoundingClientRect().width / 208;
span.remove();
return { chars: Math.round(para.getBoundingClientRect().width / avg), fontSize: fs };
});
};
async function setSize(px) {
await page.goto(`${BASE}/#/settings`, { waitUntil: 'domcontentloaded' });
await page.waitForSelector('.st-slider', { timeout: 8000 });
// React tracks the previous value of a controlled input, so assigning .value
// directly is ignored. Go through the native setter, then dispatch.
await page.evaluate((value) => {
const el = document.querySelector('.st-slider');
const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set;
setter.call(el, String(value));
el.dispatchEvent(new Event('input', { bubbles: true }));
}, px);
await page.waitForTimeout(250);
// Confirm the setting actually took, so this check can never pass vacuously.
const applied = await page.evaluate(() =>
getComputedStyle(document.documentElement).getPropertyValue('--st-content-fs').trim(),
);
if (applied !== `${px}px`) {
throw new Error(`text size did not apply: asked for ${px}px, --st-content-fs is "${applied}"`);
}
}
async function prepareConversation() {
await page.goto(`${BASE}/#/chat`, { waitUntil: 'domcontentloaded' });
await page.waitForTimeout(1300);
await page.click('button.nav-new');
await page.waitForTimeout(300);
await page.fill('textarea', 'read the readme');
await page.keyboard.press('Enter');
await page.waitForTimeout(6500);
}
const rows = [];
await prepareConversation();
for (const size of [10, 16, 22]) {
await setSize(size);
await page.goto(`${BASE}/#/chat`, { waitUntil: 'domcontentloaded' });
await page.waitForTimeout(1000);
rows.push([`${size}px · normal`, await measure()]);
await page.keyboard.press('Meta+Shift+F');
await page.waitForTimeout(700);
rows.push([`${size}px · focus`, await measure()]);
await page.keyboard.press('Escape');
await page.waitForTimeout(400);
}
await browser.close();
let failures = 0;
console.log('reading measure (target 45–75 characters per line)\n');
for (const [label, m] of rows) {
if (!m) {
console.log(` ${label.padEnd(16)} no prose found`);
failures += 1;
continue;
}
const ok = m.chars >= MIN && m.chars <= MAX;
if (!ok) failures += 1;
console.log(` ${label.padEnd(16)} ${String(m.chars).padStart(3)} chars/line at ${m.fontSize} ${ok ? 'PASS' : 'FAIL'}`);
}
if (errors.length) {
failures += errors.length;
console.log(`\n page errors: ${errors.join('; ')}`);
}
console.log(failures ? `\nreading measure: ${failures} failure(s)` : '\nreading measure: every size inside the comfortable band');
process.exit(failures ? 1 : 0);