Elffuss BraidHub

utopia-ia/elffuss-code public

7c24e7b60e19 · 2.3 KiBRawPermalink
1// Bug real reportado: el historial de la Mente («≡ historial») vivía SOLO en
2// memoria/DOM — al recargar la página (cerrar pestaña, refrescar) se perdía
3// todo. Ahora se persiste en IndexedDB y sobrevive a una recarga REAL.
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({ args: ['--enable-unsafe-webgpu', '--use-angle=metal', '--autoplay-policy=no-user-gesture-required'] });
9const ctx = await b.newContext(); await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
10const p = await ctx.newPage({ viewport: { width: 1300, height: 850 } });
11await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500);
12
13await p.locator('#activity img').click(); await p.waitForTimeout(1000);
14await p.evaluate(async () => {
15 const m = await import('/js/mind.js');
16 m.pushThought('ceo', { type: 'cycle', n: 1, text: 'Ciclo de prueba antes de recargar la página.' });
17 m.pushThought('arq', { type: 'open', name: 'Arquitectura' });
18 m.pushThought('arq', { type: 'token', text: 'esta línea debe sobrevivir a la recarga de verdad.\n' });
19});
20await p.waitForTimeout(700); // que el guardado (debounce 400ms) llegue a disco
21const before = await p.evaluate(() => document.getElementById('mind-log-body').innerText);
22ok('el historial se ve ANTES de recargar', /debe sobrevivir/.test(before), before.slice(0, 60));
23
24// RECARGA REAL de la página (no solo cerrar/abrir la Mente en la misma sesión)
25await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500);
26await p.locator('#activity img').click(); await p.waitForTimeout(1200);
27const after = await p.evaluate(() => document.getElementById('mind-log-body')?.innerText || '');
28ok('el historial SOBREVIVE a una recarga real de la página', /debe sobrevivir/.test(after), after.slice(0, 80));
29ok('también se conserva el ciclo/evento del CEO', /Ciclo de prueba/.test(after));
30
31console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ HISTORIAL PERSISTENTE OK — sobrevive a recargar la página');
32await b.close();
33process.exit(fails ? 1 : 0);