Elffuss BraidHub

utopia-ia/elffuss-code public

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