gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit7cfc8ab57cfc8ab5a season of more than 150 episodes starts closed on its title page; the phone gate checks itmre7cfc8ab5/tests/mobile.mjs

13.2 KB

  1. // tests/mobile.mjs — THE PHONE GATE of tracker.worldapi.org (mission MK, the creator's rule "mobile first"; the caramboleyo's phone is an
  2. // Android Chrome of about 390 px): this app's own server on its own storage (tests/seed-show.hl + tests/seed-mobile.hl), signed in with a
  3. // session file (no ident), a real headless Chrome with TOUCH emulation at 390 × 844, device scale factor 3. Proves, per page:
  4. // - nothing scrolls sideways, every link / button is a 44 px tap target (tests/mobile-measure.js), every field is ≥ 16 px:
  5. // /my/series, /my/shows is empty-state-free here (the fixture follows series only → /my/series), /my/unwatched, /my/schedule,
  6. // /search/gate (title + person rows), a title page (the TMDB / IMDb badges), a movie page with the franchise widget (its franchise
  7. // link), a franchise page (its timeline names), the timeline editor ("New franchise …"), /login/failed ("back to tracker")
  8. // - /franchises (100 timelines without a franchise): 40 per page (a page of 1,546 was 54,000 px and 20 s on the real data), the franchises on
  9. // page 1 only, a pager that a real TOUCH tap on Next / a number works, the address /franchises/page/N, the last page the rest, an
  10. // out-of-range or bad page number = the last / the first page, and the whole page loads in under 2 s
  11. // node tests/mobile.mjs (TRACKER_GATE_PORT server, default 8700; TRACKER_GATE_CHROME "8702-8709"; TRACKER_GATE_SHOTS: screenshots)
  12. import { spawn, execFileSync } from 'node:child_process';
  13. import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
  14. import { createHash } from 'node:crypto';
  15. import { dirname, join, resolve } from 'node:path';
  16. import { fileURLToPath } from 'node:url';
  17. import { launchBrowser } from './cdp.mjs';
  18. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  19. const HERE = dirname(fileURLToPath(import.meta.url));
  20. const APP = resolve(HERE, '..');
  21. const PORT = Number(process.env.TRACKER_GATE_PORT || 8700);
  22. const [CH_FROM, CH_TO] = (process.env.TRACKER_GATE_CHROME || '8702-8709').split('-').map(Number);
  23. const SHOTS = process.env.TRACKER_GATE_SHOTS || '';
  24. const BASE = `http://127.0.0.1:${PORT}`;
  25. const STORE = join(APP, '.scratch', 'mobile-store');
  26. const SESSIONS = join(APP, '.scratch', 'mobile-sessions');
  27. const MEASURE = readFileSync(join(HERE, 'mobile-measure.js'), 'utf8');
  28. rmSync(STORE, { recursive: true, force: true });
  29. rmSync(SESSIONS, { recursive: true, force: true });
  30. mkdirSync(SESSIONS, { recursive: true });
  31. if (SHOTS) mkdirSync(SHOTS, { recursive: true });
  32. let failures = 0, passes = 0;
  33. function check(label, ok, detail = '') {
  34. console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`);
  35. if (ok) passes++; else failures++;
  36. }
  37. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  38. let server = null, browser = null, log = '';
  39. async function stopServer() {
  40. if (server) {
  41. const s = server;
  42. try { s.kill('SIGTERM'); } catch {}
  43. await new Promise(r => { if (s.exitCode !== null || s.signalCode !== null) return r(); s.once('exit', r); setTimeout(r, 3000); });
  44. server = null;
  45. }
  46. }
  47. async function stop() {
  48. if (browser) { try { await browser.close(); } catch {} browser = null; }
  49. await stopServer();
  50. }
  51. async function main() {
  52. const MPACKDB = join(STORE, 'mpackdb');
  53. mkdirSync(MPACKDB, { recursive: true });
  54. const seedOut = execFileSync(join(APP, 'bin/hybriel'), ['tests/seed-show.hl'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: MPACKDB, TRACKER_SEED_IDENTITY: 'mobile-gate-identity' } }).toString()
  55. + execFileSync(join(APP, 'bin/hybriel'), ['tests/seed-mobile.hl'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: MPACKDB } }).toString();
  56. check('seed: the fixture shows + a user who follows them (tests/seed-show.hl), a franchise and 100 loose timelines (tests/seed-mobile.hl)', seedOut.includes('gate-test-show') && seedOut.includes('100 loose timelines'), seedOut);
  57. // the signed-in session: a session file named by the sha256 of its id (as hl:web writes them), the user id of the seeded user
  58. const sid = 'a1b2c3d4e5f60718293a4b5c6d7e8f90';
  59. const now = Date.now();
  60. writeFileSync(join(SESSIONS, createHash('sha256').update(sid).digest('hex')), JSON.stringify({ created: now, data: { tag: 't' }, id: sid, seen: now, user: { id: 'gateu0000000000u1' } }));
  61. server = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, env: { ...process.env, TRACKER_WARM_SYNC_MS: '600000', TRACKER_PORT: String(PORT), TRACKER_SESSIONS: SESSIONS + '/', TRACKER_STORAGE: MPACKDB,
  62. TRACKER_WATCH: '0', TRACKER_URL: BASE, HL_HOST: '127.0.0.1', TRACKER_EDITORS: 'mobile-gate-identity', TRACKER_SYNC: '0', TRACKER_ART: '0', TRACKER_PHOTOS: '0', TRACKER_BACKFILL: '0', TRACKER_REPAIR: '0', TRACKER_KINDS: '0',
  63. TRACKER_CREDITS: '0', TRACKER_COLLECTIONS: '0', TRACKER_FRANCHISE_SEED: '0', TMDB_READ_TOKEN: '' }, stdio: ['ignore', 'pipe', 'pipe'] });
  64. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  65. for (let i = 0; ; i++) {
  66. try { if ((await fetch(BASE + '/')).ok) break; } catch {}
  67. if (i > 600) throw new Error('tracker did not come up (150 s; a cold start compiles the app first, hybriel#148)\n' + log);
  68. await sleep(250);
  69. }
  70. browser = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });
  71. const page = await browser.newPage();
  72. const ev = (e) => page.evaluate(e);
  73. const hydrated = () => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1 && document.readyState === "complete"', { timeout: 60000, label: 'hydrated' });
  74. const shot = async (name) => { if (SHOTS) writeFileSync(join(SHOTS, name + '.png'), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64')); };
  75. const go = async (path) => { const t = Date.now(); await page.goto(BASE + path, { timeout: 60000 }); await hydrated(); await sleep(500); return Date.now() - t; };
  76. // a real touch tap (touchStart + touchEnd at the centre of the element), as a finger does
  77. const tap = async (x, y) => { await page.send('Input.dispatchTouchEvent', { type: 'touchStart', touchPoints: [{ x, y }] }); await page.send('Input.dispatchTouchEvent', { type: 'touchEnd', touchPoints: [] }); await sleep(600); };
  78. const tapSel = async (sel, text) => {
  79. const r = await ev(`(() => { const all = [...document.querySelectorAll(${JSON.stringify(sel)})]; const e = ${text ? `all.find(b => b.textContent.trim() === ${JSON.stringify(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 }; })()`);
  80. if (!r) return false; await tap(r.x, r.y); return true;
  81. };
  82. await page.send('Network.setCookie', { name: 'trackersid', value: sid, url: BASE });
  83. await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 3, mobile: true });
  84. await page.send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 });
  85. // ==== every page: no sideways scroll, every tap target ≥ 44 px, fields ≥ 16 px ====
  86. const PAGES = [['my-series', '/my/series', 'my-show-row'], ['my-unwatched', '/my/unwatched', 'unwatched-row'], ['my-schedule', '/my/schedule', 'schedule-row'], ['search', '/search/gate', 'search-row'],
  87. ['title', '/series/gate-test-show', 'show-header'], ['movie-widget', '/movies/pager-movie-01', 'a.fw-franchise'], ['franchises', '/franchises', 'a.franchise-row'], ['franchise', '/franchises/mobile-franchise', 'a.timeline-name'],
  88. ['timeline-edit', '/timelines/mobile-timeline-alpha/edit', 'a.edit-new-franchise'], ['login-failed', '/login/failed', 'a#home']];
  89. for (const [name, path, must] of PAGES) {
  90. await go(path);
  91. await ev('window.__W = 390');
  92. const m = await ev(MEASURE);
  93. const there = await ev(`!!document.querySelector(${JSON.stringify(must)})`);
  94. await shot('mobile-' + name + '-390');
  95. check(`390 ${path}: the page shows what it is about (${must})`, there, JSON.stringify({ h1: await ev(`(document.querySelector('h1') || {}).innerText`) }));
  96. check(`390 ${path}: no sideways scroll, every tap target ≥ 44 px, every field ≥ 16 px`, !m.hscroll && m.tapsSmall === 0 && m.inputsSmall === 0, JSON.stringify({ sw: m.docScrollWidth, small: m.tapsSmallList, inputs: m.inputsSmallList }));
  97. }
  98. // ==== /franchises: 40 timelines per page, a pager, a touch tap works ====
  99. const info = async () => ev(`JSON.stringify({ path: location.pathname, links: document.querySelectorAll('a.timeline-link').length, franchises: document.querySelectorAll('a.franchise-row').length, first: (document.querySelector('a.timeline-link timeline-link-name') || {}).textContent || null,
  100. last: (Array.from(document.querySelectorAll('a.timeline-link timeline-link-name')).pop() || {}).textContent || null, pager: !!document.querySelector('pager-box pagination'), cur: ((document.querySelector('pagination li.current') || {}).textContent || '').trim() || null,
  101. count: (document.querySelector('p.list-count') || {}).textContent || null, h: document.documentElement.scrollHeight, title: document.title })`).then(JSON.parse);
  102. const ms1 = await go('/franchises');
  103. const p1 = await info();
  104. check('franchises: the first page lists the franchise AND 40 of the 100 timelines (by name), a pager, "page 1 of 3", loaded in under 2 s (the real data\'s 1,546 took 20 s)',
  105. p1.links === 40 && p1.franchises === 1 && p1.first === 'Mobile Collection 001' && p1.last === 'Mobile Collection 040' && p1.pager && p1.cur === '1' && /100 timelines without a franchise · page 1 of 3/.test(p1.count) && ms1 < 2000, JSON.stringify({ ...p1, ms1 }));
  106. check('franchises: the page is short on a phone (40 rows, not the whole list: under 3,000 px)', p1.h < 3000, JSON.stringify(p1));
  107. check('franchises: a real touch tap on "Next" goes to /franchises/page/2: 40 more timelines, no franchise list again',
  108. await tapSel('pagination button', 'Next') && await page.waitFor(`location.pathname === '/franchises/page/2' && document.querySelectorAll('a.timeline-link').length > 0`, { timeout: 10000 }).then(() => true, () => false) && await (async () => {
  109. await sleep(500); const p2 = await info(); await shot('mobile-franchises-p2-390');
  110. return p2.links === 40 && p2.franchises === 0 && p2.first === 'Mobile Collection 041' && p2.last === 'Mobile Collection 080' && p2.cur === '2' && /page 2 of 3/.test(p2.count) && /page 2/.test(p2.title);
  111. })(), JSON.stringify(await info()));
  112. check('franchises: a real touch tap on page "3" shows the last 20, and no "No franchises yet." on a later page',
  113. await tapSel('pagination button', '3') && await page.waitFor(`location.pathname === '/franchises/page/3'`, { timeout: 10000 }).then(() => true, () => false) && await (async () => {
  114. await sleep(500); const p3 = await info();
  115. return p3.links === 20 && p3.first === 'Mobile Collection 081' && p3.last === 'Mobile Collection 100' && p3.cur === '3' && !(await ev(`document.body.innerText.includes('No franchises yet')`));
  116. })(), JSON.stringify(await info()));
  117. await go('/franchises/page/99');
  118. const p99 = await info();
  119. await go('/franchises/page/abc');
  120. const pabc = await info();
  121. check('franchises: page 99 is the last page, "abc" the first', p99.links === 20 && p99.cur === '3' && pabc.links === 40 && pabc.cur === '1' && pabc.franchises === 1, JSON.stringify({ p99, pabc }));
  122. // a timeline of the list still opens
  123. await go('/franchises');
  124. check('franchises: a real touch tap on a timeline opens it', await tapSel('a.timeline-link') && await page.waitFor(`location.pathname === '/timelines/mobile-collection-001'`, { timeout: 10000 }).then(() => true, () => false), await ev('location.pathname'));
  125. // ==== a season of 160 episodes starts closed (the real data has a soap with 1,175 in one: a 69,000 px page) ====
  126. await go('/series/mobile-soap');
  127. const soapInfo = async () => ev(`JSON.stringify({ rows: document.querySelectorAll('episode-row').length, toggles: document.querySelectorAll('button.season-toggle').length, open: document.querySelectorAll('season-row.expanded').length, h: document.documentElement.scrollHeight })`).then(JSON.parse);
  128. const so1 = await soapInfo();
  129. await shot('mobile-soap-closed-390');
  130. check('title: a season of 160 episodes starts CLOSED on a phone — its header, no episode rows, a short page', so1.toggles === 1 && so1.rows === 0 && so1.open === 0 && so1.h < 2500, JSON.stringify(so1));
  131. check('title: a real touch tap on that season\'s header opens it: its 160 episodes (and the closed season of a short series still opens as before: Gate Test Show\'s last season starts open)',
  132. await tapSel('button.season-toggle') && await page.waitFor(`document.querySelectorAll('episode-row').length >= 160`, { timeout: 20000 }).then(() => true, () => false)
  133. && await (async () => { await go('/series/gate-test-show'); const g = await soapInfo(); return g.toggles === 2 && g.open === 1 && g.rows >= 1; })(), JSON.stringify(await soapInfo()));
  134. const problems = page.problems ? page.problems() : [];
  135. check('browser: no console errors / failed requests', problems.length === 0, JSON.stringify(problems).slice(0, 2000));
  136. }
  137. try { await main(); } catch (e) {
  138. check('gate ran without throwing', false, (e && e.stack) || String(e));
  139. console.log('server log (tail):\n' + log.slice(-3000));
  140. }
  141. await stop();
  142. console.log(`\n${passes} passed, ${failures} failed`);
  143. process.exit(failures ? 1 : 0);

