| 1 | // Smoke-test de i18n del chrome (SIN modelo): carga cada app en locale en/es y |
| 2 | // comprueba que la UI estática/temprana se localiza y que el saludo de Claw ya |
| 3 | // no sale garbled. Caza errores de página que mencionen mis módulos. |
| 4 | import { chromium } from 'playwright'; |
| 5 | |
| 6 | const MY = /(i18n|humanize|ui\.js|main\.js|mind\.js|apps\.js|kernel\.js|agent\.js)/; |
| 7 | const isMine = m => MY.test(m) || /ReferenceError|is not defined|SyntaxError|Cannot access|before initialization/.test(m); |
| 8 | |
| 9 | // CLAW=… CODE=… para probar otra copia (por defecto, los puertos de siempre). |
| 10 | const CLAW = process.env.CLAW || 'http://localhost:8811'; |
| 11 | const CODE = process.env.CODE || 'http://localhost:8812'; |
| 12 | let failures = 0; |
| 13 | const ok = (label, cond, extra = '') => { console.log(`${cond ? '✓' : '✗ FAIL'} ${label}${extra ? ' — ' + extra : ''}`); if (!cond) failures++; }; |
| 14 | |
| 15 | async function load(browser, url, locale) { |
| 16 | const ctx = await browser.newContext({ locale }); |
| 17 | // Claw ya «bienvenido»: el splash de primera visita es un diálogo modal y deja |
| 18 | // inerte lo de detrás mientras está abierto. |
| 19 | await ctx.addInitScript(() => { try { localStorage.setItem('elffuss.welcomed', '1'); } catch { /* */ } }); |
| 20 | const page = await ctx.newPage(); |
| 21 | const errs = []; |
| 22 | page.on('pageerror', e => { if (isMine(e.message)) errs.push('pageerror: ' + e.message); }); |
| 23 | page.on('console', m => { if (m.type() === 'error' && isMine(m.text())) errs.push('console: ' + m.text()); }); |
| 24 | await page.goto(url + '/', { waitUntil: 'domcontentloaded' }); |
| 25 | await page.waitForTimeout(1800); // deja correr applyI18n + boot (no el modelo) |
| 26 | const lang = await page.evaluate(() => navigator.language); |
| 27 | return { ctx, page, errs, lang }; |
| 28 | } |
| 29 | |
| 30 | const browser = await chromium.launch({ args: ['--enable-unsafe-webgpu', '--disable-gpu-watchdog'] }); |
| 31 | |
| 32 | // ---------- CLAW ---------- |
| 33 | for (const locale of ['en-US', 'es-ES']) { |
| 34 | const { ctx, page, errs, lang } = await load(browser, CLAW, locale); |
| 35 | const sys = (await page.locator('.msg.sys').first().textContent().catch(() => '') || '').replace(/\s+/g, ' ').trim(); |
| 36 | const ph = await page.locator('#prompt').getAttribute('placeholder').catch(() => ''); |
| 37 | console.log(`\n== CLAW · ${locale} (navigator.language=${lang}) ==`); |
| 38 | console.log(' saludo:', JSON.stringify(sys.slice(0, 90))); |
| 39 | console.log(' placeholder:', JSON.stringify(ph)); |
| 40 | ok('sin errores de mis módulos', errs.length === 0, errs.join(' | ')); |
| 41 | ok('saludo NO garbled (sin «se crean» residual)', !/se crean/i.test(sys) || locale.startsWith('es'), sys.slice(0, 90)); |
| 42 | // runtime: t() con sustitución {var} + humanize, evaluados en el navegador real |
| 43 | const rt = await page.evaluate(async () => { |
| 44 | const i = await import('/js/i18n.js'); |
| 45 | const h = await import('/js/humanize.js'); |
| 46 | return { |
| 47 | done: i.t('done', { result: 'App X ready.' }), |
| 48 | writing: i.t('writing', { n: 7 }), |
| 49 | using: i.t('using', { name: 'app.create' }), |
| 50 | modelReady: i.t('modelReady', { where: i.t('whereGpu') }), |
| 51 | hCreate: h.humanizeTool('app.create', { name: 'Notes' }), |
| 52 | hRead: h.humanizeTool('fs.read', { path: 'a.txt' }), |
| 53 | }; |
| 54 | }); |
| 55 | console.log(' runtime:', JSON.stringify(rt)); |
| 56 | // paneles: si aun así saliera el splash, se cierra con «Entrar» (quitar el nodo |
| 57 | // a mano dejaba la página inerte: el modal no se cerraba) y se navega por las pestañas |
| 58 | if (await page.locator('#splash-enter').isVisible().catch(() => false)) await page.locator('#splash-enter').click({ timeout: 3000 }).catch(()=>{}); |
| 59 | const panels = {}; |
| 60 | for (const [tab, id] of [['apps','panel-apps'],['tareas','panel-tareas'],['permisos','panel-permisos'],['ajustes','panel-ajustes']]) { |
| 61 | await page.locator(`#tabs button[data-tab="${tab}"]`).click({ timeout: 3000 }).catch(()=>{}); |
| 62 | await page.waitForTimeout(150); |
| 63 | // Ajustes ya no empieza con un <h3>: empieza con la tarjeta de consumo («📊 …»). |
| 64 | const sel = tab === 'ajustes' ? `#${id} .card b` : `#${id} h3`; |
| 65 | panels[tab] = ((await page.locator(sel).first().textContent().catch(()=>'' ))||'').trim(); |
| 66 | } |
| 67 | const scopes = await page.evaluate(async () => { |
| 68 | const pm = await import('/js/permissions.js'); |
| 69 | return { appsLabel: pm.SCOPES.apps.label, fsDesc: pm.SCOPES.fs.desc }; |
| 70 | }); |
| 71 | const permBtns = { deny: (await page.locator('#perm-deny').textContent().catch(()=>'' )), allow: (await page.locator('#perm-allow').textContent().catch(()=>'' )) }; |
| 72 | console.log(' paneles:', JSON.stringify(panels), '| scopes:', JSON.stringify(scopes), '| permBtns:', JSON.stringify(permBtns)); |
| 73 | if (locale.startsWith('en')) { |
| 74 | ok('panel Apps EN', panels.apps === 'Apps created', panels.apps); |
| 75 | ok('panel Tasks EN', panels.tareas === 'Scheduled tasks', panels.tareas); |
| 76 | ok('panel Perms EN', panels.permisos === 'Granted permissions', panels.permisos); |
| 77 | ok('panel Settings EN', /Usage right now/.test(panels.ajustes), panels.ajustes); |
| 78 | ok('SCOPE fs EN', scopes.appsLabel === 'Apps' && /Read and write/.test(scopes.fsDesc), JSON.stringify(scopes)); |
| 79 | ok('perm btns EN', permBtns.deny === 'Deny' && permBtns.allow === 'Allow', JSON.stringify(permBtns)); |
| 80 | ok('saludo EN («I’m Elffuss»)', /I’m Elffuss|I'm Elffuss/.test(sys)); |
| 81 | ok('welcome EN («operating system»)', /operating system/i.test(sys)); |
| 82 | ok('saludo EN sin español', !/soy Elffuss|sistema operativo/i.test(sys)); |
| 83 | ok('placeholder EN', /Ask me anything/i.test(ph || '')); |
| 84 | ok('done EN + sustitución', rt.done === 'Done! App X ready. Want me to tweak anything?', rt.done); |
| 85 | ok('writing EN {n}', rt.writing === 'Elffuss is writing · 7', rt.writing); |
| 86 | ok('modelReady EN', /AI model ready · WebGPU local/.test(rt.modelReady), rt.modelReady); |
| 87 | ok('humanize EN app.create', rt.hCreate === 'creating the app “Notes”…', rt.hCreate); |
| 88 | ok('humanize EN fs.read', rt.hRead === 'reading a.txt…', rt.hRead); |
| 89 | } else { |
| 90 | ok('panel Apps ES', panels.apps === 'Apps creadas', panels.apps); |
| 91 | ok('panel Tareas ES', panels.tareas === 'Tareas programadas', panels.tareas); |
| 92 | ok('SCOPE fs ES', /Leer y escribir/.test(scopes.fsDesc), JSON.stringify(scopes)); |
| 93 | ok('perm btns ES', permBtns.deny === 'Denegar' && permBtns.allow === 'Permitir', JSON.stringify(permBtns)); |
| 94 | ok('saludo ES («soy Elffuss»)', /soy Elffuss/.test(sys)); |
| 95 | ok('welcome ES («sistema operativo»)', /sistema operativo/i.test(sys)); |
| 96 | ok('placeholder ES', /Pídeme lo que necesites/i.test(ph || '')); |
| 97 | ok('done ES + sustitución', rt.done === '¡Listo! App X ready. ¿Quieres que le cambie algo?', rt.done); |
| 98 | ok('writing ES {n}', rt.writing === 'Elffuss está escribiendo · 7', rt.writing); |
| 99 | ok('humanize ES app.create', rt.hCreate === 'creando la app «Notes»…', rt.hCreate); |
| 100 | } |
| 101 | await ctx.close(); |
| 102 | } |
| 103 | |
| 104 | // ---------- CODE ---------- |
| 105 | for (const locale of ['en-US', 'es-ES']) { |
| 106 | const { ctx, page, errs, lang } = await load(browser, CODE, locale); |
| 107 | const ph = await page.locator('#prompt').getAttribute('placeholder').catch(() => ''); |
| 108 | console.log(`\n== CODE · ${locale} (navigator.language=${lang}) ==`); |
| 109 | console.log(' placeholder:', JSON.stringify(ph)); |
| 110 | const rt = await page.evaluate(async () => { |
| 111 | const i = await import('/js/i18n.js'); |
| 112 | return { welcome: i.t('welcome', { name: 'Proj' }), writing: i.t('writing', { n: 3 }), ready: i.t('modelReady'), ph: i.t('ph') }; |
| 113 | }); |
| 114 | // Hard Work encendido y apagado: la caja vuelve a su texto, en el idioma de la |
| 115 | // página. Antes se quedaba en «Pídele código a Elffuss…» fijo y en español |
| 116 | // (Code e4415eb; 43f95b7 cambió ph y no esa línea). |
| 117 | const phTrasHardWork = await page.evaluate(() => { |
| 118 | const b = document.getElementById('btn-hardwork'); |
| 119 | if (!b) return null; |
| 120 | b.click(); b.click(); |
| 121 | return document.getElementById('prompt').placeholder; |
| 122 | }); |
| 123 | // landing (estático, vía applyI18n): tagline, botón, placeholders, un tooltip |
| 124 | const land = { |
| 125 | open: ((await page.locator('#open-project').textContent().catch(()=>'' ))||'').trim(), |
| 126 | tag: ((await page.locator('#landing .tag').textContent().catch(()=>'' ))||'').replace(/\s+/g,' ').trim(), |
| 127 | clonePh: await page.locator('#clone-url').getAttribute('placeholder').catch(()=>'' ), |
| 128 | searchTitle: await page.locator('#act-search').getAttribute('title').catch(()=>'' ), |
| 129 | }; |
| 130 | // pass-3: command palette (>) + panel de historial |
| 131 | await page.keyboard.press(process.platform === 'darwin' ? 'Meta+Shift+KeyP' : 'Control+Shift+KeyP'); |
| 132 | await page.waitForTimeout(250); |
| 133 | const palCmds = await page.locator('#pal-list .pi-name').allTextContents().catch(()=>[]); |
| 134 | const palHint = ((await page.locator('#pal-list .pi-hint').first().textContent().catch(()=>'' ))||'').trim(); |
| 135 | await page.keyboard.press('Escape').catch(()=>{}); |
| 136 | // el panel de historial vive en modo IDE (tras abrir carpeta), inalcanzable |
| 137 | // aquí sin proyecto → validamos sus claves i18n directamente (la wiring en |
| 138 | // runtime ya la prueba la command palette, mismo import t en el mismo fichero) |
| 139 | const hist = await page.evaluate(async () => { |
| 140 | const i = await import('/js/i18n.js'); |
| 141 | return { head: i.t('tHistory'), empty: i.t('histEmpty'), gCommit: i.t('gCommit'), fallback: i.t('fallbackToast') }; |
| 142 | }); |
| 143 | console.log(' runtime:', JSON.stringify(rt), '\n landing:', JSON.stringify(land), |
| 144 | '\n palette:', JSON.stringify(palCmds.slice(0,3)), 'hint:', JSON.stringify(palHint), '| hist(i18n):', JSON.stringify(hist)); |
| 145 | ok('sin errores de mis módulos', errs.length === 0, errs.join(' | ')); |
| 146 | if (locale.startsWith('en')) { |
| 147 | ok('landing botón EN', land.open === '📁 Open code folder', land.open); |
| 148 | ok('landing tagline EN', /Open your code folder/.test(land.tag), land.tag); |
| 149 | ok('landing clone placeholder EN', /paste the URL/.test(land.clonePh || ''), land.clonePh || ''); |
| 150 | ok('tooltip search EN', land.searchTitle === 'Search (Cmd/Ctrl+P)', land.searchTitle || ''); |
| 151 | ok('palette cmds EN', palCmds.includes('New conversation') && palCmds.includes('Search the code…'), JSON.stringify(palCmds)); |
| 152 | ok('palette hint EN', palHint === 'command', palHint); |
| 153 | // gCommit: «Draft the commit message» desde Code 67e2551 (rama de integración de Code). |
| 154 | ok('history/git i18n EN', hist.head === 'Conversation history' && hist.empty === 'No saved conversations yet.' && hist.gCommit === 'Draft the commit message' && /didn’t load/.test(hist.fallback), JSON.stringify(hist)); |
| 155 | // El placeholder cambió a propósito en Code 43f95b7 (la caja pasó a área de |
| 156 | // texto con @ para adjuntar): se compara con su propia clave y su idioma. |
| 157 | ok('placeholder EN = t(ph) («… attaches a file»)', ph === rt.ph && /attaches a file/.test(ph || ''), ph || ''); |
| 158 | ok('placeholder EN tras encender y apagar Hard Work = t(ph)', phTrasHardWork === rt.ph, String(phTrasHardWork)); |
| 159 | ok('welcome EN {name}', /Project “Proj” open/.test(rt.welcome), rt.welcome); |
| 160 | ok('writing EN {n} chars', rt.writing === 'Elffuss writes · 3 chars', rt.writing); |
| 161 | ok('modelReady EN', rt.ready === 'AI model ready', rt.ready); |
| 162 | } else { |
| 163 | ok('landing botón ES', land.open === '📁 Abrir carpeta de código', land.open); |
| 164 | ok('landing tagline ES', /Abre tu carpeta de código/.test(land.tag), land.tag); |
| 165 | ok('tooltip search ES', land.searchTitle === 'Buscar (Cmd/Ctrl+P)', land.searchTitle || ''); |
| 166 | ok('palette cmds ES', palCmds.includes('Nueva conversación') && palCmds.includes('Buscar en el código…'), JSON.stringify(palCmds)); |
| 167 | ok('history/git i18n ES', hist.head === 'Historial de conversaciones' && hist.empty === 'Sin conversaciones guardadas todavía.' && hist.gCommit === 'Redactar el mensaje de commit', JSON.stringify(hist)); |
| 168 | ok('placeholder ES = t(ph) («… adjunta un archivo»)', ph === rt.ph && /adjunta un archivo/.test(ph || ''), ph || ''); |
| 169 | ok('placeholder ES tras encender y apagar Hard Work = t(ph)', phTrasHardWork === rt.ph, String(phTrasHardWork)); |
| 170 | ok('welcome ES {name}', /Proyecto «Proj» abierto/.test(rt.welcome), rt.welcome); |
| 171 | ok('writing ES car.', rt.writing === 'Elffuss escribe · 3 car.', rt.writing); |
| 172 | } |
| 173 | await ctx.close(); |
| 174 | } |
| 175 | |
| 176 | await browser.close(); |
| 177 | console.log(`\n${failures ? '✗ ' + failures + ' fallo(s)' : '✓ TODO OK'}`); |
| 178 | process.exit(failures ? 1 : 0); |