| 1 | // Suite E2E de Elffuss Claw — valida FUNCIONALIDAD REAL de punta a punta. |
| 2 | // Corre en modo básico (determinista, sin GPU): ejercita el bucle agéntico, |
| 3 | // las herramientas y la UI de verdad, no mocks. |
| 4 | // |
| 5 | // BASE=https://claw.elffuss.com node e2e.mjs (o local con serve.py) |
| 6 | // npm i && npm test |
| 7 | import { chromium } from 'playwright'; |
| 8 | import { CHROME_ARGS } from './chrome-args.mjs'; |
| 9 | |
| 10 | const BASE = process.env.BASE || 'https://claw.elffuss.com'; |
| 11 | let fails = 0; |
| 12 | const ok = (name, cond, extra = '') => { console.log((cond ? '✅' : '❌') + ' ' + name + (extra ? ' — ' + extra : '')); if (!cond) fails++; }; |
| 13 | |
| 14 | const browser = await chromium.launch({ args: ['--enable-unsafe-webgpu', ...CHROME_ARGS] }); |
| 15 | |
| 16 | async function fresh(locale = 'es-ES', grants = ['apps', 'tasks', 'vault', 'web', 'memory', 'fs']) { |
| 17 | const ctx = await browser.newContext({ locale }); |
| 18 | await ctx.addInitScript(g => { |
| 19 | try { |
| 20 | localStorage.setItem('elffuss.model', 'rules'); |
| 21 | localStorage.setItem('elffuss.welcomed', '1'); |
| 22 | localStorage.setItem('elffuss.grants', JSON.stringify(g)); |
| 23 | } catch {} |
| 24 | }, grants); |
| 25 | const page = await ctx.newPage({ viewport: { width: 1440, height: 900 } }); |
| 26 | page.on('pageerror', e => { if (!/allow-same-origin/.test(e.message)) console.log(' pageerror:', e.message.slice(0, 100)); }); |
| 27 | await page.goto(BASE, { waitUntil: 'domcontentloaded' }); |
| 28 | await page.waitForTimeout(700); |
| 29 | return page; |
| 30 | } |
| 31 | const say = async (page, text, wait = 1500) => { |
| 32 | await page.fill('#prompt', text); await page.press('#prompt', 'Enter'); |
| 33 | await page.waitForTimeout(300); |
| 34 | if (await page.isVisible('#perm-dialog')) { await page.click('#perm-allow'); await page.waitForTimeout(600); } |
| 35 | await page.waitForTimeout(wait); |
| 36 | }; |
| 37 | const lastAssistant = page => page.locator('.msg.assistant').last().textContent().catch(() => ''); |
| 38 | |
| 39 | // ============ 1 · apps que se crean ============ |
| 40 | { |
| 41 | const p = await fresh(); |
| 42 | await say(p, 'hazme un reloj', 2500); |
| 43 | const shown = await p.isVisible('#appframe'); |
| 44 | const clock = await p.frameLocator('#appframe').locator('#t, h1').count().catch(() => 0); |
| 45 | ok('1 · «hazme un reloj» → app renderizada en el visualizador', shown && clock > 0); |
| 46 | await p.context().close(); |
| 47 | } |
| 48 | |
| 49 | // ============ 2 · no bucle infinito (anti-loop) ============ |
| 50 | { |
| 51 | const p = await fresh(); |
| 52 | await say(p, 'crea una app de notas', 2500); |
| 53 | const noLoop = !(await p.locator('.msg.assistant').allTextContents()).some(t => /sin pasos/i.test(t)); |
| 54 | const tools = await p.locator('.msg.tool').count(); |
| 55 | ok('2 · no se queda en bucle tras crear la app', noLoop && tools <= 3, `tools=${tools}`); |
| 56 | await p.context().close(); |
| 57 | } |
| 58 | |
| 59 | // ============ 3 · búsqueda de imágenes → galería REAL ============ |
| 60 | { |
| 61 | const p = await fresh(); |
| 62 | await say(p, 'busca fotos de perros', 7000); |
| 63 | const imgs = await p.frameLocator('#appframe').locator('img').count().catch(() => 0); |
| 64 | ok('3 · «busca fotos de perros» → galería con imágenes reales', imgs >= 4, `${imgs} imgs`); |
| 65 | await p.context().close(); |
| 66 | } |
| 67 | |
| 68 | // ============ 4 · búsqueda web (texto) REAL ============ |
| 69 | { |
| 70 | const p = await fresh(); |
| 71 | await say(p, 'busca en internet historia del reloj', 8000); |
| 72 | const res = (await p.locator('.msg.tool-result, .msg.assistant').allTextContents()).join(' '); |
| 73 | ok('4 · «busca en internet …» devuelve resultados con enlaces', /https?:\/\//.test(res), res.slice(0, 60).replace(/\n/g, ' ')); |
| 74 | await p.context().close(); |
| 75 | } |
| 76 | |
| 77 | // ============ 5 · vault cifrado (crear, guardar, revelar) ============ |
| 78 | { |
| 79 | const p = await fresh(); |
| 80 | await p.click('#tabs button[data-tab="vault"]'); |
| 81 | await p.fill('#panel-vault input[type=password]', 'master-XYZ'); |
| 82 | await p.click('#panel-vault button.primary'); |
| 83 | if (await p.isVisible('#perm-dialog')) await p.click('#perm-allow'); |
| 84 | await p.waitForTimeout(700); |
| 85 | const inputs = p.locator('#panel-vault .row input'); |
| 86 | await inputs.nth(0).fill('gmail'); await inputs.nth(1).fill('secreto123'); |
| 87 | await p.click('#panel-vault .row button.primary'); await p.waitForTimeout(500); |
| 88 | await p.click('#panel-vault .card button.ghost >> nth=0'); await p.waitForTimeout(300); |
| 89 | const revealed = await p.locator('#panel-vault .card code').first().textContent(); |
| 90 | ok('5 · vault: crear → guardar → revelar secreto cifrado', revealed === 'secreto123', revealed); |
| 91 | await p.context().close(); |
| 92 | } |
| 93 | |
| 94 | // ============ 6 · tareas programadas ============ |
| 95 | { |
| 96 | const p = await fresh(); |
| 97 | await say(p, 'recuérdame dentro de 2 minutos beber agua', 1500); |
| 98 | const reply = await lastAssistant(p); |
| 99 | await p.click('#tabs button[data-tab="tareas"]'); await p.waitForTimeout(400); |
| 100 | const inPanel = (await p.locator('#panel-tareas').textContent()).includes('beber agua'); |
| 101 | ok('6 · tarea programada aparece en el panel', /programada|beber agua/i.test(reply) && inPanel); |
| 102 | await p.context().close(); |
| 103 | } |
| 104 | |
| 105 | // ============ 7 · memoria persistente sobrevive al refresco ============ |
| 106 | { |
| 107 | const p = await fresh(); |
| 108 | await say(p, 'recuerda que mi color favorito es el violeta', 1500); |
| 109 | await p.reload({ waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1200); |
| 110 | const snap = await p.evaluate(async () => (await import('/js/tools/index.js')).snapshot()); |
| 111 | ok('7 · memoria persiste tras refrescar (en el CONTEXTO)', /violeta/i.test(snap)); |
| 112 | await p.context().close(); |
| 113 | } |
| 114 | |
| 115 | // ============ 8 · histórico persiste tras refresco ============ |
| 116 | { |
| 117 | const p = await fresh(); |
| 118 | await say(p, 'hola', 1200); |
| 119 | const before = await p.locator('.msg.user').count(); |
| 120 | await p.reload({ waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1400); |
| 121 | const after = await p.locator('.msg.user').count(); |
| 122 | ok('8 · histórico de chat sobrevive al refresco', after >= before && after > 0, `${before}→${after}`); |
| 123 | await p.context().close(); |
| 124 | } |
| 125 | |
| 126 | // ============ 9 · multilenguaje por navegador ============ |
| 127 | { |
| 128 | const p = await fresh('en-US'); |
| 129 | const tabs = await p.locator('#tabs button').allTextContents(); |
| 130 | const ph = await p.getAttribute('#prompt', 'placeholder'); |
| 131 | ok('9 · UI en inglés con navegador en-US', tabs.includes('View') && tabs.includes('Tasks') && /Ask me/.test(ph || '')); |
| 132 | await p.context().close(); |
| 133 | } |
| 134 | |
| 135 | // ============ 10 · skills instalables (catálogo real de GitHub) ============ |
| 136 | { |
| 137 | const p = await fresh(); |
| 138 | await p.click('#tabs button[data-tab="skills"]'); await p.waitForTimeout(400); |
| 139 | const repos = await p.locator('#panel-skills .card a').allTextContents(); |
| 140 | await p.locator('#panel-skills .card button', { hasText: 'Explorar' }).first().click(); |
| 141 | await p.waitForTimeout(6000); |
| 142 | const skillCards = await p.locator('#panel-skills .card').count(); |
| 143 | ok('10 · Skills: catálogo real de anthropics/skills carga', repos.some(r => /anthropics\/skills/.test(r)) && skillCards > 5, `${skillCards} filas`); |
| 144 | await p.context().close(); |
| 145 | } |
| 146 | |
| 147 | // ============ 11 · modelos ofrecidos correctos ============ |
| 148 | // El E4B OFICIAL de Google (litert:gemma-e4b) SÍ carga y responde — verificado |
| 149 | // end-to-end (baja ~2.8GB, motor GPU OK, responde). El que estaba ROTO y NO debe |
| 150 | // ofrecerse es el healed «Elffuss E4B» (export prefill_decode, ELFFUSS_LITERT_READY |
| 151 | // = false) hasta el reexport artisan. |
| 152 | { |
| 153 | const p = await fresh(); |
| 154 | const opts = await p.$$eval('#model-select option', os => os.map(o => o.textContent)); |
| 155 | ok('11 · el Elffuss E4B healed (aún roto) NO se ofrece', !opts.some(o => /Elffuss E4B|healed[^)]*E4B/i.test(o)), JSON.stringify(opts)); |
| 156 | |
| 157 | // El ORDEN importa tanto como la lista, y esto se rompió de verdad: los |
| 158 | // <optgroup> se creaban donde apareciera su primer elemento, así que al meter |
| 159 | // el 27B —agrupado— en mitad de modelOptions(), «Básico (sin modelo)» —la |
| 160 | // salida segura— quedó pintada POR DEBAJO del encabezado «⚠ Avanzado», como si |
| 161 | // fuera uno de los cerebros avisados. Ninguna prueba lo vio porque todas miran |
| 162 | // QUÉ opciones hay, no DÓNDE. La condición es la que importa: después del |
| 163 | // primer grupo no puede quedar ninguna opción suelta. |
| 164 | const orden = await p.$$eval('#model-select > *', hijos => hijos.map(h => h.tagName)); |
| 165 | const primerGrupo = orden.indexOf('OPTGROUP'); |
| 166 | ok('11b · los grupos avisados van al final, sin opciones sueltas debajo', |
| 167 | primerGrupo === -1 || !orden.slice(primerGrupo).includes('OPTION'), |
| 168 | JSON.stringify(orden)); |
| 169 | await p.context().close(); |
| 170 | } |
| 171 | |
| 172 | // ============ 12 · OG + meta para compartir ============ |
| 173 | { |
| 174 | const p = await fresh(); |
| 175 | const og = await p.getAttribute('meta[property="og:image"]', 'content'); |
| 176 | const r = await p.request.get(og); |
| 177 | ok('12 · OG image existe y se sirve', r.ok() && (+r.headers()['content-length'] > 10000), og); |
| 178 | await p.context().close(); |
| 179 | } |
| 180 | |
| 181 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ TODO VERDE — funcionalidad real validada'); |
| 182 | await browser.close(); |
| 183 | process.exit(fails ? 1 : 0); |