Elffuss BraidHub

utopia-ia/elffuss-code public

d801e6f6daaf · 4.3 KiBRawPermalink
1// Mente v2: mundo audio-reactivo + consolas flotantes + nodos clicables +
2// config de cerebro + persistencia (música/animación) + reporte al chat.
3import { chromium } from 'playwright';
4const OUT = (process.env.SCRATCH || '/tmp/elffuss-test');
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++};
7const b = await chromium.launch({ args:['--enable-unsafe-webgpu','--use-angle=metal','--autoplay-policy=no-user-gesture-required'] });
8const ctx = await b.newContext(); await ctx.addInitScript(()=>{try{localStorage.setItem('elffusscode.model','rules')}catch{}});
9const p = await ctx.newPage({ viewport:{width:1500,height:900} });
10p.on('console', m=>{ if(m.type()==='error' && !/allow-same-origin|soundcloud|widget|encrypted-media|permissions policy/i.test(m.text())) console.log(' err:', m.text().slice(0,140)); });
11await p.goto(BASE+'/',{waitUntil:'domcontentloaded'});
12await p.evaluate(async()=>{const o=await navigator.storage.getDirectory();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()};await w('README.md','# demo');await w('app.js','export const x=1;')});
13await p.goto(BASE+'/?test-opfs',{waitUntil:'domcontentloaded'}); await p.waitForTimeout(2000);
14
15await p.locator('#activity img').click(); await p.waitForTimeout(1000);
16ok('overlay + mundo WebGL', await p.locator('#mind-overlay').count()>0 && await p.evaluate(()=>{const c=document.getElementById('mind-canvas');const gl=c&&(c.getContext('webgl2')||c.getContext('webgl'));return !!gl&&!gl.isContextLost();}));
17ok('sin subtítulo (solo título)', await p.evaluate(()=>{const t=document.getElementById('mind-title');return t && !t.querySelector('span') && /MENTE DE ELFFUSS/.test(t.textContent);}));
18ok('música (SoundCloud)', await p.locator('.mind-music iframe').count()>0);
19ok('botón de config del cerebro', await p.locator('#mind-config').count()>0);
20
21// inyectar pensamientos + una mejora forjada
22await p.evaluate(async ()=>{ const m=await import('/js/mind.js');
23 m.pushThought('ceo',{type:'cycle',n:1,text:'Reparto el trabajo…'});
24 for(const [id,name] of [['arq','Arquitectura'],['cal','Calidad'],['rend','Rendimiento'],['dx','Producto/DX']]){ m.pushThought(id,{type:'open',name,focus:'foco'}); m.pushThought(id,{type:'token',text:'analizo '+name+' y propongo una mejora concreta en app.js. '}); m.pushThought(id,{type:'done'}); }
25 m.pushThought('ceo',{type:'built',text:'Guardado en .elffuss/soul/mejoras-001.md',path:'.elffuss/soul/mejoras-001.md',proposals:[{dept:'Arquitectura',text:'extraer helper'},{dept:'Calidad',text:'añadir test'}]});
26});
27await p.waitForTimeout(1000);
28ok('consolas flotantes (ancladas al mundo)', await p.locator('.mind-console').count()>=4, await p.locator('.mind-console').count()+'');
29ok('nodo de pensamiento clicable creado', await p.evaluate(()=>document.querySelectorAll('.mind-node-label').length>0));
30
31// abrir el panel de config y reprogramar la misión
32await p.locator('#mind-config').click(); await p.waitForTimeout(300);
33ok('panel de config visible (misión + carpeta)', await p.locator('#mind-cfg.show #cfg-mission').count()>0 && await p.locator('#cfg-dir').count()>0);
34ok('carpeta por defecto .elffuss/soul', (await p.locator('#cfg-dir').inputValue())==='.elffuss/soul');
35await p.locator('#cfg-mission').fill('céntrate en seguridad');
36await p.locator('#cfg-save').click(); await p.waitForTimeout(300);
37ok('la misión se reprograma', await p.evaluate(async()=>{const c=await import('/js/ceo.js');return c.getMission()==='céntrate en seguridad';}));
38
39await p.screenshot({ path: OUT+'/mind2.png' });
40
41// persistencia: cerrar y reabrir NO recrea el overlay (misma música/animación)
42await p.locator('#mind-close').click(); await p.waitForTimeout(400);
43ok('al cerrar el overlay se oculta (no se destruye)', await p.evaluate(()=>{const o=document.getElementById('mind-overlay');return o && getComputedStyle(o).display==='none';}));
44await p.locator('#activity img').click(); await p.waitForTimeout(400);
45ok('al reabrir NO se recrea (persistencia música/animación)', await p.evaluate(()=>document.querySelectorAll('#mind-overlay').length===1));
46console.log('captura → mind2.png');
47console.log(fails?`\n❌ ${fails} FALLO(S)`:'\n✅ MENTE v2 OK');
48await b.close(); process.exit(fails?1:0);