Elffuss BraidHub

utopia-ia/elffuss-code public

main · 2.6 KiBRawPermalink
1// Verifica el contraste de las tarjetas de modelo (CEREBRO) tras el fix.
2// Abre Ajustes, mide luminancia de título+subtítulo vs fondo 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';
7
8const lum = ([r, g, b]) => { const f = c => { c /= 255; return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4; }; return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b); };
9const ratio = (a, b) => { const [x, y] = [lum(a) + 0.05, lum(b) + 0.05]; return (Math.max(x, y) / Math.min(x, y)); };
10const parse = s => s.match(/\d+/g).slice(0, 3).map(Number);
11
12const br = await chromium.launch({ args: ['--enable-unsafe-webgpu', ...CHROME_ARGS] });
13const ctx = await br.newContext();
14await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
15const p = await ctx.newPage({ viewport: { width: 1200, height: 820 } });
16// En '/' solo está la landing: desde 77fb41b el IDE oculto (#ide[hidden]) no
17// se ve detrás, y los botones de Ajustes viven dentro. Se abre el IDE de prueba.
18await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
19await p.waitForSelector('#ide:not([hidden])', { timeout: 15000 });
20await p.waitForTimeout(800);
21// abrir Ajustes
22await p.click('#act-settings').catch(() => p.click('#btn-settings'));
23await p.waitForTimeout(600);
24await p.waitForSelector('.model-card', { timeout: 4000 });
25
26const cards = await p.$$('.model-card');
27let worst = 99;
28for (const c of cards) {
29 const b = await c.$('b'); const span = await c.$('span');
30 const bg = await c.evaluate(el => getComputedStyle(el).backgroundColor);
31 const bCol = await b.evaluate(el => getComputedStyle(el).color);
32 const sCol = await span.evaluate(el => getComputedStyle(el).color);
33 const name = await b.evaluate(el => el.textContent);
34 // el fondo puede ser gradiente (active) → usa bg3 base para medir peor caso
35 const bgRGB = bg.includes('gradient') || bg === 'rgba(0, 0, 0, 0)' ? [23, 27, 38] : parse(bg);
36 const rB = ratio(parse(bCol), bgRGB), rS = ratio(parse(sCol), bgRGB);
37 worst = Math.min(worst, rB, rS);
38 console.log(` ${name.padEnd(22)} título ${rB.toFixed(1)}:1 · subtítulo ${rS.toFixed(1)}:1`);
39}
40const pass = worst >= 4.5; // WCAG AA texto normal
41console.log((pass ? '✅' : '❌') + ` peor contraste = ${worst.toFixed(1)}:1 (AA exige ≥4.5:1)`);
42await p.screenshot({ path: OUT + '/contrast_settings.png' });
43console.log('captura → contrast_settings.png');
44await br.close();
45process.exit(pass ? 0 : 1);