Elffuss BraidHub

utopia-ia/elffuss-code public

5deee259aed4 · 8.4 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 await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} window.__alerts = 0; window.alert = () => { window.__alerts++; }; });
32 await ctx.route('**/js/providers/onnx.js*', r => r.fulfill({ status: 200, contentType: 'text/javascript', body: FALLA }));
33 await ctx.route(/api\.github\.com|raw\.githubusercontent\.com/, r => r.abort());
34 await ctx.route(/soundcloud/, r => r.abort());
35 const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } });
36 p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
37 await p.goto(BASE + '/?test-opfs' + query, { waitUntil: 'domcontentloaded' });
38 await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 });
39 return { ctx, p };
40};
41
42let { ctx, p } = await abre('es-ES');
43
44// 3 · ayuda del modo Básico
45await p.fill('#prompt', 'hola');
46await p.press('#prompt', 'Enter');
47await p.waitForFunction(() => !window.elffussClaw.conv.isBusy(), null, { timeout: 8000 });
48const ayuda = await p.evaluate(() => document.getElementById('chat-log').innerText);
49ok('3 · el modo Básico manda a ⚙️ Ajustes → Cerebro', /Ajustes → Cerebro/.test(ayuda) && !/selector 🧠/.test(ayuda), ayuda.slice(-160));
50
51// 1 · fallo al cargar el modelo
52await p.click('#btn-settings');
53await p.locator('#settings-panel .model-card', { hasText: 'Qwen3.5-0.8B' }).first().click();
54await p.waitForFunction(() => /No pude cargar/.test(document.getElementById('model-progress-text').textContent), null, { timeout: 8000 }).catch(() => {});
55const 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') }));
56ok('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));
57ok('1 · la píldora es una región viva con «Reintentar»', pildora.rol === 'status' && pildora.reintentar, JSON.stringify(pildora));
58// Con el teclado: desde la tarjeta del modelo se llega a «Reintentar» y se
59// pulsa. Reintentar quita sus propios botones, y el foco caía en <body>; ahora
60// vuelve a donde estaba.
61await 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'; });
62await p.focus('#tarjeta-qwen');
63await p.locator('#model-progress .mp-acciones button', { hasText: 'Reintentar' }).focus();
64await p.keyboard.press('Enter');
65const trasReintentar = await p.evaluate(() => document.activeElement?.id || document.activeElement?.tagName);
66await p.waitForFunction(() => window.__cargas === 2 && /No pude cargar/.test(document.getElementById('model-progress-text').textContent), null, { timeout: 8000 }).catch(() => {});
67ok('1 · «Reintentar» vuelve a intentar la carga', await p.evaluate(() => window.__cargas) === 2, String(await p.evaluate(() => window.__cargas)));
68const trasFallar = await p.evaluate(() => document.activeElement?.id || document.activeElement?.tagName);
69ok('1 · con el teclado, el foco vuelve a la tarjeta y no a <body>, también cuando vuelve a fallar',
70 trasReintentar === 'tarjeta-qwen' && trasFallar === 'tarjeta-qwen', `${trasReintentar} → ${trasFallar}`);
71await p.locator('#model-progress .mp-acciones button[aria-label]').focus();
72await p.keyboard.press('Enter');
73const trasCerrar = await p.evaluate(() => ({ oculta: document.getElementById('model-progress').hidden, foco: document.activeElement?.id || document.activeElement?.tagName }));
74ok('1 · ✕ esconde la píldora y el foco vuelve a la tarjeta, no a <body>', trasCerrar.oculta && trasCerrar.foco === 'tarjeta-qwen', JSON.stringify(trasCerrar));
75
76// 2 · skills sin conexión y repo que no vale
77await p.evaluate(() => document.getElementById('settings-panel').hidden || document.getElementById('btn-settings').click());
78await p.evaluate(() => window.elffussClaw.skills && document.getElementById('act-skills').click());
79await p.waitForTimeout(500);
80await p.locator('#settings-panel .sk-row button', { hasText: 'Explorar' }).first().click();
81await p.waitForSelector('#settings-panel .sk-browse .sk-msg', { timeout: 8000 }).catch(() => {});
82const skill = await p.evaluate(() => ({ msg: document.querySelector('#settings-panel .sk-browse .sk-msg')?.textContent || '', reintentar: !!document.querySelector('#settings-panel .sk-browse button') }));
83ok('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));
84await p.locator('#settings-panel input[aria-label="Añadir repo"]').fill('esto no es un repo');
85await p.locator('#settings-panel button', { hasText: 'Añadir repo' }).click();
86await p.waitForTimeout(300);
87const repo = await p.evaluate(() => ({ alerts: window.__alerts, msg: [...document.querySelectorAll('#settings-panel .sk-msg')].map(n => n.textContent).join(' | ') }));
88ok('2 · un repo que no vale se dice en línea, sin alert()', repo.alerts === 0 && /⚠️/.test(repo.msg), JSON.stringify(repo));
89await ctx.close();
90
91// 4 · desde una notificación
92({ ctx, p } = await abre('es-ES', '&notif=open'));
93await p.waitForSelector('#mind-overlay', { timeout: 45000 }).catch(() => {});
94const notif = await p.evaluate(() => ({ mente: !!document.getElementById('mind-overlay') && getComputedStyle(document.getElementById('mind-overlay')).display !== 'none', url: location.search }));
95ok('4 · ?notif=open abre la Mente y limpia la URL', notif.mente && !/notif/.test(notif.url), JSON.stringify(notif));
96await ctx.close();
97
98// 5 · en inglés
99({ ctx, p } = await abre('en-US'));
100await p.click('#btn-settings');
101await p.waitForTimeout(400);
102const en = await p.evaluate(() => ({
103 enviar: document.getElementById('btn-send').title,
104 limpiar: document.getElementById('term-clear').textContent,
105 menus: [...document.querySelectorAll('#menubar button')].map(b => b.textContent).join(','),
106 goal: document.querySelector('#perm-goalmode').closest('label').textContent.trim(),
107 tel: document.querySelector('#tel-enabled').closest('label').textContent.trim(),
108 enviarFeedback: document.getElementById('tel-send').textContent,
109}));
110ok('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));
111await ctx.close();
112
113console.log('\n errores JS:', errs[0] || 'ninguno');
114ok('sin errores de página', errs.length === 0, errs.join(' | '));
115console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ AVISOS QUE SE ENTIENDEN, EN SU IDIOMA');
116await b.close();
117process.exit(fails ? 1 : 0);