layouts
All repositories: gitoria
15.7 KB
// tests/hc-look.mjs — gate for layouts#9 lines 1–21 (HyperConductor look): fails on 4099e64, passes on the fix.// node tests/hc-look.mjs (uses LAYOUTS_GATE_PORT / LAYOUTS_GATE_CHROME)import { spawn } from 'node:child_process';import { existsSync } from 'node:fs';import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { launchBrowser } from './cdp.mjs';if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';const APP = resolve(dirname(fileURLToPath(import.meta.url)), '..');const PORT = Number(process.env.LAYOUTS_GATE_PORT || 8760);const [CH_FROM, CH_TO] = (process.env.LAYOUTS_GATE_CHROME || '8761-8764').split('-').map(Number);const BASE = `http://127.0.0.1:${PORT}`;const sleep = (ms) => new Promise(r => setTimeout(r, ms));let failures = 0, passes = 0;function check(label, ok, detail = '') {console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`);if (ok) passes++; else failures++;}let log = '', server = null, browser = null;async function startServer() {server = spawn(join(APP, 'bin/hybriel'), ['project.hl'], {cwd: APP,env: { ...process.env, LAYOUTS_PORT: String(PORT), LAYOUTS_WATCH: '0' },stdio: ['ignore', 'pipe', 'pipe'],});server.stdout.on('data', d => log += d);server.stderr.on('data', d => log += d);for (let i = 0; ; i++) {try { if ((await fetch(BASE + '/')).ok) break; } catch {}if (i > 1600) throw new Error('server did not come up\n' + log);await sleep(250);}}async function stop() {if (browser) { try { await browser.close(); } catch {} browser = null; }if (server) {try { server.kill('SIGTERM'); } catch {}await new Promise(r => {if (server.exitCode !== null || server.signalCode !== null) return r();server.once('exit', r);setTimeout(r, 3000);});server = null;}}const lum = (c) => {const v = c.map(x => { x /= 255; return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4); });return 0.2126 * v[0] + 0.7152 * v[1] + 0.0722 * v[2];};const ratio = (a, b) => { const x = lum(a), y = lum(b); return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05); };const rgbOf = (s) => (String(s).match(/rgba?\(([^)]+)\)/) || [0, '0,0,0'])[1].split(',').slice(0, 3).map(Number);const eqColor = (a, b) => {const pa = (String(a).match(/rgba?\(([^)]+)\)/) || [0, ''])[1].split(',').map(Number);const pb = (String(b).match(/rgba?\(([^)]+)\)/) || [0, ''])[1].split(',').map(Number);if (pa.length < 3 || pb.length < 3) return false;const alphaA = pa.length > 3 ? pa[3] : 1;const alphaB = pb.length > 3 ? pb[3] : 1;return Math.abs(pa[0] - pb[0]) <= 1 && Math.abs(pa[1] - pb[1]) <= 1 && Math.abs(pa[2] - pb[2]) <= 1 && Math.abs(alphaA - alphaB) <= 0.02;};async function main() {await startServer();browser = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });const page = await browser.newPage();const ev = (e) => page.evaluate(e);const size = (w, h = w < 600 ? 844 : 800) => page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: w < 600 });const open = async (path) => {await page.goto(BASE + path, { timeout: 45000 });await page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 30000, label: 'hydrated ' + path });await sleep(300);};const hover = async (sel) => {const box = await page.box(sel);await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: Math.round(box.x), y: Math.round(box.y), buttons: 0 });await sleep(100);};const kTab = async () => {await page.send('Input.dispatchKeyEvent', { type: 'keyDown', key: 'Tab', code: 'Tab', windowsVirtualKeyCode: 9 });await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key: 'Tab', code: 'Tab', windowsVirtualKeyCode: 9 });await sleep(40);};const tabTo = async (sel, max = 80) => {for (let i = 0; i < max; i++) {if (await ev(`(() => { const a = document.activeElement; return !!a && a.matches(${JSON.stringify(sel)}); })()`)) return true;await kTab();}return await ev(`(() => { const a = document.activeElement; return !!a && a.matches(${JSON.stringify(sel)}); })()`);};const checkCoreStyles = async (w) => {await size(w, w === 390 ? 844 : 800);await open('/elements');const base = await ev(`(() => {const cs = (q, pseudo) => getComputedStyle(document.querySelector(q), pseudo || null);const hdr = cs('application-header');const h1 = cs('elements-page h1');const body = getComputedStyle(document.body);const inp = cs('#el-title');const sel = cs('#el-kind');const txt = cs('#el-notes');const btn = cs('elements-page p.row button:not(.primary):not(.danger):not(:disabled)');const dng = cs('elements-page p.row button.danger');const brand = cs('application-header > a.brand');const sb = cs('#sidebar');const sbh2 = cs('#sidebar h2');const sba = cs('#sidebar nav a');const sbcur = cs('#sidebar nav a[aria-current="page"]');return {darker: hdr.backgroundColor,lighter: h1.color,bodyColor: body.color,inpBg: inp.backgroundColor, inpColor: inp.color, inpPad: inp.paddingTop + ' ' + inp.paddingLeft,selBg: sel.backgroundColor, selColor: sel.color, selPad: sel.paddingTop + ' ' + sel.paddingLeft,txtBg: txt.backgroundColor, txtColor: txt.color, txtPad: txt.paddingTop + ' ' + txt.paddingLeft,btnBg: btn.backgroundColor, btnColor: btn.color, btnWeight: btn.fontWeight, btnPad: btn.paddingTop + ' ' + btn.paddingLeft,dngBg: dng.backgroundColor, dngColor: dng.color,brandWeight: brand.fontWeight, brandSize: brand.fontSize,sbBg: sb.backgroundColor, sbW: sb.width, sbPad: sb.paddingTop, sbGap: sb.rowGap,sbh2Transform: sbh2.textTransform,sbaPad: sba.paddingTop + ' ' + sba.paddingLeft,sbcurColor: sbcur.color, sbcurBg: sbcur.backgroundColor, sbcurRadius: sbcur.borderTopLeftRadius,};})()`);check(`${w} darker token rgb(20, 25, 30)`, base.darker === 'rgb(20, 25, 30)', base.darker);check(`${w} lighter token rgb(220, 225, 230)`, base.lighter === 'rgb(220, 225, 230)', base.lighter);check(`${w} body text colour = lighter`, base.bodyColor === 'rgb(220, 225, 230)', base.bodyColor);check(`${w} fields background rgba(255, 255, 255, .12)`, eqColor(base.inpBg, 'rgba(255, 255, 255, 0.12)') && eqColor(base.selBg, 'rgba(255, 255, 255, 0.12)') && eqColor(base.txtBg, 'rgba(255, 255, 255, 0.12)'), JSON.stringify([base.inpBg, base.selBg, base.txtBg]));check(`${w} fields text colour = lighter`, base.inpColor === 'rgb(220, 225, 230)' && base.selColor === 'rgb(220, 225, 230)' && base.txtColor === 'rgb(220, 225, 230)', JSON.stringify([base.inpColor, base.selColor, base.txtColor]));check(`${w} fields padding (.3rem .5rem input/select, .5rem textarea)`, base.inpPad === '4.8px 8px' && base.selPad === '4.8px 8px' && base.txtPad === '8px 8px', JSON.stringify([base.inpPad, base.selPad, base.txtPad]));// Field focus: shadow rgba(86, 155, 212, .45), outline none; invalid field keeps red outlineconst fieldFocus = {};for (const id of ['el-title', 'el-kind', 'el-notes']) {await page.focus('#' + id);await sleep(50);fieldFocus[id] = await ev(`(() => { const c = getComputedStyle(document.querySelector('#${id}')); return { shadow: c.boxShadow, outline: c.outlineStyle }; })()`);}const focusOk = (f) => f && f.outline === 'none' && /rgba?\(86,\s*155,\s*212,\s*0\.45/.test(f.shadow) && /2px/.test(f.shadow);check(`${w} field focus: 2px rgba(86, 155, 212, .45) shadow, no outline`, focusOk(fieldFocus['el-title']) && focusOk(fieldFocus['el-kind']) && focusOk(fieldFocus['el-notes']), JSON.stringify(fieldFocus));await page.focus('#el-mail');await sleep(50);const invFocus = await ev(`(() => { const c = getComputedStyle(document.querySelector('#el-mail')); return { outline: c.outlineStyle, color: c.outlineColor }; })()`);check(`${w} invalid field keeps danger outline when focused`, invFocus.outline === 'solid' && invFocus.color === 'rgb(244, 71, 71)', JSON.stringify(invFocus));// Button default = #569bd4 (colorAction), dark text, weight 400, padding .5remcheck(`${w} button default: #569bd4 bg, dark text, weight 400, padding .5rem`, base.btnBg === 'rgb(86, 155, 212)' && base.btnColor === 'rgb(25, 30, 35)' && base.btnWeight === '400' && base.btnPad === '8px 8px', JSON.stringify({ bg: base.btnBg, col: base.btnColor, wt: base.btnWeight, pad: base.btnPad }));check(`${w} button.danger readable (>= 4.5:1)`, ratio(rgbOf(base.dngColor), rgbOf(base.dngBg)) >= 4.5, JSON.stringify({ col: base.dngColor, bg: base.dngBg }));// Button focus-visible ring: 2px #569bd4AA, 0px offsetconst reachedBtn = await tabTo('elements-page p.row button:not(.primary):not(.danger):not(:disabled)');const btnRing = await ev(`(() => { const c = getComputedStyle(document.activeElement); return { style: c.outlineStyle, w: c.outlineWidth, col: c.outlineColor, off: c.outlineOffset }; })()`);check(`${w} button focus-visible ring: 2px #569bd4AA outline, 0 offset`, reachedBtn && btnRing.style === 'solid' && btnRing.w === '2px' && eqColor(btnRing.col, 'rgba(86, 155, 212, 0.667)') && btnRing.off === '0px', JSON.stringify(btnRing));// Checkbox focus-visible ring: 2px #569bd4AA outline, no boxShadowconst reachedChk = await tabTo('elements-page input[type="checkbox"]');const chkRing = await ev(`(() => { const c = getComputedStyle(document.activeElement); return { style: c.outlineStyle, w: c.outlineWidth, col: c.outlineColor, shadow: c.boxShadow }; })()`);check(`${w} checkbox focus-visible ring: 2px #569bd4AA outline, no boxShadow`, reachedChk && chkRing.style === 'solid' && chkRing.w === '2px' && eqColor(chkRing.col, 'rgba(86, 155, 212, 0.667)') && chkRing.shadow === 'none', JSON.stringify(chkRing));// Link hover: no underlineawait hover('elements-page section a');const linkDeco = await ev(`getComputedStyle(document.querySelector('elements-page section a')).textDecorationLine`);check(`${w} link hover: no underline`, linkDeco === 'none', linkDeco);// Brand in bar: weight 100, 1.4rem (22.4px)check(`${w} brand in header: weight 100, 1.4rem`, base.brandWeight === '100' && base.brandSize === '22.4px', JSON.stringify({ w: base.brandWeight, s: base.brandSize }));if (w === 1280) {// Purple accent must NOT change default button colorActionawait page.click('accent-switcher button[value="purple"]');await sleep(150);const btnWithPurple = await ev(`getComputedStyle(document.querySelector('elements-page p.row button:not(.primary):not(.danger):not(:disabled)')).backgroundColor`);const priWithPurple = await ev(`getComputedStyle(document.querySelector('elements-page p.row button.primary')).backgroundColor`);await page.click('accent-switcher button.reset');await sleep(150);check('1280 default button stays #569bd4 (colorAction, not app accent) when accent is purple', btnWithPurple === 'rgb(86, 155, 212)' && priWithPurple === 'rgb(197, 134, 192)', JSON.stringify({ btnWithPurple, priWithPurple }));// Sidebar at desktopcheck('1280 sidebar: darker bg, 16rem, padding 1rem, gap .5rem', base.sbBg === 'rgb(20, 25, 30)' && base.sbW === '256px' && base.sbPad === '16px' && base.sbGap === '8px', JSON.stringify({ bg: base.sbBg, w: base.sbW, pad: base.sbPad, gap: base.sbGap }));check('1280 sidebar h2: no uppercase', base.sbh2Transform === 'none', base.sbh2Transform);check('1280 sidebar links: padding .25rem .5rem', base.sbaPad === '4px 8px', base.sbaPad);await hover('#sidebar nav a[href="/"]');const sbHoverBg = await ev(`getComputedStyle(document.querySelector('#sidebar nav a[href="/"]')).backgroundColor`);check('1280 sidebar link hover: no hover background', sbHoverBg === 'rgba(0, 0, 0, 0)', sbHoverBg);check('1280 sidebar active item: white on rgba(86, 155, 212, .22), radiusSmall', base.sbcurColor === 'rgb(255, 255, 255)' && eqColor(base.sbcurBg, 'rgba(86, 155, 212, 0.22)') && base.sbcurRadius === '5px', JSON.stringify({ col: base.sbcurColor, bg: base.sbcurBg, r: base.sbcurRadius }));} else {// Phone sidebar popover: below 3.25rem bar, darker bg, 16rem, padding 1rem, gap .5rem, backdrop rgba(0,0,0,.45)await page.click('application-header .menu-toggle');await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'sidebar open 390' });await sleep(200);const pop = await ev(`(() => {const el = document.querySelector('#sidebar');const r = el.getBoundingClientRect();const cs = getComputedStyle(el);const bd = getComputedStyle(el, '::backdrop');const a = getComputedStyle(document.querySelector('#sidebar nav a'));const cur = getComputedStyle(document.querySelector('#sidebar main-menu a.current'));return {x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height),bg: cs.backgroundColor, pad: cs.paddingTop, gap: cs.rowGap,bdBg: bd.backgroundColor, bdOp: bd.opacity,aPad: a.paddingTop + ' ' + a.paddingLeft,curCol: cur.color, curBg: cur.backgroundColor, curRad: cur.borderTopLeftRadius,};})()`);check('390 sidebar popover: darker bg, 16rem, left below 3.25rem bar, padding 1rem, gap .5rem', pop.x === 0 && pop.y === 52 && pop.w === 256 && pop.bg === 'rgb(20, 25, 30)' && pop.pad === '16px' && pop.gap === '8px', JSON.stringify(pop));check('390 sidebar backdrop: rgba(0, 0, 0, .45)', eqColor(pop.bdBg, 'rgba(0, 0, 0, 0.45)') && Number(pop.bdOp) === 1, JSON.stringify({ bdBg: pop.bdBg, bdOp: pop.bdOp }));check('390 sidebar active menu link: white on rgba(86, 155, 212, .22), radiusSmall', pop.curCol === 'rgb(255, 255, 255)' && eqColor(pop.curBg, 'rgba(86, 155, 212, 0.22)') && pop.curRad === '5px', JSON.stringify(pop));await ev(`document.querySelector('#sidebar').hidePopover()`);}};await checkCoreStyles(390);await checkCoreStyles(1280);// Breakpoint at 800 px (768px breakpoint means 800px is desktop layout)await size(800, 1280);await open('/elements');const bp1 = await ev(`(() => {const s = (q) => { const el = document.querySelector(q); const c = getComputedStyle(el); const r = el.getBoundingClientRect(); return { disp: c.display, pos: c.position, w: Math.round(r.width) }; };return { sb: s('#sidebar'), toggle: s('application-header .menu-toggle'), menu: s('application-header main-menu'), main: s('content-first > main') };})()`);check('800 content-first: desktop layout (sidebar beside main, no toggle, main-menu in header)', bp1.sb.disp !== 'none' && (bp1.sb.pos === 'sticky' || bp1.sb.pos === 'static') && bp1.sb.w === 256 && bp1.toggle.disp === 'none' && bp1.menu.disp !== 'none', JSON.stringify(bp1));await open('/shells/list-first/trip');const bp2 = await ev(`(() => {const a = document.querySelector('list-first > aside').getBoundingClientRect();const m = document.querySelector('list-first > main').getBoundingClientRect();return { aw: Math.round(a.width), mw: Math.round(m.width), sideBySide: m.left >= a.right - 1 };})()`);check('800 list-first: aside and main side by side', bp2.aw > 0 && bp2.mw > 0 && bp2.sideBySide, JSON.stringify(bp2));await open('/shells/three-pane/m2');const bp3 = await ev(`(() => {const s = document.querySelector('#sidebar').getBoundingClientRect();const a = document.querySelector('three-pane > aside').getBoundingClientRect();const m = document.querySelector('three-pane > main').getBoundingClientRect();return { sw: Math.round(s.width), aw: Math.round(a.width), mw: Math.round(m.width) };})()`);check('800 three-pane: sidebar, aside and main all visible without squeezing main', bp3.sw > 0 && bp3.aw > 0 && bp3.mw >= 300, JSON.stringify(bp3));}try {await main();} catch (e) {failures++;console.log('FAIL (aborted) ' + (e && e.stack || e));} finally {await stop();}console.log(`\n${passes} passed, ${failures} failed`);process.exit(failures ? 1 : 0);
Branches
Latest commits
- 2027f696layouts#9: field focus glow back to HyperConductor's .45Atlas
- 88e1d14d|||PR layouts#9: address Kunibert findings (3-pane 768px, :where invalid focus, placeholder & glow contrast)Atlas
- 8c875a78|||PR layouts#9: match HyperConductor look (lines 1-21)Atlas
- 4099e64aMerge branch 'font-segoe-ui' into mainAtlas
- e14fb795|||PR Theme font: Segoe UI first (his choice 2026-11-19)Atlas
- 44071d2cMerge branch 'hl-standard-5' into mainAtlas
- 5ea64202|||PR Gate: count the new-tab check's console errors tooAtlas
- 2752ceddMerge branch 'hl-standard-4' into mainAtlas
- ac552b81|||PR Gate: keyboard (Tab/Enter/Space) and Back/Forward/reload/new-tab checks (HL-STANDARD F5, F21)Atlas
- 8cddcaa9Merge branch 'hl-standard-2' into mainAtlas
- 2b480a64|||PR Type the route parameter of main-menu build (HL-STANDARD L10)Atlas
- ab54a39dMerge branch 'hl-standard' into mainAtlas
- 04d36fcf|||PR Type function parameters and drop unneeded let (HL-STANDARD L2, L10)Atlas
- 220c8fa4Merge branch 'readme-audit' into mainAtlas
- b78fb85a|||PR README matches the codemre
- 9f351699Preserve comments and nest supported selectors without changing rendered outputmre
- 97110ad9WIP: nest accepted layout selectors; stopped at startup parse failuremre
- ce4a0baeKeep caller slot styles whole so minimal shell apps startmre
- 12cd3992Re-vendor complete Hybriel plugins and runtime to day44mre
- b05c20feBackup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre