Elffuss BraidHub

utopia-ia/elffuss-code public

9255fd1f0dc0 · 7.4 KiBRawPermalink
1// La Mente: abrirla no enciende nada, y lo que se ve se puede pulsar.
2//
3// 1. Clic en la elfa: abre la Mente y NADA más. Antes el primer clic encendía
4// el cerebro autónomo en silencio y pedía permiso de notificaciones.
5// 2. Sin modelo (modo Básico) el cerebro no piensa: «Pensar ahora» lo dice en
6// el panel y no se escribe nada en la carpeta-alma. Antes el motor de
7// reglas generaba «4 mejoras» con el texto de ayuda dentro del proyecto.
8// 3. Las etiquetas de propuesta se pueden pulsar (antes pointer-events:none:
9// el clic se iba al lienzo) y son botones.
10// 4. «Abrir en el editor» cierra la Mente antes (antes abría DETRÁS) y las
11// rutas de la propuesta abren su fichero.
12// 5. La música no se carga sola: hay que pedirla, y se puede quitar.
13// La red a SoundCloud va bloqueada: el test solo mira si la app la PIDE.
14//
15// BASE=http://127.0.0.1:8898 node tests/mind-consent.mjs
16import { chromium } from 'playwright';
17const BASE = process.env.BASE || 'http://localhost:8799';
18let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
19
20const b = await chromium.launch();
21const ctx = await b.newContext({ locale: 'es-ES' });
22await ctx.addInitScript(() => {
23 try { localStorage.setItem('elffusscode.model', 'rules'); } catch {}
24 window.__permiso = 0;
25 if (window.Notification) Notification.requestPermission = () => { window.__permiso++; return Promise.resolve('default'); };
26});
27const sc = [];
28await ctx.route(/soundcloud/, r => { sc.push(r.request().url()); r.abort(); });
29const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } });
30const errs = []; p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
31
32await p.goto(BASE + '/manifest.json');
33await p.evaluate(async () => {
34 const root = await navigator.storage.getDirectory();
35 const escribe = async (path, txt) => {
36 const parts = path.split('/'); const name = parts.pop(); let d = root;
37 for (const x of parts) d = await d.getDirectoryHandle(x, { create: true });
38 const w = await (await d.getFileHandle(name, { create: true })).createWritable(); await w.write(txt); await w.close();
39 };
40 await escribe('src/app.js', 'export const a = 1;\n');
41 await escribe('.elffuss/soul/2026-10-10-1200-prueba.md', '# Propuesta\n\nRevisa `src/app.js`.\n');
42});
43await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
44await p.waitForFunction(() => window.monaco && document.querySelector('#tree [data-path]'), null, { timeout: 30000 });
45
46// 1 · abrir la Mente
47const esBoton = await p.evaluate(() => { const b = document.getElementById('act-mind'); return !!b && b.tagName === 'BUTTON' && !!b.getAttribute('aria-label'); });
48ok('1 · la elfa es un botón con nombre accesible', esBoton);
49await p.click('#act-mind');
50await p.waitForSelector('#mind-overlay', { timeout: 45000 });
51await p.waitForTimeout(800);
52const r1 = await p.evaluate(async () => ({ on: (await import('/js/ceo.js')).isEnabled(), permiso: window.__permiso, boton: document.getElementById('mind-playstop').textContent }));
53ok('1 · abrir la Mente NO enciende el cerebro', !r1.on && /activar/.test(r1.boton), JSON.stringify(r1));
54ok('1 · …ni pide permiso de notificaciones', r1.permiso === 0, JSON.stringify(r1));
55ok('5 · la música no se carga sola (ninguna petición a SoundCloud)', sc.length === 0, sc.join(' '));
56
57// 2 · modo Básico: no piensa
58await p.click('#mind-playstop'); // encenderlo a propósito
59await p.click('#mind-config');
60await p.click('#cfg-think-now');
61await p.waitForTimeout(300);
62const nota = await p.evaluate(() => document.getElementById('cfg-note')?.textContent || '');
63ok('2 · «Pensar ahora» sin modelo lo dice en el panel', /Sin un modelo cargado/.test(nota), nota);
64const r2 = await p.evaluate(async () => {
65 const ceo = await import('/js/ceo.js');
66 const forzado = await ceo.forceCycle();
67 const root = await navigator.storage.getDirectory();
68 const soul = await (await root.getDirectoryHandle('.elffuss')).getDirectoryHandle('soul');
69 const nombres = []; for await (const e of soul.values()) nombres.push(e.name);
70 return { forzado, nombres };
71});
72ok('2 · …y con el motor de reglas no se escribe ninguna propuesta', r2.forzado === false && r2.nombres.length === 1, JSON.stringify(r2));
73await p.click('#cfg-x');
74
75// 3 · etiqueta de propuesta pulsable
76await p.waitForSelector('.mind-node-label', { timeout: 10000 });
77const r3 = await p.evaluate(() => {
78 const lab = [...document.querySelectorAll('.mind-node-label')].find(l => l.style.display !== 'none');
79 const r = lab.getBoundingClientRect();
80 const enPunto = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2);
81 return { boton: lab.tagName === 'BUTTON', recibeClic: enPunto === lab, aria: lab.getAttribute('aria-label') };
82});
83ok('3 · la etiqueta es un botón y recibe el clic (no el lienzo)', r3.boton && r3.recibeClic && /Abrir la propuesta/.test(r3.aria || ''), JSON.stringify(r3));
84await p.evaluate(() => [...document.querySelectorAll('.mind-node-label')].find(l => l.style.display !== 'none').click());
85await p.waitForSelector('#mind-panel.show');
86const enlace = await p.evaluate(() => [...document.querySelectorAll('#mind-panel .mp-body a')].map(a => a.textContent));
87ok('4 · las rutas de la propuesta son enlaces', enlace.includes('src/app.js'), JSON.stringify(enlace));
88
89// 4 · Abrir en el editor: cierra la Mente y abre el fichero
90await p.click('#mp-open');
91await p.waitForTimeout(400);
92const r4 = await p.evaluate(() => ({
93 mente: getComputedStyle(document.getElementById('mind-overlay')).display,
94 activa: document.querySelector('#tabs-bar .tab.active')?.dataset.path,
95}));
96ok('4 · «Abrir en el editor» cierra la Mente y abre la propuesta', r4.mente === 'none' && /prueba\.md$/.test(r4.activa || ''), JSON.stringify(r4));
97await p.click('#act-mind');
98await p.waitForTimeout(500);
99await p.evaluate(() => [...document.querySelectorAll('.mind-node-label')].find(l => l.style.display !== 'none').click());
100await p.waitForSelector('#mind-panel.show');
101await p.locator('#mind-panel .mp-body a', { hasText: 'src/app.js' }).click();
102await p.waitForTimeout(400);
103const r4b = await p.evaluate(() => ({ mente: getComputedStyle(document.getElementById('mind-overlay')).display, activa: document.querySelector('#tabs-bar .tab.active')?.dataset.path }));
104ok('4 · una ruta de la propuesta cierra la Mente y abre ese fichero', r4b.mente === 'none' && r4b.activa === 'src/app.js', JSON.stringify(r4b));
105
106// 5 · la música, solo si se pide, y se puede quitar
107await p.click('#act-mind');
108await p.waitForTimeout(400);
109await p.click('.mind-music-btn');
110await p.waitForTimeout(300);
111const conMusica = await p.evaluate(() => !!document.getElementById('mind-sc'));
112await p.click('.mind-music-btn');
113await p.waitForTimeout(200);
114const sinMusica = await p.evaluate(() => !document.getElementById('mind-sc'));
115ok('5 · «Poner música» carga el reproductor y «Quitar música» lo elimina', conMusica && sinMusica && sc.length > 0, `${conMusica} ${sinMusica} ${sc.length}`);
116const leyenda = await p.evaluate(() => [...document.querySelectorAll('#mind-legend .ml-item')].every(x => x.tagName === 'BUTTON'));
117ok('3 · la leyenda de perfiles son botones (teclado)', leyenda);
118
119console.log('\n errores JS:', errs[0] || 'ninguno');
120ok('sin errores de página', errs.length === 0, errs.join(' | '));
121console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ LA MENTE PIDE PERMISO Y SE DEJA PULSAR');
122await b.close();
123process.exit(fails ? 1 : 0);