Elffuss BraidHub

utopia-ia/elffuss-claw public

main · 8.8 KiBRawPermalink
1// Ajustes: proveedores externos, feedback y «Acerca de».
2// · «Servidor Elffuss (Ornith 9B)» ya no se ofrece (el servicio está parado y
3// elegirlo fallaba siempre), aunque estuviera activado de antes.
4// · La casilla de cada proveedor tiene nombre; al activarla el aviso lleva al
5// selector de modelo (no al 🧠).
6// · El feedback dice si llegó: si falla, lo dice y el texto se queda.
7// · «Acerca de» enlaza el código, la comunidad, las incidencias y la licencia;
8// el sello del build enlaza su commit solo si es un commit limpio.
9// · Con el teclado el foco no cae a <body>: «Enviar» lo conserva mientras
10// envía, y olvidar un hecho (o deshacerlo) lo lleva al ✕ que toca.
11//
12// BASE=http://localhost:8743 node tests/ux-ajustes.mjs
13import { navegador, contexto, pagina, ok, hasta, avisos, fin, BASE } from './ux-comun.mjs';
14
15const b = await navegador();
16const { ctx } = await contexto(b, {
17 extraInit: { 'elffuss.providers': JSON.stringify({ server: { enabled: true, baseURL: 'https://claw.elffuss.com/v1', model: 'ornith-9b', apiKey: '' } }) },
18});
19const { p, errores } = await pagina(ctx);
20const foco = () => p.evaluate(() => {
21 const a = document.activeElement;
22 return !a || a === document.body ? 'BODY' : (a.getAttribute('aria-label') || a.textContent || a.id).trim().slice(0, 80);
23});
24const abrirAjustes = async () => { await p.click('#tabs button[data-tab="ajustes"]'); await p.locator('#panel-ajustes .ext-block').waitFor(); };
25await abrirAjustes();
26await p.click('#panel-ajustes .ext-block > summary');
27ok('el servidor Ornith 9B no se ofrece en Ajustes', !(await p.locator('#panel-ajustes').innerText()).includes('Ornith'));
28ok('…ni en el selector aunque estuviera activado de antes', !(await p.evaluate(() =>
29 [...document.querySelectorAll('#model-select option')].some(o => o.value === 'ext:server'))));
30
31const casilla = p.locator('#prov-ollama');
32ok('la casilla de cada proveedor tiene nombre', await casilla.getAttribute('aria-label') === 'Activar Ollama (local)'
33 && await p.locator('label[for="prov-ollama"]').count() === 1);
34await casilla.check();
35const aviso = p.locator('#toasts .toast', { hasText: 'Ollama' });
36ok('activarlo dice «elígelo en el selector de modelo», no «🧠»', await hasta(async () => /selector de modelo/.test(await aviso.innerText().catch(() => '')))
37 && !/🧠/.test(await aviso.innerText()));
38ok('…y aparece en el selector', await p.evaluate(() => [...document.querySelectorAll('#model-select option')].some(o => o.value === 'ext:ollama')));
39await aviso.locator('.toast-accion').click();
40ok('su botón lleva al selector de modelo', await p.evaluate(() => document.activeElement?.id === 'model-select'));
41
42// ── feedback ────────────────────────────────────────────────────────────────
43let estado = 500, recibido = null;
44await p.route('**/proxy/report', async route => { recibido = route.request().postDataJSON(); await route.fulfill({ status: estado, body: estado === 200 ? '{"ok":true}' : 'caído' }); });
45await abrirAjustes();
46await p.fill('#tel-feedback', 'el botón X no hace nada');
47await p.locator('#panel-ajustes button:has-text("Enviar")').focus();
48await p.keyboard.press('Enter');
49ok('si el envío falla, lo dice y el texto se queda', await hasta(async () => (await avisos(p)).some(t => /No ha llegado/.test(t)))
50 && (await p.inputValue('#tel-feedback')) === 'el botón X no hace nada' && !(await avisos(p)).some(t => /gracias/.test(t)));
51ok('…y con el teclado el foco sigue en «Enviar» (no cae a <body>)', (await foco()) === 'Enviar', await foco());
52ok('…y ofrece el sitio público de incidencias', await p.locator('#toasts .toast', { hasText: 'No ha llegado' }).locator('.toast-accion').innerText() === 'Abrir incidencias');
53estado = 200;
54await p.click('#panel-ajustes button:has-text("Enviar")');
55ok('si llega, da las gracias y vacía el texto', await hasta(async () => (await avisos(p)).some(t => /gracias/.test(t)))
56 && (await p.inputValue('#tel-feedback')) === '' && recibido?.kind === 'feedback');
57ok('enviar feedback a mano no deja encendido el envío automático', !(await p.evaluate(async () => (await import('/js/telemetry.js')).isEnabled())));
58
59// ── acerca de ───────────────────────────────────────────────────────────────
60const acerca = p.locator('#panel-ajustes [data-ruta="acerca"]');
61const hrefs = await acerca.locator('a').evaluateAll(as => as.map(a => [a.getAttribute('href'), a.getAttribute('rel')]));
62ok('«Acerca de» enlaza el código, la comunidad y las incidencias (sin referrer)',
63 hrefs.some(([h]) => h === 'https://github.com/KikoCis/elffuss-claw') && hrefs.some(([h]) => h === 'https://git.elffuss.com/elffuss/claw')
64 && hrefs.some(([h]) => h === 'https://git.elffuss.com/elffuss/claw/issues') && hrefs.every(([, r]) => r === 'noopener noreferrer'), JSON.stringify(hrefs));
65ok('…dice la licencia y, en desarrollo, que no hay sello', /Apache-2\.0/.test(await acerca.innerText()) && /de desarrollo/.test(await acerca.innerText()));
66const sellos = await p.evaluate(async () => {
67 const ui = await import('/js/ui.js');
68 const limpio = ui.enlaceBuild('7b2385c'), sucio = ui.enlaceBuild('7b2385c-dirty');
69 return { limpio: limpio.tagName + ' ' + limpio.getAttribute('href'), sucio: sucio.tagName + ' ' + (sucio.getAttribute('href') || '') };
70});
71ok('un sello limpio enlaza su commit en GitHub; uno «-dirty» no enlaza', sellos.limpio === 'A https://github.com/KikoCis/elffuss-claw/commit/7b2385c' && sellos.sucio === 'SPAN ', JSON.stringify(sellos));
72await p.goto(BASE + '/#/ajustes/acerca', { waitUntil: 'domcontentloaded' });
73await p.waitForFunction(() => !!window.elffuss?.agent);
74ok('#/ajustes/acerca lleva a esa tarjeta', await hasta(() => p.evaluate(() =>
75 document.querySelector('#panel-ajustes [data-ruta="acerca"]')?.classList.contains('resaltado'))));
76
77// ── memoria: se ve y se olvida hecho a hecho ────────────────────────────────
78await p.evaluate(async () => {
79 const db = await import('/js/db.js');
80 await db.set('memory', 'mprueba', { id: 'mprueba', fact: 'le gusta el té verde', at: Date.now() });
81 await db.set('memory', 'mprueba2', { id: 'mprueba2', fact: 'vive en Madrid', at: Date.now() + 1 });
82});
83await p.goto(BASE + '/#/memoria/mprueba', { waitUntil: 'domcontentloaded' });
84await p.waitForFunction(() => !!window.elffuss?.agent);
85const hecho = p.locator('#panel-ajustes [data-ruta="mprueba"]');
86ok('#/memoria/<id> abre Ajustes y señala ese hecho (sin el texto en la URL)', await hasta(async () =>
87 await hecho.evaluate(e => e.classList.contains('resaltado')).catch(() => false)) && !/t%C3%A9|té/.test(await p.evaluate(() => location.href)));
88await hecho.locator('button[aria-label="Olvidar «le gusta el té verde»"]').focus();
89await p.keyboard.press('Enter');
90ok('✕ lo olvida…', await hasta(async () => await hecho.count() === 0)
91 && !(await p.evaluate(async () => (await (await import('/js/db.js')).get('memory', 'mprueba')))));
92ok('…con el teclado, el foco va al ✕ del hecho que queda en su sitio', await hasta(async () => (await foco()) === 'Olvidar «vive en Madrid»'), await foco());
93await p.locator('#toasts .toast', { hasText: 'Olvidado' }).locator('.toast-accion').focus();
94await p.keyboard.press('Enter');
95ok('…y «Deshacer» lo devuelve', await hasta(async () => await hecho.count() === 1));
96ok('…con el foco en su ✕', await hasta(async () => (await foco()) === 'Olvidar «le gusta el té verde»'), await foco());
97ok('el lema de la cabecera sale en español', (await p.locator('.brand .claim').first().innerText()) === 'las apps no existen: se crean');
98
99// ── el modo básico señala el selector de modelo, no el 🧠 ───────────────────
100await p.fill('#prompt', 'hola');
101await p.press('#prompt', 'Enter');
102const enlace = p.locator('#log .msg.assistant a[href="#/modelo"]').last();
103ok('la ayuda del modo básico enlaza al «selector de modelo»', await hasta(async () => await enlace.count() === 1)
104 && !/selector 🧠/.test(await p.locator('#log').innerText()));
105await enlace.click();
106ok('…y el enlace lo enfoca (y la URL vuelve a decir dónde estás)', await hasta(() => p.evaluate(() =>
107 document.activeElement?.id === 'model-select' && location.hash !== '#/modelo')));
108
109{
110 const { ctx: c2 } = await contexto(b, { locale: 'en-US' });
111 const { p: e } = await pagina(c2);
112 ok('en inglés el lema de la cabecera sale en inglés', (await e.locator('.brand .claim').first().innerText()) === 'apps don’t exist: they get created');
113 await c2.close();
114}
115
116ok('sin errores de página', errores.length === 0, errores.slice(0, 3).join(' | '));
117await fin(b, 'AJUSTES: sin Ornith roto, casillas con nombre, feedback honesto y «Acerca de» con enlaces');