| 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 |
| 18 | import { chromium } from 'playwright'; |
| 19 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 20 | let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 21 | |
| 22 | const FALLA = `window.__cargas = (window.__cargas || 0); |
| 23 | export const name = 'onnx que falla'; export function configure() {} |
| 24 | export async function load() { window.__cargas++; throw new TypeError('Failed to fetch'); } |
| 25 | export async function chat() { return ''; }`; |
| 26 | |
| 27 | const b = await chromium.launch(); |
| 28 | const errs = []; |
| 29 | const 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 | |
| 49 | let { ctx, p } = await abre('es-ES'); |
| 50 | |
| 51 | // 3 · ayuda del modo Básico |
| 52 | await p.fill('#prompt', 'hola'); |
| 53 | await p.press('#prompt', 'Enter'); |
| 54 | await p.waitForFunction(() => !window.elffussClaw.conv.isBusy(), null, { timeout: 8000 }); |
| 55 | const ayuda = await p.evaluate(() => document.getElementById('chat-log').innerText); |
| 56 | ok('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 |
| 59 | await p.click('#btn-settings'); |
| 60 | await p.locator('#settings-panel .model-card', { hasText: 'Qwen3.5-0.8B' }).first().click(); |
| 61 | await p.waitForFunction(() => /No pude cargar/.test(document.getElementById('model-progress-text').textContent), null, { timeout: 8000 }).catch(() => {}); |
| 62 | const 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') })); |
| 63 | ok('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)); |
| 64 | ok('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. |
| 68 | await 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'; }); |
| 69 | await p.focus('#tarjeta-qwen'); |
| 70 | await p.locator('#model-progress .mp-acciones button', { hasText: 'Reintentar' }).focus(); |
| 71 | await p.keyboard.press('Enter'); |
| 72 | const trasReintentar = await p.evaluate(() => document.activeElement?.id || document.activeElement?.tagName); |
| 73 | await p.waitForFunction(() => window.__cargas === 2 && /No pude cargar/.test(document.getElementById('model-progress-text').textContent), null, { timeout: 8000 }).catch(() => {}); |
| 74 | ok('1 · «Reintentar» vuelve a intentar la carga', await p.evaluate(() => window.__cargas) === 2, String(await p.evaluate(() => window.__cargas))); |
| 75 | const trasFallar = await p.evaluate(() => document.activeElement?.id || document.activeElement?.tagName); |
| 76 | ok('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}`); |
| 78 | await p.locator('#model-progress .mp-acciones button[aria-label]').focus(); |
| 79 | await p.keyboard.press('Enter'); |
| 80 | const trasCerrar = await p.evaluate(() => ({ oculta: document.getElementById('model-progress').hidden, foco: document.activeElement?.id || document.activeElement?.tagName })); |
| 81 | ok('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 |
| 84 | await p.evaluate(() => document.getElementById('settings-panel').hidden || document.getElementById('btn-settings').click()); |
| 85 | await p.evaluate(() => window.elffussClaw.skills && document.getElementById('act-skills').click()); |
| 86 | await p.waitForTimeout(500); |
| 87 | await p.locator('#settings-panel .sk-row button', { hasText: 'Explorar' }).first().click(); |
| 88 | await p.waitForSelector('#settings-panel .sk-browse .sk-msg', { timeout: 8000 }).catch(() => {}); |
| 89 | const skill = await p.evaluate(() => ({ msg: document.querySelector('#settings-panel .sk-browse .sk-msg')?.textContent || '', reintentar: !!document.querySelector('#settings-panel .sk-browse button') })); |
| 90 | ok('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)); |
| 91 | await p.locator('#settings-panel input[aria-label="Añadir repo"]').fill('esto no es un repo'); |
| 92 | await p.locator('#settings-panel button', { hasText: 'Añadir repo' }).click(); |
| 93 | await p.waitForTimeout(300); |
| 94 | const repo = await p.evaluate(() => ({ alerts: window.__alerts, msg: [...document.querySelectorAll('#settings-panel .sk-msg')].map(n => n.textContent).join(' | ') })); |
| 95 | ok('2 · un repo que no vale se dice en línea, sin alert()', repo.alerts === 0 && /⚠️/.test(repo.msg), JSON.stringify(repo)); |
| 96 | await ctx.close(); |
| 97 | |
| 98 | // 4 · desde una notificación |
| 99 | ({ ctx, p } = await abre('es-ES', '¬if=open')); |
| 100 | await p.waitForSelector('#mind-overlay', { timeout: 45000 }).catch(() => {}); |
| 101 | const notif = await p.evaluate(() => ({ mente: !!document.getElementById('mind-overlay') && getComputedStyle(document.getElementById('mind-overlay')).display !== 'none', url: location.search })); |
| 102 | ok('4 · ?notif=open abre la Mente y limpia la URL', notif.mente && !/notif/.test(notif.url), JSON.stringify(notif)); |
| 103 | await ctx.close(); |
| 104 | |
| 105 | // 5 · en inglés |
| 106 | ({ ctx, p } = await abre('en-US')); |
| 107 | await p.click('#btn-settings'); |
| 108 | await p.waitForTimeout(400); |
| 109 | const 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 | })); |
| 117 | ok('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)); |
| 118 | await ctx.close(); |
| 119 | |
| 120 | console.log('\n errores JS:', errs[0] || 'ninguno'); |
| 121 | ok('sin errores de página', errs.length === 0, errs.join(' | ')); |
| 122 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ AVISOS QUE SE ENTIENDEN, EN SU IDIOMA'); |
| 123 | await b.close(); |
| 124 | process.exit(fails ? 1 : 0); |