| 1 | // Mente v2: mundo audio-reactivo + consolas flotantes + nodos clicables + |
| 2 | // config de cerebro + persistencia (música/animación) + reporte al chat. |
| 3 | import { chromium } from 'playwright'; |
| 4 | import { CHROME_ARGS } from './chrome-args.mjs'; |
| 5 | const OUT = (process.env.SCRATCH || '/tmp/elffuss-test'); |
| 6 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 7 | let fails = 0; const ok = (n,c,e='')=>{console.log((c?'✅':'❌')+' '+n+(e?' — '+e:''));if(!c)fails++}; |
| 8 | const b = await chromium.launch({ args:['--enable-unsafe-webgpu',...CHROME_ARGS,'--autoplay-policy=no-user-gesture-required'] }); |
| 9 | const ctx = await b.newContext({ locale: 'es-ES' }); await ctx.addInitScript(()=>{try{localStorage.setItem('elffusscode.model','rules')}catch{}}); |
| 10 | const p = await ctx.newPage({ viewport:{width:1500,height:900} }); |
| 11 | p.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)); }); |
| 12 | await p.goto(BASE+'/',{waitUntil:'domcontentloaded'}); |
| 13 | await 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;')}); |
| 14 | await p.goto(BASE+'/?test-opfs',{waitUntil:'domcontentloaded'}); await p.waitForTimeout(2000); |
| 15 | |
| 16 | await p.locator('#activity img').click(); await p.waitForTimeout(1000); |
| 17 | ok('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();})); |
| 18 | ok('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);})); |
| 19 | // La música ya no se carga sola: hay que pedirla (era una petición a un tercero sin preguntar). |
| 20 | ok('música solo a petición (botón, sin reproductor cargado)', await p.locator('.mind-music iframe').count()===0 && await p.locator('.mind-music-btn').count()===1); |
| 21 | ok('botón de config del cerebro', await p.locator('#mind-config').count()>0); |
| 22 | |
| 23 | // inyectar pensamientos + una mejora forjada |
| 24 | await p.evaluate(async ()=>{ const m=await import('/js/mind.js'); |
| 25 | m.pushThought('ceo',{type:'cycle',n:1,text:'Reparto el trabajo…'}); |
| 26 | 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'}); } |
| 27 | 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'}]}); |
| 28 | }); |
| 29 | await p.waitForTimeout(1000); |
| 30 | ok('consolas flotantes (ancladas al mundo)', await p.locator('.mind-console').count()>=4, await p.locator('.mind-console').count()+''); |
| 31 | ok('nodo de pensamiento clicable creado', await p.evaluate(()=>document.querySelectorAll('.mind-node-label').length>0)); |
| 32 | |
| 33 | // abrir el panel de config y reprogramar la misión |
| 34 | await p.locator('#mind-config').click(); await p.waitForTimeout(300); |
| 35 | ok('panel de config visible (misión + carpeta)', await p.locator('#mind-cfg.show #cfg-mission').count()>0 && await p.locator('#cfg-dir').count()>0); |
| 36 | ok('carpeta por defecto .elffuss/soul', (await p.locator('#cfg-dir').inputValue())==='.elffuss/soul'); |
| 37 | await p.locator('#cfg-mission').fill('céntrate en seguridad'); |
| 38 | await p.locator('#cfg-save').click(); await p.waitForTimeout(300); |
| 39 | ok('la misión se reprograma', await p.evaluate(async()=>{const c=await import('/js/ceo.js');return c.getMission()==='céntrate en seguridad';})); |
| 40 | |
| 41 | await p.screenshot({ path: OUT+'/mind2.png' }); |
| 42 | |
| 43 | // persistencia: cerrar y reabrir NO recrea el overlay (misma música/animación) |
| 44 | await p.locator('#mind-close').click(); await p.waitForTimeout(400); |
| 45 | ok('al cerrar el overlay se oculta (no se destruye)', await p.evaluate(()=>{const o=document.getElementById('mind-overlay');return o && getComputedStyle(o).display==='none';})); |
| 46 | await p.locator('#activity img').click(); await p.waitForTimeout(400); |
| 47 | ok('al reabrir NO se recrea (persistencia música/animación)', await p.evaluate(()=>document.querySelectorAll('#mind-overlay').length===1)); |
| 48 | console.log('captura → mind2.png'); |
| 49 | console.log(fails?`\n❌ ${fails} FALLO(S)`:'\n✅ MENTE v2 OK'); |
| 50 | await b.close(); process.exit(fails?1:0); |