Elffuss BraidHub

utopia-ia/elffuss-code public

main · 2.0 KiBRawPermalink
1// Historial del prompt del chat: ↑/↓ recuperan lo enviado y ciclan.
2import { chromium } from 'playwright';
3import { CHROME_ARGS } from './chrome-args.mjs';
4const BASE = process.env.BASE || 'http://localhost:8799';
5let fails = 0;
6const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
7
8const b = await chromium.launch({ args: ['--enable-unsafe-webgpu', ...CHROME_ARGS] });
9const ctx = await b.newContext();
10await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
11const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } });
12await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
13await p.waitForTimeout(1500);
14
15const val = () => p.locator('#prompt').inputValue();
16const submit = async (t) => { await p.locator('#prompt').fill(t); await p.locator('#prompt').press('Enter'); await p.waitForTimeout(250); };
17
18await submit('primer mensaje');
19await submit('segundo mensaje');
20ok('el prompt se vacía al enviar', (await val()) === '');
21
22await p.locator('#prompt').focus();
23await p.keyboard.press('ArrowUp');
24ok('↑ recupera el último enviado', (await val()) === 'segundo mensaje', await val());
25await p.keyboard.press('ArrowUp');
26ok('↑↑ recupera el anterior', (await val()) === 'primer mensaje', await val());
27await p.keyboard.press('ArrowDown');
28ok('↓ vuelve al siguiente', (await val()) === 'segundo mensaje', await val());
29await p.keyboard.press('ArrowDown');
30ok('↓ al final restaura el borrador vacío', (await val()) === '', JSON.stringify(await val()));
31
32// persistencia entre recargas
33await p.reload({ waitUntil: 'domcontentloaded' });
34await p.waitForTimeout(1200);
35await p.locator('#prompt').focus();
36await p.keyboard.press('ArrowUp');
37ok('el historial persiste tras recargar', (await val()) === 'segundo mensaje', await val());
38
39console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ HISTORIAL DEL CHAT OK');
40await b.close();
41process.exit(fails ? 1 : 0);