Elffuss BraidHub

utopia-ia/elffuss-code public

178a8a01c6e9 · 2.0 KiBRawPermalink
1// code.edit invocado por el AGENTE de verdad (tool-calling real, no import directo)
2import { chromium } from 'playwright';
3const BASE = process.env.BASE || 'http://localhost:8799';
4let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
5
6const b = await chromium.launch();
7const ctx = await b.newContext();
8await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
9const p = await ctx.newPage();
10await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
11await p.evaluate(async () => {
12 const o = await navigator.storage.getDirectory();
13 const f = await o.getFileHandle('config.py', { create: true });
14 const s = await f.createWritable();
15 await s.write('DEBUG = False\nMAX_RETRIES = 3\n');
16 await s.close();
17});
18await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500);
19
20await p.evaluate(() => {
21 window.elffussClaw.conv.getActive().agent.provider = {
22 chat: async (h, s, cb) => {
23 const res = h.find(m => m.role === 'user' && m.content.startsWith('[resultado code.edit]'));
24 if (!res) return '```tool\n{"tool":"code.edit","args":{"path":"config.py","search":"DEBUG = False","replace":"DEBUG = True"}}\n```';
25 return 'Hecho: ' + res.content;
26 },
27 };
28});
29await p.fill('#prompt', 'activa el modo debug en config.py');
30await p.press('#prompt', 'Enter');
31await p.waitForTimeout(800);
32
33const content = await p.evaluate(async () => (await import('/js/tools/code.js')).read({ path: 'config.py' }));
34ok('el agente aplicó la edición parcial de verdad vía tool-calling', content.includes('DEBUG = True'));
35ok('el resto del fichero se conservó intacto', content.includes('MAX_RETRIES = 3'));
36const chatLog = await p.locator('#chat-log').innerText();
37ok('el chat muestra la tool-call code.edit', /code\.edit/.test(chatLog));
38
39console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ code.edit vía tool-calling real del agente OK');
40await b.close();
41process.exit(fails ? 1 : 0);