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