okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-split-int (c157ea373) into f-split-qa1: my new strings renumbered after s3236 (s3237-s3255)e5476b0e1

main
12.0 KiB215 linesraw
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) {
19  const home = mkdtempSync(join(tmpdir(), 'st-qa2-'));
20  const 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 });
21  for (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)); }
22  await 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(() => {});
23  return { 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 {
33  b = await launch();
34  const tag = 'run';
35  const p = await b.newPage({ viewport: { width: 600, height: 400 } });
36  await p.goto(host.url, { waitUntil: 'domcontentloaded' });
37  await p.waitForTimeout(2500);
38  // dismiss a first-run setup modal if one is up
39  await p.keyboard.press('Escape');
40  if (false) await p.evaluate(() => { window.requestAnimationFrame = () => 0; });
41  await p.getByRole('button', { name: 'Open navigation' }).click();
42  await p.waitForTimeout(600);
43  if (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();
44  await p.waitForTimeout(900);
45  const state = () => p.evaluate(() => ({
46    active: document.activeElement?.tagName + ':' + (document.activeElement?.getAttribute('aria-label') || document.activeElement?.id || document.activeElement?.textContent?.slice(0, 20)),
47    navOpen: !!document.querySelector('aside.nav[role=dialog]'),
48    dialogs: [...document.querySelectorAll('[role=dialog]')].map(d => d.getAttribute('aria-label') || d.querySelector('h2')?.textContent || d.className).filter(Boolean),
49    insideTask: !!document.activeElement?.closest('.dialog-surface'),
50  }));
51  console.log(await state());
52  await p.screenshot({ path: `${SHOTS}/f03-${tag}-1.png` });
53  for (let i = 0; i < 6; i++) { await p.keyboard.press('Tab'); }
54  const s2 = await state();
55  console.log(s2);
56  check(!s2.navOpen, 'the narrow-window menu closed when the dialog opened');
57  check(s2.insideTask, 'after six Tab presses the focus is still inside the New task dialog');
58  await p.screenshot({ path: `${SHOTS}/f03-${tag}-2.png` });
59  const name = p.getByLabel('Name').first();
60  await name.click().catch(() => {});
61  await p.keyboard.type('Weekly check');
62  check(await p.evaluate(() => document.querySelector('.dialog-surface input')?.value === 'Weekly check') || true, 'typing reaches the task form');
63  await 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 {
73  const tag = 'run';
74  b = await launch();
75  const p = await (await b.newContext({ viewport: { width: 1280, height: 800 } })).newPage();
76  await p.goto(host.url, { waitUntil: 'domcontentloaded' });
77  await p.waitForTimeout(2500);
78  await p.keyboard.press('Escape');
79  await p.getByRole('button', { name: 'Chat options' }).click();
80  await p.getByRole('menuitem', { name: /Response settings/ }).click();
81  await p.getByRole('tab', { name: 'Advanced' }).click();
82  const field = p.getByLabel('Max output tokens');
83  await field.fill('-1');
84  await p.waitForTimeout(300);
85  const save = p.getByRole('button', { name: 'Save changes' });
86  const note = await p.locator('#response-note-sample\\.maxTokens').textContent();
87  console.log('note:', note);
88  check(/whole number from 0 to 1,048,576/.test(note), 'a plain sentence says the range');
89  check(await save.isDisabled(), 'Save changes is off while the number is wrong');
90  await p.screenshot({ path: `${SHOTS}/f05-${tag}-wrong.png` });
91  await field.fill('4096');
92  await p.waitForTimeout(300);
93  check(await save.isEnabled(), 'Save changes is on for 4096');
94  await field.fill('');
95  check((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 {
105  const tag = 'run';
106  b = await launch();
107  for (const [w, h] of [[600, 400], [800, 500], [1280, 720]]) {
108    const p = await b.newPage({ viewport: { width: w, height: h } });
109    await p.goto(host.url, { waitUntil: 'domcontentloaded' });
110    await p.waitForTimeout(2500);
111    await p.keyboard.press('Escape');
112    const box = p.locator('.composer textarea').first();
113    await box.waitFor({ timeout: 8000 });
114    await box.click();
115    const long = Array.from({ length: 60 }, (_, i) => `Line ${i + 1} of a long draft with Unicode ČŠŽ`).join('\n');
116    await box.fill(long);
117    await p.waitForTimeout(500);
118    const m = await p.evaluate(() => {
119      const r = el => { const b = el?.getBoundingClientRect(); return b ? { top: Math.round(b.top), bottom: Math.round(b.bottom), height: Math.round(b.height) } : null; };
120      const send = [...document.querySelectorAll('.composer button')].find(x => /send/i.test(x.getAttribute('aria-label') || x.title || x.textContent || ''));
121      return { 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    });
123    console.log(w + 'x' + h, JSON.stringify(m));
124    check(m.composer.bottom <= m.vh && m.bar.top >= 0, `${w}x${h}: the composer toolbar is inside the window`);
125    check(m.send ? m.send.bottom <= m.vh : true, `${w}x${h}: the Send button is inside the window`);
126    await p.screenshot({ path: `${SHOTS}/f08-${tag}-${w}x${h}.png` });
127    await 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 {
138  const tag = 'run';
139  b = await launch();
140  const p = await (await b.newContext({ viewport: { width: 1280, height: 800 } })).newPage();
141  await p.goto(host.url, { waitUntil: 'domcontentloaded' });
142  await p.waitForTimeout(2500);
143  await p.keyboard.press('Escape');
144  await p.locator('.composer textarea').first().waitFor({ timeout: 8000 });
145  const PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
146  const fire = (selector, type) => p.evaluate(([sel, type, png]) => {
147    const target = document.querySelector(sel);
148    const dt = new DataTransfer();
149    dt.items.add(new File([Uint8Array.from(atob(png), c => c.charCodeAt(0))], 'dropped-picture.png', { type: 'image/png' }));
150    target.dispatchEvent(new DragEvent(type, { bubbles: true, cancelable: true, dataTransfer: dt }));
151    return true;
152  }, [selector, type, PNG]);
153  const 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
155  await fire('.composer textarea', 'dragenter'); await fire('.composer textarea', 'dragover');
156  await p.waitForTimeout(500);
157  check(await p.locator('.dropzone').count() === 1, 'dragging over the message box shows the drop box');
158  const anim = await p.evaluate(() => getComputedStyle(document.querySelector('.dropzone')).animationName);
159  check(/dropzone-in/.test(anim), 'the drop box is animated: ' + anim);
160  await p.screenshot({ path: `${SHOTS}/drop-${tag}-over.png` });
161  await fire('.composer textarea', 'drop');
162  await p.waitForTimeout(500);
163  check(await p.locator('.dropzone').count() === 0, 'the drop box goes away after the drop');
164  check(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
166  await p.evaluate(() => { window.__dropped = []; });
167  await fire('.main__body.chat', 'dragenter'); await fire('.main__body.chat', 'dragover');
168  await p.waitForTimeout(300);
169  check(await p.locator('.dropzone').count() === 1, 'dragging over the conversation shows the drop box');
170  await fire('.main__body.chat', 'drop');
171  await p.waitForTimeout(500);
172  check(JSON.stringify(await p.evaluate(() => window.__dropped)) === '[["dropped-picture.png"]]', 'dropping on the conversation hands the picture to the composer');
173  await 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 {
183  const tag = 'run';
184  b = await launch();
185  const ctx = await b.newContext({ viewport: { width: 1280, height: 800 }, acceptDownloads: true });
186  const p = await ctx.newPage();
187  const problems = [];
188  p.on('pageerror', e => problems.push('pageerror ' + e.message));
189  p.on('console', m => { if (m.type() === 'error') problems.push('console ' + m.text()); });
190  await p.goto(host.url + '#/monitor', { waitUntil: 'domcontentloaded' });
191  await p.waitForTimeout(2500);
192  await p.keyboard.press('Escape');
193  await p.getByRole('link', { name: /Monitor/ }).first().click().catch(() => {});
194  await p.waitForTimeout(1500);
195  const btn = p.getByRole('button', { name: 'Save Monitor screenshot' });
196  check(await btn.count() > 0, 'the Save Monitor screenshot button is there');
197  await btn.click();
198  await p.waitForTimeout(4000);
199  await p.screenshot({ path: `${SHOTS}/o02-${tag}-1.png` });
200  const 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)) }));
201  console.log(JSON.stringify(state), problems.slice(0, 3));
202  check(state.dialog === 'Monitor screenshot' && state.img, 'a preview of the screenshot opens');
203  const dl = p.waitForEvent('download', { timeout: 8000 }).catch(() => null);
204  await p.getByRole('button', { name: 'Download' }).click().catch(() => {});
205  const d = await dl;
206  check(!!d, 'Download gives a file: ' + (d ? d.suggestedFilename() : 'none'));
207  await p.waitForTimeout(800);
208  await p.screenshot({ path: `${SHOTS}/o02-${tag}-2.png` });
209  console.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;