Elffuss BraidHub

utopia-ia/elffuss-code public

main · 3.2 KiBRawPermalink
1// Bug A: al cerrar la última pestaña → estado vacío (no Monaco en blanco).
2// Bug B: abrir/cerrar/alternar vistas (grafo/ciudad) → siempre cargan bien.
3import { chromium } from 'playwright';
4import { CHROME_ARGS } from './chrome-args.mjs';
5const OUT=(process.env.SCRATCH || '/tmp/elffuss-test');
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++};
8const b=await chromium.launch({args:['--enable-unsafe-webgpu',...CHROME_ARGS]});
9const ctx=await b.newContext(); await ctx.addInitScript(()=>{try{localStorage.setItem('elffusscode.model','rules')}catch{}});
10const p=await ctx.newPage({viewport:{width:1500,height:900}});
11p.on('pageerror',e=>{if(!/allow-same-origin/.test(e.message))console.log(' pageerror:',e.message.slice(0,120))});
12await p.goto(BASE+'/',{waitUntil:'domcontentloaded'});
13await p.evaluate(async()=>{const o=await navigator.storage.getDirectory();const w=async(path,txt)=>{const pr=path.split('/');const nm=pr.pop();let d=o;for(const x of pr)d=await d.getDirectoryHandle(x,{create:true});const f=await d.getFileHandle(nm,{create:true});const s=await f.createWritable();await s.write(txt);await s.close()};
14 await w('README.md','# demo'); await w('src/a.js',"import {b} from './b.js';\nexport const a=b;"); await w('src/b.js',"export const b=1;");});
15await p.goto(BASE+'/?test-opfs',{waitUntil:'domcontentloaded'}); await p.waitForTimeout(2500);
16
17// ── Bug A ──
18await p.locator('#tree').getByText('README.md').first().click(); await p.waitForTimeout(700);
19ok('al abrir un fichero, sin estado vacío', await p.evaluate(()=>{const e=document.getElementById('editor-empty');return !e||getComputedStyle(e).display==='none';}));
20await p.locator('#tabs-bar .tab .tab-x').first().click(); await p.waitForTimeout(500); // cerrar la pestaña (su ✕ es un botón .tab-x)
21ok('al cerrar la última pestaña → estado vacío visible', await p.evaluate(()=>{const e=document.getElementById('editor-empty');return !!e && getComputedStyle(e).display!=='none';}));
22
23// ── Bug B ── abrir/cerrar/alternar vistas varias veces
24const openArch=async()=>{ await p.click('#act-arch'); await p.waitForTimeout(3500); return p.evaluate(()=>{const g=document.getElementById('arch-graph');return !!g && !!g.querySelector('canvas') && +g.dataset.nodes>0;}); };
25const openCity=async()=>{ await p.click('#act-city'); await p.waitForTimeout(3500); return p.evaluate(()=>{const c=document.getElementById('city-canvas');const gl=c&&(c.getContext('webgl2')||c.getContext('webgl'));return !!gl && !gl.isContextLost() && c.width>50; }); };
26ok('grafo carga (1ª vez)', await openArch());
27await p.click('#view-close'); await p.waitForTimeout(400);
28ok('ciudad carga tras cerrar el grafo', await openCity());
29await p.click('#view-close'); await p.waitForTimeout(400);
30ok('grafo RE-carga (reapertura)', await openArch());
31// alternar directo grafo→ciudad sin cerrar
32ok('ciudad carga alternando directo desde el grafo', await openCity());
33ok('grafo carga alternando directo desde la ciudad', await openArch());
34await p.screenshot({path:OUT+'/bugs.png'});
35console.log(fails?`\n❌ ${fails} FALLO(S)`:'\n✅ BUGS (estado vacío + recarga de vistas) OK');
36await b.close(); process.exit(fails?1:0);