Branches

Latest commits

  • 7cfc8ab5a season of more than 150 episodes starts closed on its title page; the phone gate checks itmre
  • 59095c59tests/mobile.mjs: the phone gate (390 px touch, tap targets, /franchises paging)mre
  • 105309detap targets: every row link, the TMDB/IMDb badges, the widget links, the franchise names and the login-failed link are 44 px high on a phonemre
  • f0b86c8efranchises: 40 loose timelines per page (/franchises/page/N) and a merge sort for the names (1,546 timelines: 20 s and 54,000 px before)mre
  • b9e841a7Merge branch 'sy-sync'mre
  • d1ae2701sync components.hybriel 4922f9c: modal and pagination 44 px targets (vendored copies, verbatim) (SY)mre
  • 043624b2theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 05d89fd0deploy: security gate (tests/security.mjs)mre
  • 2ae8a47bMerge branch 'sk-sec'mre
  • 8fee5d52sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 944ad51eSK: report reports/SK-sec.md, LOGsk
  • 415487c1SK: import budget per user + id type check, gate checkssk
  • 7b8a4f74security audit SK: nosniff + image sandbox headers, face id checks, adult follow, login budget + new session at login, guest-link budget, tests/security.mjssk
  • f0f26c5areports: T18 section (gates, boot-gate, 3x3 table, search + short-id compare)mre
  • 2a8682a1deploy.sh GATES: tests/warmstart.mjsmre
  • 3761338breports/T17-boot.md: handoff (phase table, fix, numbers so far, open proof)mre
  • 52e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre
  • c87149e8tests/warmstart.mjs: the progressive start proven over HTTP (note in the window, 503 short id, after: everything); bootBeginmre
  • 593a6350boot: resumable start-up scan, the server listens first (T17)mre
  • be4890a0reports: H2 hydration audit (no test change needed)mre