tracker
All repositories: gitoria
11.8 KB
// tests/e2e-theme.mjs (mission 040): END TO END in lisbeth's already-running Chrome (CDP through ssh -L), real mouse events only,// on a SEEDED tracker (tests/seed-pager.hl: 250 titles per list) — signed out, no ident, no TMDB. One existing tab is navigated// (never /json/new, no clipboard) and put back at the end. Runs on the old tree too (copy this file + mobile-measure.js).// node tests/e2e-theme.mjs <label> <app-port> <cdp-port> <shots-dir>// <app-port> must also be a REVERSE forward on lisbeth (ssh -R <app-port>:127.0.0.1:<app-port>), so Chrome there reaches 127.0.0.1:<app-port>.// At 390 and 1280: per main page the audit (tests/mobile-measure.js: no sideways scroll, taps < 44, fields < 16 px), a screenshot;// the main menu opened (390), a pager walk by real clicks (2, Next, Previous, last, 1) with the address + current page checked, and// the sign-in modal (Follow on a title, signed out): opens, Close by a real click, Escape, and the "Sign in" link is there.import { spawn, execFileSync } from 'node:child_process';import { mkdirSync, rmSync, writeFileSync, readFileSync } from 'node:fs';import { join, resolve, dirname } from 'node:path';import { fileURLToPath } from 'node:url';const [LABEL, portArg, cdpArg, shots] = process.argv.slice(2);const APP = resolve(dirname(fileURLToPath(import.meta.url)), '..');const PORT = Number(portArg), CDP = Number(cdpArg), BASE = `http://127.0.0.1:${PORT}`;const STORE = join(APP, '.scratch', 'e2e-theme-' + LABEL);rmSync(STORE, { recursive: true, force: true });mkdirSync(join(STORE, 'mpackdb'), { recursive: true }); mkdirSync(join(STORE, 'sessions'), { recursive: true }); mkdirSync(shots, { recursive: true });let failures = 0, passes = 0;const check = (label, ok, detail = '') => { console.log(`${ok ? 'ok ' : 'FAIL'} [${LABEL}] ${label}${ok ? '' : ' — ' + detail}`); if (ok) passes++; else failures++; };const sleep = (ms) => new Promise(r => setTimeout(r, ms));const J = JSON.stringify;const MEASURE = readFileSync(join(APP, 'tests/mobile-measure.js'), 'utf8');function connect(url) {return new Promise((ok, no) => {const ws = new WebSocket(url); let n = 0; const pend = new Map();ws.addEventListener('message', (m) => { const d = JSON.parse(m.data); if (d.id && pend.has(d.id)) { const p = pend.get(d.id); pend.delete(d.id); d.error ? p.no(new Error(d.error.message)) : p.ok(d.result); } });ws.addEventListener('open', () => ok({ ws, send: (method, params = {}) => new Promise((ok2, no2) => { const id = ++n; pend.set(id, { ok: ok2, no: no2 }); ws.send(J({ id, method, params })); }) }));ws.addEventListener('error', () => no(new Error('ws error')));});}const get = async (path) => (await fetch(`http://127.0.0.1:${CDP}${path}`)).json();let page = null, server = null, tabUrlBefore = null, log = '';const ev = async (expr) => { const r = await page.send('Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true }); if (r.exceptionDetails) throw new Error('evaluate: ' + (r.exceptionDetails.exception && r.exceptionDetails.exception.description || r.exceptionDetails.text)); return r.result.value; };const waitFor = async (expr, label, timeout = 30000) => { const t0 = Date.now(); for (;;) { let v = false; try { v = await ev(expr); } catch {} if (v) return v; if (Date.now() - t0 > timeout) throw new Error('timeout: ' + label); await sleep(100); } };const shot = async (name) => { const { data } = await page.send('Page.captureScreenshot', { format: 'png' }); writeFileSync(join(shots, `${LABEL}-${name}.png`), Buffer.from(data, 'base64')); };const size = async (w, h) => { await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: w < 600 }); await sleep(400); };const click = async (x, y) => { for (const [type, buttons] of [['mouseMoved', 0], ['mousePressed', 1], ['mouseReleased', 0]]) await page.send('Input.dispatchMouseEvent', { type, x: Math.round(x), y: Math.round(y), button: 'left', clickCount: 1, buttons }); await sleep(150); };const clickSel = async (sel, text) => { const r = await ev(`(() => { const all = [...document.querySelectorAll(${J(sel)})]; const e = ${text ? `all.find(b => b.textContent.trim() === ${J(text)})` : 'all[0]'}; if (!e) return null; e.scrollIntoView({ block: 'center' }); const q = e.getBoundingClientRect(); return { x: q.left + q.width / 2, y: q.top + q.height / 2 }; })()`); if (!r) throw new Error('no ' + sel + ' ' + (text || '')); await click(r.x, r.y); };const key = async (k, code, vk) => { await page.send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: k, code, windowsVirtualKeyCode: vk, nativeVirtualKeyCode: vk }); await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key: k, code, windowsVirtualKeyCode: vk, nativeVirtualKeyCode: vk }); await sleep(200); };const hydrated = () => waitFor(`!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1`, 'hydrated');const goto = async (path) => { await page.send('Page.navigate', { url: BASE + path }); await sleep(400); await page.send('Page.bringToFront'); try { await waitFor(`location.origin === ${J(BASE)} && location.pathname === ${J(path)} && document.readyState === 'complete' && document.body.innerText.length > 6`, 'load ' + path); } catch (e) { throw new Error(e.message + ' | now: ' + await ev(`location.pathname + ' ' + document.readyState + ' ' + J(document.body.innerText.slice(0, 120))`.replace('J(', 'JSON.stringify('))); } await hydrated(); await sleep(500); };const audits = [];const audit = async (name, W) => {const m = await ev(`window.__W = ${W};` + MEASURE);const r = { page: name, W, scrollWidth: m.docScrollWidth, taps: m.taps, tapsSmall: m.tapsSmall, small: m.tapsSmallList.slice(0, 8), inputs: m.inputs, inputsSmall: m.inputsSmall, inputsSmallList: m.inputsSmallList, textSmall: m.textSmall, wide: m.wide, wideList: m.wideList.slice(0, 4), header: m.headerH };audits.push(r); console.log('AUDIT ' + J(r)); await shot(`${W}-${name}`);check(`${W}px ${name}: no sideways scroll`, !m.hscroll, `scrollWidth ${m.docScrollWidth}`);check(`${W}px ${name}: fields ≥ 16 px`, m.inputsSmall === 0, J(m.inputsSmallList));if (W < 600) check(`${W}px ${name}: taps ≥ 44 px`, m.tapsSmall === 0, J(m.tapsSmallList));};const stop = async () => {if (page) { try { await page.send('Emulation.clearDeviceMetricsOverride'); await page.send('Page.navigate', { url: tabUrlBefore }); page.ws.close(); } catch {} }if (server) { try { server.kill('SIGTERM'); } catch {} await sleep(1500); }};try {execFileSync(join(APP, 'bin/hybriel'), ['tests/seed-pager.hl'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: join(STORE, 'mpackdb') } });server = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, TRACKER_WARM_SYNC_MS: '600000', TRACKER_PORT: String(PORT), TRACKER_URL: BASE,TRACKER_SESSIONS: join(STORE, 'sessions') + '/', TRACKER_STORAGE: join(STORE, 'mpackdb'), TRACKER_WATCH: '0', TMDB_READ_TOKEN: '',TRACKER_SYNC: '0', TRACKER_ART: '0', TRACKER_PHOTOS: '0', TRACKER_BACKFILL: '0', TRACKER_SHORTIDS: '0', TRACKER_KINDS: '0', TRACKER_REPAIR: '0', TRACKER_CREDITS: '0', TRACKER_COLLECTIONS: '0', TRACKER_MERGE: '0', TRACKER_FRANCHISE_SEED: '0' } });server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);console.log('server pid', server.pid);for (let i = 0; i < 700; i++) { try { if ((await fetch(BASE + '/')).ok) break; } catch {} await sleep(250); }const tabs = (await get('/json/list')).filter(t => t.type === 'page');if (!tabs.length) throw new Error('no existing tab');tabUrlBefore = tabs[0].url;page = await connect(tabs[0].webSocketDebuggerUrl.replace(/ws:\/\/[^/]+/, `ws://127.0.0.1:${CDP}`));for (const m of ['Page.enable', 'Runtime.enable']) await page.send(m);await goto('/movies');const showPath = await ev(`document.querySelector('a.tile').getAttribute('href')`);const PAGES = [['home', '/'], ['movies', '/movies'], ['series', '/series'], ['shows', '/shows'], ['people', '/people'], ['genres', '/genres'], ['find', '/search/Pager'], ['franchises', '/franchises'], ['settings', '/settings'], ['show', showPath]];for (const [W, H] of [[390, 844], [1280, 900]]) {await size(W, H);for (const [name, path] of PAGES) { await goto(path); await audit(name, W); }// the menu: at 390 behind the toggle, at 1280 in the sidebar/header; the current page markedawait goto('/movies');if (W < 600) { await clickSel('button.menu-toggle'); await sleep(500); }// tracker marks the page's menu entry by colour (styles.hl :has() on the heading's type word), the theme's aria-current needs a path it is not givenconst cols = await ev(`(() => { const c = (h) => { const a = [...document.querySelectorAll('main-menu a[href="' + h + '"]')].find(e => e.getBoundingClientRect().width > 0); return a ? getComputedStyle(a).color : null; }; return { movies: c('/movies'), series: c('/series') }; })()`);check(`${W}px menu marks the current page (Movies differs from Series)`, !!cols.movies && cols.movies !== cols.series, J(cols) + ' ' + await ev(`JSON.stringify({ url: location.pathname, hdr: (document.querySelector('application-header') || {outerHTML: 'none'}).outerHTML.slice(0, 500), side: !!document.querySelector('#sidebar'), open: (document.querySelector('#sidebar') || {matches: () => null}).matches(':popover-open'), links: document.querySelectorAll('main-menu a').length })`));await shot(`${W}-menu-open`);if (W < 600) { await clickSel('button.menu-toggle'); await sleep(400); }// the pager walk by real clicksawait goto('/movies');const cp = () => ev(`JSON.stringify({ p: location.pathname, cur: (document.querySelector('pagination li.current') || {}).textContent, n: document.querySelectorAll('a.tile').length, hs: document.documentElement.scrollWidth > innerWidth, same: window.__same === 1 })`).then(JSON.parse);await ev(`window.__same = 1`);for (const [what, to] of [['2', 2], ['Next', 3], ['Previous', 2], ['11', 11], ['1', 1]]) {await clickSel('pagination button', what); await sleep(900);const s = await cp(); const want = to === 1 ? '/movies' : '/movies/page/' + to;check(`${W}px pager real click ${what} → ${want}, current ${to}, same document, no sideways scroll`, s.p === want && s.cur.trim() === String(to) && s.same && !s.hs && s.n > 0, J(s));if (what === 'Next' || what === '11') await shot(`${W}-pager-${what}`);}// the sign-in modalawait goto(showPath);await clickSel('button#follow'); await sleep(700);const m1 = await ev(`(() => { const d = document.querySelector('dialog'); return d ? { open: d.open, w: Math.round(d.getBoundingClientRect().width), text: d.textContent.replace(/\\s+/g, ' ').trim().slice(0, 80) } : null; })()`);check(`${W}px sign-in modal opens by a real click on Follow`, !!m1 && m1.open && /sign in/i.test(m1.text), J(m1));await shot(`${W}-modal-open`);const mt = await ev(`(() => { const d = document.querySelector('dialog'); return [...d.querySelectorAll('button, a')].map(e => { const r = e.getBoundingClientRect(); return e.textContent.trim().slice(0, 12) + ' ' + Math.round(r.width) + 'x' + Math.round(r.height); }); })()`);console.log('MODAL taps ' + J(mt));if (W < 600) check(`${W}px modal taps ≥ 44`, mt.every(s => { const [w, h] = s.split(' ').pop().split('x').map(Number); return w >= 43.5 && h >= 43.5; }), J(mt));await clickSel('dialog button', 'Close'); await sleep(500);check(`${W}px modal closes by a real click on Close`, await ev(`!document.querySelector('dialog').open`));await clickSel('button#follow'); await sleep(600); await key('Escape', 'Escape', 27);check(`${W}px modal closes by Escape`, await ev(`!document.querySelector('dialog').open`));}writeFileSync(join(shots, `${LABEL}-audits.json`), J(audits, null, 1));} catch (e) { check('ran to the end', false, e.stack || String(e)); }finally { await stop(); }console.log(`\n[${LABEL}] ${passes} passed, ${failures} failed`);process.exit(failures ? 1 : 0);
Branches
Latest commits
- d2e6d26bMerge branch 'records-park55' into mainTracker
- f567f025|||PR records: park #55, no Claude workers ruleTracker
- c21aff6bMerge branch 'records-hm55c' into mainTracker
- 9ba258d3|||PR records: HM55b resultTracker
- 64f2d300Merge branch 'records-hm55b2' into mainTracker
- ae3b80dc|||PR records: HM55b briefTracker
- 7ef3cb3bMerge branch 'records-st55' into mainTracker
- fec2e080|||PR records: STATUS HM55Tracker
- 8e174918Merge branch 'records-hm55b' into mainTracker
- b1ecee57|||PR records: HM55 stateTracker
- 28eab08cMerge branch 'records-hm55' into mainTracker
- d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
- 3059f86cMerge branch 'records-design-rule' into mainTracker
- 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
- d1390692Merge branch 'records-dp75b' into mainTracker
- a4d1a7d2|||PR records: later steps checked, branch auditTracker
- e070e16fMerge branch 'records-dp75' into mainTracker
- 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
- bfc4ea4dMerge branch 'ap62' into mainTracker
- 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker