tracker
All repositories: gitoria
13.8 KB
// tests/mobile.mjs — THE PHONE GATE of tracker.worldapi.org (mission MK, the creator's rule "mobile first"; the caramboleyo's phone is an// 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// session file (no ident), a real headless Chrome with TOUCH emulation at 390 × 844, device scale factor 3. Proves, per page:// - nothing scrolls sideways, every link / button is a 44 px tap target (tests/mobile-measure.js), every field is ≥ 16 px:// /my/series, /my/shows is empty-state-free here (the fixture follows series only → /my/series), /my/unwatched, /my/schedule,// /search/gate (title + person rows), a title page (the TMDB / IMDb badges), a movie page with the franchise widget (its franchise// link), a franchise page (its timeline names), the timeline editor ("New franchise …"), /login/failed ("back to tracker")// - /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// 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// out-of-range or bad page number = the last / the first page, and the whole page loads in under 2 s// node tests/mobile.mjs (TRACKER_GATE_PORT server, default 8700; TRACKER_GATE_CHROME "8702-8709"; TRACKER_GATE_SHOTS: screenshots)import { spawn, execFileSync } from 'node:child_process';import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { createHash } from 'node:crypto';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 HERE = dirname(fileURLToPath(import.meta.url));const APP = resolve(HERE, '..');const PORT = Number(process.env.TRACKER_GATE_PORT || 8700);const [CH_FROM, CH_TO] = (process.env.TRACKER_GATE_CHROME || '8702-8709').split('-').map(Number);const SHOTS = process.env.TRACKER_GATE_SHOTS || '';const BASE = `http://127.0.0.1:${PORT}`;const STORE = join(APP, '.scratch', 'mobile-store');const SESSIONS = join(APP, '.scratch', 'mobile-sessions');const MEASURE = readFileSync(join(HERE, 'mobile-measure.js'), 'utf8');rmSync(STORE, { recursive: true, force: true });rmSync(SESSIONS, { recursive: true, force: true });mkdirSync(SESSIONS, { recursive: true });if (SHOTS) mkdirSync(SHOTS, { recursive: true });let failures = 0, passes = 0;function check(label, ok, detail = '') {console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`);if (ok) passes++; else failures++;}const sleep = (ms) => new Promise(r => setTimeout(r, ms));let server = null, browser = null, log = '';async function stopServer() {if (server) {const s = server;try { s.kill('SIGTERM'); } catch {}await new Promise(r => { if (s.exitCode !== null || s.signalCode !== null) return r(); s.once('exit', r); setTimeout(r, 3000); });server = null;}}async function stop() {if (browser) { try { await browser.close(); } catch {} browser = null; }await stopServer();}async function main() {const MPACKDB = join(STORE, 'mpackdb');mkdirSync(MPACKDB, { recursive: true });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()+ execFileSync(join(APP, 'bin/hybriel'), ['tests/seed-mobile.hl'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: MPACKDB } }).toString();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);// 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 userconst sid = 'a1b2c3d4e5f60718293a4b5c6d7e8f90';const now = Date.now();writeFileSync(join(SESSIONS, createHash('sha256').update(sid).digest('hex')), JSON.stringify({ created: now, data: { tag: 't' }, id: sid, seen: now, user: { id: 'gateu0000000000u1' } }));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,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',TRACKER_CREDITS: '0', TRACKER_COLLECTIONS: '0', TRACKER_FRANCHISE_SEED: '0', TMDB_READ_TOKEN: '' }, 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 > 600) throw new Error('tracker did not come up (150 s; a cold start compiles the app first, hybriel#148)\n' + log);await sleep(250);}browser = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });const page = await browser.newPage();const ev = (e) => page.evaluate(e);const hydrated = () => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1 && document.readyState === "complete"', { timeout: 60000, label: 'hydrated' });const shot = async (name) => { if (SHOTS) writeFileSync(join(SHOTS, name + '.png'), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64')); };const go = async (path) => { const t = Date.now(); await page.goto(BASE + path, { timeout: 60000 }); await hydrated(); await sleep(500); return Date.now() - t; };// a real touch tap (touchStart + touchEnd at the centre of the element), as a finger doesconst 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); };const tapSel = async (sel, text) => {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 }; })()`);if (!r) return false; await tap(r.x, r.y); return true;};await page.send('Network.setCookie', { name: 'trackersid', value: sid, url: BASE });await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 3, mobile: true });await page.send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 });// ==== every page: no sideways scroll, every tap target ≥ 44 px, fields ≥ 16 px ====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'],['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'],['timeline-edit', '/timelines/mobile-timeline-alpha/edit', 'a.edit-new-franchise'], ['login-failed', '/login/failed', 'a#home']];for (const [name, path, must] of PAGES) {await go(path);await ev('window.__W = 390');const m = await ev(MEASURE);const there = await ev(`!!document.querySelector(${JSON.stringify(must)})`);await shot('mobile-' + name + '-390');check(`390 ${path}: the page shows what it is about (${must})`, there, JSON.stringify({ h1: await ev(`(document.querySelector('h1') || {}).innerText`) }));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 }));}// the badges stay small to the eye (24 px pill: the 44 px tap area is transparent border, the background stops at the padding box)await go('/series/gate-test-show');const badge = await ev(`JSON.stringify(Array.from(document.querySelectorAll('a.extlink')).map(e => [e.clientHeight, getComputedStyle(e).backgroundClip, Math.round(e.getBoundingClientRect().height)]))`).then(JSON.parse);check('title: the TMDB / IMDb badges look 24 px high (padding box, background clipped to it) with a 44 px tap box', badge.length >= 2 && badge.every(b => b[0] <= 26 && b[1] === 'padding-box' && b[2] >= 44), JSON.stringify(badge));// ==== a season of 160 episodes starts closed (the real data has a soap with 1,175 in one: a 69,000 px page) ====await go('/series/mobile-soap');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);const so1 = await soapInfo();await shot('mobile-soap-closed-390');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));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)',await tapSel('button.season-toggle') && await page.waitFor(`document.querySelectorAll('episode-row').length >= 160`, { timeout: 20000 }).then(() => true, () => false)&& 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()));// ==== /franchises: 40 timelines per page, a pager, a touch tap works ====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,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,count: (document.querySelector('p.list-count') || {}).textContent || null, h: document.documentElement.scrollHeight, title: document.title })`).then(JSON.parse);const ms1 = await go('/franchises');const p1 = await info();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)',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 }));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));check('franchises: a real touch tap on "Next" goes to /franchises/page/2: 40 more timelines, no franchise list again',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 () => {await sleep(500); const p2 = await info(); await shot('mobile-franchises-p2-390');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);})(), JSON.stringify(await info()));check('franchises: a real touch tap on page "3" shows the last 20, and no "No franchises yet." on a later page',await tapSel('pagination button', '3') && await page.waitFor(`location.pathname === '/franchises/page/3'`, { timeout: 10000 }).then(() => true, () => false) && await (async () => {await sleep(500); const p3 = await info();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')`));})(), JSON.stringify(await info()));await go('/franchises/page/99');const p99 = await info();await go('/franchises/page/abc');const pabc = await info();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 }));// a timeline of the list still opensawait go('/franchises');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'));const problems = page.problems ? page.problems() : [];check('browser: no console errors / failed requests', problems.length === 0, JSON.stringify(problems).slice(0, 2000));}try { await main(); } catch (e) {check('gate ran without throwing', false, (e && e.stack) || String(e));console.log('server log (tail):\n' + log.slice(-3000));}await stop();console.log(`\n${passes} passed, ${failures} failed`);process.exit(failures ? 1 : 0);
Branches
Latest commits
- 59ef1e4atests/browser: repair 'done' check counts the 404 titles the first run already finished (race: failed=1 when Bulk Film 79 ran before the restart)mre
- 5925fc4dreports/MK-mobile.md: rebase update, gate countsmre
- 6adbc7f0extlink badges: background-clip after the background shorthand (it reset the clip: the pills were 44 px tall); gates check the lookmre
- 8d3b0f20widget: the franchise link's 44 px tap area no longer overlaps the Prequel/Sequel rowmre
- 1d98dcfdbrowser gate: the badges' size check reads the padding box (the 44 px tap area is transparent border)mre
- 2f9e29ffreports/MK-mobile.md, deploy.sh GATES: tests/mobile.mjs, theme check markermre
- 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