Elffuss BraidHub

utopia-ia/elffuss-code public

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