Elffuss BraidHub

utopia-ia/elffuss-code public

6fb41f3536ee · 6.7 KiBRawPermalink
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
6import { chromium } from 'playwright';
7import { CHROME_ARGS } from './chrome-args.mjs';
8
9const BASE = process.env.BASE || 'https://code.elffuss.com';
10let fails = 0;
11const ok = (name, cond, extra = '') => { console.log((cond ? '✅' : '❌') + ' ' + name + (extra ? ' — ' + extra : '')); if (!cond) fails++; };
12
13const browser = await chromium.launch({ args: ['--enable-unsafe-webgpu', ...CHROME_ARGS] });
14
15// siembra un proyecto en OPFS y entra al IDE
16async 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}
34const 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 const tab = await p.locator('.tab.active').textContent().catch(() => '');
54 ok('2 · abrir archivo del árbol → Monaco con su contenido', hasCode && /index\.js/.test(tab));
55 await p.context().close();
56}
57
58// ============ 3 · el agente busca en el código (code.search) ============
59{
60 const p = await ide();
61 await say(p, 'busca saludo', 1800);
62 const res = (await p.locator('.msg.assistant, .msg.tool-result').allTextContents()).join(' ');
63 ok('3 · «busca saludo» encuentra el símbolo en el código', /index\.js:1|saludo/.test(res));
64 await p.context().close();
65}
66
67// ============ 4 · el agente ESCRIBE un archivo (code.write → disco) ============
68{
69 const p = await ide();
70 await say(p, 'escribe src/nuevo.js: export const pi = 3.1416;', 1800);
71 const written = await p.evaluate(async () => {
72 const opfs = await navigator.storage.getDirectory();
73 const src = await opfs.getDirectoryHandle('src');
74 return (await (await (await src.getFileHandle('nuevo.js')).getFile()).text()).includes('3.1416');
75 });
76 ok('4 · «escribe archivo» persiste a disco de verdad', written);
77 await p.context().close();
78}
79
80// ============ 5 · Command Palette (Cmd/Ctrl+P) encuentra archivos ============
81{
82 const p = await ide();
83 await p.evaluate(() => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'p', metaKey: true, bubbles: true })));
84 await p.waitForTimeout(400);
85 const open = await p.isVisible('#palette');
86 await p.fill('#pal-input', 'utils'); await p.waitForTimeout(400);
87 const hits = await p.locator('.pal-item .pi-name').allTextContents();
88 await p.locator('.pal-item').first().click(); await p.waitForTimeout(700);
89 const tab = await p.locator('.tab.active').textContent().catch(() => '');
90 ok('5 · Command Palette abre, busca y abre el archivo', open && hits.some(h => /utils\.py/.test(h)) && /utils\.py/.test(tab));
91 await p.context().close();
92}
93
94// ============ 6 · barra de menú File/Edit/View/Git ============
95{
96 const p = await ide();
97 const menus = await p.locator('#menubar button').allTextContents();
98 await p.click('#menubar button[data-menu="view"]'); await p.waitForTimeout(300);
99 const viewItems = await p.locator('#topmenu .menu-item b').allTextContents();
100 ok('6 · barra de menú con File/Edit/View/Git y desplegable', JSON.stringify(menus) === JSON.stringify(['File', 'Edit', 'View', 'Git']) && viewItems.length > 0);
101 await p.context().close();
102}
103
104// ============ 7 · Skills (catálogo real) accesible ============
105{
106 const p = await ide();
107 await p.click('#act-skills'); await p.waitForTimeout(500);
108 const repos = await p.locator('#settings-panel a').allTextContents().catch(() => []);
109 ok('7 · icono Skills abre el panel con los repos', repos.some(r => /anthropics\/skills/.test(r)));
110 await p.context().close();
111}
112
113// ============ 8 · el E4B roto NO es cargable (anti-crash) ============
114{
115 const p = await ide();
116 const opts = await p.$$eval('#model-select option', os => os.map(o => o.textContent));
117 ok('8 · Gemma E4B roto no se ofrece en el selector', !opts.some(o => /E4B/.test(o)), JSON.stringify(opts));
118 await p.context().close();
119}
120
121// ============ 9 · histórico del chat persiste tras refresco ============
122{
123 const p = await ide();
124 await say(p, 'árbol', 1500);
125 const before = await p.locator('#chat-log .msg').count();
126 await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(4000);
127 const after = await p.locator('#chat-log .msg').count();
128 ok('9 · histórico del chat sobrevive al refresco', after >= before && before > 0, `${before}→${after}`);
129 await p.context().close();
130}
131
132// ============ 10 · OG image para compartir ============
133{
134 const p = await ide();
135 const og = await p.getAttribute('meta[property="og:image"]', 'content');
136 const r = await p.request.get(og);
137 ok('10 · OG image existe y se sirve', r.ok() && (+r.headers()['content-length'] > 10000), og);
138 await p.context().close();
139}
140
141console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ TODO VERDE — IDE validado end-to-end');
142await browser.close();
143process.exit(fails ? 1 : 0);