Elffuss BraidHub

utopia-ia/elffuss-code public

main · 4.0 KiBRawPermalink
1// Verifica la Ciudad 3D (motor VibeCodeViewer vendorizado): siembra un proyecto
2// anidado, abre la vista, comprueba que el WebGL pinta la metrópolis y captura.
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;
8const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
9
10const b = await chromium.launch({ args: ['--enable-unsafe-webgpu', ...CHROME_ARGS] });
11const ctx = await b.newContext();
12await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
13const p = await ctx.newPage({ viewport: { width: 1500, height: 900 } });
14p.on('pageerror', e => { if (!/allow-same-origin/.test(e.message)) console.log(' pageerror:', e.message.slice(0, 160)); });
15p.on('console', m => { if (m.type() === 'error' && !/allow-same-origin/.test(m.text())) console.log(' console.error:', m.text().slice(0, 160)); });
16
17// proyecto anidado (varios distritos, edificios con plantas y ficheros)
18await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
19await p.evaluate(async () => {
20 const o = await navigator.storage.getDirectory();
21 const w = async (path, txt) => { const parts = path.split('/'); const name = parts.pop(); let d = o; for (const x of parts) d = await d.getDirectoryHandle(x, { create: true }); const f = await d.getFileHandle(name, { create: true }); const s = await f.createWritable(); await s.write(txt); await s.close(); };
22 const body = n => 'x'.repeat(200 + n * 137);
23 await w('README.md', '# demo city\n' + body(3));
24 await w('package.json', '{ "name": "demo" }');
25 for (const [i, f] of ['index.js', 'app.js', 'router.js', 'store.js'].entries()) await w('src/' + f, body(i + 2));
26 for (const [i, f] of ['Button.jsx', 'Modal.jsx', 'Nav.jsx'].entries()) await w('src/components/' + f, body(i + 1));
27 for (const [i, f] of ['api.js', 'auth.js'].entries()) await w('src/services/' + f, body(i + 4));
28 for (const [i, f] of ['helpers.js', 'format.js', 'dates.js'].entries()) await w('lib/' + f, body(i));
29 for (const [i, f] of ['unit.test.js', 'e2e.test.js'].entries()) await w('tests/' + f, body(i + 1));
30 await w('docs/guide.md', body(6));
31});
32await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
33await p.waitForTimeout(2500);
34
35// abrir la Ciudad 3D
36await p.click('#act-city');
37await p.waitForTimeout(4500); // construir modelo + montar three + primeros frames
38
39const head = await p.locator('#view-body .view-head').textContent().catch(() => '');
40ok('cabecera de la ciudad presente', /distritos/.test(head), head.slice(0, 60));
41const hasCanvas = await p.locator('#city-canvas').count();
42ok('canvas de la ciudad montado', hasCanvas > 0);
43
44// el motor real montó la escena (canvas con tamaño real + contexto WebGL vivo).
45// El brillo de píxeles se valida por la CAPTURA (readPixels fuera del loop da
46// negro por preserveDrawingBuffer:false, no es fiable aquí).
47const glState = await p.evaluate(() => {
48 const c = document.getElementById('city-canvas'); if (!c) return { ok: false };
49 const gl = c.getContext('webgl2') || c.getContext('webgl');
50 return { ok: !!gl, w: c.width, h: c.height, lost: gl ? gl.isContextLost() : true };
51});
52ok('canvas con tamaño real y contexto WebGL vivo', glState.ok && glState.w > 100 && glState.h > 100 && !glState.lost, JSON.stringify(glState));
53
54// clic en el centro → debería abrir un fichero (raycast contra la ciudad)
55await p.mouse.click(560, 400);
56await p.waitForTimeout(600);
57
58// captura recortada del lienzo: prueba visual de la metrópolis
59const cnv = await p.locator('#city-canvas');
60await cnv.screenshot({ path: OUT + '/city_vcc_canvas.png' }).catch(() => {});
61await p.screenshot({ path: OUT + '/city_vcc.png' });
62console.log('capturas → city_vcc.png, city_vcc_canvas.png');
63console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ CIUDAD 3D (VibeCodeViewer) OK');
64await b.close();
65process.exit(fails ? 1 : 0);