| 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. |
| 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 | |
| 8 | const 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); }; |
| 9 | const ratio = (a, b) => { const [x, y] = [lum(a) + 0.05, lum(b) + 0.05]; return (Math.max(x, y) / Math.min(x, y)); }; |
| 10 | const parse = s => s.match(/\d+/g).slice(0, 3).map(Number); |
| 11 | |
| 12 | const br = await chromium.launch({ args: ['--enable-unsafe-webgpu', ...CHROME_ARGS] }); |
| 13 | const ctx = await br.newContext(); |
| 14 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); |
| 15 | const 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. |
| 18 | await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); |
| 19 | await p.waitForSelector('#ide:not([hidden])', { timeout: 15000 }); |
| 20 | await p.waitForTimeout(800); |
| 21 | // abrir Ajustes |
| 22 | await p.click('#act-settings').catch(() => p.click('#btn-settings')); |
| 23 | await p.waitForTimeout(600); |
| 24 | await p.waitForSelector('.model-card', { timeout: 4000 }); |
| 25 | |
| 26 | const cards = await p.$$('.model-card'); |
| 27 | let worst = 99; |
| 28 | for (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 | } |
| 40 | const pass = worst >= 4.5; // WCAG AA texto normal |
| 41 | console.log((pass ? '✅' : '❌') + ` peor contraste = ${worst.toFixed(1)}:1 (AA exige ≥4.5:1)`); |
| 42 | await p.screenshot({ path: OUT + '/contrast_settings.png' }); |
| 43 | console.log('captura → contrast_settings.png'); |
| 44 | await br.close(); |
| 45 | process.exit(pass ? 0 : 1); |