Elffuss BraidHub

utopia-ia/elffuss-code public

main · 4.0 KiBRawPermalink
1// Bug real reportado: un enlace del chat con solo el NOMBRE del fichero
2// («config.py») fallaba con «no existe» aunque el fichero real vivía en una
3// subcarpeta (drone_hacker/config.py) — el mensaje de error ya lo SUGERÍA
4// («¿Quizá: drone_hacker/config.py?») pero no se abría solo. openFile ahora
5// resuelve por nombre cuando hay una única coincidencia en el proyecto.
6import { chromium } from 'playwright';
7const BASE = process.env.BASE || 'http://localhost:8799';
8let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
9
10const b = await chromium.launch();
11const ctx = await b.newContext({ locale: 'es-ES' }); await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
12const p = await ctx.newPage();
13await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
14await p.evaluate(async () => {
15 const o = await navigator.storage.getDirectory();
16 const dir = await o.getDirectoryHandle('drone_hacker', { create: true });
17 const f = await dir.getFileHandle('config.py', { create: true });
18 const s = await f.createWritable(); await s.write('# el config real de drone_hacker'); await s.close();
19 // un homónimo AMBIGUO en otra carpeta, para el caso de "varias coincidencias"
20 const dir2 = await o.getDirectoryHandle('otro', { create: true });
21 const f2 = await dir2.getFileHandle('ambiguo.py', { create: true }); const s2 = await f2.createWritable(); await s2.write('a'); await s2.close();
22 const dir3 = await o.getDirectoryHandle('mas', { create: true });
23 const f3 = await dir3.getFileHandle('ambiguo.py', { create: true }); const s3 = await f3.createWritable(); await s3.write('b'); await s3.close();
24});
25await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500);
26
27// caso EXACTO del bug: el chat menciona solo "config.py" (sin ruta)
28await p.evaluate(async () => {
29 const m = await import('/js/main.js');
30 m.reportImprovements({ proposals: [{ dept: 'Arquitectura', text: 'Revisa el fichero de configuración con sustancia suficiente para el filtro de calidad.' }, { dept: 'Calidad', text: 'Otra propuesta sólida y con contenido real para el segundo departamento.' }], path: 'config.py' });
31});
32await p.waitForTimeout(300);
33await p.locator('.msg.md code.file-link', { hasText: 'config.py' }).first().click();
34await p.waitForTimeout(600);
35ok('el enlace con SOLO el nombre abre el fichero REAL (resuelto por nombre)', /drone_hacker\/config\.py|config\.py/.test(await p.locator('#tabs-bar').innerText()));
36ok('sin barra de error (no falló)', await p.locator('#statusbar').innerText().then(t => !/No pude abrir/.test(t)));
37const content = await p.evaluate(() => window.monaco?.editor.getModels().map(m => m.getValue()).join('|') || '');
38ok('el contenido es el REAL del fichero resuelto', /el config real de drone_hacker/.test(content), content.slice(0, 50));
39
40// homónimos AMBIGUOS (2 ficheros con el mismo nombre) → error claro, no adivina
41const openRes = await p.evaluate(async () => {
42 const ide = await import('/js/ide.js');
43 try { await ide.openFile('ambiguo.py'); return 'ok'; } catch (e) { return 'err:' + e.message; }
44});
45const ambiguousTab = await p.locator('#tabs-bar').innerText();
46ok('con homónimos ambiguos NO abre ninguno al azar (sin pestaña ambiguo.py suelta sin contexto)', !/^ambiguo\.py$/m.test(ambiguousTab.split('\n').find(l => l === 'ambiguo.py') || ''));
47
48// contador de streaming: dice "car." (caracteres), no ambigüo con tokens
49await p.evaluate(async () => {
50 const m = await import('/js/main.js');
51 const th = m.thinkingBubble();
52 th.tick('hola');
53 window.__label = document.querySelector('.msg.thinking span').textContent;
54 th.remove();
55});
56const labelText = await p.evaluate(() => window.__label);
57ok('el contador de streaming se etiqueta como caracteres, no tokens', /car\./.test(labelText), labelText);
58
59console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ ENLACES DEL CHAT (resolución por nombre) OK');
60await b.close();
61process.exit(fails ? 1 : 0);