gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit1ed5457e1ed5457etracker#20 + #21 (mission 068): typed headings "<Type> | <name>" in type colours; TV titles split into Series (/series) and Shows (/shows) by TMDB type + Reality/Talk/News genres — kind stored by sync/import/adult backfill + new kind backfill (resumes), /movies/<slug>, /shows/<slug> of a series/movie → 301, /my/series + /my/shows, home 5 tiles + 3 rows, search/filmography labels; gates kinds 32 + browser 266, tests/realdata-068.mjs, tools/count-kinds.hl, docs/kinds.md, README + STATUSmre1ed5457e/tests/browser.mjs

172.2 KB

  1. // tests/browser.mjs — THE GATE of tracker.worldapi.org#1: this app's own server on its own storage, its OWN ident
  2. // (a copy of ident's code without .env, codes to a mail sink: tests/identkit.mjs, same as calendar's gate), a real
  3. // headless Chrome. Proves: signed out (header shows "Log in with ident") -> sign in -> the header selector shows
  4. // signed in, "Log out" appears, the page itself stays empty -> sign out -> signed out again (a reload confirms it).
  5. //
  6. // node tests/browser.mjs (TRACKER_GATE_PORT server, default 8700; TRACKER_GATE_IDENT_PORT ident, default 8701;
  7. // TRACKER_GATE_CHROME "8702-8709" = Chrome debug ports; TRACKER_GATE_TMDB_PORT the fake
  8. // TMDB, default 8710)
  9. import { spawn, execFileSync } from 'node:child_process';
  10. import { existsSync, mkdirSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
  11. import { dirname, join, resolve } from 'node:path';
  12. import { fileURLToPath } from 'node:url';
  13. import { inflateSync } from 'node:zlib';
  14. import { launchBrowser } from './cdp.mjs';
  15. import { startIdent } from './identkit.mjs';
  16. import { startFakeTmdb, PNG } from './faketmdb.mjs';
  17. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  18. const HERE = dirname(fileURLToPath(import.meta.url));
  19. const APP = resolve(HERE, '..');
  20. const PORT = Number(process.env.TRACKER_GATE_PORT || 8700);
  21. const [CH_FROM, CH_TO] = (process.env.TRACKER_GATE_CHROME || '8702-8709').split('-').map(Number);
  22. const IDENT_PORT = Number(process.env.TRACKER_GATE_IDENT_PORT || 8701);
  23. const TMDB_PORT = Number(process.env.TRACKER_GATE_TMDB_PORT || 8710);
  24. const BASE = `http://127.0.0.1:${PORT}`;
  25. const STORE = join(APP, '.scratch', 'gate-store');
  26. const IDENT_DIR = process.env.TRACKER_GATE_IDENT_DIR || [resolve(APP, '../ident.worldapi.org'), '/media/STORAGE/projects/ident.worldapi.org'].find(d => existsSync(join(d, 'project.hl')));
  27. const SCRATCH = join(APP, '.scratch');
  28. const SESSIONS = join(SCRATCH, 'gate-sessions');
  29. rmSync(SESSIONS, { recursive: true, force: true });
  30. rmSync(STORE, { recursive: true, force: true });
  31. mkdirSync(SESSIONS, { 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. // tracker#29: the first pixel of a PNG (8-bit RGB/RGBA, as Chrome's screenshots are) — the first pixel of the first row is
  38. // stored raw under every PNG filter (no left / upper neighbour), so no unfiltering is needed
  39. function pngFirstPixel(buf) {
  40. let pos = 8, idat = [];
  41. const colorType = buf[25];
  42. while (pos < buf.length) {
  43. const len = buf.readUInt32BE(pos), type = buf.toString('latin1', pos + 4, pos + 8);
  44. if (type === 'IDAT') idat.push(buf.subarray(pos + 8, pos + 8 + len));
  45. pos += 12 + len;
  46. }
  47. const raw = inflateSync(Buffer.concat(idat));
  48. return colorType === 2 || colorType === 6 ? [raw[1], raw[2], raw[3]] : null;
  49. }
  50. const ACCENT = [78, 201, 176];
  51. const colorDist = (a, b) => a && b ? Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) : Infinity;
  52. // tracker#29 (the creator: "in /my/unwatched all checkboxes are active"): an unwatched check is EMPTY — nothing filled,
  53. // muted grey outline circle + check (the #11 shape) — and a watched one SOLID — accent disc, dark check; `look` is checkLook()
  54. const lookEmpty = (g) => !!g && /\bregular\b/.test(g.cls) && g.w > 10 && g.onTop && g.fill === 'rgba(0, 0, 0, 0)'
  55. && g.stroke === 'rgb(145, 150, 155)' && g.mark === 'rgb(145, 150, 155)' && colorDist(g.pixel, ACCENT) > 150;
  56. const lookSolid = (g) => !!g && /\bsolid\b/.test(g.cls) && g.w > 10 && g.onTop && g.fill === 'rgb(78, 201, 176)'
  57. && g.mark === 'rgb(15, 20, 25)' && colorDist(g.pixel, ACCENT) < 40;
  58. let ident = null, server = null, browser = null, log = '', tmdb = null;
  59. async function stopServer() {
  60. if (server) {
  61. const s = server;
  62. try { s.kill('SIGTERM'); } catch {}
  63. await new Promise(r => { if (s.exitCode !== null || s.signalCode !== null) return r(); s.once('exit', r); setTimeout(r, 3000); });
  64. server = null;
  65. }
  66. }
  67. async function stop() {
  68. if (ident) { try { await ident.stop(); } catch {} ident = null; }
  69. if (browser) { try { await browser.close(); } catch {} browser = null; }
  70. await stopServer();
  71. if (tmdb) { try { await tmdb.stop(); } catch {} tmdb = null; }
  72. }
  73. // tracker.worldapi.org#9: what the fake TMDB (tests/faketmdb.mjs) knows about the two fixture shows (tmdbId 1001,
  74. // 1002, tests/seed-show.hl). Show 1: season 0 (must NOT be synced — the show has no season 0), S1 with the two
  75. // fixture episodes (no tmdbId locally → matched by number; E2 renamed "Second Episode") + a new E3 (released),
  76. // S2 unchanged, a NEW S3 (E1 released, E2 upcoming 2098-06-01). Show 2 (no seasons yet): a NEW S1 E1 (upcoming
  77. // 2097-01-01). Both have a poster.
  78. // tracker.worldapi.org#12: TMDB's external_ids — show 1 a DIFFERENT imdb id than the stored tt0000001 (must not overwrite)
  79. // + a tvdb id (fills); show 2 an imdb id (fills) + a different tvdb id than the stored 4002 (must not overwrite). The movie
  80. // 1003 (only via /movie/): an imdb id. The fake TVmaze knows imdb tt0000001 → 501 and thetvdb 4002 → 502 (tt0000002 is unknown).
  81. const gateTmdbMovies = () => ({ 1003: { id: 1003, title: 'Gate Test Movie', poster_path: '/gate3.png', external_ids: { imdb_id: 'tt0000003', wikidata_id: 'Q1' } },
  82. // tracker.worldapi.org#14: a movie only TMDB has — imported from the search
  83. 1005: { id: 1005, title: 'Gate Import Movie', poster_path: '/gate5.png', release_date: '2001-05-05', overview: 'an imported movie', genres: [{ id: 18, name: 'Drama' }], external_ids: { imdb_id: 'tt0000005' } },
  84. // mission 054 (tests/seed-adult.hl): what TMDB says about the titles whose adult flag we don't know yet; 1120 is unknown (404)
  85. 1011: { id: 1011, title: 'Adult Gate Movie', adult: true, poster_path: '/flag11.png' },
  86. 1012: { id: 1012, title: 'Flagless Gate Movie', adult: false, poster_path: '/flag12.png', external_ids: { imdb_id: 'tt0001012' } },
  87. 1013: { id: 1013, title: 'Flagless Adult Movie', adult: true, poster_path: '/flag13.png', external_ids: {} },
  88. ...Object.fromEntries(Array.from({ length: 10 }, (_, k) => [1101 + k, { id: 1101 + k, title: 'Backfill Movie ' + String(k + 1).padStart(2, '0'), adult: false, poster_path: `/bf${k + 1}.png`, external_ids: {} }])) });
  89. // tracker.worldapi.org#15: TVmaze's episode lists — at first the SAME as TMDB's (same numbers, same days, + a special without
  90. // a number that must be ignored), so the first syncs take nothing from TVmaze; the "TVmaze merge" block below changes them.
  91. const gateTvmazeEpisodes = () => ({
  92. 501: [{ id: 8001, season: 1, number: 1, name: 'Pilot', airdate: '2020-01-01' }, { id: 8002, season: 1, number: 2, name: 'Second Episode', airdate: '2020-06-15' },
  93. { id: 8003, season: 1, number: 3, name: 'Third', airdate: '2020-09-01' }, { id: 8004, season: 2, number: 1, name: 'Season Two Opener', airdate: '2099-01-01' },
  94. { id: 8005, season: 3, number: 1, name: 'Third Season Start', airdate: '2021-05-05' }, { id: 8006, season: 3, number: 2, name: 'Coming Soon', airdate: '2098-06-01' },
  95. { id: 8099, season: 3, number: null, name: 'A TVmaze Special', airdate: '2021-06-01', type: 'significant_special' }],
  96. 502: [{ id: 8101, season: 1, number: 1, name: 'Brand New', airdate: '2097-01-01' }],
  97. });
  98. const gateTvmaze = () => ({ imdb: { tt0000001: 501 }, thetvdb: { 4002: 502, 4004: 504 }, episodes: gateTvmazeEpisodes() });
  99. // tracker.worldapi.org#14: TMDB's search/multi for "gate": the two titles we HAVE (tv 1001, movie 1003 — left out of the web
  100. // list), a person (dropped), and three new ones: tv 1004 + movie 1005 (importable) and tv 1006 (in the search, but its details
  101. // answer 404 — the failed import)
  102. const gateSearch = () => ({ gate: [
  103. { media_type: 'tv', id: 1001, name: 'Gate Test Show', first_air_date: '2024-01-01', poster_path: '/gate1.png', overview: 'have it' },
  104. { media_type: 'tv', id: 1004, name: 'Gate Import Show', first_air_date: '2023-02-02', poster_path: '/gate4.png', overview: 'new series' },
  105. { media_type: 'person', id: 77, name: 'Gate Person' },
  106. { media_type: 'movie', id: 1003, title: 'Gate Test Movie', release_date: '1996-11-18', poster_path: '/gate3.png' },
  107. { media_type: 'movie', id: 1005, title: 'Gate Import Movie', release_date: '2001-05-05', poster_path: null, overview: 'new movie' },
  108. { media_type: 'tv', id: 1006, name: 'Gate Broken Show', first_air_date: '', poster_path: '/gate6.png' },
  109. // mission 054: an ADULT title in TMDB's answer (despite include_adult=false) — never in our web list
  110. { media_type: 'movie', id: 1030, title: 'Gate Adult Web', adult: true, release_date: '2002-02-02', poster_path: '/gate30.png' }] });
  111. // tracker.worldapi.org#16: TMDB's people. Test Actor (3002): facts + a photo; credits = two titles we HAVE (tv 1001, movie 1003),
  112. // new ones — a movie as cast AND crew ("Hero / Director"), a series, an ADULT movie (stored, never shown), an undated one (last),
  113. // a crew-only one, and 80 more movies (87 titles → 3 batches of 40 after the TMDB step). Second Actor (3003): two titles that
  114. // exist by then. Complete Person (3001) must never be asked.
  115. const gatePersons = () => {
  116. const bulk = [];
  117. for (let i = 1; i <= 80; i++) bulk.push({ media_type: 'movie', id: 2100 + i, title: 'Bulk Film ' + String(i).padStart(2, '0'), release_date: '2005-01-01', character: 'Extra', adult: false, poster_path: null, genre_ids: [] });
  118. return {
  119. 3002: { id: 3002, name: 'Test Actor', biography: 'Test Actor bio from TMDB.', birthday: '1970-05-06', deathday: null, place_of_birth: 'Fixture Town', profile_path: '/face2.png', imdb_id: 'nm0000002', adult: false,
  120. combined_credits: {
  121. cast: [
  122. { media_type: 'tv', id: 1001, name: 'Gate Test Show', first_air_date: '2024-01-01', character: 'Someone', poster_path: '/gate1.png' },
  123. { media_type: 'movie', id: 1003, title: 'Gate Test Movie', release_date: '1996-11-18', character: 'Cameo', poster_path: '/gate3.png' },
  124. { media_type: 'movie', id: 2001, title: 'Person Film One', release_date: '2010-05-05', character: 'Hero', adult: false, poster_path: '/pf1.png', genre_ids: [18], overview: 'a film of the person', original_language: 'en' },
  125. { media_type: 'tv', id: 2002, name: 'Person Series', first_air_date: '2015-03-03', character: 'Lead', adult: false, poster_path: null, genre_ids: [18, 10765] },
  126. { media_type: 'movie', id: 2003, title: 'Hidden Adult Film', release_date: '2012-01-01', character: 'X', adult: true, poster_path: null },
  127. { media_type: 'movie', id: 2004, title: 'Announced Film', release_date: '', character: 'Villain', adult: false, poster_path: null },
  128. ...bulk],
  129. crew: [
  130. { media_type: 'movie', id: 2001, title: 'Person Film One', release_date: '2010-05-05', job: 'Director', adult: false, poster_path: '/pf1.png' },
  131. { media_type: 'movie', id: 2005, title: 'Directed Only', release_date: '2018-08-08', job: 'Writer', adult: false, poster_path: null }] } },
  132. 3003: { id: 3003, name: 'Second Actor', biography: '', birthday: null, deathday: null, place_of_birth: null, profile_path: null,
  133. combined_credits: { cast: [{ media_type: 'movie', id: 2001, title: 'Person Film One', release_date: '2010-05-05', character: 'Sidekick', poster_path: '/pf1.png' },
  134. { media_type: 'tv', id: 1001, name: 'Gate Test Show', first_air_date: '2024-01-01', character: 'Guest', poster_path: '/gate1.png' },
  135. // TMDB's credit says not adult, but OUR record of it is (adult = true, stored by Test Actor's fill): still hidden
  136. { media_type: 'movie', id: 2003, title: 'Hidden Adult Film', release_date: '2012-01-01', character: 'Y', adult: false }], crew: [] } },
  137. 3001: { id: 3001, name: 'Complete Person', combined_credits: { cast: [{ media_type: 'movie', id: 2999, title: 'Must Not Appear', release_date: '2000-01-01' }], crew: [] } },
  138. };
  139. };
  140. const gateTmdbShows = () => ({
  141. 1001: { id: 1001, name: 'Gate Test Show', overview: 'TMDB overview', status: 'Returning Series', poster_path: '/gate1.png', external_ids: { imdb_id: 'tt9999999', tvdb_id: 4001, tvrage_id: null }, seasons: [
  142. { id: 90, season_number: 0, name: 'Specials', air_date: '2019-01-01', episodes: [{ id: 5000, episode_number: 1, name: 'A Special', air_date: '2019-01-01' }] },
  143. { id: 91, season_number: 1, name: 'Season 1', air_date: '2020-01-01', episodes: [
  144. { id: 5001, episode_number: 1, name: 'Pilot', air_date: '2020-01-01' },
  145. { id: 5002, episode_number: 2, name: 'Second Episode', air_date: '2020-06-15' },
  146. { id: 5003, episode_number: 3, name: 'Third', air_date: '2020-09-01' }] },
  147. { id: 92, season_number: 2, name: 'Season 2', air_date: '2099-01-01', episodes: [{ id: 5004, episode_number: 1, name: 'Season Two Opener', air_date: '2099-01-01' }] },
  148. { id: 93, season_number: 3, name: 'Season 3', air_date: '2021-05-05', episodes: [
  149. { id: 5005, episode_number: 1, name: 'Third Season Start', air_date: '2021-05-05' },
  150. { id: 5006, episode_number: 2, name: 'Coming Soon', air_date: '2098-06-01' }] }] },
  151. // tracker.worldapi.org#14: NOT in our database — imported from the search (no one follows it, the sync never asks for it)
  152. 1004: { id: 1004, name: 'Gate Import Show', overview: 'an imported series', status: 'Returning Series', poster_path: '/gate4.png', first_air_date: '2023-02-02',
  153. original_language: 'en', genres: [{ id: 18, name: 'Drama' }, { id: 10765, name: 'Sci-Fi & Fantasy' }], external_ids: { imdb_id: 'tt0000004', tvdb_id: 4004 }, seasons: [
  154. { id: 95, season_number: 1, name: 'Season 1', air_date: '2023-02-02', episodes: [
  155. { id: 8001, episode_number: 1, name: 'Imported One', air_date: '2023-02-02' }, { id: 8002, episode_number: 2, name: 'Imported Two', air_date: '2023-02-09' }] }] },
  156. // mission 054: a series whose adult flag we don't know yet (tests/seed-adult.hl) — TMDB says not adult
  157. 1014: { id: 1014, name: 'Flagless Gate Series', adult: false, overview: 'flagless', status: 'Ended', poster_path: '/flag14.png', external_ids: { imdb_id: 'tt0001014', tvdb_id: 4014 }, seasons: [
  158. { id: 96, season_number: 1, name: 'Season 1', air_date: '2001-03-03', episodes: [{ id: 9601, episode_number: 1, name: 'Flagless Pilot', air_date: '2001-03-03' }] }] },
  159. 1002: { id: 1002, name: 'Unwatched Gate Show', overview: 'second', status: 'Returning Series', poster_path: '/gate2.png', external_ids: { imdb_id: 'tt0000002', tvdb_id: 4999 }, seasons: [
  160. { id: 94, season_number: 1, name: 'Season 1', air_date: '2097-01-01', episodes: [{ id: 7001, episode_number: 1, name: 'Brand New', air_date: '2097-01-01' }] }] },
  161. });
  162. async function main() {
  163. ident = await startIdent({ identDir: IDENT_DIR, workDir: join(STORE, 'ident'), port: IDENT_PORT });
  164. const alice = await ident.signIn('[email protected]');
  165. const APPKEY = await ident.registerApp(alice, 'tracker (gate)', [BASE]);
  166. check('ident: our own ident runs (a copy without .env), tracker is registered', /^pk_[0-9a-f]{32}$/.test(APPKEY.key) && !existsSync(join(STORE, 'ident', 'ident-code', '.env')));
  167. // tracker.worldapi.org#5: learn alice's per-app identity (a throwaway code, consumed here) so the
  168. // fixture below can seed a follow for the SAME user the real login flow will later resolve to
  169. // (users.hl `ensureUser` matches an existing users.db row by `identity`, reusing its id) — this is
  170. // the only way to give /unwatched a known followed show before the browser ever signs in.
  171. const preCode = await ident.selectorCode(alice, APPKEY, BASE);
  172. const aliceIdentity = await ident.exchange(APPKEY, preCode);
  173. // tracker.worldapi.org#4/#5: a tiny fixture show (tests/seed-show.hl) — written BEFORE the server
  174. // starts, self-assigned ids only (never update(), see that file's header)
  175. const MPACKDB = join(STORE, 'mpackdb');
  176. mkdirSync(MPACKDB, { recursive: true });
  177. const seedOut = execFileSync(join(APP, 'bin/hybriel'), ['tests/seed-show.hl'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: MPACKDB, TRACKER_SEED_IDENTITY: aliceIdentity } }).toString();
  178. check('seed: the fixture show was written, alice follows it', seedOut.includes('gate-test-show') && seedOut.includes('follows it'), seedOut);
  179. // tracker.worldapi.org#8: the fixture show's poster FILE exists (a 1×1 png), the second show has none →
  180. // /my/series must give the first its own /posters/sh1.png and the second the one placeholder URL /posters/none
  181. mkdirSync(join(MPACKDB, 'posters'), { recursive: true });
  182. writeFileSync(join(MPACKDB, 'posters', 'sh1.png'), Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==', 'base64'));
  183. // tracker.worldapi.org#9: the fake TMDB. EVERY run of the app/tool in this gate points at it with the gate's own
  184. // token — the runtime loads the project's real .env (TMDB_READ_TOKEN) by itself, the environment given here wins
  185. tmdb = await startFakeTmdb({ port: TMDB_PORT, shows: gateTmdbShows(), movies: gateTmdbMovies(), tvmaze: gateTvmaze(), search: gateSearch(), persons: gatePersons() });
  186. const TMDB_ENV = { TMDB_READ_TOKEN: 'gate-token', TMDB_BASE_URL: tmdb.base + '/3', TMDB_IMAGE_URL: tmdb.base + '/t/p', TVMAZE_BASE_URL: tmdb.base + '/tvmaze' };
  187. // mission 060 (tracker#27): the gate's own file of OLD short ids (the real one maps the old export's 702) — Gate Test Show's oldId
  188. // sh1 had '100jh'; '100ji' belonged to a show we don't have (reserved: never handed out)
  189. const OLD_SHORT_IDS = join(STORE, 'old-short-ids.json');
  190. writeFileSync(OLD_SHORT_IDS, JSON.stringify({ sh1: '100jh', 'gone-old': '100ji' }));
  191. const startServer = async (extra = {}) => {
  192. log = '';
  193. server = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, env: { ...process.env, TRACKER_PORT: String(PORT), TRACKER_SESSIONS: SESSIONS + '/', TRACKER_STORAGE: MPACKDB, TRACKER_WATCH: '0',
  194. TRACKER_URL: BASE, IDENT_URL: ident.base, IDENT_EXCHANGE_URL: ident.base, TRACKER_KEY: APPKEY.key, TRACKER_SECRET: APPKEY.secret, ...TMDB_ENV, TRACKER_SYNC: '0', TRACKER_BACKFILL: '0', TRACKER_KINDS: '0', TRACKER_OLD_SHORT_IDS: OLD_SHORT_IDS, ...extra }, stdio: ['ignore', 'pipe', 'pipe'] });
  195. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  196. for (let i = 0; ; i++) {
  197. try { if ((await fetch(BASE + '/')).ok) break; } catch {}
  198. if (i > 80) throw new Error('tracker did not come up\n' + log);
  199. await new Promise(r => setTimeout(r, 250));
  200. }
  201. };
  202. await startServer();
  203. check('tracker is up', true);
  204. // mission 060: the FIRST start gives every fixture record its short id in the background (the old one for sh1)
  205. for (let i = 0; i < 100 && !/short ids done/.test(log); i++) await new Promise(r => setTimeout(r, 100));
  206. const firstShortIds = log.split('\n').filter(l => l.startsWith('short ids')).join('\n');
  207. check('short ids: the first start finds every record without one, gives them theirs in the background, the old one kept (oldKept=1)',
  208. /short ids: (\d+) records, 0 with a short id, \1 without, 2 old ids/.test(firstShortIds) && /short ids: backfill start, \d+ records, 40 ms per batch/.test(firstShortIds)
  209. && /short ids done: assigned=\d+ oldKept=1 /.test(firstShortIds), firstShortIds);
  210. browser = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });
  211. const page = await browser.newPage();
  212. globalThis.__gatePage = page;
  213. page.captureNetwork();
  214. await page.captureWs(); // tracker#17: which faces a season click sends (wsSent)
  215. // tracker#17: a FAKE DELAY for one face — while `window.__delayFace = { name, ms }` is set, an outgoing websocket frame
  216. // naming that face is sent `ms` later (the real socket, only held back), so the gate sees the state BEFORE the answer
  217. await page.addInitScript(`(() => {
  218. const Native = window.WebSocket;
  219. if (!Native) return;
  220. window.WebSocket = class extends Native {
  221. send(d) {
  222. const f = window.__delayFace;
  223. if (f && String(d).includes(f.name)) { setTimeout(() => super.send(d), f.ms); return; }
  224. return super.send(d);
  225. }
  226. };
  227. })()`);
  228. const ev = (e) => page.evaluate(e);
  229. const hydrated = () => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 15000, label: 'hydrated' });
  230. // tracker#29: how a REAL check on the page looks (no copy): scrolled into view, the pointer moved off it (hover is accent);
  231. // its circle's fill + stroke and the check's stroke (computed), whether it is the topmost element there, and the SCREENSHOT
  232. // pixel inside the disc off the check mark (svg point 12,6) — background when empty, accent when solid
  233. const checkLook = async (sel) => {
  234. await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: 0, y: 0 });
  235. const g = JSON.parse(await ev(`JSON.stringify((() => { const b = document.querySelector(${JSON.stringify(sel)}); if (!b) return null; b.scrollIntoView({ block: 'center' });
  236. const s = b.querySelector('svg').getBoundingClientRect(), c = getComputedStyle(b.querySelector('circle')), p = getComputedStyle(b.querySelector('path'));
  237. const x = s.left + s.width * 12 / 24, y = s.top + s.height * 6 / 24, top = document.elementFromPoint(x, y);
  238. return { cls: b.getAttribute('class'), w: s.width, x: x + scrollX, y: y + scrollY, onTop: !!top && (top === b || b.contains(top)), fill: c.fill, stroke: c.stroke, mark: p.stroke }; })())`));
  239. if (!g) return null;
  240. const shot = await page.send('Page.captureScreenshot', { format: 'png', clip: { x: g.x, y: g.y, width: 1, height: 1, scale: 1 } });
  241. g.pixel = pngFirstPixel(Buffer.from(shot.data, 'base64'));
  242. return g;
  243. };
  244. // mission 047: every check icon AND season caret on the page is a real SVG element (not XHTML) and actually drawn
  245. const svgState = () => ev(`JSON.stringify((() => {
  246. const svgs = Array.from(document.querySelectorAll('button.checkicon svg, season-caret svg'));
  247. const shapes = Array.from(document.querySelectorAll('button.checkicon svg circle, button.checkicon svg path, season-caret svg path'));
  248. return { svgs: svgs.length, badNs: svgs.concat(shapes).filter(e => e.namespaceURI !== 'http://www.w3.org/2000/svg').length,
  249. undrawn: Array.from(document.querySelectorAll('button.checkicon svg circle')).filter(c => !(c.getBoundingClientRect().width > 0)).length };
  250. })())`);
  251. const svgOk = (st) => { const v = JSON.parse(st); return v.svgs > 0 && v.badNs === 0 && v.undrawn === 0; };
  252. // the caret's direction per season row, top to bottom (tracker#17): 'down' (closed, no transform) or 'up' (open,
  253. // rotate(180deg) = matrix(-1, 0, 0, -1, 0, 0)); waits out the caret's .15 s transition first
  254. const carets = async () => { await new Promise(r => setTimeout(r, 250)); return ev(`JSON.stringify(Array.from(document.querySelectorAll('season-row')).map(r => {
  255. const t = getComputedStyle(r.querySelector('season-caret')).transform;
  256. if (t === 'none') return 'down';
  257. const m = t.startsWith('matrix(') ? t.slice(7, -1).split(',').map(Number) : [];
  258. return m.length === 6 && Math.abs(m[0] + 1) < 1e-6 && Math.abs(m[3] + 1) < 1e-6 && Math.abs(m[1]) < 1e-6 ? 'up' : t;
  259. }))`); };
  260. // tracker.worldapi.org#12: the header's link icons as [label, href, target, rel], in order
  261. const extLinks = () => ev(`JSON.stringify(Array.from(document.querySelectorAll('show-links a.extlink')).map(a => [a.textContent, a.getAttribute('href'), a.getAttribute('target'), a.getAttribute('rel')]))`);
  262. const linksAre = (got, want) => JSON.stringify(JSON.parse(got)) === JSON.stringify(want.map(([l, h]) => [l, h, '_blank', 'noopener']));
  263. const TMDB_TV = 'https://www.themoviedb.org/tv/', TMDB_MOVIE = 'https://www.themoviedb.org/movie/', IMDB = 'https://www.imdb.com/title/', TVDB = 'https://thetvdb.com/dereferrer/series/', TVMAZE = 'https://www.tvmaze.com/shows/';
  264. // a click on a link icon: a NEW tab opens at that address (no access to this one: noopener), this tab stays where it is.
  265. // The new tab is closed again at once (it would load the real site).
  266. const clickOpensNewTab = async (sel) => {
  267. const seen = new Map();
  268. const off = browser.conn.onEvent((m) => {
  269. if ((m.method === 'Target.targetCreated' || m.method === 'Target.targetInfoChanged') && m.params.targetInfo.type === 'page') seen.set(m.params.targetInfo.targetId, m.params.targetInfo);
  270. });
  271. await browser.conn.send('Target.setDiscoverTargets', { discover: true });
  272. const known = new Set(seen.keys());
  273. const before = await ev('location.href');
  274. await page.click(sel);
  275. const fresh = () => [...seen.values()].find(i => !known.has(i.targetId) && i.url && i.url !== 'about:blank');
  276. for (let i = 0; i < 100 && !fresh(); i++) await new Promise(r => setTimeout(r, 50));
  277. const tab = fresh();
  278. off();
  279. await browser.conn.send('Target.setDiscoverTargets', { discover: false });
  280. if (tab) await browser.conn.send('Target.closeTarget', { targetId: tab.targetId }).catch(() => {});
  281. return { url: tab ? tab.url : null, canAccessOpener: tab ? tab.canAccessOpener : null, stayed: (await ev('location.href')) === before };
  282. };
  283. // tracker.worldapi.org#13: the poster tiles of a row/grid as "title|year|href|poster"
  284. const tilesOf = (sel) => ev(`JSON.stringify(Array.from(document.querySelectorAll(${JSON.stringify(sel)} + ' a.tile')).map(a => [a.querySelector('tile-title').textContent, a.querySelector('tile-year').textContent, a.getAttribute('href'), a.querySelector('img.tile-poster').getAttribute('src')].join('|')))`).then(JSON.parse);
  285. const titlesOf = async (sel) => (await tilesOf(sel)).map(t => t.split('|')[0]);
  286. const movieRange = (from, to) => { const o = []; for (let i = from; i >= to; i--) o.push('Pager Movie ' + String(i).padStart(2, '0')); return o; };
  287. const pagerState = () => ev(`JSON.stringify({ items: Array.from(document.querySelectorAll('pagination li')).map(l => l.textContent.trim()), current: (document.querySelector('pagination li.current') || { textContent: '' }).textContent.trim() })`).then(JSON.parse);
  288. // hybriel 64527baa (in the vendored ff51cf46): a face taking `session` also answers with a sync of every member derived
  289. // from session — a handler that ALSO appended the returned row would show it twice. After every face-driven change:
  290. // each row (by its button value) once. Waits 400 ms first so a late sync has landed.
  291. const rowsOnce = async (sel) => { await new Promise(r => setTimeout(r, 400)); return JSON.parse(await ev(`JSON.stringify((() => { const v = Array.from(document.querySelectorAll(${JSON.stringify(sel)})).map(b => b.value); return { n: v.length, unique: new Set(v).size === v.length, values: v }; })())`)); };
  292. const modalOpen = () => ev(`!!(document.querySelector('dialog#signin') && document.querySelector('dialog#signin').open)`);
  293. const loginAs = async (who) => {
  294. const code = await ident.selectorCode(who, APPKEY, BASE);
  295. await page.goto(BASE + '/login/callback?ident_code=' + code);
  296. await page.waitForSelector('#logout');
  297. await hydrated();
  298. };
  299. // ---- signed out: header shows the selector + "Log in with ident", the page itself is empty ----
  300. await page.goto(BASE + '/');
  301. await hydrated();
  302. check('signed out: the identity selector is in the header', await ev(`!!document.querySelector('#selector')`));
  303. check('signed out: "Log in with ident" shows, no "Log out"', (await ev(`!!document.querySelector('#loginbutton')`)) && !(await ev(`!!document.querySelector('#logout')`)));
  304. // mission 056: signed out on a phone the header is ONE row ("choose ident" + "Log in" never wrap); " with ident" from 40rem on
  305. const headerRow = () => ev(`JSON.stringify((() => { const h = document.querySelector('application-header').getBoundingClientRect();
  306. const parts = [document.querySelector('application-header .brand'), document.querySelector('#searchlink'), document.querySelector('#selector'), document.querySelector('#loginbutton')].map(e => e.getBoundingClientRect());
  307. return { h: Math.round(h.height), oneRow: parts.every(r => r.top >= h.top && r.bottom <= h.bottom && r.top < parts[0].bottom && r.bottom > parts[0].top), right: Math.round(Math.max(...parts.map(r => r.right))),
  308. sw: document.documentElement.scrollWidth, text: document.querySelector('#loginbutton').innerText.trim(), choose: document.querySelector('#selector').shadowRoot.querySelector('[part~="button"]').getBoundingClientRect().height }; })())`).then(JSON.parse);
  309. const rows56 = {};
  310. for (const [w, mobile] of [[320, true], [390, true], [1280, false]]) {
  311. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: 800, deviceScaleFactor: mobile ? 2 : 1, mobile });
  312. await page.goto(BASE + '/');
  313. await hydrated();
  314. await page.waitFor(`!!document.querySelector('#selector').shadowRoot && !!document.querySelector('#selector').shadowRoot.querySelector('[part~="button"]')`, { timeout: 5000, label: 'selector drawn' });
  315. rows56[w] = await headerRow();
  316. if (process.env.TRACKER_GATE_SHOTS) writeFileSync(join(process.env.TRACKER_GATE_SHOTS, `header-signed-out-${w}.png`), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  317. }
  318. await page.send('Emulation.clearDeviceMetricsOverride', {});
  319. await page.goto(BASE + '/');
  320. await hydrated();
  321. check('signed out: the header is ONE row at 320/390/1280 px (≤ 56 px high, nothing below the brand, no sideways scroll); a phone says "Log in", a wide screen "Log in with ident"',
  322. [320, 390, 1280].every(w => rows56[w].oneRow && rows56[w].h <= 56 && rows56[w].sw <= w && rows56[w].right <= w && rows56[w].choose <= 40) && rows56[320].text === 'Log in' && rows56[390].text === 'Log in' && rows56[1280].text === 'Log in with ident', JSON.stringify(rows56));
  323. // ---- tracker.worldapi.org#13: the homepage signed OUT — no icon tiles, the text, "Movies" (→ /movies) with the 10
  324. // latest RELEASED movies (not the 2099 one), "Shows" (→ /shows) with the series by newest released episode ----
  325. check('home signed out: no icon tiles, no centered sign-in; the text about the site (with the sign-in hint)', (await ev(`document.querySelectorAll('a.hometile').length`)) === 0
  326. && /keeps track of the series and movies you follow/.test(await ev(`document.querySelector('home-intro').textContent`)) && /Log in with ident/.test(await ev(`document.querySelector('home-intro').textContent`)));
  327. check('home: the headings "Movies", "Series" and "Shows" link to /movies, /series and /shows (tracker#21)', (await ev(`[document.querySelector('#home-movies h2 a'), document.querySelector('#home-series h2 a'), document.querySelector('#home-shows h2 a')].map(a => a.textContent + ' ' + a.getAttribute('href')).join(',')`)) === 'Movies /movies,Series /series,Shows /shows');
  328. let tl = await tilesOf('#home-movies');
  329. check('home: the 10 latest RELEASED movies, newest first (Pager Movie 30…21; the 2099 one is not out yet), each poster + title + year → its page',
  330. JSON.stringify(tl.map(t => t.split('|')[0])) === JSON.stringify(movieRange(30, 21)) && tl[0] === 'Pager Movie 30|2001|/movies/pager-movie-30|/posters/none', JSON.stringify(tl));
  331. tl = await tilesOf('#home-series');
  332. check('home: the series by newest RELEASED episode (Pager Older Series 2021-01-01, Gate Test Show 2020-06-15; one with no released episode is left out)',
  333. JSON.stringify(tl) === JSON.stringify(['Pager Older Series|2019|/series/pager-older-series|/posters/none', 'Gate Test Show|2024|/series/gate-test-show|/posters/sh1.png']), JSON.stringify(tl));
  334. check('home: every tile poster loaded (the placeholder or the real file)', await ev(`new Promise(r => setTimeout(r, 300)).then(() => Array.from(document.querySelectorAll('img.tile-poster')).filter(i => i.getBoundingClientRect().right <= innerWidth).every(i => i.complete && i.naturalWidth > 0))`));
  335. // ---- tracker.worldapi.org#4: /shows/:slug signed OUT — the header/genres/cast show, no checks ----
  336. await page.goto(BASE + '/series/gate-test-show');
  337. await hydrated();
  338. check('signed out: the show header renders (title, genre, cast)', (await ev(`document.querySelector('show-header h1 type-name').textContent`)) === 'Gate Test Show'
  339. && (await ev(`document.querySelector('.genre-pill').textContent`)) === 'Drama'
  340. && (await ev(`document.querySelector('.artist-link').textContent`)) === 'Test Actor');
  341. // ---- tracker.worldapi.org#12: link icons only for the ids the show has (before any sync: show 1 has tmdb + imdb) ----
  342. let lk = await extLinks();
  343. check('link icons: show 1 (tmdbId + imdbId only) has exactly TMDB (tv/1001) and IMDb (tt0000001), each target=_blank rel=noopener',
  344. linksAre(lk, [['TMDB', TMDB_TV + '1001'], ['IMDb', IMDB + 'tt0000001/']]), lk);
  345. check('link icons: monochrome badges (one colour for all, no image), small (≤ 1.6rem high)',
  346. (await ev(`(() => { const a = Array.from(document.querySelectorAll('a.extlink')); const c = a.map(e => getComputedStyle(e)); return a.length > 0 && new Set(c.map(x => x.backgroundColor + x.color)).size === 1 && a.every(e => !e.querySelector('img') && e.getBoundingClientRect().height <= 25.6) })()`)));
  347. const nt = await clickOpensNewTab('a.extlink[data-site="imdb"]');
  348. check('link icons: a click opens the show on IMDb in a NEW tab without access to this one (noopener); this page stays', nt.url === IMDB + 'tt0000001/' && nt.canAccessOpener === false && nt.stayed, JSON.stringify(nt));
  349. await page.goto(BASE + '/series/unwatched-gate-show');
  350. await hydrated();
  351. lk = await extLinks();
  352. check('link icons: show 2 (tmdbId + tvdbId only) has exactly TMDB and TheTVDB (dereferrer/series/4002)', linksAre(lk, [['TMDB', TMDB_TV + '1002'], ['TVDB', TVDB + '4002']]), lk);
  353. await page.goto(BASE + '/movies/gate-test-movie');
  354. await hydrated();
  355. lk = await extLinks();
  356. check('link icons: a movie (tmdbId only) has exactly TMDB as /movie/1003', linksAre(lk, [['TMDB', TMDB_MOVIE + '1003']]), lk);
  357. await page.goto(BASE + '/series/gate-test-show');
  358. await hydrated();
  359. check('signed out: the latest season (2) is expanded, season 1 collapsed', (await ev(`document.querySelectorAll('episode-row').length`)) === 1);
  360. // ---- mission 058 (tracker#22): every episode row shows its air date (rendered on the server); (#25) the genre pill → /genres/<genre>
  361. check('#22: the episode row shows its air date (S02E01 "Season Two Opener" 2099-01-01), at the row\'s right, muted',
  362. (await ev(`document.querySelector('episode-row episode-date').textContent`)) === '2099-01-01'
  363. && (await ev(`(() => { const r = document.querySelector('episode-row'), d = r.querySelector('episode-date'), t = r.querySelector('episode-title'); return d.getBoundingClientRect().left >= t.getBoundingClientRect().right && getComputedStyle(d).color !== getComputedStyle(t).color })()`)));
  364. check('#25: the genre pill links to /genres/Drama', (await ev(`document.querySelector('.genre-pill').getAttribute('href')`)) === '/genres/Drama');
  365. // mission 047: signed out the checks and "Follow" are VISIBLE; a click opens the sign-in modal and writes nothing
  366. check('signed out (mission 047): the season + episode checks are visible (drawn SVG) and so is "Follow"',
  367. (await ev(`document.querySelectorAll('button.checkicon').length`)) === 3 && svgOk(await svgState())
  368. && (await ev(`document.querySelector('#follow').textContent`)) === 'Follow' && (await ev(`document.querySelector('#follow').getBoundingClientRect().width > 0`)), await svgState());
  369. check('signed out: the sign-in modal is closed at first', !(await modalOpen()));
  370. await page.click('button.checkicon[value="ep0000000000ep0e3"]');
  371. await page.waitFor(`document.querySelector('dialog#signin').open`, { timeout: 5000, label: 'modal after a check click' }).catch(() => {});
  372. check('signed out: a check click opens the modal "You need to sign in to follow shows and mark episodes" with a sign-in link (ident login) and Close',
  373. (await modalOpen()) && (await ev(`document.querySelector('dialog#signin p').textContent`)) === 'You need to sign in to follow shows and mark episodes.'
  374. && (await ev(`document.querySelector('#signin-link').getAttribute('href')`)).startsWith(ident.base + '/login?key=')
  375. && (await ev(`document.querySelector('#signin-link').getBoundingClientRect().width > 0`))
  376. && (await ev(`Array.from(document.querySelectorAll('dialog#signin footer button')).map(b => b.textContent).join()`)) === 'Close',
  377. await ev(`document.querySelector('dialog#signin') ? document.querySelector('dialog#signin').outerHTML.slice(0, 600) : 'no dialog'`));
  378. if (process.env.TRACKER_GATE_SHOTS) { mkdirSync(process.env.TRACKER_GATE_SHOTS, { recursive: true }); writeFileSync(join(process.env.TRACKER_GATE_SHOTS, 'signed-out-modal-1280.png'), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64')); }
  379. await page.click('dialog#signin footer button');
  380. await page.waitFor(`!document.querySelector('dialog#signin').open`, { timeout: 5000, label: 'modal closed' }).catch(() => {});
  381. check('signed out: Close closes the modal; the check stayed unwatched (nothing written)', !(await modalOpen())
  382. && (await ev(`document.querySelector('button.checkicon[value="ep0000000000ep0e3"]').getAttribute('class')`)) === 'checkicon regular');
  383. await page.click('#follow');
  384. await page.waitFor(`document.querySelector('dialog#signin').open`, { timeout: 5000, label: 'modal after Follow' }).catch(() => {});
  385. check('signed out: "Follow" opens the same modal and stays "Follow"', (await modalOpen()) && (await ev(`document.querySelector('#follow').textContent`)) === 'Follow');
  386. await page.click('dialog#signin footer button');
  387. await page.click('button.checkicon[value="se000000000se0s1"]');
  388. await page.waitFor(`document.querySelector('dialog#signin').open`, { timeout: 5000, label: 'modal after a season check' }).catch(() => {});
  389. check('signed out: a SEASON check opens the modal too', await modalOpen());
  390. await page.click('dialog#signin footer button');
  391. await page.goto(BASE + '/series/gate-test-show');
  392. await hydrated();
  393. check('signed out: after a reload every check is still unwatched (the clicks wrote nothing)',
  394. (await ev(`Array.from(document.querySelectorAll('button.checkicon')).every(b => b.getAttribute('class') === 'checkicon regular')`)));
  395. // ---- mission 058 (tracker#24): a MOVIE's page has a watched check (the episodes' icon); signed out a click opens the modal
  396. await page.goto(BASE + '/movies/gate-test-movie');
  397. await hydrated();
  398. const movieWatch = () => ev(`JSON.stringify((() => { const b = document.querySelector('#moviewatch'); return b ? { cls: b.getAttribute('class'), label: document.querySelector('movie-watch-label').textContent, n: document.querySelectorAll('#moviewatch').length,
  399. svg: b.querySelector('svg').namespaceURI === 'http://www.w3.org/2000/svg' && b.querySelector('circle').getBoundingClientRect().width > 0 } : null; })())`).then(JSON.parse);
  400. let mw = await movieWatch();
  401. check('#24 signed out: the movie page shows the watched check (drawn SVG, "checkicon regular") with "Not watched"; a series page has none',
  402. mw && mw.cls === 'checkicon regular' && mw.label === 'Not watched' && mw.svg && mw.n === 1, JSON.stringify(mw));
  403. await page.click('#moviewatch');
  404. await page.waitFor(`document.querySelector('dialog#signin').open`, { timeout: 5000, label: 'modal after the movie check' }).catch(() => {});
  405. check('#24 signed out: a click opens the sign-in modal ("You need to sign in to follow movies and mark them watched.", the ident link)',
  406. (await modalOpen()) && (await ev(`document.querySelector('dialog#signin p').textContent`)) === 'You need to sign in to follow movies and mark them watched.'
  407. && (await ev(`document.querySelector('#signin-link').getAttribute('href')`)).startsWith(ident.base + '/login?key='));
  408. if (process.env.TRACKER_GATE_SHOTS) writeFileSync(join(process.env.TRACKER_GATE_SHOTS, 'movie-signed-out-modal-1280.png'), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  409. await page.click('dialog#signin footer button');
  410. await page.goto(BASE + '/movies/gate-test-movie');
  411. await hydrated();
  412. mw = await movieWatch();
  413. check('#24 signed out: after a reload the movie is still not watched (nothing written)', mw && mw.cls === 'checkicon regular', JSON.stringify(mw));
  414. // ---- tracker.worldapi.org#5: /my/unwatched signed OUT — no rows, no checks ----
  415. await page.goto(BASE + '/my/unwatched');
  416. await hydrated();
  417. check('signed out: /my/unwatched shows no rows and asks to sign in', (await ev(`document.querySelectorAll('unwatched-row').length`)) === 0
  418. && (await ev(`document.querySelector('.muted').textContent`)) === 'Sign in to see the shows you follow.');
  419. // ---- tracker.worldapi.org#6: /my/schedule signed OUT — no rows, no checks ----
  420. await page.goto(BASE + '/my/schedule');
  421. await hydrated();
  422. check('signed out: /my/schedule shows no rows and asks to sign in', (await ev(`document.querySelectorAll('schedule-row').length`)) === 0
  423. && (await ev(`document.querySelector('.muted').textContent`)) === 'Sign in to see the shows you follow.');
  424. // ---- tracker.worldapi.org#7: /my/series signed OUT — no rows, the same sign-in message ----
  425. await page.goto(BASE + '/my/series');
  426. await hydrated();
  427. check('signed out: /my/series shows no rows and asks to sign in', (await ev(`document.querySelectorAll('my-show-row').length`)) === 0
  428. && (await ev(`document.querySelector('.muted').textContent`)) === 'Sign in to see the series you follow.');
  429. // ==== tracker.worldapi.org#14: THE SEARCH, signed OUT — the header's magnifier, our database as you type, "Fetch from web"
  430. // (the fake TMDB's search/multi), "Add" → the sign-in modal ====
  431. const searchFor = () => ev(`document.querySelector('search-page') ? document.querySelector('search-page').getAttribute('data-for') : null`);
  432. const searchTitles = () => ev(`JSON.stringify(Array.from(document.querySelectorAll('#titles search-row')).map(r => [r.querySelector('.search-title').textContent, r.querySelector('.search-title').getAttribute('href'), r.querySelector('search-type').textContent]))`);
  433. const searchPeople = () => ev(`JSON.stringify(Array.from(document.querySelectorAll('#people .search-person')).map(a => [a.textContent, a.getAttribute('href')]))`);
  434. const webList = () => ev(`JSON.stringify(Array.from(document.querySelectorAll('web-row')).map(r => [r.querySelector('web-title').textContent, r.querySelector('button.add').value, r.querySelector('search-type').textContent]))`);
  435. const typeSearch = async (text) => {
  436. await page.type('#searchinput', text, { clear: true });
  437. await page.waitFor(`document.querySelector('search-page').getAttribute('data-for') === ${JSON.stringify(text)}`, { timeout: 10000, label: 'results for ' + text });
  438. };
  439. const GATE_TITLES = [['Gate Test Show (2024)', '/series/gate-test-show', 'Series'], ['Gate Test Movie (1996)', '/movies/gate-test-movie', 'Movie'], ['Unwatched Gate Show (2025)', '/series/unwatched-gate-show', 'Series']];
  440. check('search: the header has the magnifier (a drawn SVG) linking to /search',
  441. (await ev(`document.querySelector('#searchlink').getAttribute('href')`)) === '/search'
  442. && (await ev(`(() => { const s = document.querySelector('#searchlink svg'); return s.namespaceURI === 'http://www.w3.org/2000/svg' && s.querySelector('circle').getBoundingClientRect().width > 0 })()`)));
  443. await ev(`window.__w052 = 'same document'`);
  444. await page.click('#searchlink');
  445. await page.waitFor(`location.pathname === '/search' && !!document.querySelector('#searchinput')`, { timeout: 10000, label: 'search page' });
  446. check('search: the magnifier opens /search (client-side), an empty search field and "Search our shows, movies and people."',
  447. (await ev('window.__w052')) === 'same document' && (await ev(`document.querySelector('#searchinput').value`)) === ''
  448. && (await ev(`document.querySelector('#searchnote').textContent`)) === 'Search our shows, movies and people.' && !(await ev(`!!document.querySelector('#fetchweb')`)));
  449. await typeSearch('g');
  450. check('search: one letter → "Type at least 2 letters.", no "Fetch from web"', (await ev(`document.querySelector('#searchnote').textContent`)) === 'Type at least 2 letters.' && !(await ev(`!!document.querySelector('#fetchweb')`)));
  451. await page.type('#searchinput', 'ate');
  452. await page.waitFor(`document.querySelector('search-page').getAttribute('data-for') === 'gate'`, { timeout: 10000, label: 'results for gate' });
  453. let st14 = await searchTitles();
  454. check('search: typing "gate" lists our titles at once — name start first, the year, Series/Movie, linking to the show; the address follows (/search/gate)',
  455. st14 === JSON.stringify(GATE_TITLES) && (await ev('location.pathname')) === '/search/gate' && (await ev('window.__w052')) === 'same document', st14);
  456. await typeSearch('test act');
  457. check('search: people too — "test act" finds the person "Test Actor" (/person/Test-Actor) and no title', (await searchPeople()) === JSON.stringify([['Test Actor', '/person/Test-Actor']]) && (await searchTitles()) === '[]', await searchPeople());
  458. await typeSearch('GATE tést');
  459. check('search: case and accents do not matter ("GATE tést" = gate test); the address carries the text encoded',
  460. (await searchTitles()) === JSON.stringify(GATE_TITLES.slice(0, 2)) && (await ev('location.pathname')) === '/search/GATE%20t%C3%A9st', (await searchTitles()) + ' ' + (await ev('location.pathname')));
  461. await typeSearch('zzqq');
  462. check('search: nothing found → "Nothing in our database yet." and "Fetch from web"', (await ev(`document.querySelector('#searchnote').textContent`)) === 'Nothing in our database yet.' && (await ev(`!!document.querySelector('#fetchweb')`)));
  463. await page.goto(BASE + '/search/GATE%20t%C3%A9st');
  464. await hydrated();
  465. check('search: the address alone (reload / shared link) renders the same results on the server, the text in the field',
  466. (await ev(`document.querySelector('#searchinput').value`)) === 'GATE tést' && (await searchTitles()) === JSON.stringify(GATE_TITLES.slice(0, 2)) && (await searchFor()) === 'GATE tést');
  467. const bad14 = await fetch(BASE + '/search/x%zz');
  468. const bad14b = await fetch(BASE + '/search/%E0%80');
  469. check('search: a malformed address is no error — /search/x%zz 200 with the text taken literally, /search/%E0%80 (broken UTF-8) 200',
  470. bad14.status === 200 && (await bad14.text()).includes('value="x%zz"') && bad14b.status === 200 && (await bad14b.text()).includes('<search-page'), bad14.status + ' ' + bad14b.status);
  471. await typeSearch('gate/te');
  472. check('search: a "/" in the text goes into the address as a space (an encoded / would split the path) — and that address reloads to the same titles',
  473. (await ev('location.pathname')) === '/search/gate%20te' && (await searchTitles()) === JSON.stringify(GATE_TITLES.slice(0, 2)), await ev('location.pathname'));
  474. await page.goto(BASE + '/search/gate%20te');
  475. await hydrated();
  476. check('search: … reloaded', (await searchTitles()) === JSON.stringify(GATE_TITLES.slice(0, 2)) && (await ev(`document.querySelector('#searchinput').value`)) === 'gate te');
  477. await page.goto(BASE + '/search/gate');
  478. await hydrated();
  479. const searchesBefore = tmdb.searchRequests.length;
  480. await page.click('#fetchweb');
  481. await page.waitFor(`document.querySelectorAll('web-row').length > 0 || !!document.querySelector('#webnote')`, { timeout: 10000, label: 'web results' });
  482. let wl = await webList();
  483. const GATE_WEB = [['Gate Import Show (2023)', 'tv:1004', 'TV'], ['Gate Import Movie (2001)', 'movie:1005', 'Movie'], ['Gate Broken Show', 'tv:1006', 'TV']];
  484. check('search: "Fetch from web" (signed out too) lists TMDB\'s titles WE DON\'T HAVE — not tv 1001 / movie 1003 (ours), no person; one search/multi request with the token',
  485. wl === JSON.stringify(GATE_WEB) && tmdb.searchRequests.length === searchesBefore + 1 && tmdb.searchRequests[searchesBefore].path === '/3/search/multi?query=gate&include_adult=false&page=1'
  486. && tmdb.searchRequests[searchesBefore].authorization === 'Bearer gate-token', wl + ' ' + JSON.stringify(tmdb.searchRequests));
  487. check('search: the web rows\' small posters come from TMDB\'s image host (w92); one without a poster gets /posters/none',
  488. (await ev(`JSON.stringify(Array.from(document.querySelectorAll('web-row img')).map(i => i.getAttribute('src')))`)) === JSON.stringify([tmdb.base + '/t/p/w92/gate4.png', '/posters/none', tmdb.base + '/t/p/w92/gate6.png']));
  489. const requestsBefore = tmdb.requests.length;
  490. await page.click('web-row button.add[value="tv:1004"]');
  491. await page.waitFor(`document.querySelector('dialog#signin').open`, { timeout: 5000, label: 'modal after Add' }).catch(() => {});
  492. check('search: signed out, "Add" opens the sign-in modal ("You need to sign in to add titles.", sign-in link) and sends nothing',
  493. (await modalOpen()) && (await ev(`document.querySelector('dialog#signin p').textContent`)) === 'You need to sign in to add titles.'
  494. && (await ev(`document.querySelector('#signin-link').getAttribute('href')`)).startsWith(ident.base + '/login?key=') && tmdb.requests.length === requestsBefore);
  495. if (process.env.TRACKER_GATE_SHOTS) writeFileSync(join(process.env.TRACKER_GATE_SHOTS, 'search-signed-out-modal-1280.png'), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  496. await page.click('dialog#signin footer button');
  497. await page.waitFor(`!document.querySelector('dialog#signin').open`, { timeout: 5000, label: 'modal closed' }).catch(() => {});
  498. check('search: Close closes it; the web list is still there', !(await modalOpen()) && (await webList()) === JSON.stringify(GATE_WEB));
  499. // ---- tracker.worldapi.org#3: no bottom border on the header, no border on filled buttons ----
  500. check('the header has no bottom border', (await ev(`getComputedStyle(document.querySelector('application-header')).borderBottomWidth`)) === '0px');
  501. check('"Log in with ident" has no border', (await ev(`getComputedStyle(document.querySelector('#loginbutton')).borderTopWidth`)) === '0px');
  502. check('the ident selector\'s "choose ident" button has no border', (await ev(`getComputedStyle(document.querySelector('#selector').shadowRoot.querySelector('[part~="button"]')).borderTopWidth`)) === '0px');
  503. // ---- tracker.worldapi.org#8: the old addresses answer a permanent redirect to the /my/ ones ----
  504. for (const [from, to] of [['/unwatched', '/my/unwatched'], ['/schedule', '/my/schedule']]) {
  505. const m = await fetch(BASE + from, { redirect: 'manual' });
  506. check(`${from} answers 301 → ${to}`, m.status === 301 && m.headers.get('location') === to, m.status + ' ' + m.headers.get('location'));
  507. }
  508. await page.goto(BASE + '/unwatched');
  509. await hydrated();
  510. check('the browser following /unwatched lands on /my/unwatched', (await ev(`location.pathname`)) === '/my/unwatched' && !!(await ev(`document.querySelector('unwatched-page')`)));
  511. // ---- tracker.worldapi.org#8: the show page says "1 episode" for one, "2 episodes" for two ----
  512. await page.goto(BASE + '/series/gate-test-show');
  513. await hydrated();
  514. check('show page: season counts "1 episode" (singular) and "2 episodes"', JSON.stringify(await ev(`Array.from(document.querySelectorAll('season-count')).map(e => e.textContent)`)) === JSON.stringify(['1 episode', '2 episodes']),
  515. JSON.stringify(await ev(`Array.from(document.querySelectorAll('season-count')).map(e => e.textContent)`)));
  516. let r = await fetch(BASE + '/login/callback', { redirect: 'manual' });
  517. check('login: /login/callback without a code → /login/failed', r.status === 302 && r.headers.get('location') === '/login/failed');
  518. // ---- sign in: the header selector flips to signed in, "Log out" appears, page stays empty ----
  519. await loginAs(alice);
  520. check('signed in: the selector is still in the header, now signed in', (await ev(`!!document.querySelector('#selector')`)) && (await ev(`document.querySelector('#selector').classList.contains('in')`)));
  521. check('signed in: "Log out" shows, no "Log in with ident"', (await ev(`!!document.querySelector('#logout')`)) && !(await ev(`!!document.querySelector('#loginbutton')`)));
  522. check('home signed in: five icon tiles (tracker#21) → /my/unwatched, /my/schedule, /my/series, /my/shows, /my/movies, each with a drawn svg icon; the text + the rows below them, no sign-in hint',
  523. (await ev(`Array.from(document.querySelectorAll('home-nav a.hometile')).map(a => a.textContent.trim() + ' ' + a.getAttribute('href') + ' ' + (a.querySelector('svg').namespaceURI === 'http://www.w3.org/2000/svg' && a.querySelector('svg').getBoundingClientRect().width > 30)).join(',')`))
  524. === 'Unwatched /my/unwatched true,Schedule /my/schedule true,Series /my/series true,Shows /my/shows true,Movies /my/movies true'
  525. && (await ev(`document.querySelector('home-nav').getBoundingClientRect().bottom <= document.querySelector('home-intro').getBoundingClientRect().top && document.querySelector('home-intro').getBoundingClientRect().bottom <= document.querySelector('#home-movies').getBoundingClientRect().top`))
  526. && !/Log in with ident/.test(await ev(`document.querySelector('home-intro').textContent`)) && (await ev(`document.querySelectorAll('#home-movies a.tile').length`)) === 10);
  527. await ev(`window.__w050 = 'same document'`);
  528. await page.click('a.hometile[href="/my/movies"]');
  529. await page.waitFor(`location.pathname === '/my/movies' && !!document.querySelector('my-movies-page')`, { timeout: 10000, label: 'icon → /my/movies' });
  530. check('home: the Movies icon leads to /my/movies (client-side, no reload); nothing followed yet → "You follow no movies yet."', (await ev('window.__w050')) === 'same document'
  531. && (await ev(`document.querySelector('my-movies-page p.muted').textContent`)) === 'You follow no movies yet.');
  532. check('"Log out" has no border (only inverted buttons have one)', (await ev(`getComputedStyle(document.querySelector('#logout')).borderTopWidth`)) === '0px');
  533. check('the ident selector\'s signed-in status has no border', (await ev(`(() => { const e = document.querySelector('#selector').shadowRoot.querySelector('[part~="status"]'); return e ? getComputedStyle(e).borderTopWidth : '0px' })()`)) === '0px');
  534. check('the header brand "tracker" has font weight 100', (await ev(`getComputedStyle(document.querySelector('application-header .brand')).fontWeight`)) === '100');
  535. // ---- tracker.worldapi.org#5: /unwatched signed IN — only already-released, unwatched episodes of
  536. // followed shows, newest release first; a click removes the row. Run BEFORE the show-page checks
  537. // below (which toggle these same fixture episodes watched) so all three still start unwatched here.
  538. await page.goto(BASE + '/my/unwatched');
  539. await hydrated();
  540. const unwatchedRowTexts = () => ev(`Array.from(document.querySelectorAll('.unwatched-show')).map(e => e.textContent)`);
  541. check('signed in: /my/unwatched lists only already-released episodes, newest release first (not the future one), titles with the year',
  542. JSON.stringify(await unwatchedRowTexts()) === JSON.stringify(['Gate Test Show (2024)', 'Gate Test Show (2024)'])
  543. && (await ev(`document.querySelectorAll('unwatched-row').length`)) === 2);
  544. check('signed in: /my/unwatched shows show title, the episode as S01E02 + title and release date, linking to the show',
  545. (await ev(`document.querySelector('unwatched-row unwatched-episode').textContent`)) === 'S01E02 · Second'
  546. && (await ev(`document.querySelector('unwatched-row unwatched-date').textContent`)) === '2020-06-15'
  547. && (await ev(`document.querySelector('unwatched-row .unwatched-show').getAttribute('href')`)) === '/series/gate-test-show');
  548. check('signed in: /my/unwatched starts with regular (unwatched) check icons', (await ev(`document.querySelectorAll('unwatched-row button.checkicon.regular').length`)) === 2);
  549. let looks = [await checkLook('unwatched-row:nth-of-type(1) button.checkicon'), await checkLook('unwatched-row:nth-of-type(2) button.checkicon')];
  550. check('#29: /my/unwatched — every row\'s check LOOKS empty on screen (muted outline, nothing filled, background pixel inside the disc)',
  551. looks.every(lookEmpty), JSON.stringify(looks));
  552. await page.click('unwatched-row button.checkicon');
  553. await page.waitFor(`document.querySelectorAll('unwatched-row').length === 1`, { timeout: 10000, label: 'unwatched row removed' });
  554. let once = await rowsOnce('unwatched-row button.checkicon');
  555. check('session-sync: after the /my/unwatched click (face unwatchedToggle) every row appears once', once.unique && once.n === 1, JSON.stringify(once));
  556. check('click an unwatched episode\'s check: it disappears from the list', (await ev(`document.querySelectorAll('unwatched-row').length`)) === 1
  557. && (await ev(`document.querySelector('unwatched-episode').textContent`)) === 'S01E01 · Pilot');
  558. await page.goto(BASE + '/my/unwatched');
  559. await hydrated();
  560. check('reload: the watch from /my/unwatched is server-side, not just client state', (await ev(`document.querySelectorAll('unwatched-row').length`)) === 1
  561. && (await ev(`document.querySelector('unwatched-episode').textContent`)) === 'S01E01 · Pilot');
  562. // ---- tracker.worldapi.org#7: /my/series signed IN — followed shows, newest follow first, small
  563. // poster, title linking to the show, the last watched episode (only ep 2 "Second" is watched so far)
  564. const myShows = () => ev(`Array.from(document.querySelectorAll('my-show-row')).map(r => ({
  565. title: r.querySelector('.myshow-title') && r.querySelector('.myshow-title').textContent,
  566. href: r.querySelector('.myshow-title') && r.querySelector('.myshow-title').getAttribute('href'),
  567. poster: r.querySelector('img.myshow-poster') && r.querySelector('img.myshow-poster').getAttribute('src'),
  568. posterLoaded: !!(r.querySelector('img.myshow-poster') && r.querySelector('img.myshow-poster').complete && r.querySelector('img.myshow-poster').naturalWidth > 0),
  569. episode: r.querySelector('my-show-episode') ? r.querySelector('my-show-episode').textContent : null }))`);
  570. const waitPostersLoaded = () => page.waitFor(`Array.from(document.querySelectorAll('img.myshow-poster')).every(i => i.complete && i.naturalWidth > 0)`, { timeout: 10000, label: 'posters loaded' });
  571. await page.goto(BASE + '/my/series');
  572. await hydrated();
  573. await waitPostersLoaded();
  574. let ms = await myShows();
  575. check('signed in: /my/series lists both followed shows, newest follow first, with the year (2025 from `release` — that show has no `year`)', JSON.stringify(ms.map(m => m.title)) === JSON.stringify(['Unwatched Gate Show (2025)', 'Gate Test Show (2024)']), JSON.stringify(ms));
  576. check('signed in: /my/series titles link to the show pages', ms.length === 2 && ms[0].href === '/series/unwatched-gate-show' && ms[1].href === '/series/gate-test-show', JSON.stringify(ms));
  577. check('signed in: /my/series shows a loaded poster per row (its own file, else the one placeholder URL /posters/none)', ms.length === 2 && ms.every(m => m.posterLoaded) && ms[1].poster === '/posters/sh1.png' && ms[0].poster === '/posters/none', JSON.stringify(ms));
  578. check('signed in: /my/series shows the last watched episode as S01E02, none for the never-watched show', ms.length === 2 && ms[1].episode === 'S01E02' && ms[0].episode === null, JSON.stringify(ms));
  579. check('/my/series: the poster is small (2.5rem wide)', (await ev(`getComputedStyle(document.querySelector('img.myshow-poster')).width`)) === '40px');
  580. // ---- tracker.worldapi.org#6: /schedule signed IN — only NOT-yet-released episodes of followed
  581. // shows, soonest first, no check icons at all (read-only page, unaffected by any watch toggle above)
  582. await page.goto(BASE + '/my/schedule');
  583. await hydrated();
  584. check('signed in: /my/schedule lists only the not-yet-released episode, title with the year', (await ev(`document.querySelectorAll('schedule-row').length`)) === 1
  585. && (await ev(`document.querySelector('.schedule-show').textContent`)) === 'Gate Test Show (2024)');
  586. check('signed in: /my/schedule shows show title, the episode as S02E01 + title, release date, linking to the show, no checks',
  587. (await ev(`document.querySelector('schedule-row schedule-episode').textContent`)) === 'S02E01 · Season Two Opener'
  588. && (await ev(`document.querySelector('schedule-row schedule-date').textContent`)) === '2099-01-01'
  589. && (await ev(`document.querySelector('schedule-row .schedule-show').getAttribute('href')`)) === '/series/gate-test-show'
  590. && (await ev(`document.querySelectorAll('schedule-row button.checkicon').length`)) === 0);
  591. // ---- tracker.worldapi.org#4: /shows/:slug signed IN — check icons, episode toggle, season toggle,
  592. // collapse/expand, and a reload proves the watch really is server-side ----
  593. const EP3 = 'ep0000000000ep0e3'; // season 2 (expanded by default), episode 1 "Season Two Opener"
  594. const EP1 = 'ep0000000000ep0e1'; // season 1 (collapsed by default), episode 1 "Pilot"
  595. const EP2 = 'ep0000000000ep0e2'; // season 1, episode 2 "Second"
  596. const SEASON1 = 'se000000000se0s1';
  597. const checkClass = (id) => ev(`document.querySelector('button.checkicon[value="${id}"]').getAttribute('class')`);
  598. const clickValue = (sel, id) => page.click(`${sel}[value="${id}"]`);
  599. await page.goto(BASE + '/series/gate-test-show');
  600. await hydrated();
  601. check('signed in: episode check icons show, starting "regular" (not watched)', (await checkClass(EP3)) === 'checkicon regular');
  602. looks = [await checkLook(`button.checkicon[value="${EP3}"]`), await checkLook(`button.checkicon[value="${SEASON1}"]`)];
  603. check('#29: show page — an unwatched episode\'s and an unwatched season\'s check LOOK empty on screen', looks.every(lookEmpty), JSON.stringify(looks));
  604. await clickValue('button.checkicon', EP3);
  605. await page.waitFor(`document.querySelector('button.checkicon[value="${EP3}"]').getAttribute('class') === 'checkicon solid'`, { timeout: 10000, label: 'ep3 solid' });
  606. check('click an episode check: it turns solid', (await checkClass(EP3)) === 'checkicon solid');
  607. looks = [await checkLook(`button.checkicon[value="${EP3}"]`)];
  608. check('#29: show page — the watched episode\'s check LOOKS solid on screen (accent pixel inside the disc)', looks.every(lookSolid), JSON.stringify(looks));
  609. check('season 1 starts collapsed (no episode rows of it yet)', (await ev(`document.querySelectorAll('episode-row').length`)) === 1);
  610. await clickValue('button.checkicon', SEASON1);
  611. await page.waitFor(`document.querySelector('button.checkicon[value="${SEASON1}"]').getAttribute('class') === 'checkicon solid'`, { timeout: 10000, label: 'season1 solid' });
  612. check('click a season check: the season itself turns solid', (await checkClass(SEASON1)) === 'checkicon solid');
  613. await clickValue('button.season-toggle', SEASON1);
  614. await page.waitForSelector(`button.checkicon[value="${EP1}"]`, { timeout: 10000 });
  615. check('expanding season 1 shows its episodes already solid (the season check watched them too)',
  616. (await checkClass(EP1)) === 'checkicon solid' && (await checkClass(EP2)) === 'checkicon solid');
  617. await page.goto(BASE + '/series/gate-test-show');
  618. await hydrated();
  619. check('reload: episode 3\'s watch is server-side, not just client state', (await checkClass(EP3)) === 'checkicon solid');
  620. await clickValue('button.season-toggle', SEASON1);
  621. await page.waitForSelector(`button.checkicon[value="${EP1}"]`, { timeout: 10000 });
  622. check('reload: season 1\'s bulk watch is server-side too', (await checkClass(EP1)) === 'checkicon solid' && (await checkClass(EP2)) === 'checkicon solid' && (await checkClass(SEASON1)) === 'checkicon solid');
  623. // ---- mission 047, the creator's additions on the show page (signed in) ----
  624. check('episodes are not indented: an episode\'s check is exactly under its season\'s check (same left edge)',
  625. (await ev(`Math.abs(document.querySelector('episode-row button.checkicon').getBoundingClientRect().left - document.querySelector('season-row button.checkicon').getBoundingClientRect().left) < 0.5`)));
  626. check('artist links are orange #ce9178 (not red)', (await ev(`getComputedStyle(document.querySelector('.artist-link')).color`)) === 'rgb(206, 145, 120)');
  627. // (mission 058 checked the unwatched look on a hidden COPY of a check here; tracker#29 checks REAL checks instead, above and
  628. // in the #23 block below, where an episode and its season really are unwatched)
  629. looks = [await checkLook(`button.checkicon[value="${SEASON1}"]`), await checkLook(`button.checkicon[value="${EP1}"]`)];
  630. check('a watched check is solid on screen: filled accent disc, dark check (season 1 + its episode 1)', looks.every(lookSolid), JSON.stringify(looks));
  631. // ---- tracker.worldapi.org#7: /my/series again — S02E01 was watched BEFORE season 1's bulk watch, so
  632. // this proves "last" = the highest season/episode watched, not the most recently watched one
  633. await page.goto(BASE + '/my/series');
  634. await hydrated();
  635. ms = await myShows();
  636. check('/my/series: the last episode is the HIGHEST watched (S02E01), not the most recent watch; the other show still none',
  637. ms.length === 2 && ms[1].episode === 'S02E01' && ms[0].episode === null, JSON.stringify(ms));
  638. // ---- mission 047 (the creator: "i dont see the check marks"): a CLIENT-SIDE navigation /my/series → click the show
  639. // title builds the show page in the browser; its check <svg> must be an SVG element (the old vendored build made it
  640. // in the XHTML namespace: nothing drawn, circle width 0). A window marker proves no full page load happened.
  641. await ev(`window.__w047 = 'same document'`);
  642. await page.click(`a.myshow-title[href="/series/gate-test-show"]`);
  643. await page.waitFor(`location.pathname === '/series/gate-test-show' && !!document.querySelector('button.checkicon svg circle')`, { timeout: 10000, label: 'show page after client-side navigation' });
  644. const svgNs = await ev(`JSON.stringify({ marker: window.__w047 || null, ns: document.querySelector('button.checkicon svg').namespaceURI,
  645. circleNs: document.querySelector('button.checkicon svg circle').namespaceURI,
  646. circleWidth: document.querySelector('button.checkicon svg circle').getBoundingClientRect().width })`);
  647. const sv = JSON.parse(svgNs);
  648. check('client-side navigation /my/series → show page: the check svg is in the SVG namespace and its circle is drawn (width > 0)',
  649. sv.marker === 'same document' && sv.ns === 'http://www.w3.org/2000/svg' && sv.circleNs === 'http://www.w3.org/2000/svg' && sv.circleWidth > 0, svgNs);
  650. lk = await extLinks();
  651. check('client-side navigation: the link icons are there too (TMDB + IMDb)', linksAre(lk, [['TMDB', TMDB_TV + '1001'], ['IMDb', IMDB + 'tt0000001/']]), lk);
  652. // mission 047 #11: the checks also vanished after expanding/collapsing a season — same cause; and the caret flips
  653. let cs = await carets();
  654. check('season caret at the header\'s right edge (tracker#17): UP for the open season 2, DOWN for the closed season 1',
  655. cs === JSON.stringify(['up', 'down']) && (await ev(`(() => { const r = document.querySelector('season-row'); return Math.abs(r.getBoundingClientRect().right - r.querySelector('season-caret').getBoundingClientRect().right) < 2 })()`)), cs);
  656. await clickValue('button.season-toggle', SEASON1);
  657. await page.waitForSelector(`button.checkicon[value="${EP1}"]`, { timeout: 10000 });
  658. let st = await svgState();
  659. cs = await carets();
  660. check('after EXPANDING season 1 (client-side): every check + caret is a drawn SVG, season 1\'s caret now points UP', svgOk(st) && cs === JSON.stringify(['up', 'up']), st + ' ' + cs);
  661. once = await rowsOnce('show-seasons button.checkicon');
  662. check('after EXPANDING (face showSeasonEpisodes) every season/episode row appears once (2 seasons + 3 episodes), no skeleton left', once.unique && once.n === 5 && (await ev(`document.querySelectorAll('skeleton-row').length`)) === 0, JSON.stringify(once));
  663. const airDates = () => ev(`JSON.stringify(Array.from(document.querySelectorAll('episode-row')).map(r => r.querySelector('episode-title').textContent + ' ' + r.querySelector('episode-date').textContent))`);
  664. let ad = await airDates();
  665. check('#22: an opened season\'s episodes (filled in the browser from showSeasonEpisodes) show their air dates too', ad === JSON.stringify(['Season Two Opener 2099-01-01', 'Pilot 2020-01-01', 'Second 2020-06-15']), ad);
  666. await clickValue('button.checkicon', EP1);
  667. await page.waitFor(`document.querySelector('button.checkicon[value="${EP1}"]').getAttribute('class') === 'checkicon regular'`, { timeout: 10000, label: 'ep1 regular' });
  668. st = await svgState();
  669. check('after an EPISODE click: every check is still a drawn SVG', svgOk(st), st);
  670. once = await rowsOnce('show-seasons button.checkicon');
  671. check('session-sync: after an EPISODE click (face showToggleEpisode) every row appears once', once.unique && once.n === 5, JSON.stringify(once));
  672. // ---- mission 058 (tracker#23): the season's check = ALL its episodes watched — live with the face's answer, and after a reload
  673. ad = await airDates();
  674. check('#23: season 1 was checked, episode 1 unchecked → the season check turns OFF at once (no reload); #22: the dates are still there',
  675. (await checkClass(SEASON1)) === 'checkicon regular' && (await checkClass(EP2)) === 'checkicon solid' && ad === JSON.stringify(['Season Two Opener 2099-01-01', 'Pilot 2020-01-01', 'Second 2020-06-15']), (await checkClass(SEASON1)) + ' ' + ad);
  676. const reloadOpenSeason1 = async () => {
  677. await page.goto(BASE + '/series/gate-test-show');
  678. await hydrated();
  679. await clickValue('button.season-toggle', SEASON1);
  680. await page.waitForSelector(`button.checkicon[value="${EP1}"]`, { timeout: 10000 });
  681. };
  682. await reloadOpenSeason1();
  683. check('#23: after a reload season 1 is still OFF (episode 1 unwatched, episode 2 watched)', (await checkClass(SEASON1)) === 'checkicon regular' && (await checkClass(EP1)) === 'checkicon regular' && (await checkClass(EP2)) === 'checkicon solid');
  684. looks = [await checkLook(`button.checkicon[value="${SEASON1}"]`), await checkLook(`button.checkicon[value="${EP1}"]`), await checkLook(`button.checkicon[value="${EP2}"]`)];
  685. check('#29: …and on screen: season 1 + episode 1 LOOK empty, episode 2 solid', lookEmpty(looks[0]) && lookEmpty(looks[1]) && lookSolid(looks[2]), JSON.stringify(looks));
  686. await clickValue('button.checkicon', EP1);
  687. await page.waitFor(`document.querySelector('button.checkicon[value="${EP1}"]').getAttribute('class') === 'checkicon solid'`, { timeout: 10000, label: 'ep1 solid again' });
  688. check('#23: checking episode 1 again → every episode of season 1 watched → the season check turns ON at once', (await checkClass(SEASON1)) === 'checkicon solid');
  689. once = await rowsOnce('show-seasons button.checkicon');
  690. check('#23: …every row once after it (hybriel#121)', once.unique && once.n === 5, JSON.stringify(once));
  691. await reloadOpenSeason1();
  692. check('#23: after a reload season 1 is ON (both episodes watched)', (await checkClass(SEASON1)) === 'checkicon solid' && (await checkClass(EP1)) === 'checkicon solid' && (await checkClass(EP2)) === 'checkicon solid');
  693. await clickValue('button.checkicon', EP2);
  694. await page.waitFor(`document.querySelector('button.checkicon[value="${SEASON1}"]').getAttribute('class') === 'checkicon regular'`, { timeout: 10000, label: 'season 1 off after ep2' });
  695. await clickValue('button.checkicon', SEASON1);
  696. await page.waitFor(`document.querySelector('button.checkicon[value="${SEASON1}"]').getAttribute('class') === 'checkicon solid'`, { timeout: 10000, label: 'season 1 on (partial → all)' }).catch(() => {});
  697. check('#23: a PARTLY watched season\'s check (episode 2 unchecked) watches the rest — season and both episodes ON',
  698. (await checkClass(SEASON1)) === 'checkicon solid' && (await checkClass(EP1)) === 'checkicon solid' && (await checkClass(EP2)) === 'checkicon solid');
  699. await clickValue('button.season-toggle', SEASON1);
  700. await page.waitFor(`!document.querySelector('button.checkicon[value="${EP1}"]')`, { timeout: 10000, label: 'season 1 collapsed' });
  701. st = await svgState();
  702. cs = await carets();
  703. check('after COLLAPSING season 1 again: every check + caret is a drawn SVG, its caret points DOWN again', svgOk(st) && cs === JSON.stringify(['up', 'down']), st + ' ' + cs);
  704. // ---- tracker#17: SKELETON rows while a season's episodes load. The face's frame is held back 1.5 s (`__delayFace`), so
  705. // the state right after the click is the one BEFORE the answer. Season 1 has 2 episodes → 2 skeleton rows.
  706. const skeletonState = () => ev(`JSON.stringify((() => { const sk = Array.from(document.querySelectorAll('skeleton-row'));
  707. const ep = document.querySelector('episode-row'), t = sk[0] && sk[0].querySelector('skeleton-title');
  708. return { n: sk.length, ep1: !!document.querySelector('button.checkicon[value="${EP1}"]'), anim: t ? getComputedStyle(t).animationName : null,
  709. parts: sk.every(r => r.querySelector('skeleton-check') && r.querySelector('skeleton-number') && r.querySelector('skeleton-title')),
  710. h: sk[0] ? Math.round(sk[0].getBoundingClientRect().height) : 0, epH: ep ? Math.round(ep.getBoundingClientRect().height) : 0,
  711. checkW: sk[0] ? Math.round(sk[0].querySelector('skeleton-check').getBoundingClientRect().width) : 0,
  712. afterSeason1: sk[0] ? sk[0].previousElementSibling.querySelector('button.season-toggle').value === '${SEASON1}' : false }; })())`).then(JSON.parse);
  713. const delayFace = (ms) => ev(`window.__delayFace = ${ms ? `{ name: 'showSeasonEpisodes', ms: ${ms} }` : 'null'}`);
  714. for (const [w, h, mobile] of [[390, 844, true], [1280, 900, false]]) {
  715. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: mobile ? 2 : 1, mobile });
  716. await delayFace(1500);
  717. await clickValue('button.season-toggle', SEASON1);
  718. await page.waitFor(`document.querySelectorAll('skeleton-row').length > 0`, { timeout: 1000, label: 'skeleton' }).catch(() => {});
  719. await ev(`document.querySelector('skeleton-row') && document.querySelector('skeleton-row').scrollIntoView({ block: 'center' })`);
  720. let sk = await skeletonState();
  721. cs = await carets();
  722. check(`${w} px (tracker#17): right after the click, before the answer — 2 skeleton rows (season 1 has 2 episodes) under season 1, in the episode row's shape (check disc, number, title; same height), shimmering; no episode yet; caret already UP`,
  723. sk.n === 2 && !sk.ep1 && sk.anim === 'tracker-shimmer' && sk.parts && Math.abs(sk.h - sk.epH) <= 1 && sk.checkW === 32 && sk.afterSeason1 && cs === JSON.stringify(['up', 'up']), JSON.stringify(sk) + ' ' + cs);
  724. if (process.env.TRACKER_GATE_SHOTS) { mkdirSync(process.env.TRACKER_GATE_SHOTS, { recursive: true }); writeFileSync(join(process.env.TRACKER_GATE_SHOTS, `show-skeleton-${w}.png`), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64')); }
  725. await page.waitForSelector(`button.checkicon[value="${EP1}"]`, { timeout: 10000 });
  726. sk = await skeletonState();
  727. once = await rowsOnce('show-seasons button.checkicon');
  728. check(`${w} px (tracker#17): after the answer the skeleton is gone and the real rows are there once each (2 seasons + 3 episodes, hybriel#121), still solid`,
  729. sk.n === 0 && once.unique && once.n === 5 && (await checkClass(EP1)) === 'checkicon solid' && (await checkClass(EP2)) === 'checkicon solid', JSON.stringify(sk) + ' ' + JSON.stringify(once));
  730. if (process.env.TRACKER_GATE_SHOTS) writeFileSync(join(process.env.TRACKER_GATE_SHOTS, `show-open-${w}.png`), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  731. await clickValue('button.season-toggle', SEASON1);
  732. await page.waitFor(`!document.querySelector('button.checkicon[value="${EP1}"]')`, { timeout: 10000, label: 'season 1 closed' });
  733. if (process.env.TRACKER_GATE_SHOTS) writeFileSync(join(process.env.TRACKER_GATE_SHOTS, `show-closed-${w}.png`), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  734. }
  735. await page.send('Emulation.clearDeviceMetricsOverride', {});
  736. // closed again WHILE loading: the late answer must not bring the rows back
  737. const sent0 = (await page.wsSent()).length;
  738. await delayFace(1200);
  739. await clickValue('button.season-toggle', SEASON1);
  740. await page.waitFor(`document.querySelectorAll('skeleton-row').length === 2`, { timeout: 1000, label: 'skeleton 2' }).catch(() => {});
  741. await clickValue('button.season-toggle', SEASON1);
  742. await new Promise(r => setTimeout(r, 1800));
  743. once = await rowsOnce('show-seasons button.checkicon');
  744. cs = await carets();
  745. check('tracker#17: a season closed again while loading stays closed after the late answer (only season 2\'s episode, no skeleton, caret down)',
  746. once.n === 3 && !once.values.includes(EP1) && (await ev(`document.querySelectorAll('skeleton-row').length`)) === 0 && cs === JSON.stringify(['up', 'down']), JSON.stringify(once) + ' ' + cs);
  747. await delayFace(0);
  748. // closing asks the server nothing; opening sends exactly the one sessionless face (no showRows)
  749. const sentNow = (await page.wsSent()).slice(sent0);
  750. check('tracker#17: opening sends only showSeasonEpisodes (never the session face showRows), closing sends nothing',
  751. sentNow.filter(f => f.includes('showSeasonEpisodes')).length === 1 && !sentNow.some(f => f.includes('showRows')), JSON.stringify(sentNow));
  752. // ---- mission 047 #12: FOLLOW on the show page — "Following" filled; a click unfollows ("Follow", outlined in the
  753. // accent), the show leaves /my/series; a click follows again (follow date = now) → the top of /my/series; reloads keep it
  754. const followState = () => ev(`JSON.stringify((() => { const b = document.querySelector('#follow'); const c = getComputedStyle(b);
  755. return { text: b.textContent, cls: b.getAttribute('class'), bg: c.backgroundColor, border: c.borderTopWidth + ' ' + c.borderTopColor }; })())`);
  756. let fs = JSON.parse(await followState());
  757. check('follow: alice follows the show → "Following", the filled accent button (no border)', fs.text === 'Following' && fs.cls === 'follow' && fs.bg === 'rgb(78, 201, 176)' && fs.border.startsWith('0px'), JSON.stringify(fs));
  758. await page.click('#follow');
  759. await page.waitFor(`document.querySelector('#follow').textContent === 'Follow'`, { timeout: 10000, label: 'unfollowed' }).catch(() => {});
  760. fs = JSON.parse(await followState());
  761. check('follow: a click unfollows → "Follow", outlined (1px accent border, transparent)', fs.text === 'Follow' && fs.cls === 'follow inverted' && fs.border === '1px rgb(78, 201, 176)' && fs.bg === 'rgba(0, 0, 0, 0)', JSON.stringify(fs));
  762. await page.goto(BASE + '/series/gate-test-show');
  763. await hydrated();
  764. check('follow: the unfollow survives a reload', (await ev(`document.querySelector('#follow').textContent`)) === 'Follow');
  765. await page.goto(BASE + '/my/series');
  766. await hydrated();
  767. ms = await myShows();
  768. check('follow: the unfollowed show is gone from /my/series', ms.length === 1 && ms[0].href === '/series/unwatched-gate-show', JSON.stringify(ms));
  769. await page.goto(BASE + '/series/gate-test-show');
  770. await hydrated();
  771. await page.click('#follow');
  772. await page.waitFor(`document.querySelector('#follow').textContent === 'Following'`, { timeout: 10000, label: 'followed' }).catch(() => {});
  773. check('follow: a click follows again → "Following"', (await ev(`document.querySelector('#follow').textContent`)) === 'Following');
  774. await new Promise(r => setTimeout(r, 400));
  775. check('session-sync: after the Follow toggles (face showToggleFollow) ONE Follow button, one show header, every season row once',
  776. (await ev(`document.querySelectorAll('#follow').length === 1 && document.querySelectorAll('show-header').length === 1`)) && (await rowsOnce('season-row button.checkicon')).unique);
  777. await page.goto(BASE + '/my/series');
  778. await hydrated();
  779. ms = await myShows();
  780. check('follow: followed just now → the TOP of /my/series (newest follow first), after a reload', ms.length === 2 && ms[0].href === '/series/gate-test-show' && ms[1].href === '/series/unwatched-gate-show', JSON.stringify(ms));
  781. await page.goto(BASE + '/series/gate-test-show');
  782. await hydrated();
  783. check('follow: "Following" survives a reload', (await ev(`document.querySelector('#follow').textContent`)) === 'Following');
  784. // ==== tracker.worldapi.org#13: /movies, /shows (24 per page, the copied pagination, the page in the PATH) and
  785. // /my/movies (the Follow button on a movie's page) ====
  786. await page.goto(BASE + '/');
  787. await hydrated();
  788. await ev(`window.__w050 = 'same document'`);
  789. await page.click('#home-movies h2 a');
  790. await page.waitFor(`location.pathname === '/movies' && document.querySelectorAll('a.tile').length === 24`, { timeout: 10000, label: 'heading → /movies' });
  791. let titles = await titlesOf('tile-grid');
  792. check('/movies (the homepage heading, client-side): page 1 = 24 movies, release date desc — the 2099 one first, then Pager Movie 30…08',
  793. (await ev('window.__w050')) === 'same document' && JSON.stringify(titles) === JSON.stringify(['Pager Future Movie', ...movieRange(30, 8)]), JSON.stringify(titles));
  794. let pg = await pagerState();
  795. check('/movies: the pagination says "1 2 Next", 1 current (no Previous on the first page); "33 movies … page 1 of 2"',
  796. JSON.stringify(pg) === JSON.stringify({ items: ['1', '2', 'Next'], current: '1' }) && /^33 movies, newest first · page 1 of 2$/.test(await ev(`document.querySelector('.list-count').textContent`)), JSON.stringify(pg));
  797. await ev(`Array.from(document.querySelectorAll('pagination button')).find(b => b.textContent.trim() === 'Next').click()`);
  798. await page.waitFor(`location.pathname === '/movies/page/2' && document.querySelectorAll('a.tile').length === 9`, { timeout: 10000, label: 'Next → page 2' });
  799. titles = await titlesOf('tile-grid');
  800. pg = await pagerState();
  801. check('/movies "Next": the address is /movies/page/2 (client-side), the last 9: Pager Movie 07…01, the 1996 fixture movie, the undated one last; "Previous 1 2", 2 current; title says page 2',
  802. (await ev('window.__w050')) === 'same document' && JSON.stringify(titles) === JSON.stringify([...movieRange(7, 1), 'Gate Test Movie', 'Pager Undated Movie'])
  803. && JSON.stringify(pg) === JSON.stringify({ items: ['Previous', '1', '2'], current: '2' }) && (await ev('document.title')) === 'Movies, page 2 — tracker', JSON.stringify({ titles, pg }));
  804. await ev(`Array.from(document.querySelectorAll('pagination button')).find(b => b.textContent.trim() === '1').click()`);
  805. await page.waitFor(`location.pathname === '/movies' && document.querySelectorAll('a.tile').length === 24`, { timeout: 10000, label: '1 → /movies' });
  806. check('/movies: the page number "1" goes back to /movies (page 1)', (await pagerState()).current === '1' && (await titlesOf('tile-grid'))[0] === 'Pager Future Movie');
  807. await ev('history.back()');
  808. await page.waitFor(`location.pathname === '/movies/page/2' && document.querySelectorAll('a.tile').length === 9`, { timeout: 10000, label: 'Back → page 2' });
  809. check('/movies: the browser\'s Back returns to /movies/page/2 with page 2 shown', (await pagerState()).current === '2' && (await ev('window.__w050')) === 'same document');
  810. await page.goto(BASE + '/movies/page/2');
  811. await hydrated();
  812. check('/movies/page/2 loaded directly: the same 9 movies, 2 current', (await ev(`document.querySelectorAll('a.tile').length`)) === 9 && (await pagerState()).current === '2');
  813. await page.goto(BASE + '/movies/page/99');
  814. await hydrated();
  815. const p99 = await pagerState();
  816. await page.goto(BASE + '/movies/page/abc');
  817. await hydrated();
  818. check('/movies: a page past the end shows the last page, a page that is no number the first', p99.current === '2' && (await pagerState()).current === '1');
  819. await page.goto(BASE + '/');
  820. await hydrated();
  821. await ev(`window.__w050 = 'same document'`);
  822. await page.click('#home-series h2 a');
  823. await page.waitFor(`location.pathname === '/series' && !!document.querySelector('tile-grid a.tile')`, { timeout: 10000, label: 'heading → /series' });
  824. tl = await tilesOf('tile-grid');
  825. check('/series (the homepage heading): every series (no movies) by newest released episode, the one with none released last; one page → no pagination at all',
  826. (await ev('window.__w050')) === 'same document' && JSON.stringify(tl.map(t => t.split('|')[0])) === JSON.stringify(['Pager Older Series', 'Gate Test Show', 'Unwatched Gate Show'])
  827. && (await ev(`document.querySelectorAll('pagination').length`)) === 0, JSON.stringify(tl));
  828. // ---- mission 058 (tracker#25): /genres/<genre> — the /movies list narrowed to a genre, movies AND series, newest first, 24
  829. // per page, adult hidden. Action: Pager Future Movie (2099), Pager Older Series (series, newest episode 2021-01-01), Pager Movie
  830. // 30…01 (2001) = 32; Hidden Action Film (adult, 2050) never
  831. await page.goto(BASE + '/genres/Action');
  832. await hydrated();
  833. await ev(`window.__w058 = 'same document'`);
  834. tl = await tilesOf('tile-grid');
  835. pg = await pagerState();
  836. check('#25 /genres/Action: h1 "Action", "32 titles, newest first · page 1 of 2", 24 tiles newest first — movies AND the series, each poster + title + year → its page; the adult one is not there',
  837. (await ev(`document.querySelector('#genre-page h1 type-name').textContent`)) === 'Action' && (await ev(`document.querySelector('.list-count').textContent`)) === '32 titles, newest first · page 1 of 2'
  838. && JSON.stringify(tl.map(t => t.split('|')[0])) === JSON.stringify(['Pager Future Movie', 'Pager Older Series', ...movieRange(30, 9)])
  839. && tl[1] === 'Pager Older Series|2019|/series/pager-older-series|/posters/none' && !tl.some(t => t.includes('Hidden Action')) && JSON.stringify(pg) === JSON.stringify({ items: ['1', '2', 'Next'], current: '1' }), JSON.stringify({ tl, pg }));
  840. await ev(`Array.from(document.querySelectorAll('pagination button')).find(b => b.textContent.trim() === 'Next').click()`);
  841. await page.waitFor(`location.pathname === '/genres/Action/page/2' && document.querySelectorAll('a.tile').length === 8`, { timeout: 10000, label: 'genre Next → page 2' }).catch(() => {});
  842. titles = await titlesOf('tile-grid');
  843. check('#25: "Next" → /genres/Action/page/2 (client-side): the last 8 (Pager Movie 08…01), "Previous 1 2", title "Action, page 2 — tracker"',
  844. (await ev('window.__w058')) === 'same document' && (await ev('location.pathname')) === '/genres/Action/page/2' && JSON.stringify(titles) === JSON.stringify(movieRange(8, 1))
  845. && JSON.stringify(await pagerState()) === JSON.stringify({ items: ['Previous', '1', '2'], current: '2' }) && (await ev('document.title')) === 'Action, page 2 — tracker', JSON.stringify(titles));
  846. await page.goto(BASE + '/genres/Action/page/2');
  847. await hydrated();
  848. check('#25: /genres/Action/page/2 loaded directly: the same 8, 2 current', JSON.stringify(await titlesOf('tile-grid')) === JSON.stringify(movieRange(8, 1)) && (await pagerState()).current === '2');
  849. const g301 = await fetch(BASE + '/genre/Action', { redirect: 'manual' });
  850. check('#25: the old pill address /genre/Action answers 301 → /genres/Action', g301.status === 301 && g301.headers.get('location') === '/genres/Action', g301.status + ' ' + g301.headers.get('location'));
  851. await page.goto(BASE + '/series/gate-test-show');
  852. await hydrated();
  853. await ev(`window.__w058 = 'same document'`);
  854. await page.click('.genre-pill');
  855. await page.waitFor(`location.pathname === '/genres/Drama' && !!document.querySelector('#genre-page h1')`, { timeout: 10000, label: 'pill → /genres/Drama' });
  856. tl = await tilesOf('tile-grid');
  857. check('#25: the show page\'s "Drama" pill opens /genres/Drama (client-side): the one Drama title, no pagination',
  858. (await ev('window.__w058')) === 'same document' && JSON.stringify(tl) === JSON.stringify(['Gate Test Show|2024|/series/gate-test-show|/posters/sh1.png']) && (await ev(`document.querySelectorAll('pagination').length`)) === 0, JSON.stringify(tl));
  859. await page.goto(BASE + '/genres/No-Such-Genre');
  860. await hydrated();
  861. check('#25: an unknown genre says "Not found", no tiles', (await ev(`document.querySelector('#genre-page h1').textContent`)) === 'Not found' && (await ev(`document.querySelectorAll('a.tile').length`)) === 0);
  862. await page.goto(BASE + '/series');
  863. await hydrated();
  864. await ev(`window.__w050 = 'same document'`);
  865. // a movie's page has the Follow button (the show page) → /my/movies; /my/series stays series only
  866. await page.click('a.tile[href="/series/gate-test-show"]');
  867. await page.waitFor(`location.pathname === '/series/gate-test-show' && !!document.querySelector('#follow')`, { timeout: 10000, label: 'tile → show page' });
  868. check('/series: a tile opens the show page (client-side)', (await ev('window.__w050')) === 'same document');
  869. await page.goto(BASE + '/movies/gate-test-movie');
  870. await hydrated();
  871. check('a movie\'s page has the Follow button ("Follow": alice does not follow it yet)', (await ev(`document.querySelector('#follow').textContent`)) === 'Follow');
  872. await page.click('#follow');
  873. await page.waitFor(`document.querySelector('#follow').textContent === 'Following'`, { timeout: 10000, label: 'movie followed' }).catch(() => {});
  874. // ---- mission 058 (tracker#24): the movie's watched check, signed in — a click marks it watched, a reload keeps it ----
  875. mw = await movieWatch();
  876. check('#24 signed in: the movie starts "Not watched" (regular check)', mw && mw.cls === 'checkicon regular' && mw.label === 'Not watched', JSON.stringify(mw));
  877. looks = [await checkLook('#moviewatch')];
  878. check('#29: movie page — the unwatched movie\'s check LOOKS empty on screen', looks.every(lookEmpty), JSON.stringify(looks));
  879. await page.click('#moviewatch');
  880. await page.waitFor(`document.querySelector('#moviewatch').getAttribute('class') === 'checkicon solid'`, { timeout: 10000, label: 'movie watched' }).catch(() => {});
  881. await new Promise(r => setTimeout(r, 400));
  882. mw = await movieWatch();
  883. check('#24 signed in: a click → the solid check and "Watched" (one check, no modal)', mw && mw.cls === 'checkicon solid' && mw.label === 'Watched' && mw.n === 1 && !(await modalOpen()), JSON.stringify(mw));
  884. await page.goto(BASE + '/movies/gate-test-movie');
  885. await hydrated();
  886. mw = await movieWatch();
  887. check('#24 signed in: the watch survives a reload', mw && mw.cls === 'checkicon solid' && mw.label === 'Watched', JSON.stringify(mw));
  888. looks = [await checkLook('#moviewatch')];
  889. check('#29: movie page — the watched movie\'s check LOOKS solid on screen', looks.every(lookSolid), JSON.stringify(looks));
  890. await page.click('#moviewatch');
  891. await page.waitFor(`document.querySelector('#moviewatch').getAttribute('class') === 'checkicon regular'`, { timeout: 10000, label: 'movie unwatched' }).catch(() => {});
  892. mw = await movieWatch();
  893. const mwOff = mw && mw.cls === 'checkicon regular' && mw.label === 'Not watched';
  894. await page.goto(BASE + '/movies/gate-test-movie');
  895. await hydrated();
  896. mw = await movieWatch();
  897. check('#24 signed in: a second click unchecks it ("Not watched"), also after a reload', mwOff && mw && mw.cls === 'checkicon regular', JSON.stringify(mw));
  898. await page.click('#moviewatch');
  899. await page.waitFor(`document.querySelector('#moviewatch').getAttribute('class') === 'checkicon solid'`, { timeout: 10000, label: 'movie watched again' }).catch(() => {});
  900. if (process.env.TRACKER_GATE_SHOTS) {
  901. for (const [w, h, mobile] of [[390, 844, true], [1280, 900, false]]) {
  902. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: mobile ? 2 : 1, mobile });
  903. await page.goto(BASE + '/movies/gate-test-movie');
  904. await hydrated();
  905. writeFileSync(join(process.env.TRACKER_GATE_SHOTS, `movie-watched-${w}.png`), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  906. }
  907. await page.send('Emulation.clearDeviceMetricsOverride', {});
  908. }
  909. await page.goto(BASE + '/my/movies');
  910. await hydrated();
  911. const mmWatched = await ev(`JSON.stringify({ count: (document.querySelector('#mymovies-count') || {}).textContent, marks: Array.from(document.querySelectorAll('my-show-row')).map(r => !!r.querySelector('my-movie-watched svg circle')) })`).then(JSON.parse);
  912. check('#24: /my/movies counts it — "1 movie · 1 watched", the row has the solid check', mmWatched.count === '1 movie · 1 watched' && JSON.stringify(mmWatched.marks) === '[true]', JSON.stringify(mmWatched));
  913. looks = [await checkLook('my-movie-watched.checkicon')];
  914. check('#29: /my/movies — the watched movie\'s mark LOOKS solid on screen (an unwatched movie has no mark, #24)', looks.every(lookSolid), JSON.stringify(looks));
  915. const myMovies = await ev(`JSON.stringify(Array.from(document.querySelectorAll('my-show-row')).map(r => [r.querySelector('a.myshow-title').textContent, r.querySelector('a.myshow-title').getAttribute('href'), r.querySelector('img.myshow-poster').getAttribute('src')].join('|')))`);
  916. check('/my/movies: the movie alice just followed — title with year, its page, the poster (placeholder URL)', myMovies === JSON.stringify(['Gate Test Movie (1996)|/movies/gate-test-movie|/posters/none']), myMovies);
  917. await page.goto(BASE + '/my/series');
  918. await hydrated();
  919. ms = await myShows();
  920. check('/my/series stays SERIES only: the followed movie is not there', ms.length === 2 && ms.every(m => m.href !== '/movies/gate-test-movie'), JSON.stringify(ms));
  921. // ---- mission 047, MOBILE FIRST: at a phone's 390 px the header is ONE row (brand + ident selector + "Log out"), and
  922. // no page scrolls sideways; at 1280 px the same pages. Screenshots of both widths with TRACKER_GATE_SHOTS.
  923. const pages = [['home', '/'], ['show', '/series/gate-test-show'], ['my-shows', '/my/series'], ['my-unwatched', '/my/unwatched'], ['my-schedule', '/my/schedule'],
  924. ['movies', '/movies'], ['movies-page-2', '/movies/page/2'], ['series-list', '/series'], ['shows-list', '/shows'], ['my-shows-kind', '/my/shows'], ['my-movies', '/my/movies'], ['search', '/search/gate'],
  925. ['genre-action', '/genres/Action'], ['genre-action-page-2', '/genres/Action/page/2'], ['movie', '/movies/gate-test-movie']];
  926. if (process.env.TRACKER_GATE_SHOTS) mkdirSync(process.env.TRACKER_GATE_SHOTS, { recursive: true });
  927. for (const [w, h, mobile] of [[390, 844, true], [1280, 900, false]]) {
  928. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: mobile ? 2 : 1, mobile });
  929. const bad = [];
  930. for (const [name, path] of pages) {
  931. await page.goto(BASE + path);
  932. await hydrated();
  933. const m = JSON.parse(await ev(`JSON.stringify((() => {
  934. const hd = document.querySelector('application-header').getBoundingClientRect();
  935. const mid = (s) => { const r = document.querySelector(s).getBoundingClientRect(); return r.top + r.height / 2; };
  936. const mids = ['application-header .brand', '#selector', '#logout'].map(mid);
  937. const wd = (s) => Math.round(document.querySelector(s).getBoundingClientRect().width);
  938. return { headerH: hd.height, spread: Math.max(...mids) - Math.min(...mids), scrollW: document.documentElement.scrollWidth, widths: ['application-header .brand', '#userbox', '#selector', '#logout'].map(wd) };
  939. })())`));
  940. if (m.spread > 8 || m.headerH > 64 || m.scrollW > w) bad.push(name + ' ' + JSON.stringify(m));
  941. if (name === 'show') {
  942. // mission 047 #8: phone = title first, then the poster at the full content width, then genres/plot/cast;
  943. // desktop unchanged = poster left (10rem), title right of it
  944. const L = JSON.parse(await ev(`JSON.stringify((() => { const b = (s) => { const r = document.querySelector(s).getBoundingClientRect(); return { l: r.left, r: r.right, t: r.top, b: r.bottom, w: r.width }; };
  945. const main = document.querySelector('main'); const cs = getComputedStyle(main);
  946. return { h1: b('show-header h1'), follow: b('#follow'), links: b('show-links'), poster: b('show-poster img'), genres: b('show-genres'), summary: b('show-summary'), cast: b('show-cast'),
  947. content: main.getBoundingClientRect().width - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight) }; })())`));
  948. const ok = mobile
  949. ? L.h1.b <= L.links.t && L.links.b <= L.poster.t && Math.abs(L.poster.w - L.content) < 1 && L.poster.b <= L.genres.t && L.genres.b <= L.summary.t && L.summary.b <= L.cast.t && L.follow.t < L.poster.t
  950. : Math.abs(L.poster.w - 160) < 1 && L.poster.r <= L.h1.l && L.h1.t < L.poster.b && L.poster.t <= L.genres.t && L.poster.r <= L.links.l && L.h1.b <= L.links.t && L.links.b <= L.genres.t;
  951. check(`${w} px: show page layout — ${mobile ? 'title (+ Follow) first, the link icons under it, then the poster at the full content width, then genres, plot, cast' : 'poster left (10rem), the title right of it, the link icons under the title'}`, ok, JSON.stringify(L));
  952. }
  953. if (process.env.TRACKER_GATE_SHOTS) {
  954. if (name === 'my-shows' || name === 'my-movies') await waitPostersLoaded();
  955. // #13: every poster tile in view loaded
  956. await page.waitFor(`Array.from(document.querySelectorAll('img.tile-poster')).filter(i => { const r = i.getBoundingClientRect(); return r.top < innerHeight && r.bottom > 0 && r.left < innerWidth && r.right > 0 }).every(i => i.complete && i.naturalWidth > 0)`, { timeout: 10000, label: 'tiles loaded' });
  957. const shot = await page.send('Page.captureScreenshot', { format: 'png' });
  958. writeFileSync(join(process.env.TRACKER_GATE_SHOTS, `${name}-${w}.png`), Buffer.from(shot.data, 'base64'));
  959. }
  960. }
  961. check(`${w} px: on every page the header is one row (brand, ident selector, "Log out" side by side, ≤ 64 px high) and nothing scrolls sideways`, bad.length === 0, bad.join('; '));
  962. }
  963. await page.send('Emulation.clearDeviceMetricsOverride', {});
  964. // ==== tracker.worldapi.org#9: THE TMDB SYNC, against the fake TMDB — first the tool (app stopped: hl:mpackdb is
  965. // one process per storage), twice (idempotent), then the pages; then the app's own daily run ====
  966. check('sync: the app ran with the daily sync switched off until now (TRACKER_SYNC=0), no TMDB request yet', log.includes('tmdb sync: off (TRACKER_SYNC=0)') && tmdb.requests.length === 0, log);
  967. await page.goto('about:blank'); // leave the app first: an open page would log websocket reconnect errors
  968. await stopServer();
  969. // spawned, not execFileSync: the fake TMDB lives in THIS node process and must keep answering meanwhile
  970. const runTool = () => new Promise((ok) => {
  971. const p = spawn(join(APP, 'bin/hybriel'), ['tools/sync-tmdb.hl', '--limit', '5'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: MPACKDB, ...TMDB_ENV }, stdio: ['ignore', 'pipe', 'pipe'] });
  972. let o = '';
  973. p.stdout.on('data', d => o += d); p.stderr.on('data', d => o += d);
  974. p.on('exit', () => ok(o));
  975. });
  976. let out = await runTool();
  977. let done = (out.match(/tmdb sync done: .*/) || [''])[0];
  978. check('sync tool: 3 followed shows (2 series + a movie another user follows) → 2 new seasons (show 1 S3, show 2 S1), 4 new episodes, the 3 fixture episodes updated (tmdbId by S/E number, E2 renamed), 3 posters, 5 ids filled, 3 TVmaze lookups + 2 TVmaze episode lists (#15: they agree with TMDB → nothing taken), 0 errors',
  979. done.includes('shows=3 newSeasons=2 newEpisodes=4 updatedEpisodes=3') && done.includes('posters=3 ids=5') && done.includes('tvmazeRequests=5 errors=0 tvmazeEpisodes=0 tvmazeSeasons=0 tvmazeFilled=0 tvmazeSkipped=0'), out);
  980. // per show, in this order (the order BETWEEN shows follows the follow table, which the follow test above reshuffled)
  981. const perShow = [['/3/tv/1001?append_to_response=external_ids', '/3/tv/1001?append_to_response=season/1,season/2,season/3', '/t/p/w342/gate1.png'],
  982. ['/3/tv/1002?append_to_response=external_ids', '/3/tv/1002?append_to_response=season/1', '/t/p/w342/gate2.png'], ['/3/movie/1003?append_to_response=external_ids', '/t/p/w342/gate3.png']];
  983. const paths = tmdb.requests.map(q => q.path);
  984. check('sync tool: every TMDB call carried the Bearer token, season 0 was never asked for; per show ONE details request that also brings external_ids (no extra request), one for its seasons, the poster; the movie only via /movie/, never /tv/1003',
  985. tmdb.requests.filter(q => q.path.startsWith('/3/')).every(q => q.authorization === 'Bearer gate-token') && !paths.some(p => p.includes('season/0'))
  986. && JSON.stringify([...paths].sort()) === JSON.stringify(perShow.flat().sort()) && perShow.every(list => list.every((p, i) => i === 0 || paths.indexOf(list[i - 1]) < paths.indexOf(p))),
  987. JSON.stringify(paths));
  988. check('sync tool: TVmaze asked only for shows without a TVmaze id: show 1 by imdb (hit), show 2 by imdb (404) then by thetvdb (hit); then (#15) each series\' episode list by the found id; never for the movie',
  989. JSON.stringify([...tmdb.tvmazeRequests].sort()) === JSON.stringify(['/tvmaze/lookup/shows?imdb=tt0000001', '/tvmaze/lookup/shows?imdb=tt0000002', '/tvmaze/lookup/shows?thetvdb=4002', '/tvmaze/shows/501', '/tvmaze/shows/502', '/tvmaze/shows/501/episodes', '/tvmaze/shows/502/episodes'].sort()),
  990. JSON.stringify(tmdb.tvmazeRequests));
  991. const tvmazeBefore = tmdb.tvmazeRequests.length;
  992. out = await runTool();
  993. done = (out.match(/tmdb sync done: .*/) || [''])[0];
  994. check('sync tool again: idempotent — nothing new, nothing updated, no poster downloaded again, no id filled, no TVmaze lookup (every show has its TVmaze id now) — only the 2 episode lists, nothing taken from them',
  995. done.includes('newSeasons=0 newEpisodes=0 updatedEpisodes=0 updatedSeasons=0 posters=0 ids=0') && done.includes('tvmazeRequests=2 errors=0 tvmazeEpisodes=0 tvmazeSeasons=0 tvmazeFilled=0 tvmazeSkipped=0')
  996. && JSON.stringify(tmdb.tvmazeRequests.slice(tvmazeBefore).sort()) === JSON.stringify(['/tvmaze/shows/501/episodes', '/tvmaze/shows/502/episodes']), out);
  997. await startServer();
  998. await page.goto(BASE + '/my/schedule');
  999. await hydrated();
  1000. const scheduleRows = () => ev(`Array.from(document.querySelectorAll('schedule-row')).map(r => r.querySelector('.schedule-show').textContent + ' | ' + r.querySelector('schedule-episode').textContent + ' | ' + r.querySelector('schedule-date').textContent)`);
  1001. let rows = await scheduleRows();
  1002. check('after the sync: /my/schedule lists the new upcoming episodes of both shows, soonest first', JSON.stringify(rows) === JSON.stringify([
  1003. 'Unwatched Gate Show (2025) | S01E01 · Brand New | 2097-01-01', 'Gate Test Show (2024) | S03E02 · Coming Soon | 2098-06-01', 'Gate Test Show (2024) | S02E01 · Season Two Opener | 2099-01-01']), JSON.stringify(rows));
  1004. await page.goto(BASE + '/my/unwatched');
  1005. await hydrated();
  1006. rows = await ev(`Array.from(document.querySelectorAll('unwatched-row')).map(r => r.querySelector('unwatched-episode').textContent + ' | ' + r.querySelector('unwatched-date').textContent)`);
  1007. check('after the sync: /my/unwatched lists the newly released episodes (S03E01, S01E03), newest first', JSON.stringify(rows) === JSON.stringify(['S03E01 · Third Season Start | 2021-05-05', 'S01E03 · Third | 2020-09-01']), JSON.stringify(rows));
  1008. await page.goto(BASE + '/my/series');
  1009. await hydrated();
  1010. await waitPostersLoaded();
  1011. ms = await myShows();
  1012. check('after the sync: /my/series shows both real posters (/posters/sh2.png is new), loaded', ms.length === 2 && ms.every(m => m.posterLoaded) && ms[0].poster === '/posters/sh1.png' && ms[1].poster === '/posters/sh2.png', JSON.stringify(ms));
  1013. r = await fetch(BASE + '/posters/sh2.png');
  1014. const posterBytes = Buffer.from(await r.arrayBuffer());
  1015. check('the downloaded poster is served by /posters/… byte for byte (image/png), stored in storage (mpackdb/posters/)', r.status === 200 && r.headers.get('content-type') === 'image/png' && posterBytes.equals(PNG) && existsSync(join(MPACKDB, 'posters', 'sh2.png')));
  1016. await page.goto(BASE + '/series/gate-test-show');
  1017. await hydrated();
  1018. const seasonCounts = await ev(`Array.from(document.querySelectorAll('season-row')).map(e => e.querySelector('season-label').textContent + ': ' + e.querySelector('season-count').textContent)`);
  1019. check('after the sync: the show page has S3 (new) S2 S1, no season 0, no duplicated episode (S1 has 3)', JSON.stringify(seasonCounts) === JSON.stringify(['Season 3: 2 episodes', 'Season 2: 1 episode', 'Season 1: 3 episodes']), JSON.stringify(seasonCounts));
  1020. check('after the sync: the latest season shows its new episodes, the poster is the downloaded one',
  1021. JSON.stringify(await ev(`Array.from(document.querySelectorAll('episode-row episode-title')).map(e => e.textContent)`)) === JSON.stringify(['Third Season Start', 'Coming Soon'])
  1022. && (await ev(`document.querySelector('show-poster img').getAttribute('src')`)) === '/posters/sh1.png' && (await ev(`document.querySelector('show-poster img').naturalWidth`)) > 0);
  1023. await clickValue('button.season-toggle', SEASON1);
  1024. await page.waitForSelector(`button.checkicon[value="${EP1}"]`, { timeout: 10000 });
  1025. const s1 = await ev(`Array.from(document.querySelectorAll('episode-row')).map(e => e.querySelector('episode-number').textContent + ' ' + e.querySelector('episode-title').textContent + ' ' + e.querySelector('button.checkicon').getAttribute('class'))`);
  1026. check('after the sync: S1 keeps its episodes (same ids, still watched), E2 renamed from TMDB, E3 new and unwatched',
  1027. s1.includes('1 Pilot checkicon solid') && s1.includes('2 Second Episode checkicon solid') && s1.includes('3 Third checkicon regular') && s1.length === 5, JSON.stringify(s1));
  1028. // ---- tracker.worldapi.org#12: after the sync every show has the ids it lacked — the stored ones unchanged ----
  1029. await page.goto(BASE + '/series/gate-test-show');
  1030. await hydrated();
  1031. lk = await extLinks();
  1032. check('after the sync: show 1 has all four icons — its OWN imdb id kept (tt0000001, not TMDB\'s tt9999999), tvdb 4001 + TVmaze 501 filled',
  1033. linksAre(lk, [['TMDB', TMDB_TV + '1001'], ['IMDb', IMDB + 'tt0000001/'], ['TVDB', TVDB + '4001'], ['TVmaze', TVMAZE + '501']]), lk);
  1034. await page.goto(BASE + '/series/unwatched-gate-show');
  1035. await hydrated();
  1036. lk = await extLinks();
  1037. check('after the sync: show 2 has all four — imdb tt0000002 filled, its OWN tvdb 4002 kept (not 4999), TVmaze 502 (found by thetvdb after imdb missed)',
  1038. linksAre(lk, [['TMDB', TMDB_TV + '1002'], ['IMDb', IMDB + 'tt0000002/'], ['TVDB', TVDB + '4002'], ['TVmaze', TVMAZE + '502']]), lk);
  1039. await page.goto(BASE + '/movies/gate-test-movie');
  1040. await hydrated();
  1041. lk = await extLinks();
  1042. check('after the sync: the movie has TMDB (/movie/1003) + IMDb (tt0000003 filled), no TheTVDB/TVmaze, no seasons',
  1043. linksAre(lk, [['TMDB', TMDB_MOVIE + '1003'], ['IMDb', IMDB + 'tt0000003/']]) && (await ev(`document.querySelectorAll('season-row').length`)) === 0, lk);
  1044. // ---- tracker.worldapi.org#13: the public lists are built at start — after the sync (tool, then a restart) show 1's new
  1045. // S03E01 (2021-05-05) puts it before Pager Older Series (2021-01-01); show 2 has only an upcoming episode: still last
  1046. await page.goto(BASE + '/series');
  1047. await hydrated();
  1048. tl = await titlesOf('tile-grid');
  1049. check('after the sync + restart: /series by newest released episode — Gate Test Show (S03E01 2021-05-05) first now, its synced poster; Unwatched Gate Show (only upcoming) last',
  1050. JSON.stringify(tl) === JSON.stringify(['Gate Test Show', 'Pager Older Series', 'Unwatched Gate Show']) && (await tilesOf('tile-grid'))[0].endsWith('|/posters/sh1.png'), JSON.stringify(tl));
  1051. if (process.env.TRACKER_GATE_SHOTS) {
  1052. await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 2, mobile: true });
  1053. for (const [name, path] of [['synced-show-390', '/series/gate-test-show'], ['synced-movie-390', '/movies/gate-test-movie']]) {
  1054. await page.goto(BASE + path);
  1055. await hydrated();
  1056. writeFileSync(join(process.env.TRACKER_GATE_SHOTS, name + '.png'), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  1057. }
  1058. await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });
  1059. for (const [name, path] of [['synced-show', '/series/gate-test-show'], ['synced-movie', '/movies/gate-test-movie'], ['synced-my-shows', '/my/series'], ['synced-my-unwatched', '/my/unwatched'], ['synced-my-schedule', '/my/schedule']]) {
  1060. await page.goto(BASE + path);
  1061. await hydrated();
  1062. if (name === 'synced-my-shows') await waitPostersLoaded();
  1063. const shot = await page.send('Page.captureScreenshot', { format: 'png' });
  1064. writeFileSync(join(process.env.TRACKER_GATE_SHOTS, name + '.png'), Buffer.from(shot.data, 'base64'));
  1065. }
  1066. await page.send('Emulation.clearDeviceMetricsOverride', {});
  1067. }
  1068. // ---- THE DAILY RUN INSIDE THE APP: TRACKER_SYNC_HOUR = this very UTC hour, so the app's own clock starts the
  1069. // run right after boot. TMDB now has one more episode and answers slowly (700 ms per request): the run takes
  1070. // seconds, and pages asked for meanwhile must still be answered between two shows, never after the whole run.
  1071. await page.goto('about:blank');
  1072. await stopServer();
  1073. tmdb.shows[1001].seasons[3].episodes.push({ id: 5007, episode_number: 3, name: 'Added Live', air_date: '2096-03-03' });
  1074. // tracker.worldapi.org#13: and show 2 an episode that is ALREADY OUT — the running app must move it to the top of /series
  1075. tmdb.shows[1002].seasons[0].episodes.push({ id: 7002, episode_number: 2, name: 'Out Already', air_date: '2022-02-02' });
  1076. tmdb.delayMs = 700;
  1077. const before = tmdb.requests.length, tvmazeBeforeRun = tmdb.tvmazeRequests.length;
  1078. await startServer({ TRACKER_SYNC: '1', TRACKER_SYNC_HOUR: String(new Date().getUTCHours()) });
  1079. const lat = [];
  1080. const t0 = Date.now();
  1081. while (!log.includes('tmdb sync done') && Date.now() - t0 < 30000) {
  1082. const a = Date.now();
  1083. await fetch(BASE + '/');
  1084. lat.push({ at: a - t0, ms: Date.now() - a, running: log.includes('tmdb sync: start') && !log.includes('tmdb sync done') });
  1085. await new Promise(r => setTimeout(r, 150));
  1086. }
  1087. const runDone = (log.match(/tmdb sync done: .*/) || [''])[0];
  1088. check('in-app daily run: started by the app\'s own clock at the configured hour, found the 2 new episodes, 0 errors',
  1089. log.includes('tmdb sync: daily at ' + new Date().getUTCHours() + ':00 UTC') && log.includes('tmdb sync: start, 3 followed shows') && runDone.includes('newSeasons=0 newEpisodes=2 updatedEpisodes=0') && runDone.includes('errors=0'), log);
  1090. const during = lat.filter(l => l.running);
  1091. const runSecs = Number((runDone.match(/seconds=([0-9.]+)/) || [0, 0])[1]);
  1092. console.log(` (in-app run ${runSecs} s; ${during.length} pages asked during it, slowest ${Math.max(0, ...during.map(l => l.ms))} ms)`);
  1093. check('in-app daily run: the server kept answering DURING the run (between shows) — every page < 2.5 s though the run took ≥ 3 s',
  1094. runSecs >= 3 && during.length >= 3 && during.every(l => l.ms < 2500), 'run ' + runSecs + ' s, during: ' + JSON.stringify(during));
  1095. check('in-app daily run: the Bearer token on every call, 5 requests (2 per series, 1 for the movie; no poster again: unchanged), no TVmaze lookup, only the 2 episode lists (#15)', tmdb.requests.slice(before).filter(q => q.path.startsWith('/3/')).every(q => q.authorization === 'Bearer gate-token') && tmdb.requests.length - before === 5
  1096. && JSON.stringify(tmdb.tvmazeRequests.slice(tvmazeBeforeRun).sort()) === JSON.stringify(['/tvmaze/shows/501/episodes', '/tvmaze/shows/502/episodes']), JSON.stringify(tmdb.requests.slice(before)) + JSON.stringify(tmdb.tvmazeRequests.slice(tvmazeBeforeRun)));
  1097. await page.goto(BASE + '/my/schedule');
  1098. await hydrated();
  1099. rows = await scheduleRows();
  1100. check('after the in-app run: /my/schedule has the episode TMDB added meanwhile (S03E03, 2096-03-03) on top', rows.length === 4 && rows[0] === 'Gate Test Show (2024) | S03E03 · Added Live | 2096-03-03', JSON.stringify(rows));
  1101. await page.goto(BASE + '/series');
  1102. await hydrated();
  1103. tl = await titlesOf('tile-grid');
  1104. check('after the in-app run (no restart): /series has Unwatched Gate Show on top — its new S01E02 (2022-02-02) is out; the homepage row too',
  1105. JSON.stringify(tl) === JSON.stringify(['Unwatched Gate Show', 'Gate Test Show', 'Pager Older Series']), JSON.stringify(tl));
  1106. await page.goto(BASE + '/');
  1107. await hydrated();
  1108. tl = await titlesOf('#home-series');
  1109. check('after the in-app run: the homepage\'s Shows row has it first as well', JSON.stringify(tl) === JSON.stringify(['Unwatched Gate Show', 'Gate Test Show', 'Pager Older Series']), JSON.stringify(tl));
  1110. // ==== tracker.worldapi.org#15: THE TVMAZE MERGE — TVmaze knows more than TMDB: show 1 (TVmaze 501) gets S3E4's real
  1111. // title + air date (TMDB: "Episode 4", no date), a new S3E5 and a new season 4; TVmaze's other name for S3E1 must NOT
  1112. // replace TMDB's; its S1E1 airs on another day but has the same title (still agrees). Show 2 (502) TVmaze numbers
  1113. // differently (S1E1 another title, 7 years off — like a split pilot) → TVmaze is ignored for it. ====
  1114. await page.goto('about:blank');
  1115. await stopServer();
  1116. tmdb.delayMs = 0;
  1117. tmdb.shows[1001].seasons[3].episodes.push({ id: 5008, episode_number: 4, name: 'Episode 4' });
  1118. const tvm501 = tmdb.tvmaze.episodes[501].filter(e => !(e.season === 3 && e.number === 1));
  1119. tvm501.push({ id: 8005, season: 3, number: 1, name: 'Other Name From TVmaze', airdate: '2021-05-05' }, { id: 8007, season: 3, number: 3, name: 'Added Live', airdate: '2096-03-03' },
  1120. { id: 8008, season: 3, number: 4, name: 'Real Fourth', airdate: '2096-04-04' }, { id: 8009, season: 3, number: 5, name: 'Only On TVmaze', airdate: '2096-05-05' },
  1121. { id: 8010, season: 4, number: 1, name: 'New Season Premiere', airdate: '2096-06-06' });
  1122. tmdb.tvmaze.episodes[501] = tvm501;
  1123. tmdb.tvmaze.episodes[502] = [{ id: 8101, season: 1, number: 1, name: 'Brand New Pre-Pilot', airdate: '2090-01-01' }, { id: 8102, season: 1, number: 2, name: 'Should Not Appear', airdate: '2097-02-01' }];
  1124. // a date that differs (another country's premiere) but the SAME title still counts as the same numbering
  1125. tvm501.find(e => e.season === 1 && e.number === 1).airdate = '2019-12-20';
  1126. out = await runTool();
  1127. done = (out.match(/tmdb sync done: .*/) || [''])[0];
  1128. check('tvmaze merge: TMDB adds S3E4 ("Episode 4", no date); TVmaze adds 2 episodes (S3E5, S4E1) + 1 season (S4), fills 1 episode (S3E4), skips show 2 (numbered differently), 0 errors',
  1129. done.includes('newSeasons=0 newEpisodes=1 updatedEpisodes=0') && done.includes('tvmazeRequests=2 errors=0 tvmazeEpisodes=2 tvmazeSeasons=1 tvmazeFilled=1 tvmazeSkipped=1') && out.includes('SKIPPED (numbered differently)'), out);
  1130. out = await runTool();
  1131. done = (out.match(/tmdb sync done: .*/) || [''])[0];
  1132. check('tvmaze merge again: idempotent — nothing new, nothing filled, no TMDB update (TMDB\'s "Episode 4" does not replace TVmaze\'s "Real Fourth")',
  1133. done.includes('newSeasons=0 newEpisodes=0 updatedEpisodes=0 updatedSeasons=0') && done.includes('errors=0 tvmazeEpisodes=0 tvmazeSeasons=0 tvmazeFilled=0 tvmazeSkipped=1'), out);
  1134. await startServer();
  1135. await page.goto(BASE + '/my/schedule');
  1136. await hydrated();
  1137. rows = await scheduleRows();
  1138. check('tvmaze merge: /my/schedule shows what only TVmaze has (S03E04 with its TVmaze title + date, S03E05, S04E01), in date order; nothing of show 2\'s differently numbered TVmaze list', JSON.stringify(rows) === JSON.stringify([
  1139. 'Gate Test Show (2024) | S03E03 · Added Live | 2096-03-03', 'Gate Test Show (2024) | S03E04 · Real Fourth | 2096-04-04', 'Gate Test Show (2024) | S03E05 · Only On TVmaze | 2096-05-05',
  1140. 'Gate Test Show (2024) | S04E01 · New Season Premiere | 2096-06-06', 'Unwatched Gate Show (2025) | S01E01 · Brand New | 2097-01-01',
  1141. 'Gate Test Show (2024) | S03E02 · Coming Soon | 2098-06-01', 'Gate Test Show (2024) | S02E01 · Season Two Opener | 2099-01-01']), JSON.stringify(rows));
  1142. const seasonsAndTitles = async () => {
  1143. await page.goto(BASE + '/series/gate-test-show');
  1144. await hydrated();
  1145. const seasons = await ev(`Array.from(document.querySelectorAll('season-row')).map(e => e.querySelector('season-label').textContent + ': ' + e.querySelector('season-count').textContent)`);
  1146. await clickValue('button.season-toggle', await ev(`Array.from(document.querySelectorAll('season-row')).find(e => e.querySelector('season-label').textContent === 'Season 3').querySelector('button.season-toggle').value`));
  1147. await page.waitFor(`document.querySelectorAll('episode-row').length >= 6`, { timeout: 10000, label: 'S3 expanded' });
  1148. const titles = await ev(`Array.from(document.querySelectorAll('episode-row')).map(e => e.querySelector('episode-number').textContent + ' ' + e.querySelector('episode-title').textContent)`);
  1149. return { seasons, titles };
  1150. };
  1151. let tst = await seasonsAndTitles();
  1152. check('tvmaze merge: the show page has the new Season 4 (1 episode) and Season 3 with 5 — S3E1 keeps TMDB\'s title, S3E4 TVmaze\'s',
  1153. JSON.stringify(tst.seasons) === JSON.stringify(['Season 4: 1 episode', 'Season 3: 5 episodes', 'Season 2: 1 episode', 'Season 1: 3 episodes'])
  1154. && JSON.stringify(tst.titles) === JSON.stringify(['1 New Season Premiere', '1 Third Season Start', '2 Coming Soon', '3 Added Live', '4 Real Fourth', '5 Only On TVmaze']), JSON.stringify(tst));
  1155. if (process.env.TRACKER_GATE_SHOTS) {
  1156. for (const [w, h, mobile] of [[390, 844, true], [1280, 900, false]]) {
  1157. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: mobile ? 2 : 1, mobile });
  1158. for (const [name, path] of [['tvmaze-schedule', '/my/schedule'], ['tvmaze-show', '/series/gate-test-show']]) {
  1159. await page.goto(BASE + path);
  1160. await hydrated();
  1161. writeFileSync(join(process.env.TRACKER_GATE_SHOTS, `${name}-${w}.png`), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  1162. }
  1163. }
  1164. await page.send('Emulation.clearDeviceMetricsOverride', {});
  1165. }
  1166. // TMDB catches up: it now lists S3E5 (its own title) and season 4 — the TMDB step ADOPTS TVmaze's rows by number (no
  1167. // duplicate), TMDB's values win; its "Episode 4" still never replaces "Real Fourth"
  1168. await page.goto('about:blank');
  1169. await stopServer();
  1170. tmdb.shows[1001].seasons[3].episodes.push({ id: 5009, episode_number: 5, name: 'Official Fifth', air_date: '2096-05-05' });
  1171. tmdb.shows[1001].seasons.push({ id: 95, season_number: 4, name: 'Season 4', air_date: '2096-06-06', episodes: [{ id: 5010, episode_number: 1, name: 'New Season Premiere', air_date: '2096-06-06' }] });
  1172. out = await runTool();
  1173. done = (out.match(/tmdb sync done: .*/) || [''])[0];
  1174. check('tvmaze merge, TMDB catches up: TMDB adopts the 2 TVmaze episodes (updatedEpisodes=2: tmdbId set, S3E5 renamed), creates nothing, TVmaze adds nothing',
  1175. done.includes('newSeasons=0 newEpisodes=0 updatedEpisodes=2 updatedSeasons=0') && done.includes('errors=0 tvmazeEpisodes=0 tvmazeSeasons=0 tvmazeFilled=0'), out);
  1176. await startServer();
  1177. tst = await seasonsAndTitles();
  1178. check('tvmaze merge, TMDB caught up: still S4 1 / S3 5 episodes (no duplicates), S3E5 now TMDB\'s "Official Fifth", S3E4 still "Real Fourth"',
  1179. JSON.stringify(tst.seasons) === JSON.stringify(['Season 4: 1 episode', 'Season 3: 5 episodes', 'Season 2: 1 episode', 'Season 1: 3 episodes'])
  1180. && JSON.stringify(tst.titles) === JSON.stringify(['1 New Season Premiere', '1 Third Season Start', '2 Coming Soon', '3 Added Live', '4 Real Fourth', '5 Official Fifth']), JSON.stringify(tst));
  1181. // ==== tracker.worldapi.org#14: THE SEARCH, signed IN — "Add" imports the title like the daily sync and opens its page ====
  1182. tmdb.delayMs = 0;
  1183. await page.goto(BASE + '/search/gate');
  1184. await hydrated();
  1185. await page.click('#fetchweb');
  1186. await page.waitFor(`document.querySelectorAll('web-row').length > 0`, { timeout: 10000, label: 'web results (signed in)' });
  1187. const dbBefore = await searchTitles();
  1188. // hybriel#121/#122: a SESSION face (searchImport) that stays on the page — tv 1006's details answer 404 — must leave every
  1189. // list as it was: each row once, the route-param text still in the field and in data-for
  1190. await page.click('web-row button.add[value="tv:1006"]');
  1191. await page.waitFor(`!!document.querySelector('#importerror')`, { timeout: 10000, label: 'import error' }).catch(() => {});
  1192. await new Promise(r => setTimeout(r, 300));
  1193. check('search import: a failed import (TMDB 404) says so and stays — the database list, the web list and the text are unchanged, no row twice (hybriel#121/#122)',
  1194. (await ev(`document.querySelector('#importerror') ? document.querySelector('#importerror').textContent : ''`)) === 'Could not add it: TMDB: HTTP 404 for /tv/1006'
  1195. && (await searchTitles()) === dbBefore && dbBefore === JSON.stringify(GATE_TITLES) && (await webList()) === JSON.stringify(GATE_WEB)
  1196. && (await ev(`document.querySelector('#searchinput').value`)) === 'gate' && (await searchFor()) === 'gate' && (await ev('location.pathname')) === '/search/gate',
  1197. (await ev(`document.querySelector('search-page').outerHTML.slice(0, 1500)`)));
  1198. await typeSearch('gate t');
  1199. check('search import: after that session face the page still searches (typing "gate t" → the two "Gate Test" titles)', (await searchTitles()) === JSON.stringify(GATE_TITLES.slice(0, 2)), await searchTitles());
  1200. await typeSearch('gate');
  1201. await page.click('#fetchweb');
  1202. await page.waitFor(`document.querySelectorAll('web-row').length > 0`, { timeout: 10000 });
  1203. const reqBefore = tmdb.requests.length;
  1204. await page.click('web-row button.add[value="tv:1004"]');
  1205. await page.waitFor(`location.pathname !== '/search/gate' && !!document.querySelector('show-header h1')`, { timeout: 15000, label: 'imported show page' });
  1206. await page.waitFor(`!!document.querySelector('show-poster img') && document.querySelector('show-poster img').complete`, { timeout: 5000 }).catch(() => {});
  1207. const imp = JSON.parse(await ev(`JSON.stringify({ path: location.pathname, h1: document.querySelector('show-header h1 type-name').textContent,
  1208. seasons: Array.from(document.querySelectorAll('season-row')).map(r => r.querySelector('season-label').textContent + ': ' + r.querySelector('season-count').textContent),
  1209. episodes: Array.from(document.querySelectorAll('episode-row episode-title')).map(e => e.textContent), genres: Array.from(document.querySelectorAll('.genre-pill')).map(g => g.textContent),
  1210. poster: document.querySelector('show-poster img') ? document.querySelector('show-poster img').getAttribute('src') : null,
  1211. posterW: document.querySelector('show-poster img') ? document.querySelector('show-poster img').naturalWidth : 0, summary: document.querySelector('show-summary').textContent })`));
  1212. lk = await extLinks();
  1213. check('search import: "Add" on tv 1004 adds it and opens its page /series/Gate-Import-Show — season, episodes, poster (downloaded), genres matched by name, the summary',
  1214. imp.path === '/series/Gate-Import-Show' && imp.h1 === 'Gate Import Show' && JSON.stringify(imp.seasons) === JSON.stringify(['Season 1: 2 episodes'])
  1215. && JSON.stringify(imp.episodes) === JSON.stringify(['Imported One', 'Imported Two']) && JSON.stringify(imp.genres) === JSON.stringify(['Drama'])
  1216. && imp.poster === '/posters/tmdb-tv-1004.png' && imp.posterW > 0 && imp.summary === 'an imported series' && existsSync(join(MPACKDB, 'posters', 'tmdb-tv-1004.png')), JSON.stringify(imp));
  1217. // mission 060: the imported title has its short id AT ONCE (claimed at creation, no restart, the run's backfill was done)
  1218. const impSid = await ev(`(document.querySelector('show-poster #shortid') || {}).textContent || null`);
  1219. check('short ids: a search import has its short id at once, under the poster (5 characters a–z 0–9)', /^[a-z0-9]{5}$/.test(impSid || '') && impSid !== '100jh', impSid);
  1220. check('search import: the ids came like the daily sync\'s — TMDB, IMDb tt0000004, TVDB 4004, TVmaze 504 (looked up by thetvdb)',
  1221. linksAre(lk, [['TMDB', TMDB_TV + '1004'], ['IMDb', IMDB + 'tt0000004/'], ['TVDB', TVDB + '4004'], ['TVmaze', TVMAZE + '504']]), lk);
  1222. const impPaths = tmdb.requests.slice(reqBefore).map(q => q.path);
  1223. check('search import: TMDB asked exactly like the sync (details, seasons, poster) + one details request for the new record, all with the token',
  1224. JSON.stringify(impPaths) === JSON.stringify(['/3/tv/1004', '/3/tv/1004?append_to_response=external_ids', '/3/tv/1004?append_to_response=season/1', '/t/p/w342/gate4.png'])
  1225. && tmdb.requests.slice(reqBefore).filter(q => q.path.startsWith('/3/')).every(q => q.authorization === 'Bearer gate-token'), JSON.stringify(impPaths));
  1226. await page.goto(BASE + '/search/gate');
  1227. await hydrated();
  1228. st14 = await searchTitles();
  1229. check('search import: our database has it at once (the index too): "gate" now also lists Gate Import Show (2023)',
  1230. st14 === JSON.stringify([GATE_TITLES[0], GATE_TITLES[1], ['Gate Import Show (2023)', '/series/Gate-Import-Show', 'Series'], GATE_TITLES[2]]), st14);
  1231. await page.click('#fetchweb');
  1232. await page.waitFor(`document.querySelectorAll('web-row').length > 0`, { timeout: 10000 });
  1233. wl = await webList();
  1234. check('search import: the web list leaves it out now (we have it)', wl === JSON.stringify(GATE_WEB.slice(1)), wl);
  1235. await page.click('web-row button.add[value="movie:1005"]');
  1236. await page.waitFor(`location.pathname === '/movies/Gate-Import-Movie' && !!document.querySelector('show-header h1')`, { timeout: 15000, label: 'imported movie page' });
  1237. lk = await extLinks();
  1238. check('search import: a MOVIE (movie 1005) → /movies/Gate-Import-Movie, synced via /movie/ (TMDB /movie/1005 + IMDb), no seasons',
  1239. (await ev(`document.querySelector('show-header h1 type-name').textContent`)) === 'Gate Import Movie' && linksAre(lk, [['TMDB', TMDB_MOVIE + '1005'], ['IMDb', IMDB + 'tt0000005/']])
  1240. && (await ev(`document.querySelectorAll('season-row').length`)) === 0 && !tmdb.requests.some(q => q.path.startsWith('/3/tv/1005')), lk);
  1241. await page.goto(BASE + '/search/gate%20import');
  1242. await hydrated();
  1243. st14 = await searchTitles();
  1244. check('search import: both imported titles are found, each once', st14 === JSON.stringify([['Gate Import Show (2023)', '/series/Gate-Import-Show', 'Series'], ['Gate Import Movie (2001)', '/movies/Gate-Import-Movie', 'Movie']]), st14);
  1245. // merge of #13 + #14: an imported title is in the public lists at once (catalog.hl refreshCatalogShow), no restart
  1246. await page.goto(BASE + '/movies');
  1247. await hydrated();
  1248. titles = await titlesOf('tile-grid');
  1249. await page.goto(BASE + '/series');
  1250. await hydrated();
  1251. tl = await titlesOf('tile-grid');
  1252. check('search import → the lists at once: /movies has Gate Import Movie (2001-05-05) right after the 2099 one, /series has Gate Import Show',
  1253. titles[0] === 'Pager Future Movie' && titles[1] === 'Gate Import Movie' && titles.filter(t => t === 'Gate Import Movie').length === 1 && tl.filter(t => t === 'Gate Import Show').length === 1, JSON.stringify({ titles, tl }));
  1254. // mission 058 (#25): the genre lists too (catalog.hl refreshGenres) — both imports are Drama (TMDB genre 18 = ours by name)
  1255. await page.goto(BASE + '/genres/Drama');
  1256. await hydrated();
  1257. titles = await titlesOf('tile-grid');
  1258. check('#25: imported titles are in their genre at once — /genres/Drama: Gate Import Show (episode 2023-02-09), Gate Test Show (S03E01 2021-05-05), Gate Import Movie (2001-05-05)',
  1259. JSON.stringify(titles) === JSON.stringify(['Gate Import Show', 'Gate Test Show', 'Gate Import Movie']), JSON.stringify(titles));
  1260. if (process.env.TRACKER_GATE_SHOTS) {
  1261. for (const [w, h, mobile] of [[390, 844, true], [1280, 900, false]]) {
  1262. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: mobile ? 2 : 1, mobile });
  1263. await page.goto(BASE + '/search/gate');
  1264. await hydrated();
  1265. await page.click('#fetchweb');
  1266. await page.waitFor(`document.querySelectorAll('web-row').length > 0`, { timeout: 10000 });
  1267. await page.waitFor(`Array.from(document.querySelectorAll('img')).every(i => i.complete)`, { timeout: 5000 }).catch(() => {});
  1268. writeFileSync(join(process.env.TRACKER_GATE_SHOTS, `search-web-${w}.png`), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  1269. }
  1270. await page.send('Emulation.clearDeviceMetricsOverride', {});
  1271. }
  1272. check('search: the server log has no error (the imports logged their sync counts)', !/error absorbed/i.test(log) && (log.match(/search import: /g) || []).length === 2, log.split('\n').filter(l => /search|error/i.test(l)).join('\n'));
  1273. // ==== mission 054: ADULT TITLES — the public lists and the search show only titles TMDB says are NOT adult (unknown =
  1274. // hidden); a followed adult title stays on /my/* and its page; the in-app BACKFILL asks TMDB title by title, resumes
  1275. // after a restart, and pages stay fast meanwhile. tests/seed-adult.hl adds the titles (app stopped) ====
  1276. await page.goto('about:blank'); // mission 056: a tab left on a page logs websocket reconnect errors while the server is down
  1277. await stopServer();
  1278. const seedAdult = execFileSync(join(APP, 'bin/hybriel'), ['tests/seed-adult.hl'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: MPACKDB, TRACKER_SEED_USER: 'gateu0000000000u1' } }).toString();
  1279. check('adult: fixture written (1 adult title alice follows, 14 with an unknown flag)', seedAdult.includes('15 titles') && seedAdult.includes('follows Adult Gate Movie'), seedAdult);
  1280. await startServer();
  1281. const ADULT_ALL = ['Adult Gate Movie', 'Flagless Gate Movie', 'Flagless Adult Movie', 'Flagless Gate Series', 'Gone Gate Movie', 'Backfill Movie'];
  1282. // the signed-OUT HTML of a page (node fetch, no cookie): which of these titles it names
  1283. const namesIn = async (path) => { const h = await (await fetch(BASE + path)).text(); return ADULT_ALL.filter(t => h.includes(t)); };
  1284. const allMoviesHtml = async () => { let h = ''; for (const p of ['/movies', '/movies/page/2']) h += await (await fetch(BASE + p)).text(); return h; };
  1285. const mh = await allMoviesHtml();
  1286. let seen = { home: await namesIn('/'), movies: ADULT_ALL.filter(t => mh.includes(t)), shows: await namesIn('/series') };
  1287. check('adult (backfill off): signed out, the homepage, every /movies page and /series list NONE of the adult/unknown titles; the count is unchanged (34 movies)',
  1288. seen.home.length === 0 && seen.movies.length === 0 && seen.shows.length === 0 && mh.includes('34 movies, newest first'), JSON.stringify(seen));
  1289. let sr = await (await fetch(BASE + '/search/flagless')).text();
  1290. const sr2 = await (await fetch(BASE + '/search/adult%20gate')).text();
  1291. check('adult (backfill off): the search finds none of them ("flagless", "adult gate" → "Nothing in our database yet.")',
  1292. sr.includes('Nothing in our database yet.') && !sr.includes('class="search-title"') && sr2.includes('Nothing in our database yet.'), sr.slice(sr.indexOf('<search-page'), sr.indexOf('<search-page') + 600));
  1293. await page.goto(BASE + '/my/movies');
  1294. await hydrated();
  1295. const myMv = await ev(`JSON.stringify(Array.from(document.querySelectorAll('my-show-row')).map(r => r.querySelector('a.myshow-title').textContent))`);
  1296. check('adult: alice follows the adult movie → it IS on her /my/movies (newest follow first)', JSON.parse(myMv)[0] === 'Adult Gate Movie (2001)', myMv);
  1297. await page.click('a.myshow-title[href="/movies/adult-gate-movie"]');
  1298. await page.waitFor(`location.pathname === '/movies/adult-gate-movie' && !!document.querySelector('show-page')`, { timeout: 10000, label: 'adult page (alice)' });
  1299. await page.waitFor(`!!document.querySelector('show-header h1')`, { timeout: 5000 }).catch(() => {});
  1300. check('adult: …and its page opens for her (client-side from /my/movies, and on a reload) with "Following"',
  1301. (await ev(`document.querySelector('show-header h1') ? document.querySelector('show-header h1 type-name').textContent : 'none'`)) === 'Adult Gate Movie'
  1302. && (await (async () => { await page.goto(BASE + '/movies/adult-gate-movie'); await hydrated(); return ev(`(document.querySelector('show-header h1 type-name') || {}).textContent + '|' + (document.querySelector('#follow') || {}).textContent`); })()) === 'Adult Gate Movie|Following');
  1303. // mission 056: the adult title's PAGE is "Not found" for anyone who does not follow it — signed out (no cookie) here
  1304. const adultOut = await (await fetch(BASE + '/movies/adult-gate-movie')).text();
  1305. // the page's h1: "Not found", or the title (tracker#20: its <type-name> after the type word)
  1306. const pageH1 = (h) => { const m = h.match(/<show-page[^>]*>[\s\S]*?<h1[^>]*>([\s\S]*?)<\/h1>/); if (!m) return undefined; const n = m[1].match(/<type-name[^>]*>([^<]*)</); return (n ? n[1] : m[1]).trim(); };
  1307. check('adult (056): signed out, /movies/adult-gate-movie says "Not found" and names no title (a non-adult page still opens: Flagless Gate Movie is unknown, not hidden)',
  1308. pageH1(adultOut) === 'Not found' && !adultOut.includes('Adult Gate Movie') && pageH1(await (await fetch(BASE + '/movies/flagless-gate-movie')).text()) === 'Flagless Gate Movie', pageH1(adultOut));
  1309. await page.goto(BASE + '/');
  1310. await hydrated();
  1311. const homeIn = await ev(`document.querySelector('home').textContent`);
  1312. check('adult: signed in too, the homepage rows have none of them (only /my/* is personal)', ADULT_ALL.every(t => !homeIn.includes(t)), homeIn);
  1313. await page.goto(BASE + '/search/gate');
  1314. await hydrated();
  1315. const wsBefore = tmdb.searchRequests.length;
  1316. await page.click('#fetchweb');
  1317. await page.waitFor(`document.querySelectorAll('web-row').length > 0 || !!document.querySelector('#webnote')`, { timeout: 10000, label: 'web results (adult)' });
  1318. wl = await webList();
  1319. check('adult: "Fetch from web" asks TMDB with include_adult=false and leaves out the result TMDB marks adult (Gate Adult Web)',
  1320. !wl.includes('Gate Adult Web') && wl.includes('Gate Broken Show') && tmdb.searchRequests.length === wsBefore + 1 && tmdb.searchRequests[wsBefore].path.includes('include_adult=false'), wl);
  1321. check('adult (backfill off): the log says so, no TMDB request was made for the unknown titles', log.includes('adult backfill: off (TRACKER_BACKFILL=0)') && !tmdb.requests.some(q => /\/3\/(movie|tv)\/(1012|1013|1014|1120|11\d\d)/.test(q.path)), log);
  1322. // ---- the BACKFILL: every answer slowed down to 300 ms; stopped after 6 titles, started again → it goes on with the rest ----
  1323. await page.goto('about:blank'); // mission 056: a tab left on a page logs websocket reconnect errors while the server is down
  1324. await stopServer();
  1325. tmdb.delayMs = 300;
  1326. const bfReq = tmdb.requests.length;
  1327. await startServer({ TRACKER_BACKFILL: '1', TRACKER_BACKFILL_LOG_EVERY: '3' });
  1328. const waitLog = async (re, ms) => { const t0 = Date.now(); while (!re.test(log) && Date.now() - t0 < ms) await new Promise(r => setTimeout(r, 100)); return re.test(log); };
  1329. const got6 = await waitLog(/adult backfill: 6\/14 titles/, 30000);
  1330. const log1 = log;
  1331. await page.goto('about:blank'); // mission 056: a tab left on a page logs websocket reconnect errors while the server is down
  1332. await stopServer();
  1333. const asked1 = tmdb.requests.slice(bfReq).map(q => q.path).filter(p => /^\/3\/(movie|tv)\//.test(p));
  1334. check('backfill: started with the 14 unknown titles, logs every 3 (TRACKER_BACKFILL_LOG_EVERY), one details request per title (+ external_ids), with the token',
  1335. got6 && log1.includes('adult backfill: start, 14 titles without an adult flag') && /adult backfill: 3\/14 titles/.test(log1)
  1336. && asked1.every(p => p.endsWith('?append_to_response=external_ids')) && tmdb.requests.slice(bfReq).filter(q => q.path.startsWith('/3/')).every(q => q.authorization === 'Bearer gate-token'), log1.split('\n').filter(l => /backfill/.test(l)).join('\n'));
  1337. const bfReq2 = tmdb.requests.length;
  1338. await startServer({ TRACKER_BACKFILL: '1', TRACKER_BACKFILL_LOG_EVERY: '3' });
  1339. // the start line comes with the clock's first tick, which can be after the first page answer (mission 056: it was)
  1340. await waitLog(/adult backfill: start, \d+ titles/, 5000);
  1341. const left = Number((log.match(/adult backfill: start, (\d+) titles/) || [])[1]);
  1342. // pages DURING the run: signed out, the homepage, /movies and a search, back to back, timed
  1343. const during54 = [];
  1344. const t054 = Date.now();
  1345. while (!/adult backfill done/.test(log) && Date.now() - t054 < 60000) {
  1346. for (const p of ['/', '/movies', '/search/backfill']) { const t = Date.now(); await (await fetch(BASE + p)).text(); during54.push({ p, ms: Date.now() - t }); }
  1347. }
  1348. const bfSecs = (Date.now() - t054) / 1000;
  1349. const asked2 = tmdb.requests.slice(bfReq2).map(q => q.path).filter(p => /^\/3\/(movie|tv)\//.test(p));
  1350. const askedIds = [...asked1, ...asked2].map(p => p.match(/\/3\/(?:movie|tv)\/(\d+)/)[1]);
  1351. const twice = askedIds.filter((x, k) => askedIds.indexOf(x) !== k);
  1352. const doneLine = (log.match(/adult backfill done: .*/) || [''])[0];
  1353. console.log(` (backfill second start: ${left} titles left, ${bfSecs} s; ${during54.length} pages asked during it, slowest ${Math.max(0, ...during54.map(l => l.ms))} ms; ${doneLine})`);
  1354. check('backfill RESUMES after a restart: the second start finds only the titles still unknown (≤ 8 of 14), every one of the 14 was asked, none twice except at most the one cut off by the stop',
  1355. left >= 1 && left <= 8 && new Set(askedIds).size === 14 && twice.length <= 1 && asked1.length + asked2.length - twice.length === 14, JSON.stringify({ left, asked1, asked2, twice }));
  1356. check('backfill: done — it stops when nothing is unknown (the done line with its counts); the 404 (1120) was logged',
  1357. /^adult backfill done: \d+\/\d+ titles, adult=\d+ notAdult=\d+ unknown=\d+ posters=\d+ ids=\d+ requests=\d+ errors=\d+ retries=0 seconds=/.test(doneLine) && (log1 + log).includes('HTTP 404 for /movie/1120'), (log1 + log).split('\n').filter(l => /backfill/.test(l)).join('\n'));
  1358. check('backfill: pages stay fast during the run (300 ms per TMDB answer) — every page < 1.2 s, and pages were asked during it',
  1359. during54.length >= 6 && during54.every(l => l.ms < 1200), JSON.stringify(during54.filter(l => l.ms >= 500)));
  1360. // the lists updated AS the flags arrived (no restart since the run)
  1361. seen = { home: await namesIn('/'), shows: await namesIn('/series') };
  1362. const mh2 = await allMoviesHtml();
  1363. seen.movies = ADULT_ALL.filter(t => mh2.includes(t));
  1364. check('backfill → the lists at once (no restart): /movies has Flagless Gate Movie + the 10 Backfill Movies (45 movies), NOT the adult ones or the 404; /series and the homepage have Flagless Gate Series (+ the homepage Flagless Gate Movie)',
  1365. JSON.stringify(seen.movies) === JSON.stringify(['Flagless Gate Movie', 'Backfill Movie']) && mh2.includes('Backfill Movie 10') && mh2.includes('Backfill Movie 01') && mh2.includes('45 movies, newest first')
  1366. && JSON.stringify(seen.shows) === JSON.stringify(['Flagless Gate Series']) && JSON.stringify(seen.home) === JSON.stringify(['Flagless Gate Movie', 'Flagless Gate Series']), JSON.stringify(seen));
  1367. sr = await (await fetch(BASE + '/search/flagless')).text();
  1368. check('backfill → the search at once: "flagless" finds Flagless Gate Series + Flagless Gate Movie, not Flagless Adult Movie',
  1369. sr.includes('Flagless Gate Movie') && sr.includes('Flagless Gate Series') && !sr.includes('Flagless Adult Movie'), sr.slice(sr.indexOf('<search-page'), sr.indexOf('<search-page') + 900));
  1370. check('backfill: the ADULT title\'s poster is NOT downloaded (Flagless Adult Movie: asked, but no /t/p/w342/flag13.png request, no posters/admvfa.* file)',
  1371. !tmdb.requests.some(q => q.path.includes('flag13')) && !readdirSync(join(MPACKDB, 'posters')).some(f => f.startsWith('admvfa.')) && tmdb.requests.some(q => q.path.startsWith('/3/movie/1013?')),
  1372. (log1 + log).split('\n').filter(l => /backfill/.test(l)).join('\n'));
  1373. const pr = await fetch(BASE + '/posters/admvfl.png');
  1374. check('backfill: the poster was downloaded and is served (/posters/admvfl.png, image/png)', pr.status === 200 && pr.headers.get('content-type') === 'image/png' && existsSync(join(MPACKDB, 'posters', 'admvfl.png')));
  1375. // a third start: nothing unknown is left that TMDB can answer (the 404 is marked) → no request at all
  1376. await page.goto('about:blank'); // mission 056: a tab left on a page logs websocket reconnect errors while the server is down
  1377. await stopServer();
  1378. const bfReq3 = tmdb.requests.length;
  1379. tmdb.delayMs = 0;
  1380. await startServer({ TRACKER_BACKFILL: '1' });
  1381. await waitLog(/adult backfill: nothing to do/, 5000);
  1382. await new Promise(r => setTimeout(r, 500));
  1383. check('backfill: a restart afterwards has nothing to do (the 404 title is marked, not asked again) — no TMDB request',
  1384. log.includes('adult backfill: start, 0 titles') && log.includes('adult backfill: nothing to do') && tmdb.requests.length === bfReq3, log.split('\n').filter(l => /backfill/.test(l)).join('\n'));
  1385. check('adult: the server log has no error', !/error absorbed/i.test(log), log);
  1386. await page.goto(BASE + '/');
  1387. await hydrated();
  1388. if (process.env.TRACKER_GATE_SHOTS) writeFileSync(join(process.env.TRACKER_GATE_SHOTS, 'adult-home-1280.png'), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  1389. // mission 056: alice UNFOLLOWS the adult movie on its page (a session face → hl:web's session sync re-derives `found` with
  1390. // the page's slug, hybriel#122): she no longer follows it → "Not found" at once, on a reload, and it leaves /my/movies
  1391. await page.goto(BASE + '/movies/adult-gate-movie');
  1392. await hydrated();
  1393. const adultBefore = await ev(`(document.querySelector('show-header h1 type-name') || {}).textContent + '|' + (document.querySelector('#follow') || {}).textContent`);
  1394. await page.click('#follow');
  1395. const adultGone = await page.waitFor(`(document.querySelector('show-page h1') || {}).textContent === 'Not found'`, { timeout: 5000, label: 'adult page hidden after unfollow' }).then(() => true, () => false);
  1396. const adultAfter = await ev(`(document.querySelector('show-page h1') || {}).textContent + '|' + ((document.querySelector('#follow') || {}).textContent || '')`);
  1397. await page.goto(BASE + '/movies/adult-gate-movie');
  1398. await hydrated();
  1399. const adultReload = await ev(`(document.querySelector('show-page h1') || {}).textContent`);
  1400. await page.goto(BASE + '/my/movies');
  1401. await hydrated();
  1402. const myMv2 = await ev(`Array.from(document.querySelectorAll('a.myshow-title')).map(a => a.textContent).join(',')`);
  1403. check('adult (056): alice sees the adult page while she follows it; after Unfollow ON the page it says "Not found" (no reload), on a reload too, and it is off her /my/movies',
  1404. adultBefore === 'Adult Gate Movie|Following' && adultGone && adultAfter === 'Not found|' && adultReload === 'Not found' && !myMv2.includes('Adult Gate Movie'), JSON.stringify({ adultBefore, adultAfter, adultReload, myMv2 }));
  1405. // and a normal show page still works after a session face (mission 054's failure: the browser re-derived `found` → `rows`)
  1406. await page.goto(BASE + '/series/gate-test-show');
  1407. await hydrated();
  1408. const ep56 = await ev(`(() => { const b = document.querySelector('episode-row button.checkicon'); return b ? b.value + '|' + b.className : null; })()`);
  1409. await page.click('episode-row button.checkicon');
  1410. const ep56ok = await page.waitFor(`document.querySelector('episode-row button.checkicon').className !== ${JSON.stringify((ep56 || '|').split('|')[1])}`, { timeout: 5000, label: 'episode toggled (056)' }).then(() => true, () => false);
  1411. await page.click('episode-row button.checkicon');
  1412. const ep56back = await page.waitFor(`document.querySelector('episode-row button.checkicon').className === ${JSON.stringify((ep56 || '|').split('|')[1])}`, { timeout: 5000, label: 'episode toggled back (056)' }).then(() => true, () => false);
  1413. check('adult (056): on a normal show page an episode check toggles and toggles back (the session face + sync with the new `found`)', ep56 !== null && ep56ok && ep56back, ep56);
  1414. // ==== tracker.worldapi.org#16: PERSON PAGES — a complete person at once; an incomplete one fetches TMDB on the first visit
  1415. // ("Loading filmography…", filled without a reload, step by step), titles added once, adult hidden, the links, client-side
  1416. // navigation show → person → show → Back ====
  1417. const filmRows = () => ev(`JSON.stringify(Array.from(document.querySelectorAll('a.film-row')).map(a => [a.querySelector('film-title').textContent, a.querySelector('film-year').textContent, a.querySelector('film-type').textContent, a.querySelector('film-role').textContent, a.getAttribute('href')]))`).then(JSON.parse);
  1418. const personFacts = () => ev(`JSON.stringify({ h1: (document.querySelector('person-meta h1 type-name') || {}).textContent || null, facts: Array.from(document.querySelectorAll('person-fact')).map(f => f.textContent),
  1419. bio: (document.querySelector('person-bio') || {}).textContent || null, photo: (document.querySelector('person-photo img') || { getAttribute: () => null }).getAttribute('src'),
  1420. photoLoaded: !!(document.querySelector('person-photo img') && document.querySelector('person-photo img').complete && document.querySelector('person-photo img').naturalWidth > 0),
  1421. loading: !!document.querySelector('#personloading'), error: (document.querySelector('#fillerror') || {}).textContent || null })`).then(JSON.parse);
  1422. await page.goto(BASE + '/person/Complete-Person');
  1423. await hydrated();
  1424. await new Promise(r => setTimeout(r, 600));
  1425. let pf = await personFacts();
  1426. let fr = await filmRows();
  1427. check('person: a COMPLETE person shows at once — name, born/died, bio, the filmography newest first with roles and years; no loading, TMDB not asked',
  1428. pf.h1 === 'Complete Person' && JSON.stringify(pf.facts) === JSON.stringify(['Born 3 February 1950 in Gate City', 'Died 1 January 2020']) && pf.bio === 'A fixture person who is complete.'
  1429. && pf.photo === null && !pf.loading && JSON.stringify(fr) === JSON.stringify([['Gate Test Show', '2024', 'Series', 'Old Role', '/series/gate-test-show'], ['Gate Test Movie', '1996', 'Movie', 'Movie Role', '/movies/gate-test-movie']])
  1430. && tmdb.personRequests.length === 0, JSON.stringify({ pf, fr, req: tmdb.personRequests }));
  1431. await page.goto(BASE + '/person/Nobody-Here');
  1432. await hydrated();
  1433. check('person: an unknown slug says "Not found"', (await ev(`document.querySelector('person-page h1').textContent`)) === 'Not found');
  1434. check('person: /profiles/<bad name> answers 400', (await fetch(BASE + '/profiles/..%2Fx')).status === 400 || (await fetch(BASE + '/profiles/a%20b')).status === 400);
  1435. // client-side: the show page's cast link → the person page (a window marker proves no reload); TMDB answers slowly (900 ms)
  1436. // so the loading state is seen; then it fills in by itself
  1437. tmdb.personDelayMs = 900;
  1438. await page.goto(BASE + '/series/gate-test-show');
  1439. await hydrated();
  1440. await ev(`window.__w055 = 'same document'`);
  1441. const fillT0 = Date.now();
  1442. await page.click('a.artist-link[href="/person/Test-Actor"]');
  1443. await page.waitFor(`location.pathname === '/person/Test-Actor' && !!document.querySelector('person-meta h1')`, { timeout: 10000, label: 'person page after the cast click' });
  1444. pf = await personFacts();
  1445. const rowsBefore = (await filmRows()).length;
  1446. // meanwhile another request: answered while the fill runs (the fetch steps yield)
  1447. check('person: first visit (client-side from the cast link) shows "Loading filmography…" and no rows yet',
  1448. pf.h1 === 'Test Actor' && pf.loading && (await ev(`document.querySelector('#personloading').textContent`)).startsWith('Loading filmography') && rowsBefore === 0, JSON.stringify({ pf, rowsBefore }));
  1449. await page.waitFor(`!document.querySelector('#personloading') && document.querySelectorAll('a.film-row').length > 0`, { timeout: 20000, label: 'filmography filled in' });
  1450. const fillMs = Date.now() - fillT0;
  1451. await page.waitFor(`document.querySelector('person-photo img') && document.querySelector('person-photo img').complete`, { timeout: 5000, label: 'photo' }).catch(() => {});
  1452. pf = await personFacts();
  1453. fr = await filmRows();
  1454. const marker16 = await ev('window.__w055 || null');
  1455. check('person: the filmography filled in WITHOUT a reload (same document) — facts and the photo from TMDB too',
  1456. marker16 === 'same document' && !pf.loading && pf.error === null && JSON.stringify(pf.facts) === JSON.stringify(['Born 6 May 1970 in Fixture Town']) && pf.bio === 'Test Actor bio from TMDB.'
  1457. && pf.photo === '/profiles/p1.png' && pf.photoLoaded, JSON.stringify({ marker16, pf, fillMs }));
  1458. const bio0 = await ev(`document.querySelector('person-bio').className`);
  1459. await page.click('person-bio');
  1460. await page.waitFor(`document.querySelector('person-bio').className === 'full'`, { timeout: 5000, label: 'bio open' }).catch(() => {});
  1461. const bio1 = await ev(`document.querySelector('person-bio').className + '|' + getComputedStyle(document.querySelector('person-bio')).webkitLineClamp`);
  1462. check('person: the bio is SHORT (four lines) until clicked, then whole', bio0 === 'short' && bio1 === 'full|none', bio0 + ' → ' + bio1);
  1463. const titles16 = fr.map(r => r[0]);
  1464. check('person: 86 rows (87 TMDB titles − the adult one), newest first, undated last; roles of cast + crew merged; the adult title hidden',
  1465. fr.length === 86 && JSON.stringify(fr.slice(0, 4)) === JSON.stringify([['Gate Test Show', '2024', 'Series', 'Someone', '/series/gate-test-show'], ['Directed Only', '2018', 'Movie', 'Writer', '/movies/Directed-Only'],
  1466. ['Person Series', '2015', 'Series', 'Lead', '/series/Person-Series'], ['Person Film One', '2010', 'Movie', 'Hero / Director', '/movies/Person-Film-One']])
  1467. && titles16[4] === 'Bulk Film 01' && titles16[83] === 'Bulk Film 80' && JSON.stringify(fr[84]) === JSON.stringify(['Gate Test Movie', '1996', 'Movie', 'Cameo', '/movies/gate-test-movie'])
  1468. && JSON.stringify(fr[85]) === JSON.stringify(['Announced Film', '', 'Movie', 'Villain', '/movies/Announced-Film']) && !titles16.includes('Hidden Adult Film'), JSON.stringify(fr.slice(0, 6)) + ' … ' + JSON.stringify(fr.slice(-3)));
  1469. const posters16 = JSON.parse(await ev(`JSON.stringify(Array.from(document.querySelectorAll('a.film-row img.film-poster')).slice(0, 4).map(i => i.getAttribute('src')))`));
  1470. check('person: posters — our file when we have one (show 1), else TMDB\'s small one (w92), else the placeholder',
  1471. posters16[0] === '/posters/sh1.png' && posters16[1] === '/posters/none' && posters16[3] === tmdb.base + '/t/p/w92/pf1.png', JSON.stringify(posters16));
  1472. const pr16 = tmdb.personRequests.map(q => q.path);
  1473. const fillLines = log.split('\n').filter(l => l.startsWith('person fill: '));
  1474. check('person: ONE TMDB request (person + combined_credits, Bearer token) + the photo (w185); the fill ran in 4 steps (TMDB, then 3 × 40 titles) and added 85 titles (2 existed)',
  1475. JSON.stringify(pr16) === JSON.stringify(['/3/person/3002?append_to_response=combined_credits', '/t/p/w185/face2.png']) && tmdb.personRequests[0].authorization === 'Bearer gate-token'
  1476. && fillLines.length === 1 && /^person fill: Test Actor \(tmdb 3002\) credits=87 added=85 requests=2 steps=4 /.test(fillLines[0]), JSON.stringify({ pr16, fillLines }));
  1477. tmdb.personDelayMs = 0;
  1478. // the links: a row → its show page (client-side); Back → the person page, complete now (no loading)
  1479. await page.click('a.film-row[href="/series/gate-test-show"]');
  1480. await page.waitFor(`location.pathname === '/series/gate-test-show' && !!document.querySelector('show-header h1')`, { timeout: 10000, label: 'show page from the filmography' });
  1481. const back1 = await ev(`document.querySelector('show-header h1 type-name').textContent + '|' + (window.__w055 || '')`);
  1482. await ev('history.back()');
  1483. await page.waitFor(`location.pathname === '/person/Test-Actor' && document.querySelectorAll('a.film-row').length === 86`, { timeout: 10000, label: 'Back to the person' });
  1484. pf = await personFacts();
  1485. check('person: a filmography row → the show page (client-side), Back → the person page, filled, no loading again',
  1486. back1 === 'Gate Test Show|same document' && !pf.loading && (await ev('window.__w055 || null')) === 'same document', JSON.stringify({ back1, pf }));
  1487. await page.click('a.film-row[href="/movies/Person-Film-One"]');
  1488. await page.waitFor(`location.pathname === '/movies/Person-Film-One' && !!document.querySelector('show-header h1')`, { timeout: 10000, label: 'new title page' });
  1489. lk = await extLinks();
  1490. check('person: a title the fill added has its page (/movies/Person-Film-One: title, the overview, TMDB link, genre Drama, the person in its cast)',
  1491. (await ev(`document.querySelector('show-header h1 type-name').textContent`)) === 'Person Film One' && (await ev(`document.querySelector('show-summary').textContent`)) === 'a film of the person'
  1492. && linksAre(lk, [['TMDB', TMDB_MOVIE + '2001']]) && (await ev(`Array.from(document.querySelectorAll('a.genre-pill')).map(a => a.textContent).join(',')`)) === 'Drama'
  1493. && (await ev(`Array.from(document.querySelectorAll('a.artist-link')).map(a => a.textContent + ' ' + a.getAttribute('href')).join(',')`)) === 'Test Actor /person/Test-Actor', lk);
  1494. // second visit (full load): complete — TMDB not asked again, nothing added, same rows
  1495. await page.goto(BASE + '/person/Test-Actor');
  1496. await hydrated();
  1497. await new Promise(r => setTimeout(r, 700));
  1498. pf = await personFacts();
  1499. check('person: a SECOND visit is complete at once — no loading, the same 86 rows, TMDB not asked again, no second fill',
  1500. !pf.loading && (await filmRows()).length === 86 && tmdb.personRequests.length === 2 && log.split('\n').filter(l => l.startsWith('person fill: ')).length === 1, JSON.stringify({ pf, req: tmdb.personRequests.length }));
  1501. // another person whose credits we have by now: linked, nothing added (no duplicate titles)
  1502. await page.goto(BASE + '/person/Second-Actor');
  1503. await hydrated();
  1504. await page.waitFor(`!document.querySelector('#personloading')`, { timeout: 15000, label: 'second actor filled' });
  1505. fr = await filmRows();
  1506. const second = log.split('\n').filter(l => l.startsWith('person fill: Second Actor'));
  1507. check('person: a second person with titles we have — linked, added=0, no photo; the title OUR record marks adult hidden though the credit is not',
  1508. JSON.stringify(fr) === JSON.stringify([['Gate Test Show', '2024', 'Series', 'Guest', '/series/gate-test-show'], ['Person Film One', '2010', 'Movie', 'Sidekick', '/movies/Person-Film-One']])
  1509. && second.length === 1 && / added=0 requests=1 /.test(second[0]) && (await personFacts()).photo === null, JSON.stringify({ fr, second }));
  1510. await page.goto(BASE + '/search/person%20film');
  1511. await hydrated();
  1512. check('person: the search finds the added title once', (await ev(`Array.from(document.querySelectorAll('a.search-title')).filter(a => a.textContent === 'Person Film One (2010)').length`)) === 1);
  1513. check('person: the server log has no error', !/error absorbed|not stored/i.test(log), log.split('\n').filter(l => /person|error/i.test(l)).join('\n'));
  1514. for (const [w, h, mobile] of [[390, 844, true], [1280, 900, false]]) {
  1515. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: mobile ? 2 : 1, mobile });
  1516. for (const [name, path] of [['person', '/person/Test-Actor'], ['person-complete', '/person/Complete-Person']]) {
  1517. await page.goto(BASE + path);
  1518. await hydrated();
  1519. await page.waitFor(`Array.from(document.querySelectorAll('img')).filter(i => i.getBoundingClientRect().top < innerHeight).every(i => i.complete)`, { timeout: 5000 }).catch(() => {});
  1520. check(`person: ${path} at ${w} px — no sideways scroll, header one row`, (await ev('document.documentElement.scrollWidth')) <= w && (await ev(`document.querySelector('application-header').getBoundingClientRect().height`)) <= 64);
  1521. if (process.env.TRACKER_GATE_SHOTS) writeFileSync(join(process.env.TRACKER_GATE_SHOTS, `${name}-${w}.png`), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  1522. }
  1523. }
  1524. await page.send('Emulation.clearDeviceMetricsOverride', {});
  1525. // ==== mission 060 (tracker.worldapi.org#27): SHORT IDS — every title and person has one (5 characters, a–z 0–9), shown below
  1526. // the poster / photo (small, muted, monospace); Gate Test Show keeps its old one (sh1 → 100jh); records created by the app
  1527. // get one at once (the search import, the person fill); `/<shortId>` answers 301 to the page; unique across both tables;
  1528. // the background backfill resumes after a restart and repairs a duplicate ====
  1529. const SID = /^[a-z0-9]{5}$/;
  1530. // the short id under the image: its text, where it sits, how it looks
  1531. const shortIdInfo = () => ev(`JSON.stringify((() => { const l = document.querySelector('#shortid'); if (!l) return null;
  1532. const box = l.parentElement; const img = box.querySelector('img'); const r = l.getBoundingClientRect(); const ir = img ? img.getBoundingClientRect() : null;
  1533. const cs = getComputedStyle(l); const muted = document.createElement('span'); muted.className = 'muted'; document.body.appendChild(muted);
  1534. const mc = getComputedStyle(muted).color; muted.remove();
  1535. return { text: l.textContent, parent: box.tagName.toLowerCase(), below: ir ? r.top >= ir.bottom - 1 && r.left < ir.right && r.right > ir.left : null,
  1536. mono: /monospace/.test(cs.fontFamily), muted: cs.color === mc, small: parseFloat(cs.fontSize) < parseFloat(getComputedStyle(document.body).fontSize), visible: r.width > 0 && r.height > 0 }; })())`).then(JSON.parse);
  1537. const shortIdOf = async (path) => { await page.goto(BASE + path); await hydrated(); return shortIdInfo(); };
  1538. let si = await shortIdOf('/series/gate-test-show');
  1539. check('short ids: Gate Test Show (old id sh1) keeps its OLD short id 100jh — under the poster, small, muted, monospace',
  1540. si && si.text === '100jh' && si.parent === 'show-poster' && si.below && si.mono && si.muted && si.small && si.visible, JSON.stringify(si));
  1541. const sidMovie = await shortIdOf('/movies/gate-test-movie');
  1542. const sidSeries2 = await shortIdOf('/series/unwatched-gate-show');
  1543. check('short ids: a movie and a series without an old one got a NEW one (5 characters a–z 0–9, not an old one), shown even without a poster file',
  1544. sidMovie && SID.test(sidMovie.text) && sidSeries2 && SID.test(sidSeries2.text) && !['100jh', '100ji'].includes(sidMovie.text) && sidMovie.text !== sidSeries2.text && sidMovie.visible, JSON.stringify({ sidMovie, sidSeries2 }));
  1545. const sidActor = await shortIdOf('/person/Test-Actor');
  1546. const sidComplete = await shortIdOf('/person/Complete-Person');
  1547. check('short ids: a person — under the photo (Test Actor), without a photo under the name and facts (Complete Person); monospace, muted',
  1548. sidActor && SID.test(sidActor.text) && sidActor.parent === 'person-photo' && sidActor.below && sidActor.mono && sidActor.muted
  1549. && sidComplete && SID.test(sidComplete.text) && sidComplete.parent === 'person-meta' && sidComplete.below === null && sidComplete.mono && sidComplete.muted, JSON.stringify({ sidActor, sidComplete }));
  1550. // created by the app during THIS run (the person fill above) or an earlier one (the search import, #14): the backfill of this
  1551. // run had nothing left before the fill → the fill's titles got theirs when they were created
  1552. const sidFilled = await shortIdOf('/movies/Person-Film-One');
  1553. const sidImported = await shortIdOf('/series/Gate-Import-Show');
  1554. check('short ids: NEW records get one at creation — a title the person fill added in this run (the run\'s backfill was finished before) and a search import',
  1555. sidFilled && SID.test(sidFilled.text) && sidImported && SID.test(sidImported.text) && /short ids( done|: nothing to do)/.test(log) && log.indexOf('person fill: Test Actor') > log.search(/short ids( done|: nothing to do)/),
  1556. JSON.stringify({ sidFilled, sidImported, lines: log.split('\n').filter(l => /short ids|person fill/.test(l)) }));
  1557. // the redirect: /<shortId> → 301 to the page (a show, a person; upper case too); anything else 404; the browser lands on the page
  1558. const redir = async (p) => { const r = await fetch(BASE + p, { redirect: 'manual' }); return r.status + ' ' + (r.headers.get('location') || ''); };
  1559. const rd = { old: await redir('/100jh'), upper: await redir('/100JH'), movie: await redir('/' + sidMovie.text), person: await redir('/' + sidActor.text),
  1560. unknown: await redir('/zzzzz'), reserved: await redir('/100ji'), short: await redir('/abc'), movies: (await fetch(BASE + '/movies', { redirect: 'manual' })).status };
  1561. check('short ids: /<shortId> answers 301 to the page (show, movie, person, upper case read as lower); unknown / reserved-but-unused / not a short id → 404; /movies untouched',
  1562. rd.old === '301 /series/gate-test-show' && rd.upper === '301 /series/gate-test-show' && rd.movie === '301 /movies/gate-test-movie' && rd.person === '301 /person/Test-Actor'
  1563. && rd.unknown === '404 ' && rd.reserved === '404 ' && rd.short === '404 ' && rd.movies === 200, JSON.stringify(rd));
  1564. await page.goto(BASE + '/' + sidComplete.text);
  1565. await hydrated();
  1566. check('short ids: the browser opening /<shortId> lands on the page', (await ev(`location.pathname + '|' + (document.querySelector('person-meta h1 type-name') || {}).textContent`)) === '/person/Complete-Person|Complete Person');
  1567. for (const [w, h, mobile] of [[390, 844, true], [1280, 900, false]]) {
  1568. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: mobile ? 2 : 1, mobile });
  1569. for (const [name, path] of [['shortid-show', '/series/gate-test-show'], ['shortid-movie', '/movies/gate-test-movie'], ['shortid-person', '/person/Test-Actor'], ['shortid-person-nophoto', '/person/Complete-Person']]) {
  1570. await page.goto(BASE + path);
  1571. await hydrated();
  1572. await page.waitFor(`Array.from(document.querySelectorAll('img')).filter(i => i.getBoundingClientRect().top < innerHeight).every(i => i.complete)`, { timeout: 5000 }).catch(() => {});
  1573. si = await shortIdInfo();
  1574. const inView = await ev(`(() => { const r = document.querySelector('#shortid').getBoundingClientRect(); return r.right <= innerWidth && r.left >= 0; })()`);
  1575. check(`short ids: ${path} at ${w} px — the short id visible under the image, no sideways scroll`, si && si.visible && si.below !== false && inView && (await ev('document.documentElement.scrollWidth')) <= w, JSON.stringify(si));
  1576. if (process.env.TRACKER_GATE_SHOTS) {
  1577. if (mobile) await ev(`document.querySelector('#shortid').scrollIntoView({ block: 'center' })`);
  1578. writeFileSync(join(process.env.TRACKER_GATE_SHOTS, `${name}-${w}.png`), Buffer.from((await page.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  1579. }
  1580. }
  1581. }
  1582. await page.send('Emulation.clearDeviceMetricsOverride', {});
  1583. check('short ids: the server log has no short-id problem', !/short ids: .*(not stored|gets a new one)/.test(log), log.split('\n').filter(l => /short ids/.test(l)).join('\n'));
  1584. // unique across shows + persons, every record has one (the counting tool, app stopped); then the RESUME: 60 persons without one
  1585. // (+ two sharing 'aaaa1') added with the app stopped; a start with a 1 ms budget per batch is stopped after ≥ 5; the next start
  1586. // goes on with only the rest, keeps 'aaaa1' for one of the two and gives the other a new one
  1587. await page.goto('about:blank');
  1588. await stopServer();
  1589. const countShortIds = () => execFileSync(join(APP, 'bin/hybriel'), ['tools/count-short-ids.hl'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: MPACKDB, TRACKER_OLD_SHORT_IDS: OLD_SHORT_IDS } }).toString();
  1590. let sidCount = countShortIds();
  1591. const rowsOf = (c, kind) => (c.match(new RegExp(kind + 's rows=(\\d+) withShortId=(\\d+) without=(\\d+) malformed=(\\d+)')) || []).slice(1).map(Number);
  1592. let sidShows = rowsOf(sidCount, 'show'), sidPersons = rowsOf(sidCount, 'person');
  1593. check('short ids: EVERY show and person has one, none twice across both tables, the old one kept (tools/count-short-ids.hl)',
  1594. sidShows[0] > 40 && sidShows[0] === sidShows[1] && sidShows[2] === 0 && sidShows[3] === 0 && sidPersons[0] >= 3 && sidPersons[0] === sidPersons[1] && sidPersons[2] === 0 && sidCount.includes('duplicates across shows+persons=0')
  1595. && sidCount.includes('kept=1 notYet=0 lost=0 oldIdOnAnotherRecord=0'), sidCount);
  1596. const seedSid = execFileSync(join(APP, 'bin/hybriel'), ['tests/seed-shortids.hl'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: MPACKDB } }).toString();
  1597. await startServer({ TRACKER_SHORTID_BUDGET_MS: '1', TRACKER_SHORTID_LOG_EVERY: '5' });
  1598. for (let i = 0; i < 100 && !/short ids: \d+ assigned, \d+ left/.test(log); i++) await new Promise(r => setTimeout(r, 50));
  1599. const resume1 = log;
  1600. await page.goto('about:blank');
  1601. await stopServer();
  1602. sidCount = countShortIds();
  1603. sidPersons = rowsOf(sidCount, 'person');
  1604. // B (the duplicate) is LAST in the queue: until the run reaches it the stored data still has aaaa1 twice (the start's map does not)
  1605. const bLeft = sidCount.includes('duplicates across shows+persons=1') && /DUPLICATE aaaa1: person sp0000000000dupa and person sp0000000000dupb/.test(sidCount) ? 1 : 0;
  1606. const missing = sidPersons[2] + bLeft;
  1607. check('short ids (resume): 62 persons added (60 without, 2 sharing aaaa1); a start finds 61 to do (B: the duplicate), is stopped part way — some got one, the rest not; no other duplicate',
  1608. seedSid.includes('62 persons') && /short ids: \d+ records, \d+ with a short id, 61 without/.test(resume1) && /has "aaaa1", taken by person sp0000000000dupa — gets a new one/.test(resume1)
  1609. && sidPersons[2] > 0 && missing < 61 && (sidCount.includes('duplicates across shows+persons=0') || bLeft === 1),
  1610. resume1.split('\n').filter(l => /short ids/.test(l)).join('\n') + '\n' + sidCount);
  1611. await startServer();
  1612. for (let i = 0; i < 100 && !/short ids done/.test(log); i++) await new Promise(r => setTimeout(r, 100));
  1613. const resume2 = log.split('\n').filter(l => l.startsWith('short ids')).join('\n');
  1614. await page.goto('about:blank');
  1615. await stopServer();
  1616. sidCount = countShortIds();
  1617. sidPersons = rowsOf(sidCount, 'person');
  1618. check('short ids (resume): the next start goes on with ONLY the rest (' + missing + '), then every person has one, none twice',
  1619. new RegExp('short ids: \\d+ records, \\d+ with a short id, ' + missing + ' without').test(resume2) && new RegExp('short ids done: assigned=' + missing + ' ').test(resume2)
  1620. && sidPersons[0] === sidPersons[1] && sidPersons[2] === 0 && sidCount.includes('duplicates across shows+persons=0'), resume2 + '\n' + sidCount);
  1621. await startServer();
  1622. const dupA = await shortIdOf('/person/Dupe-Person-A'), dupB = await shortIdOf('/person/Dupe-Person-B');
  1623. check('short ids: of the two persons sharing aaaa1 one keeps it, the other has its own now; a third start has nothing to do',
  1624. dupA && dupB && [dupA.text, dupB.text].filter(t => t === 'aaaa1').length === 1 && SID.test(dupA.text) && SID.test(dupB.text) && /short ids: nothing to do/.test(log), JSON.stringify({ dupA, dupB, log: log.split('\n').filter(l => /short ids/.test(l)) }));
  1625. // ==== tracker.worldapi.org#10: THE INSTALLABLE APP — hl:web's own manifest + service worker (project.hl appIcons /
  1626. // offline = [ Home ]). The manifest and every icon over HTTP; Chrome's own verdict (installability, manifest parse);
  1627. // the worker registered for the whole app; then OFFLINE: the tab loses the network (the note appears), the server
  1628. // is stopped too (CDP's offline emulation does not reach the service worker's own fetches — measured — so only a
  1629. // dead server proves the cache), and `/` still opens: header + the note. A data page gets hl:web's "Unavailable
  1630. // offline" page. A separate tab, so its expected socket errors stay out of the main tab's console check.
  1631. const html = await (await fetch(BASE + '/')).text();
  1632. const mhref = (html.match(/<link rel="manifest" href="([^"]+)"/) || [])[1];
  1633. check('pwa: every page head links the manifest, the apple-touch-icon, the favicon and the theme colour (the token `darker`)',
  1634. mhref === '/__hl/manifest.webmanifest' && html.includes('<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png">')
  1635. && html.includes('<link rel="icon" href="/icons/favicon.svg">') && html.includes('<meta name="theme-color" content="rgb(15, 20, 25)">'), html.slice(0, 900));
  1636. const mres = await fetch(BASE + mhref);
  1637. const man = await mres.json();
  1638. check('pwa: the manifest is served as application/manifest+json: name "tracker", start_url /, scope /, display standalone, the token colours',
  1639. /manifest\+json/.test(mres.headers.get('content-type') || '') && man.name === 'tracker' && man.short_name === 'tracker' && man.start_url === '/' && man.scope === '/'
  1640. && man.display === 'standalone' && man.theme_color === 'rgb(15, 20, 25)' && man.background_color === 'rgb(25, 30, 35)', JSON.stringify(man));
  1641. const iconOk = [];
  1642. for (const ic of man.icons || []) {
  1643. const ir = await fetch(BASE + ic.src);
  1644. const b = Buffer.from(await ir.arrayBuffer());
  1645. iconOk.push(ir.ok && ic.type === 'image/png' && b.readUInt32BE(16) === Number(ic.sizes.split('x')[0]) && b.readUInt32BE(20) === Number(ic.sizes.split('x')[1]));
  1646. }
  1647. check('pwa: every manifest icon loads and is a real PNG of its declared size (192 + 512, any + maskable)',
  1648. iconOk.length === 4 && iconOk.every(Boolean) && ['any', 'maskable'].every(pu => ['192x192', '512x512'].every(sz => man.icons.some(i => i.purpose === pu && i.sizes === sz))), JSON.stringify(man.icons) + ' ' + JSON.stringify(iconOk));
  1649. const touch = await fetch(BASE + '/icons/apple-touch-icon.png');
  1650. const touchBytes = Buffer.from(await touch.arrayBuffer());
  1651. const fav = await fetch(BASE + '/icons/favicon.svg');
  1652. const favText = await fav.text();
  1653. const ico = await fetch(BASE + '/favicon.ico');
  1654. const icoBytes = Buffer.from(await ico.arrayBuffer());
  1655. check('pwa: apple-touch-icon is a 180×180 PNG, the favicon an SVG in tracker green, /favicon.ico a real icon file',
  1656. touch.ok && touchBytes.readUInt32BE(16) === 180 && fav.ok && /image\/svg\+xml/.test(fav.headers.get('content-type') || '') && favText.includes('#4ec9b0')
  1657. && ico.ok && icoBytes.readUInt32BE(0) === 0x00000100, `${touch.status} ${fav.status} ${ico.status}`);
  1658. await page.goto('about:blank'); // the server goes down below: the main tab must not sit on a page meanwhile
  1659. const app = await browser.newPage();
  1660. const aev = (e) => app.evaluate(e);
  1661. const appHydrated = () => app.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 15000, label: 'app tab hydrated' });
  1662. await app.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 2, mobile: true });
  1663. await app.goto(BASE + '/');
  1664. await appHydrated();
  1665. await app.waitFor(`navigator.serviceWorker.getRegistration().then(r => !!(r && r.active))`, { timeout: 15000, label: 'service worker active' });
  1666. await app.waitFor(`!!navigator.serviceWorker.controller`, { timeout: 10000, label: 'page controlled by the worker' });
  1667. const inst = await app.send('Page.getInstallabilityErrors');
  1668. check('pwa: Chrome reports no installability error', (inst.installabilityErrors || []).length === 0, JSON.stringify(inst));
  1669. const am = await app.send('Page.getAppManifest');
  1670. check('pwa: Chrome parses the manifest without errors', am.url && am.url.endsWith('/__hl/manifest.webmanifest') && (am.errors || []).length === 0, JSON.stringify(am.errors));
  1671. check('pwa: hl:web\'s service worker is registered for the whole app (scope /) and controls the page',
  1672. (await aev(`navigator.serviceWorker.getRegistration().then(r => new URL(r.scope).pathname + ' ' + new URL(r.active.scriptURL).pathname)`)) === '/ /__hl/sw.js' && (await aev('!!navigator.serviceWorker.controller')));
  1673. check('pwa: online, no offline note', !(await aev(`!!document.querySelector('#offline')`)));
  1674. if (process.env.TRACKER_GATE_SHOTS) writeFileSync(join(process.env.TRACKER_GATE_SHOTS, 'pwa-phone-online.png'), Buffer.from((await app.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  1675. await app.setOffline(true);
  1676. await app.waitFor(`!!document.querySelector('#offline')`, { timeout: 5000, label: 'offline note (live)' }).catch(() => {});
  1677. check('offline: the open page says so within seconds (the shell\'s tick)', (await aev(`document.querySelector('#offline') ? document.querySelector('#offline').textContent : ''`)) === 'You are offline. Your shows and lists need the network.');
  1678. await stopServer();
  1679. let down = false;
  1680. try { await fetch(BASE + '/'); } catch { down = true; }
  1681. await app.goto(BASE + '/');
  1682. await app.waitFor(`!!document.querySelector('#offline')`, { timeout: 8000, label: 'offline note after reload' }).catch(() => {});
  1683. // the Shows row: 3 fixture series + Gate Import Show (#14's import, in the lists at once since the #13/#14 merge)
  1684. check('offline: with the server gone too, a reload of / still opens the shell from the worker\'s cache — header, brand, the note, the home (#13: its text and both rows — 5 shows since mission 054 added Flagless Gate Series)',
  1685. down && (await aev(`document.querySelector('application-header .brand') ? document.querySelector('application-header .brand').textContent : ''`)) === 'tracker'
  1686. && (await aev(`!!document.querySelector('#offline')`)) && (await aev(`!!document.querySelector('home-intro') && document.querySelectorAll('#home-movies a.tile').length === 10 && document.querySelectorAll('#home-series a.tile').length === 5`))
  1687. && (await aev(`getComputedStyle(document.querySelector('application-header')).backgroundColor`)) === 'rgb(15, 20, 25)', 'server down: ' + down);
  1688. if (process.env.TRACKER_GATE_SHOTS) writeFileSync(join(process.env.TRACKER_GATE_SHOTS, 'pwa-phone-offline.png'), Buffer.from((await app.send('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
  1689. await app.goto(BASE + '/my/series');
  1690. check('offline: a data page (/my/series) is not kept — hl:web\'s "Unavailable offline" page', (await aev(`!!document.querySelector('main[data-hl-offline]') && document.querySelector('h1').textContent`)) === 'Unavailable offline');
  1691. await app.setOffline(false);
  1692. await startServer();
  1693. await app.goto(BASE + '/');
  1694. await appHydrated();
  1695. await app.waitFor(`!document.querySelector('#offline')`, { timeout: 5000, label: 'note gone' }).catch(() => {});
  1696. check('back online: / from the server again, no offline note', !(await aev(`!!document.querySelector('#offline')`)));
  1697. await app.close();
  1698. await page.goto(BASE + '/my/schedule');
  1699. await hydrated();
  1700. // ---- sign out: back to signed out, a reload confirms the app's own session (not just client state) ----
  1701. await page.click('#logout');
  1702. await page.waitForSelector('#loginbutton', { timeout: 15000 });
  1703. check('sign out returns to the signed-out header', (await ev(`!!document.querySelector('#loginbutton')`)) && !(await ev(`!!document.querySelector('#logout')`)));
  1704. await page.goto(BASE + '/');
  1705. await hydrated();
  1706. check('reload after sign-out stays signed out', (await ev(`!!document.querySelector('#loginbutton')`)) && !(await ev(`!!document.querySelector('#logout')`)));
  1707. const problems = page.problems();
  1708. check('no console errors/warnings', problems.length === 0, page.dumpConsole());
  1709. }
  1710. try {
  1711. await main();
  1712. } catch (e) {
  1713. check('gate ran without throwing', false, (e.stack || String(e)) + (globalThis.__gatePage ? '\nbrowser console:\n' + globalThis.__gatePage.dumpConsole() : '') + '\nserver log (tail):\n' + log.slice(-2000));
  1714. } finally {
  1715. await stop();
  1716. }
  1717. console.log(`\n${passes} passed, ${failures} failed`);
  1718. process.exit(failures === 0 ? 0 : 1);

Branches

Latest commits

  • 1ed5457etracker#20 + #21 (mission 068): typed headings "<Type> | <name>" in type colours; TV titles split into Series (/series) and Shows (/shows) by TMDB type + Reality/Talk/News genres — kind stored by sync/import/adult backfill + new kind backfill (resumes), /movies/<slug>, /shows/<slug> of a series/movie → 301, /my/series + /my/shows, home 5 tiles + 3 rows, search/filmography labels; gates kinds 32 + browser 266, tests/realdata-068.mjs, tools/count-kinds.hl, docs/kinds.md, README + STATUSmre
  • fa1f9dfatracker#29 (mission 063): unwatched check muted grey outline + check (accent only on hover), watched stays solid — no code regression, the accent outline read as ticked; gate checks real checks visibly (computed style + screenshot pixel) on /my/unwatched, show, movie, /my/movies; gate 266, tests/realdata-063.mjs, README + STATUSmre
  • d8b12d67tracker#27 (mission 060): short ids for movies, series and persons — old 702 kept (data/old-short-ids.json), new random [a-z0-9]{5} unique across both, claimed at creation, background backfill (resumes), shown under poster/photo, /<shortId> → 301; gate 259, tests/realdata-060*, README + STATUSmre
  • f14db671tracker#22-#25 (mission 058): episode air dates, season check = all episodes watched, movie watched check (+ /my/movies count), /genres/<genre> pages (movies + series, newest first, paginated); gate 238, tests/realdata-058.mjs, README + STATUSmre
  • 1704ec45tracker#17 (mission 057): season caret down/up, skeleton rows while a season loads, sessionless showSeasonEpisodes face (no page re-mount), client-only close; gate 214, tests/realdata-057.mjs, README + STATUSmre
  • f2fe3e36mission 056: README + STATUS (merge, fixes, Hybriel 8590df63, real-data check), tests/realdata-056.mjs, tools/check-public-slugs.hlmre
  • f40c250emission 056: re-vendor hybriel master 8590df63 (#121, #122); an adult title's page is Not found for non-followers; gate: leave the page before stopping the servermre
  • 2b7fdd6cmission 056: signed-out header one row on phones ("Log in", nowrap), backfill skips adult titles' posters, gate checksmre
  • 2c53d5efMerge branch 't16-person' (tracker#16 person pages) into main; filmography shows only public titles (054 adult flag), gate race fix (backfill start line)mre
  • c171227emission 054: hide adult/unknown titles from the public lists and the search; in-app adult-flag backfill (TMDB details + poster per title, resumes), gate + real-data proofmre
  • 139fafd8tracker#16: short bio (4 lines, click = all), real-data check script, README + STATUSmre
  • 93be9476tracker#16: person pages /person/<slug> with the filmography fetched from TMDB on the first visit (step by step), gatemre
  • 47a3cae6STATUS: mission 053 merge commit idsmre
  • dcc5eecaMerge branch 't14-search'mre
  • 03edc783Merge branch 't15-tvmaze'mre
  • 71b46345tracker#15: numbering check by date or title, placeholder titles in other languages, docs + real-data proofmre
  • 6bb2daf1tracker#13: homepage (tiles, intro, latest movies/shows), /shows, /movies/page/N, /my/movies; lists cached in memorymre
  • b8bd1157tracker#14: README + STATUS (search, real-data numbers, gate, merge notes)mre
  • 65c694a8tracker#14: search — header magnifier, /search/<text> (in-memory word-prefix index over titles + people), Fetch from web (TMDB search/multi, ours left out), Add = import via syncShow; gate +25 checks, real-data scriptmre
  • 34f2c15btracker#15: TVmaze merge in the sync (gaps only: new episodes/seasons, empty titles/air dates; numbering check), fake TVmaze episodes + gatemre