Elffuss BraidHub

utopia-ia/elffuss-code public

main · 3.9 KiBRawPermalink
1// Lo adjuntado con @ se ve como fichas encima de la caja, cada una con su ×.
2// Antes el adjunto era solo texto dentro del mensaje: para saber qué iba
3// adjunto había que leerlo, y para quitarlo, encontrarlo y borrarlo a mano.
4//
5// BASE=http://localhost:8799 node tests/attach-chips.mjs
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' });
12await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
13const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } });
14const errs = []; p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
15await p.goto(BASE + '/manifest.json');
16await p.evaluate(async () => {
17 const o = await navigator.storage.getDirectory();
18 const w = async (path, txt) => { const parts = path.split('/'); const name = parts.pop(); let d = o; for (const x of parts) d = await d.getDirectoryHandle(x, { create: true }); const f = await d.getFileHandle(name, { create: true }); const s = await f.createWritable(); await s.write(txt); await s.close(); };
19 await w('README.md', '# demo');
20 await w('src/app.js', 'export const app = 1;');
21});
22await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
23await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 });
24const fichas = () => p.evaluate(() => ({
25 oculto: document.getElementById('attach-chips').hidden,
26 fichas: [...document.querySelectorAll('#attach-chips .attach-chip')].map(c => c.firstChild.textContent),
27 quitar: [...document.querySelectorAll('#attach-chips .attach-chip button')].map(b => b.getAttribute('aria-label')),
28 texto: document.getElementById('prompt').value,
29}));
30const elige = async (frag, ruta) => {
31 await p.focus('#prompt');
32 await p.keyboard.type(frag);
33 await p.locator('#menu .menu-item', { hasText: '@' + ruta }).first().click();
34};
35
36ok('sin adjuntos no hay fichas', (await fichas()).oculto);
37await p.focus('#prompt'); await p.keyboard.type('mira ');
38await elige('@app', 'src/app.js');
39let f = await fichas();
40ok('adjuntar con @ pone una ficha con la ruta', !f.oculto && JSON.stringify(f.fichas) === '["@src/app.js"]' && /@src\/app\.js/.test(f.texto), JSON.stringify(f));
41ok(' …y su × dice qué quita', f.quitar[0] === 'Quitar @src/app.js del mensaje', JSON.stringify(f.quitar));
42await p.keyboard.type('y ');
43await elige('@READ', 'README.md');
44f = await fichas();
45ok('dos adjuntos, dos fichas', JSON.stringify(f.fichas) === '["@src/app.js","@README.md"]', JSON.stringify(f));
46await p.locator('#attach-chips .attach-chip button').first().click();
47f = await fichas();
48ok('× quita la ficha Y la @ruta del mensaje', JSON.stringify(f.fichas) === '["@README.md"]' && !/@src\/app\.js/.test(f.texto) && /@README\.md/.test(f.texto), JSON.stringify(f));
49ok(' …y el foco vuelve a la caja', await p.evaluate(() => document.activeElement?.id) === 'prompt');
50// borrar la @ruta a mano también se lleva su ficha
51await p.evaluate(() => { const t = document.getElementById('prompt'); t.value = t.value.replace('@README.md', ''); t.dispatchEvent(new Event('input')); });
52f = await fichas();
53ok('borrar la @ruta a mano también quita su ficha', f.oculto && f.fichas.length === 0, JSON.stringify(f));
54// al enviar, las fichas se van con el mensaje
55await elige('@app', 'src/app.js');
56await p.keyboard.press('Enter');
57await p.waitForTimeout(400);
58f = await fichas();
59ok('al enviar, las fichas se van con el mensaje', f.oculto && f.texto === '', JSON.stringify(f));
60
61console.log('\n errores JS:', errs[0] || 'ninguno');
62ok('sin errores de página', errs.length === 0, errs.join(' | '));
63console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ ADJUNTOS COMO FICHAS QUE SE QUITAN');
64await b.close();
65process.exit(fails ? 1 : 0);