| 1 | // Suite E2E de Elffuss Code — valida FUNCIONALIDAD REAL del IDE de punta a punta. |
| 2 | // Usa el gancho ?test-opfs (proyecto en OPFS del navegador, sin picker nativo) |
| 3 | // y el modo básico determinista. Ejercita árbol, Monaco, herramientas y chrome. |
| 4 | // |
| 5 | // BASE=https://code.elffuss.com node e2e.mjs |
| 6 | import { chromium } from 'playwright'; |
| 7 | import { CHROME_ARGS } from './chrome-args.mjs'; |
| 8 | |
| 9 | const BASE = process.env.BASE || 'https://code.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', ...CHROME_ARGS] }); |
| 14 | |
| 15 | // siembra un proyecto en OPFS y entra al IDE |
| 16 | async function ide() { |
| 17 | const ctx = await browser.newContext(); |
| 18 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); |
| 19 | const page = await ctx.newPage({ viewport: { width: 1500, height: 900 } }); |
| 20 | page.on('pageerror', e => { if (!/allow-same-origin/.test(e.message)) console.log(' pageerror:', e.message.slice(0, 100)); }); |
| 21 | await page.goto(BASE + '/?seed-only', { waitUntil: 'domcontentloaded' }); |
| 22 | await page.evaluate(async () => { |
| 23 | const opfs = await navigator.storage.getDirectory(); |
| 24 | const w = async (dir, name, txt) => { const fh = await dir.getFileHandle(name, { create: true }); const s = await fh.createWritable(); await s.write(txt); await s.close(); }; |
| 25 | await w(opfs, 'README.md', '# demo project\nUn proyecto de prueba para Elffuss Code.'); |
| 26 | await w(opfs, 'index.js', 'function saludo(n){ return `hola ${n}` }\nconsole.log(saludo("mundo"));'); |
| 27 | const src = await opfs.getDirectoryHandle('src', { create: true }); |
| 28 | await w(src, 'utils.py', 'def suma(a,b):\n return a+b\n'); |
| 29 | }); |
| 30 | await page.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); |
| 31 | await page.waitForTimeout(4000); // Monaco desde CDN |
| 32 | return page; |
| 33 | } |
| 34 | const say = async (page, text, wait = 1500) => { |
| 35 | await page.fill('#prompt', text); await page.press('#prompt', 'Enter'); await page.waitForTimeout(wait); |
| 36 | }; |
| 37 | |
| 38 | // ============ 1 · IDE se abre con el proyecto ============ |
| 39 | { |
| 40 | const p = await ide(); |
| 41 | const shown = await p.isVisible('#ide'); |
| 42 | const files = await p.locator('#tree .file').allTextContents(); |
| 43 | ok('1 · IDE abierto con árbol de archivos', shown && files.length >= 2, JSON.stringify(files)); |
| 44 | await p.context().close(); |
| 45 | } |
| 46 | |
| 47 | // ============ 2 · abrir archivo en Monaco desde el árbol ============ |
| 48 | { |
| 49 | const p = await ide(); |
| 50 | await p.locator('#tree .file', { hasText: 'index.js' }).click(); |
| 51 | await p.waitForTimeout(1000); |
| 52 | const hasCode = await p.evaluate(() => window.monaco?.editor.getModels().some(m => m.getValue().includes('saludo'))); |
| 53 | // Solo las pestañas del EDITOR: desde c769f18 las conversaciones también son |
| 54 | // .tab.active (en #conv-tabs) y el selector suelto encontraba dos. |
| 55 | const tab = await p.locator('#tabs-bar .tab.active').textContent({ timeout: 5000 }).catch(e => 'ERROR: ' + e.message.split('\n')[0]); |
| 56 | ok('2 · abrir archivo del árbol → Monaco con su contenido', hasCode && /index\.js/.test(tab), tab); |
| 57 | await p.context().close(); |
| 58 | } |
| 59 | |
| 60 | // ============ 3 · el agente busca en el código (code.search) ============ |
| 61 | { |
| 62 | const p = await ide(); |
| 63 | await say(p, 'busca saludo', 1800); |
| 64 | const res = (await p.locator('.msg.assistant, .msg.tool-result').allTextContents()).join(' '); |
| 65 | ok('3 · «busca saludo» encuentra el símbolo en el código', /index\.js:1|saludo/.test(res)); |
| 66 | await p.context().close(); |
| 67 | } |
| 68 | |
| 69 | // ============ 4 · el agente ESCRIBE un archivo (code.write → disco) ============ |
| 70 | { |
| 71 | const p = await ide(); |
| 72 | await say(p, 'escribe src/nuevo.js: export const pi = 3.1416;', 1800); |
| 73 | const written = await p.evaluate(async () => { |
| 74 | const opfs = await navigator.storage.getDirectory(); |
| 75 | const src = await opfs.getDirectoryHandle('src'); |
| 76 | return (await (await (await src.getFileHandle('nuevo.js')).getFile()).text()).includes('3.1416'); |
| 77 | }); |
| 78 | ok('4 · «escribe archivo» persiste a disco de verdad', written); |
| 79 | await p.context().close(); |
| 80 | } |
| 81 | |
| 82 | // ============ 5 · Command Palette (Cmd/Ctrl+P) encuentra archivos ============ |
| 83 | { |
| 84 | const p = await ide(); |
| 85 | await p.evaluate(() => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'p', metaKey: true, bubbles: true }))); |
| 86 | await p.waitForTimeout(400); |
| 87 | const open = await p.isVisible('#palette'); |
| 88 | await p.fill('#pal-input', 'utils'); await p.waitForTimeout(400); |
| 89 | const hits = await p.locator('.pal-item .pi-name').allTextContents(); |
| 90 | await p.locator('.pal-item').first().click(); await p.waitForTimeout(700); |
| 91 | // Solo las pestañas del EDITOR: desde c769f18 las conversaciones también son |
| 92 | // .tab.active (en #conv-tabs) y el selector suelto encontraba dos. |
| 93 | const tab = await p.locator('#tabs-bar .tab.active').textContent({ timeout: 5000 }).catch(e => 'ERROR: ' + e.message.split('\n')[0]); |
| 94 | ok('5 · Command Palette abre, busca y abre el archivo', open && hits.some(h => /utils\.py/.test(h)) && /utils\.py/.test(tab)); |
| 95 | await p.context().close(); |
| 96 | } |
| 97 | |
| 98 | // ============ 6 · barra de menú File/Edit/View/Git ============ |
| 99 | { |
| 100 | const p = await ide(); |
| 101 | const menus = await p.locator('#menubar button').allTextContents(); |
| 102 | await p.click('#menubar button[data-menu="view"]'); await p.waitForTimeout(300); |
| 103 | const viewItems = await p.locator('#topmenu .menu-item b').allTextContents(); |
| 104 | ok('6 · barra de menú con File/Edit/View/Git y desplegable', JSON.stringify(menus) === JSON.stringify(['File', 'Edit', 'View', 'Git']) && viewItems.length > 0); |
| 105 | await p.context().close(); |
| 106 | } |
| 107 | |
| 108 | // ============ 7 · Skills (catálogo real) accesible ============ |
| 109 | { |
| 110 | const p = await ide(); |
| 111 | await p.click('#act-skills'); await p.waitForTimeout(500); |
| 112 | const repos = await p.locator('#settings-panel a').allTextContents().catch(() => []); |
| 113 | ok('7 · icono Skills abre el panel con los repos', repos.some(r => /anthropics\/skills/.test(r))); |
| 114 | await p.context().close(); |
| 115 | } |
| 116 | |
| 117 | // ============ 8 · el E4B roto NO es cargable (anti-crash) ============ |
| 118 | { |
| 119 | const p = await ide(); |
| 120 | // El E4B «healed» propio (roto) no se ofrece. El Gemma-4 E4B oficial de Google |
| 121 | // SÍ (de7a37e, con GPU de verdad): se mira el id y el nombre, no «E4B» suelto. |
| 122 | const opts = await p.$$eval('#model-select option', os => os.map(o => ({ id: o.value, label: o.textContent }))); |
| 123 | ok('8 · el E4B healed (roto) no se ofrece en el selector', !opts.some(o => o.id === 'litert' || o.id === 'litert:elffuss-e4b' || /Elffuss[^·]*E4B|healed/i.test(o.label)), JSON.stringify(opts.map(o => o.label))); |
| 124 | await p.context().close(); |
| 125 | } |
| 126 | |
| 127 | // ============ 9 · histórico del chat persiste tras refresco ============ |
| 128 | { |
| 129 | const p = await ide(); |
| 130 | await say(p, 'árbol', 1500); |
| 131 | const before = await p.locator('#chat-log .msg').count(); |
| 132 | await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(4000); |
| 133 | const after = await p.locator('#chat-log .msg').count(); |
| 134 | ok('9 · histórico del chat sobrevive al refresco', after >= before && before > 0, `${before}→${after}`); |
| 135 | await p.context().close(); |
| 136 | } |
| 137 | |
| 138 | // ============ 10 · OG image para compartir ============ |
| 139 | { |
| 140 | const p = await ide(); |
| 141 | const og = await p.getAttribute('meta[property="og:image"]', 'content'); |
| 142 | const r = await p.request.get(og); |
| 143 | ok('10 · OG image existe y se sirve', r.ok() && (+r.headers()['content-length'] > 10000), og); |
| 144 | await p.context().close(); |
| 145 | } |
| 146 | |
| 147 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ TODO VERDE — IDE validado end-to-end'); |
| 148 | await browser.close(); |
| 149 | process.exit(fails ? 1 : 0); |