Elffuss BraidHub

utopia-ia/elffuss-code public

99a5df28cf0f · 2.3 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';
4const OUT = (process.env.SCRATCH || '/tmp/elffuss-test');
5const BASE = process.env.BASE || 'http://localhost:8799';
6
7const 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); };
8const ratio = (a, b) => { const [x, y] = [lum(a) + 0.05, lum(b) + 0.05]; return (Math.max(x, y) / Math.min(x, y)); };
9const parse = s => s.match(/\d+/g).slice(0, 3).map(Number);
10
11const br = await chromium.launch({ args: ['--enable-unsafe-webgpu', '--use-angle=metal'] });
12const ctx = await br.newContext();
13await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
14const p = await ctx.newPage({ viewport: { width: 1200, height: 820 } });
15await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
16await p.waitForTimeout(800);
17// abrir Ajustes
18await p.click('#act-settings').catch(() => p.click('#btn-settings'));
19await p.waitForTimeout(600);
20await p.waitForSelector('.model-card', { timeout: 4000 });
21
22const cards = await p.$$('.model-card');
23let worst = 99;
24for (const c of cards) {
25 const b = await c.$('b'); const span = await c.$('span');
26 const bg = await c.evaluate(el => getComputedStyle(el).backgroundColor);
27 const bCol = await b.evaluate(el => getComputedStyle(el).color);
28 const sCol = await span.evaluate(el => getComputedStyle(el).color);
29 const name = await b.evaluate(el => el.textContent);
30 // el fondo puede ser gradiente (active) → usa bg3 base para medir peor caso
31 const bgRGB = bg.includes('gradient') || bg === 'rgba(0, 0, 0, 0)' ? [23, 27, 38] : parse(bg);
32 const rB = ratio(parse(bCol), bgRGB), rS = ratio(parse(sCol), bgRGB);
33 worst = Math.min(worst, rB, rS);
34 console.log(` ${name.padEnd(22)} título ${rB.toFixed(1)}:1 · subtítulo ${rS.toFixed(1)}:1`);
35}
36const pass = worst >= 4.5; // WCAG AA texto normal
37console.log((pass ? '✅' : '❌') + ` peor contraste = ${worst.toFixed(1)}:1 (AA exige ≥4.5:1)`);
38await p.screenshot({ path: OUT + '/contrast_settings.png' });
39console.log('captura → contrast_settings.png');
40await br.close();
41process.exit(pass ? 0 : 1);