okami.mom/strata

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

Niko1221merge f-split-agent2 c7b65c7f7 (/loop, /goal, /time-skip, keyless search, system-browser tool, Settings Tools, Plan refuses connected tools) into f-split-intea2d565e6

main
10.2 KiB180 linesraw
1/**
2 * The three slash commands through the real app on a real model, with screenshots (playwright-core + installed Chrome).
3 *
4 *   STRATA_URL=http://127.0.0.1:8899 SHOTS=./shots WORKDIR=<the host's workspace> MODEL='Qwen test' node scripts/agent2-flow.mjs
5 *
6 * Steps (each prints ok/FAIL):
7 *   1. typing "/" lists /time-skip, /goal and /loop with plain descriptions;
8 *   2. /loop 1m <message>: the first answer arrives, the loop repeats it a minute later, /loop shows it, /loop stop ends it;
9 *   3. /goal <objective>: the assistant works until the goal is complete (Manual mode: Approve cards are clicked), /goal shows it;
10 *   4. /time-skip <request>: a job runs on a copy, the sidebar lists the changed file, Keep the update changes the file in WORKDIR,
11 *      Put the original back restores it.
12 * Environment: STRATA_URL (required), SHOTS, WORKDIR, MODEL (picker text), CHROME, SKIP (comma list of steps to skip: menu,loop,goal,timeskip),
13 * LOOP_WAIT_MS (how long to wait for the second loop run, default 150000).
14 */
15import { chromium } from 'playwright-core';
16import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
17import { join, resolve } from 'node:path';
18
19const BASE = process.env.STRATA_URL;
20if (!BASE) { console.error('STRATA_URL is required'); process.exit(2); }
21const SHOTS = resolve(process.env.SHOTS ?? 'agent2-shots');
22mkdirSync(SHOTS, { recursive: true });
23const WORKDIR = process.env.WORKDIR;
24const MODEL = process.env.MODEL ?? 'Qwen test';
25const SKIP = new Set((process.env.SKIP ?? '').split(',').filter(Boolean));
26const CHROME = process.env.CHROME ?? ['C:/Program Files/Google/Chrome/Application/chrome.exe', '/usr/bin/google-chrome'].find(existsSync);
27
28let failed = false;
29const check = (ok, label) => { console.log(`${ok ? 'ok  ' : 'FAIL'} ${label}`); if (!ok) failed = true; };
30const browser = await chromium.launch({ executablePath: CHROME, headless: true });
31const page = await browser.newPage({ viewport: { width: 1512, height: 1000 } });
32const problems = [];
33page.on('pageerror', e => problems.push(`pageerror: ${e.message}`));
34page.on('console', m => { if (m.type() === 'error') problems.push(`console: ${m.text().slice(0, 200)}`); });
35const shot = async name => { await page.waitForTimeout(400); await page.screenshot({ path: join(SHOTS, `${name}.png`) }); console.log(`shot ${name}.png`); };
36const send = async text => { await page.locator('textarea').first().fill(text); await page.getByRole('button', { name: 'Send' }).click(); };
37const idle = async (ms = 900000) => page.waitForFunction(() => document.documentElement.dataset.streaming !== 'true', null, { timeout: ms });
38const started = async () => page.waitForFunction(() => document.documentElement.dataset.streaming === 'true', null, { timeout: 30000 });
39const text = () => page.evaluate(() => document.querySelector('.chat')?.innerText ?? document.body.innerText);
40
41/** Approve every card that asks until the turn is over. */
42async function approveUntilIdle(label) {
43  let asked = 0; const seen = new Set();
44  for (;;) {
45    const streaming = await page.evaluate(() => document.documentElement.dataset.streaming === 'true');
46    const cards = page.locator('.toolcard[data-state="proposed"]');
47    const n = await cards.count();
48    for (let i = 0; i < n; i++) {
49      const card = cards.nth(i);
50      const key = (await card.innerText()).slice(0, 200);
51      if (!seen.has(key)) { seen.add(key); asked++; await shot(`${label}-approve-${asked}`); }
52      await card.getByRole('button', { name: 'Approve' }).click().catch(() => {});
53    }
54    if (!streaming && n === 0) break;
55    await page.waitForTimeout(400);
56  }
57  return asked;
58}
59
60try {
61  await page.goto(`${BASE}/#/chat`);
62  await page.waitForTimeout(2000);
63  const skip = page.getByText('Go straight to the app');
64  if (await skip.count()) { await skip.click(); await page.waitForTimeout(600); }
65  await page.getByRole('button', { name: 'New chat' }).first().click();
66  await page.waitForTimeout(600);
67  await page.getByRole('button', { name: /Choose model/ }).first().click();
68  await page.waitForTimeout(300);
69  await page.getByRole('menuitemradio', { name: new RegExp(MODEL) }).first().click();
70  await page.waitForTimeout(300);
71
72  // 1. the menu
73  if (!SKIP.has('menu')) {
74    await page.locator('textarea').first().fill('/');
75    await page.waitForSelector('.slashmenu', { timeout: 5000 });
76    const menu = await page.locator('.slashmenu').innerText();
77    await shot('01-slash-menu');
78    check(/\/time-skip/.test(menu) && /Try a change on a copy/.test(menu), '/time-skip is listed with its plain description');
79    check(/\/goal/.test(menu) && /keep working until it is done/.test(menu), '/goal is listed with its plain description');
80    check(/\/loop/.test(menu) && /every few minutes/.test(menu), '/loop is listed with its plain description');
81    await page.locator('textarea').first().fill('/lo');
82    await shot('01b-slash-menu-filtered');
83    await page.locator('textarea').first().fill('');
84  }
85
86  // 2. /loop
87  if (!SKIP.has('loop')) {
88    await send('/loop 1m Reply with exactly three words about the sea.');
89    await page.waitForTimeout(1500);
90    await shot('02a-loop-started');
91    let body = await text();
92    check(/Loop started: .Reply with exactly three words about the sea\.. every minute/.test(body), 'a note says the loop started and how often');
93    await started().catch(() => {});
94    await idle();
95    await shot('02b-loop-first-answer');
96    const firstCount = (await text()).split('Reply with exactly three words about the sea.').length - 1;
97    const t0 = Date.now();
98    const wait = Number(process.env.LOOP_WAIT_MS ?? 150000);
99    await page.waitForFunction(n => (document.querySelector('.chat')?.innerText ?? '').split('Reply with exactly three words about the sea.').length - 1 > n, firstCount, { timeout: wait }).catch(() => {});
100    await idle();
101    await shot('02c-loop-second-run');
102    const secondCount = (await text()).split('Reply with exactly three words about the sea.').length - 1;
103    check(secondCount > firstCount, `the loop sent the message again on its own (${Math.round((Date.now() - t0) / 1000)} s after the first answer)`);
104    await send('/loop');
105    await page.waitForTimeout(800);
106    check(/A loop is running in this chat/.test(await text()), '/loop says a loop is running');
107    await send('/loop stop');
108    await page.waitForTimeout(800);
109    await shot('02d-loop-stopped');
110    check(/The loop is stopped/.test(await text()), '/loop stop says it is stopped');
111    const afterStop = (await text()).split('Reply with exactly three words about the sea.').length - 1;
112    await page.waitForTimeout(75000);
113    await idle();
114    check((await text()).split('Reply with exactly three words about the sea.').length - 1 === afterStop, 'nothing more was sent after stopping');
115  }
116
117  // 3. /goal
118  if (!SKIP.has('goal')) {
119    await page.getByRole('button', { name: 'New chat' }).first().click();
120    await page.waitForTimeout(600);
121    await page.getByRole('button', { name: /Choose model/ }).first().click();
122    await page.waitForTimeout(300);
123    await page.getByRole('menuitemradio', { name: new RegExp(MODEL) }).first().click();
124    await page.waitForTimeout(300);
125    await send('/goal Create a file called goal-done.txt in the current folder that contains the single word done, then confirm it exists.');
126    await started().catch(() => {});
127    const asked = await approveUntilIdle('03');
128    await idle();
129    await shot('03a-goal-finished');
130    const body = await text();
131    check(!!WORKDIR && existsSync(join(WORKDIR, 'goal-done.txt')), 'the goal produced goal-done.txt');
132    check(/goal is complete|goal-done\.txt/i.test(body), 'the chat says the goal is complete or names the file');
133    console.log(`approval cards: ${asked}`);
134    await send('/goal');
135    await page.waitForTimeout(1500);
136    await shot('03b-goal-status');
137  }
138
139  // 4. /time-skip
140  if (!SKIP.has('timeskip')) {
141    await page.getByRole('button', { name: 'New chat' }).first().click();
142    await page.waitForTimeout(600);
143    await page.getByRole('button', { name: /Choose model/ }).first().click();
144    await page.waitForTimeout(300);
145    await page.getByRole('menuitemradio', { name: new RegExp(MODEL) }).first().click();
146    await page.waitForTimeout(300);
147    const notes = WORKDIR ? join(WORKDIR, 'notes.md') : null;
148    const before = notes && existsSync(notes) ? readFileSync(notes, 'utf8') : null;
149    await send('/time-skip Add a second line to notes.md that says: second line added.');
150    await page.waitForTimeout(2500);
151    await shot('04a-timeskip-working');
152    await page.waitForFunction(() => /Ready to compare|Update kept|Saved version kept|could not be completed|stopped|interrupted/i.test(document.querySelector('#time-skip-content .ts-heading')?.innerText ?? ''), null, { timeout: 1200000 }).catch(() => {});
153    await shot('04b-timeskip-ready');
154    const panel = await page.locator('#time-skip-content').innerText().catch(() => '');
155    check(/Ready to compare/.test(panel), 'the sidebar says the result is ready to compare');
156    check(/notes\.md/.test(panel), 'the sidebar names the changed file');
157    check(!notes || readFileSync(notes, 'utf8') === before, 'your file is untouched until you choose');
158    await page.getByRole('button', { name: 'Compare' }).first().click().catch(() => {});
159    await page.waitForTimeout(800);
160    await shot('04c-timeskip-compare');
161    await page.getByRole('button', { name: /Back to chat|Done comparing/ }).first().click().catch(() => {});
162    await page.getByRole('button', { name: 'Keep the update' }).first().click();
163    await page.waitForTimeout(4000);
164    await shot('04d-timeskip-kept');
165    check(!notes || /second line added/i.test(readFileSync(notes, 'utf8')), 'Keep the update put the revision in your file');
166    await page.getByRole('button', { name: 'Put the original back' }).first().click();
167    await page.waitForTimeout(4000);
168    await shot('04e-timeskip-restored');
169    check(!notes || readFileSync(notes, 'utf8') === before, 'Put the original back restored your file');
170  }
171} catch (e) {
172  console.log('ERROR', e.message);
173  await shot('zz-error').catch(() => {});
174  failed = true;
175} finally {
176  const text = problems.filter(p => !/Failed to load resource|ERR_|favicon/.test(p));
177  console.log(`page problems: ${text.length}`); text.slice(0, 8).forEach(p => console.log('  ' + p));
178  await browser.close();
179}
180process.exit(failed ? 1 : 0);