Elffuss BraidHub

utopia-ia/elffuss-code public

main · 8.9 KiBRawPermalink
1// Avisos que se entienden y textos en el idioma de la interfaz.
2//
3// 1. Fallo al cargar el modelo: en palabras de persona («sin conexión…», no
4// «Failed to fetch»), en una región viva, con «Reintentar» que reintenta.
5// Con el teclado, Reintentar y ✕ devuelven el foco a donde estaba (antes
6// quitaban sus propios botones con el foco dentro y caía a <body>).
7// 2. Skills: sin conexión, «Explorar» lo dice dentro del panel con
8// «Reintentar»; un repo que no vale se dice en línea, sin alert().
9// 3. El modo Básico manda a ⚙️ Ajustes → Cerebro, no a un «selector 🧠» que
10// no existe.
11// 4. Abierto desde una notificación con la app cerrada (?notif=open), la
12// Mente aparece y la URL queda limpia.
13// 5. En inglés: Enviar/Parar, «limpiar» del terminal, Modo Objetivo y
14// Feedback de Ajustes, y la barra de menús, ya no salen en español.
15// Nada sale a la red: el modelo y GitHub van interceptados.
16//
17// BASE=http://127.0.0.1:8898 node tests/messages-ux.mjs
18import { chromium } from 'playwright';
19const BASE = process.env.BASE || 'http://localhost:8799';
20let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
21
22const FALLA = `window.__cargas = (window.__cargas || 0);
23export const name = 'onnx que falla'; export function configure() {}
24export async function load() { window.__cargas++; throw new TypeError('Failed to fetch'); }
25export async function chat() { return ''; }`;
26
27const b = await chromium.launch();
28const errs = [];
29const abre = async (locale, query = '') => {
30 const ctx = await b.newContext({ locale });
31 // WebGPU simulada y pequeña: desde d526a74 la tarjeta del ONNX ligero solo sale
32 // con WebGPU, y el navegador de pruebas tiene navigator.gpu sin adaptador.
33 await ctx.addInitScript(() => {
34 try { localStorage.setItem('elffusscode.model', 'rules'); } catch {}
35 window.__alerts = 0; window.alert = () => { window.__alerts++; };
36 const falsa = { requestAdapter: async () => ({ limits: { maxBufferSize: 2 ** 28 }, features: new Set(), info: {}, requestDevice: async () => { throw new Error('no hace falta'); } }) };
37 try { Object.defineProperty(Navigator.prototype, 'gpu', { get() { return falsa; }, configurable: true }); } catch { /* */ }
38 });
39 await ctx.route('**/js/providers/onnx.js*', r => r.fulfill({ status: 200, contentType: 'text/javascript', body: FALLA }));
40 await ctx.route(/api\.github\.com|raw\.githubusercontent\.com/, r => r.abort());
41 await ctx.route(/soundcloud/, r => r.abort());
42 const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } });
43 p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
44 await p.goto(BASE + '/?test-opfs' + query, { waitUntil: 'domcontentloaded' });
45 await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 });
46 return { ctx, p };
47};
48
49let { ctx, p } = await abre('es-ES');
50
51// 3 · ayuda del modo Básico
52await p.fill('#prompt', 'hola');
53await p.press('#prompt', 'Enter');
54await p.waitForFunction(() => !window.elffussClaw.conv.isBusy(), null, { timeout: 8000 });
55const ayuda = await p.evaluate(() => document.getElementById('chat-log').innerText);
56ok('3 · el modo Básico manda a ⚙️ Ajustes → Cerebro', /Ajustes → Cerebro/.test(ayuda) && !/selector 🧠/.test(ayuda), ayuda.slice(-160));
57
58// 1 · fallo al cargar el modelo
59await p.click('#btn-settings');
60await p.locator('#settings-panel .model-card', { hasText: 'Qwen3.5-0.8B' }).first().click();
61await p.waitForFunction(() => /No pude cargar/.test(document.getElementById('model-progress-text').textContent), null, { timeout: 8000 }).catch(() => {});
62const pildora = await p.evaluate(() => ({ txt: document.getElementById('model-progress-text').textContent, rol: document.getElementById('model-progress').getAttribute('role'), reintentar: !!document.querySelector('#model-progress .mp-acciones button') }));
63ok('1 · el fallo se dice en palabras de persona, no «Failed to fetch»', /no se pudo descargar/.test(pildora.txt) && !/Failed to fetch/.test(pildora.txt), JSON.stringify(pildora));
64ok('1 · la píldora es una región viva con «Reintentar»', pildora.rol === 'status' && pildora.reintentar, JSON.stringify(pildora));
65// Con el teclado: desde la tarjeta del modelo se llega a «Reintentar» y se
66// pulsa. Reintentar quita sus propios botones, y el foco caía en <body>; ahora
67// vuelve a donde estaba.
68await p.evaluate(() => { const c = [...document.querySelectorAll('#settings-panel .model-card')].find(x => /Qwen3.5-0.8B/.test(x.textContent)); if (c) c.id = 'tarjeta-qwen'; });
69await p.focus('#tarjeta-qwen');
70await p.locator('#model-progress .mp-acciones button', { hasText: 'Reintentar' }).focus();
71await p.keyboard.press('Enter');
72const trasReintentar = await p.evaluate(() => document.activeElement?.id || document.activeElement?.tagName);
73await p.waitForFunction(() => window.__cargas === 2 && /No pude cargar/.test(document.getElementById('model-progress-text').textContent), null, { timeout: 8000 }).catch(() => {});
74ok('1 · «Reintentar» vuelve a intentar la carga', await p.evaluate(() => window.__cargas) === 2, String(await p.evaluate(() => window.__cargas)));
75const trasFallar = await p.evaluate(() => document.activeElement?.id || document.activeElement?.tagName);
76ok('1 · con el teclado, el foco vuelve a la tarjeta y no a <body>, también cuando vuelve a fallar',
77 trasReintentar === 'tarjeta-qwen' && trasFallar === 'tarjeta-qwen', `${trasReintentar} → ${trasFallar}`);
78await p.locator('#model-progress .mp-acciones button[aria-label]').focus();
79await p.keyboard.press('Enter');
80const trasCerrar = await p.evaluate(() => ({ oculta: document.getElementById('model-progress').hidden, foco: document.activeElement?.id || document.activeElement?.tagName }));
81ok('1 · ✕ esconde la píldora y el foco vuelve a la tarjeta, no a <body>', trasCerrar.oculta && trasCerrar.foco === 'tarjeta-qwen', JSON.stringify(trasCerrar));
82
83// 2 · skills sin conexión y repo que no vale
84await p.evaluate(() => document.getElementById('settings-panel').hidden || document.getElementById('btn-settings').click());
85await p.evaluate(() => window.elffussClaw.skills && document.getElementById('act-skills').click());
86await p.waitForTimeout(500);
87await p.locator('#settings-panel .sk-row button', { hasText: 'Explorar' }).first().click();
88await p.waitForSelector('#settings-panel .sk-browse .sk-msg', { timeout: 8000 }).catch(() => {});
89const skill = await p.evaluate(() => ({ msg: document.querySelector('#settings-panel .sk-browse .sk-msg')?.textContent || '', reintentar: !!document.querySelector('#settings-panel .sk-browse button') }));
90ok('2 · sin conexión, «Explorar» lo dice dentro del panel con «Reintentar»', /sin conexión/.test(skill.msg) && skill.reintentar && !/FAILED TO FETCH/.test(skill.msg), JSON.stringify(skill));
91await p.locator('#settings-panel input[aria-label="Añadir repo"]').fill('esto no es un repo');
92await p.locator('#settings-panel button', { hasText: 'Añadir repo' }).click();
93await p.waitForTimeout(300);
94const repo = await p.evaluate(() => ({ alerts: window.__alerts, msg: [...document.querySelectorAll('#settings-panel .sk-msg')].map(n => n.textContent).join(' | ') }));
95ok('2 · un repo que no vale se dice en línea, sin alert()', repo.alerts === 0 && /⚠️/.test(repo.msg), JSON.stringify(repo));
96await ctx.close();
97
98// 4 · desde una notificación
99({ ctx, p } = await abre('es-ES', '&notif=open'));
100await p.waitForSelector('#mind-overlay', { timeout: 45000 }).catch(() => {});
101const notif = await p.evaluate(() => ({ mente: !!document.getElementById('mind-overlay') && getComputedStyle(document.getElementById('mind-overlay')).display !== 'none', url: location.search }));
102ok('4 · ?notif=open abre la Mente y limpia la URL', notif.mente && !/notif/.test(notif.url), JSON.stringify(notif));
103await ctx.close();
104
105// 5 · en inglés
106({ ctx, p } = await abre('en-US'));
107await p.click('#btn-settings');
108await p.waitForTimeout(400);
109const en = await p.evaluate(() => ({
110 enviar: document.getElementById('btn-send').title,
111 limpiar: document.getElementById('term-clear').textContent,
112 menus: [...document.querySelectorAll('#menubar button')].map(b => b.textContent).join(','),
113 goal: document.querySelector('#perm-goalmode').closest('label').textContent.trim(),
114 tel: document.querySelector('#tel-enabled').closest('label').textContent.trim(),
115 enviarFeedback: document.getElementById('tel-send').textContent,
116}));
117ok('5 · en inglés, nada de lo de antes sale en español', en.enviar === 'Send' && en.limpiar === 'clear' && en.menus === 'File,Edit,View,Git' && /^Treat the next message/.test(en.goal) && /^Automatically send/.test(en.tel) && en.enviarFeedback === 'Send', JSON.stringify(en));
118await ctx.close();
119
120console.log('\n errores JS:', errs[0] || 'ninguno');
121ok('sin errores de página', errs.length === 0, errs.join(' | '));
122console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ AVISOS QUE SE ENTIENDEN, EN SU IDIOMA');
123await b.close();
124process.exit(fails ? 1 : 0);