Elffuss BraidHub

utopia-ia/elffuss-code public

9828539d2fc0 · 2.8 KiBRawPermalink
1// End-to-end del bug «ficheros vacíos»: un mensaje del modelo con VARIAS
2// code.write debe escribir TODOS los ficheros con su contenido. Inyectamos un
3// proveedor falso (sin modelo real) y comprobamos el contenido en OPFS.
4import { chromium } from 'playwright';
5const BASE = process.env.BASE || 'http://localhost:8799';
6let fails = 0;
7const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
8
9const b = await chromium.launch({ args: ['--enable-unsafe-webgpu', '--use-angle=metal'] });
10const ctx = await b.newContext();
11await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
12const p = await ctx.newPage();
13await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
14await p.waitForTimeout(2000);
15
16const events = await p.evaluate(async () => {
17 const { Agent } = await import('/js/agent.js');
18 const msg = `He creado la estructura. Ahora los ficheros:
19\`\`\`tool
20{"tool":"code.write","args":{"path":"proj/index.html","content":"<!DOCTYPE html>\\n<html lang=\\"en\\"><body><h1>vLLM</h1></body></html>"}}
21\`\`\`
22El CSS:
23\`\`\`tool
24{"tool":"code.write","args":{"path":"proj/style.css","content":"body { margin: 0; font-family: system-ui; }"}}
25\`\`\`
26Y el script:
27\`\`\`tool
28{"tool":"code.write","args":{"path":"proj/script.js","content":"console.log('vLLM explainer');"}}
29\`\`\`
30Listo!`;
31 let n = 0;
32 const fake = { chat: async () => (n++ === 0 ? msg : 'Proyecto creado ✔') };
33 const a = new Agent(fake);
34 const ev = [];
35 await a.handle('crea un mini proyecto web que explique vllm', e => ev.push(e.type + (e.tool ? ':' + e.tool : '')));
36 return ev;
37});
38const writes = events.filter(e => e === 'tool_result:code.write').length;
39ok('se ejecutan las 3 code.write del mismo mensaje', writes === 3, `${writes} writes · eventos: ${events.join(',')}`);
40
41const files = await p.evaluate(async () => {
42 const o = await navigator.storage.getDirectory();
43 const read = async (path) => { let d = o; const parts = path.split('/'); const name = parts.pop(); for (const x of parts) d = await d.getDirectoryHandle(x); return (await (await d.getFileHandle(name)).getFile()).text(); };
44 return { idx: await read('proj/index.html').catch(() => ''), css: await read('proj/style.css').catch(() => ''), js: await read('proj/script.js').catch(() => '') };
45});
46ok('index.html NO está vacío', files.idx.includes('<h1>vLLM</h1>'), JSON.stringify(files.idx.slice(0, 40)));
47ok('style.css NO está vacío (llaves intactas)', files.css.includes('margin: 0'), JSON.stringify(files.css.slice(0, 40)));
48ok('script.js NO está vacío', files.js.includes('vLLM explainer'), JSON.stringify(files.js.slice(0, 40)));
49
50console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ MULTI-WRITE OK — los ficheros se crean con contenido');
51await b.close();
52process.exit(fails ? 1 : 0);