Elffuss BraidHub

utopia-ia/elffuss-code public

main · 2.5 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';
5import { CHROME_ARGS } from './chrome-args.mjs';
6const BASE = process.env.BASE || 'http://localhost:8799';
7let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
8
9const b = await chromium.launch({ args: ['--enable-unsafe-webgpu', ...CHROME_ARGS, '--autoplay-policy=no-user-gesture-required'] });
10const ctx = await b.newContext(); await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
11const p = await ctx.newPage({ viewport: { width: 1300, height: 850 } });
12await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500);
13
14await p.locator('#activity img').click(); await p.waitForTimeout(1000);
15await p.evaluate(async () => {
16 const m = await import('/js/mind.js');
17 m.pushThought('ceo', { type: 'cycle', n: 1, text: 'Ciclo de prueba antes de recargar la página.' });
18 m.pushThought('arq', { type: 'open', name: 'Arquitectura' });
19 m.pushThought('arq', { type: 'token', text: 'esta línea debe sobrevivir a la recarga de verdad.\n' });
20});
21await p.waitForTimeout(700); // que el guardado (debounce 400ms) llegue a disco
22const before = await p.evaluate(() => document.getElementById('mind-log-body').innerText);
23ok('el historial se ve ANTES de recargar', /debe sobrevivir/.test(before), before.slice(0, 60));
24
25// RECARGA REAL de la página (no solo cerrar/abrir la Mente en la misma sesión)
26await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500);
27await p.locator('#activity img').click();
28// espera a que la Mente pinte su historial (con un tope), no un tiempo fijo:
29// con extensiones de código arrancando a la vez la página tarda más en pintarlo
30let after = '';
31for (let i = 0; i < 50 && !/debe sobrevivir/.test(after); i++) { await p.waitForTimeout(200); after = await p.evaluate(() => document.getElementById('mind-log-body')?.innerText || ''); }
32ok('el historial SOBREVIVE a una recarga real de la página', /debe sobrevivir/.test(after), after.slice(0, 80));
33ok('también se conserva el ciclo/evento del CEO', /Ciclo de prueba/.test(after));
34
35console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ HISTORIAL PERSISTENTE OK — sobrevive a recargar la página');
36await b.close();
37process.exit(fails ? 1 : 0);