Elffuss BraidHub

utopia-ia/elffuss-code public

2df00d521f0c · 2.4 KiBRawPermalink
1// Feedback claro al enviar (antes el botón siempre se veía igual, sin
2// distinguir enviado/pensando) + Enter explícito tras recuperar del
3// historial con ↑ (antes dependía del submit-on-Enter nativo del <form>).
4import { chromium } from 'playwright';
5const OUT = (process.env.SCRATCH || '/tmp/elffuss-test');
6const BASE = process.env.BASE || 'http://localhost:8799';
7let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
8
9const b = await chromium.launch();
10const ctx = await b.newContext();
11await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
12const p = await ctx.newPage();
13await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500);
14
15// proveedor lento para poder observar el estado "enviando"
16await p.evaluate(() => {
17 window.elffussClaw.agent.provider = {
18 chat: async (h, s, onToken) => { await new Promise(r => setTimeout(r, 1200)); onToken('ok'); return 'ok'; },
19 };
20});
21
22ok('el botón de enviar empieza normal (sin "sending")', !(await p.locator('#btn-send').evaluate(el => el.classList.contains('sending'))));
23await p.fill('#prompt', 'hola');
24await p.press('#prompt', 'Enter');
25await p.waitForTimeout(150);
26// Desde 2421c1b el botón NO se deshabilita mientras genera: pasa a ■ Parar.
27ok('el botón de enviar pasa a ■ PARAR mientras genera (sending + is-stop, clicable)', await p.locator('#btn-send').evaluate(el => el.classList.contains('sending') && el.classList.contains('is-stop') && !el.disabled));
28await p.waitForTimeout(1500);
29ok('al terminar, el botón vuelve a su estado normal', await p.locator('#btn-send').evaluate(el => !el.classList.contains('sending') && !el.disabled));
30
31// historial con ArrowUp + Enter EXPLÍCITO (requestSubmit, no submit nativo)
32await p.click('#prompt');
33await p.press('#prompt', 'ArrowUp');
34await p.waitForTimeout(80);
35const recalled = await p.inputValue('#prompt');
36ok('ArrowUp recupera el último mensaje', recalled === 'hola', recalled);
37await p.press('#prompt', 'Enter');
38await p.waitForTimeout(150);
39ok('Enter tras ArrowUp limpia el input (se mandó)', (await p.inputValue('#prompt')) === '');
40ok('Enter tras ArrowUp SÍ manda directamente (2 mensajes de usuario)', await p.locator('.msg.user').count() === 2);
41
42console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ FEEDBACK DE ENVÍO + HISTORIAL→ENTER OK');
43await b.close();
44process.exit(fails ? 1 : 0);