gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmaind2e6d26bMerge branch 'records-park55' into mainTrackermain/tests/e2e-theme.mjs

11.8 KB

  1. // tests/e2e-theme.mjs (mission 040): END TO END in lisbeth's already-running Chrome (CDP through ssh -L), real mouse events only,
  2. // on a SEEDED tracker (tests/seed-pager.hl: 250 titles per list) — signed out, no ident, no TMDB. One existing tab is navigated
  3. // (never /json/new, no clipboard) and put back at the end. Runs on the old tree too (copy this file + mobile-measure.js).
  4. // node tests/e2e-theme.mjs <label> <app-port> <cdp-port> <shots-dir>
  5. // <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>.
  6. // At 390 and 1280: per main page the audit (tests/mobile-measure.js: no sideways scroll, taps < 44, fields < 16 px), a screenshot;
  7. // the main menu opened (390), a pager walk by real clicks (2, Next, Previous, last, 1) with the address + current page checked, and
  8. // the sign-in modal (Follow on a title, signed out): opens, Close by a real click, Escape, and the "Sign in" link is there.
  9. import { spawn, execFileSync } from 'node:child_process';
  10. import { mkdirSync, rmSync, writeFileSync, readFileSync } from 'node:fs';
  11. import { join, resolve, dirname } from 'node:path';
  12. import { fileURLToPath } from 'node:url';
  13. const [LABEL, portArg, cdpArg, shots] = process.argv.slice(2);
  14. const APP = resolve(dirname(fileURLToPath(import.meta.url)), '..');
  15. const PORT = Number(portArg), CDP = Number(cdpArg), BASE = `http://127.0.0.1:${PORT}`;
  16. const STORE = join(APP, '.scratch', 'e2e-theme-' + LABEL);
  17. rmSync(STORE, { recursive: true, force: true });
  18. mkdirSync(join(STORE, 'mpackdb'), { recursive: true }); mkdirSync(join(STORE, 'sessions'), { recursive: true }); mkdirSync(shots, { recursive: true });
  19. let failures = 0, passes = 0;
  20. const check = (label, ok, detail = '') => { console.log(`${ok ? 'ok ' : 'FAIL'} [${LABEL}] ${label}${ok ? '' : ' — ' + detail}`); if (ok) passes++; else failures++; };
  21. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  22. const J = JSON.stringify;
  23. const MEASURE = readFileSync(join(APP, 'tests/mobile-measure.js'), 'utf8');
  24. function connect(url) {
  25. return new Promise((ok, no) => {
  26. const ws = new WebSocket(url); let n = 0; const pend = new Map();
  27. 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); } });
  28. 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 })); }) }));
  29. ws.addEventListener('error', () => no(new Error('ws error')));
  30. });
  31. }
  32. const get = async (path) => (await fetch(`http://127.0.0.1:${CDP}${path}`)).json();
  33. let page = null, server = null, tabUrlBefore = null, log = '';
  34. 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; };
  35. 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); } };
  36. const shot = async (name) => { const { data } = await page.send('Page.captureScreenshot', { format: 'png' }); writeFileSync(join(shots, `${LABEL}-${name}.png`), Buffer.from(data, 'base64')); };
  37. const size = async (w, h) => { await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: w < 600 }); await sleep(400); };
  38. 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); };
  39. 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); };
  40. 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); };
  41. const hydrated = () => waitFor(`!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1`, 'hydrated');
  42. 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); };
  43. const audits = [];
  44. const audit = async (name, W) => {
  45. const m = await ev(`window.__W = ${W};` + MEASURE);
  46. 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 };
  47. audits.push(r); console.log('AUDIT ' + J(r)); await shot(`${W}-${name}`);
  48. check(`${W}px ${name}: no sideways scroll`, !m.hscroll, `scrollWidth ${m.docScrollWidth}`);
  49. check(`${W}px ${name}: fields ≥ 16 px`, m.inputsSmall === 0, J(m.inputsSmallList));
  50. if (W < 600) check(`${W}px ${name}: taps ≥ 44 px`, m.tapsSmall === 0, J(m.tapsSmallList));
  51. };
  52. const stop = async () => {
  53. if (page) { try { await page.send('Emulation.clearDeviceMetricsOverride'); await page.send('Page.navigate', { url: tabUrlBefore }); page.ws.close(); } catch {} }
  54. if (server) { try { server.kill('SIGTERM'); } catch {} await sleep(1500); }
  55. };
  56. try {
  57. execFileSync(join(APP, 'bin/hybriel'), ['tests/seed-pager.hl'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: join(STORE, 'mpackdb') } });
  58. 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,
  59. TRACKER_SESSIONS: join(STORE, 'sessions') + '/', TRACKER_STORAGE: join(STORE, 'mpackdb'), TRACKER_WATCH: '0', TMDB_READ_TOKEN: '',
  60. 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' } });
  61. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  62. console.log('server pid', server.pid);
  63. for (let i = 0; i < 700; i++) { try { if ((await fetch(BASE + '/')).ok) break; } catch {} await sleep(250); }
  64. const tabs = (await get('/json/list')).filter(t => t.type === 'page');
  65. if (!tabs.length) throw new Error('no existing tab');
  66. tabUrlBefore = tabs[0].url;
  67. page = await connect(tabs[0].webSocketDebuggerUrl.replace(/ws:\/\/[^/]+/, `ws://127.0.0.1:${CDP}`));
  68. for (const m of ['Page.enable', 'Runtime.enable']) await page.send(m);
  69. await goto('/movies');
  70. const showPath = await ev(`document.querySelector('a.tile').getAttribute('href')`);
  71. const PAGES = [['home', '/'], ['movies', '/movies'], ['series', '/series'], ['shows', '/shows'], ['people', '/people'], ['genres', '/genres'], ['find', '/search/Pager'], ['franchises', '/franchises'], ['settings', '/settings'], ['show', showPath]];
  72. for (const [W, H] of [[390, 844], [1280, 900]]) {
  73. await size(W, H);
  74. for (const [name, path] of PAGES) { await goto(path); await audit(name, W); }
  75. // the menu: at 390 behind the toggle, at 1280 in the sidebar/header; the current page marked
  76. await goto('/movies');
  77. if (W < 600) { await clickSel('button.menu-toggle'); await sleep(500); }
  78. // 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 given
  79. const 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') }; })()`);
  80. 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 })`));
  81. await shot(`${W}-menu-open`);
  82. if (W < 600) { await clickSel('button.menu-toggle'); await sleep(400); }
  83. // the pager walk by real clicks
  84. await goto('/movies');
  85. 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);
  86. await ev(`window.__same = 1`);
  87. for (const [what, to] of [['2', 2], ['Next', 3], ['Previous', 2], ['11', 11], ['1', 1]]) {
  88. await clickSel('pagination button', what); await sleep(900);
  89. const s = await cp(); const want = to === 1 ? '/movies' : '/movies/page/' + to;
  90. 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));
  91. if (what === 'Next' || what === '11') await shot(`${W}-pager-${what}`);
  92. }
  93. // the sign-in modal
  94. await goto(showPath);
  95. await clickSel('button#follow'); await sleep(700);
  96. 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; })()`);
  97. check(`${W}px sign-in modal opens by a real click on Follow`, !!m1 && m1.open && /sign in/i.test(m1.text), J(m1));
  98. await shot(`${W}-modal-open`);
  99. 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); }); })()`);
  100. console.log('MODAL taps ' + J(mt));
  101. 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));
  102. await clickSel('dialog button', 'Close'); await sleep(500);
  103. check(`${W}px modal closes by a real click on Close`, await ev(`!document.querySelector('dialog').open`));
  104. await clickSel('button#follow'); await sleep(600); await key('Escape', 'Escape', 27);
  105. check(`${W}px modal closes by Escape`, await ev(`!document.querySelector('dialog').open`));
  106. }
  107. writeFileSync(join(shots, `${LABEL}-audits.json`), J(audits, null, 1));
  108. } catch (e) { check('ran to the end', false, e.stack || String(e)); }
  109. finally { await stop(); }
  110. console.log(`\n[${LABEL}] ${passes} passed, ${failures} failed`);
  111. 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