Elffuss BraidHub

utopia-ia/elffuss-code public

main · 4.0 KiBRawPermalink
1// Los paths entre backticks en el chat deben poder abrirse directamente (sin
2// tener que ir a buscarlos a mano), y NO confundirse con código real que
3// también use backticks.
4import { chromium } from 'playwright';
5const BASE = process.env.BASE || 'http://localhost:8799';
6let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
7
8const b = await chromium.launch();
9const ctx = await b.newContext(); await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
10const p = await ctx.newPage();
11await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
12await p.evaluate(async () => {
13 const o = await navigator.storage.getDirectory();
14 const w = async (n, t) => { const f = await o.getFileHandle(n, { create: true }); const s = await f.createWritable(); await s.write(t); await s.close(); };
15 await w('README.md', '# el fichero real que se abrirá');
16 const dir = await o.getDirectoryHandle('.elffuss', { create: true }).then(d => d.getDirectoryHandle('soul', { create: true }));
17 const f = await dir.getFileHandle('nota.md', { create: true }); const s = await f.createWritable(); await s.write('# nota real'); await s.close();
18});
19await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500);
20
21const addMsg = (cls, text) => p.evaluate(async ({ cls, text }) => {
22 // addMsg no está exportado (closure de main.js): la disparamos vía el mismo
23 // camino real que usa la app — reportImprovements, que SÍ está exportado y
24 // hace addMsg con un path entre backticks, exactamente el caso real.
25 const m = await import('/js/main.js');
26 m.reportImprovements({ proposals: [{ dept: 'Arquitectura', text: 'Propuesta con sustancia suficiente para pasar el filtro de calidad, de verdad.' }, { dept: 'Calidad', text: 'Otra propuesta sólida y con contenido real para el segundo departamento.' }], path: text });
27}, { cls, text });
28
29await addMsg('assistant', 'README.md');
30await p.waitForTimeout(300);
31const link1 = p.locator('.msg.md code.file-link', { hasText: 'README.md' });
32ok('el path entre backticks se convierte en enlace clicable', await link1.count() > 0);
33
34// clic → abre el fichero REAL en el editor (Monaco)
35await link1.first().click();
36await p.waitForTimeout(600);
37const tabText = await p.locator('#tabs-bar').innerText().catch(() => '');
38ok('el clic abre el fichero REAL en una pestaña del editor', /README\.md/.test(tabText), tabText);
39const editorContent = await p.evaluate(() => window.monaco?.editor.getModels().map(m => m.getValue()).join('|') || '');
40ok('el contenido mostrado es el REAL del fichero', /el fichero real que se abrirá/.test(editorContent), editorContent.slice(0, 60));
41
42// ruta con subcarpetas también debe funcionar
43await addMsg('assistant', '.elffuss/soul/nota.md');
44await p.waitForTimeout(300);
45const link2 = p.locator('.msg.md code.file-link', { hasText: '.elffuss/soul/nota.md' });
46ok('rutas con subcarpetas también se linkan', await link2.count() > 0);
47await link2.first().click();
48await p.waitForTimeout(600);
49ok('abre el fichero real dentro de subcarpetas', /nota\.md/.test(await p.locator('#tabs-bar').innerText()));
50
51// un código que NO es un path (JS de verdad) no debe volverse clicable ni romperse
52const codeMsgOk = await p.evaluate(async () => {
53 const m = await import('/js/main.js');
54 m.reportImprovements({ proposals: [{ dept: 'Rendimiento', text: 'usa `const x = 1` en vez de var, y sustancia de sobra para el filtro' }, { dept: 'Producto/DX', text: 'otra propuesta con suficiente sustancia real para el segundo hueco' }], path: null });
55 return true;
56});
57ok('reportImprovements con snippet de código no-path no rompe nada', codeMsgOk);
58const nonFileLink = p.locator('.msg.md code', { hasText: 'const x = 1' });
59ok('un snippet de código real NO se vuelve un file-link', await nonFileLink.evaluate(el => el.classList.contains('file-link')).catch(() => false) === false);
60
61console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ PATHS CLICABLES EN EL CHAT OK');
62await b.close();
63process.exit(fails ? 1 : 0);