gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8dd423f78dd423f7README: login.js stays by caramboleyo's explicit rulemre8dd423f7/tests/faketmdb.mjs

13.0 KB

  1. // tests/faketmdb.mjs — A FAKE TMDB for the gate (tracker.worldapi.org#9): a tiny local HTTP server that answers
  2. // the three calls lib/sync.hl makes, from fixed JSON — no real TMDB call ever happens in the gate. The app is
  3. // pointed at it with TMDB_BASE_URL=<base>/3 and TMDB_IMAGE_URL=<base>/t/p.
  4. //
  5. // GET /3/tv/<id> details (shows[id] minus the episodes)
  6. // GET /3/tv/<id>?append_to_response=season/1,… the same + "season/<n>" = { name, overview, air_date, episodes }
  7. // GET /t/p/w342|w780/<file>.png a 1×1 png (w780: a backdrop, mission 032)
  8. // …?append_to_response=…,external_ids + "external_ids" = shows[id].external_ids (tracker.worldapi.org#12)
  9. // GET /3/movie/<id>[?append_to_response=external_ids] movies[id]: { id, title, poster_path } (+ external_ids)
  10. // GET /3/search/multi?query=… tracker.worldapi.org#14: { results = search[query in lower case] }
  11. // — recorded in `fake.searchRequests`, NOT in `fake.requests`
  12. // GET /t/p/w92/<file>.png the search page's small posters → `fake.thumbRequests`
  13. // GET /3/person/<id>[?append_to_response=combined_credits] tracker.worldapi.org#16: persons[id] (+ its combined_credits)
  14. // GET /t/p/w185/<file>.png a person's photo (1×1 png) — both recorded in `fake.personRequests`
  15. // and A FAKE TVMAZE under /tvmaze (the app gets TVMAZE_BASE_URL=<base>/tvmaze):
  16. // GET /tvmaze/lookup/shows?imdb=tt…|thetvdb=<id> 301 → /tvmaze/shows/<id> (like the real one), 404 when unknown
  17. // GET /tvmaze/shows/<id> { id, name }
  18. // GET /tvmaze/shows/<id>?embed=episodes + summary (tvmaze.summaries[id], HTML) + _embedded.episodes = tvmaze.episodes[id]
  19. // (tracker.worldapi.org#15, #18): [{ id, season, number, name, airdate }]; 404 without episodes
  20. // GET /tvmaze/updates/shows?since=day|week|month tracker.worldapi.org#18: tvmaze.updates ({ "<id>": <time> })
  21. // both /tvmaze/shows/<id> answers carry `status` = tvmaze.statuses[id] (tracker#35; null when none) and `type` = tvmaze.types[id]
  22. // (tracker#43; null when none); an id in tvmaze.missing → 404
  23. // GET /3/tv/changes, /3/movie/changes?start_date=…&end_date=…&page=n tracker.worldapi.org#18: `fake.changes` { tv: [ids], movie: [ids] },
  24. // `fake.changesPageSize` (100) per page — recorded in `fake.requests` like every TMDB call;
  25. // `fake.changesFail` = true answers 503
  26. //
  27. // GET /3/collection/<id> tracker.worldapi.org#19 (mission 066): collections[id] = { id, name, parts }; a
  28. // movie's details carry `belongs_to_collection` when its fixture has one
  29. // …?append_to_response=…,credits (movie) / aggregate_credits (tv) tracker.worldapi.org#26: the fixture's `credits` /
  30. // `aggregate_credits` ({ cast: [...] }); details also carry homepage,
  31. // tagline, status, genres of the fixture
  32. // tracker.worldapi.org#28: a series' details carry the fixture's `created_by`
  33. // (default []); credits may carry `crew` (movie: { job }, series: { jobs })
  34. // mission 054: every details / search answer carries TMDB's `adult` (false unless the fixture sets it). Mission 068 (tracker#21):
  35. // a TV details answer carries the fixture's `type` (Scripted, Talk Show, …; none when the fixture has none).
  36. // `fake.shows` is mutable (the gate adds an episode before the in-app run), `fake.delayMs` slows every answer
  37. // down, `fake.requests` records every TMDB/image request (path, authorization) so the gate can prove what was asked;
  38. // TVmaze requests go to `fake.tvmazeRequests` (paths) instead.
  39. import http from 'node:http';
  40. export const PNG = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==', 'base64');
  41. export async function startFakeTmdb({ port, shows, movies = {}, tvmaze = { imdb: {}, thetvdb: {} }, search = {}, persons = {}, collections = {} }) {
  42. const fake = { shows, movies, tvmaze, search, persons, collections, changes: { tv: [], movie: [] }, changesPageSize: 100, changesFail: false, delayMs: 0, personDelayMs: 0, requests: [], tvmazeRequests: [], searchRequests: [], thumbRequests: [], personRequests: [], base: `http://127.0.0.1:${port}` };
  43. const details = (s) => ({
  44. id: s.id, name: s.name, adult: s.adult ?? false, overview: s.overview, status: s.status, poster_path: s.poster_path, backdrop_path: s.backdrop_path ?? null,
  45. first_air_date: s.first_air_date, genres: s.genres, original_language: s.original_language, homepage: s.homepage, tagline: s.tagline, created_by: s.created_by || [], type: s.type,
  46. number_of_seasons: s.seasons.filter(x => x.season_number > 0).length,
  47. number_of_episodes: s.seasons.filter(x => x.season_number > 0).reduce((a, x) => a + x.episodes.length, 0),
  48. seasons: s.seasons.map(x => ({ id: x.id, season_number: x.season_number, name: x.name, overview: x.overview || '', air_date: x.air_date, episode_count: x.episodes.length })),
  49. });
  50. const server = http.createServer((req, res) => {
  51. const url = new URL(req.url, fake.base);
  52. if (url.pathname.startsWith('/tvmaze/')) {
  53. fake.tvmazeRequests.push(url.pathname + url.search);
  54. const json = (code, body, headers = {}) => { res.writeHead(code, { 'content-type': 'application/json', ...headers }); res.end(JSON.stringify(body)); };
  55. if (url.pathname === '/tvmaze/lookup/shows') {
  56. const [param, value] = [...url.searchParams.entries()][0] || [];
  57. const id = param && (fake.tvmaze[param] || {})[value];
  58. return id ? json(301, {}, { location: `${fake.base}/tvmaze/shows/${id}` }) : json(404, { name: 'Not Found', status: 404 });
  59. }
  60. if (url.pathname === '/tvmaze/updates/shows') return json(200, fake.tvmaze.updates || {});
  61. const em = url.pathname.match(/^\/tvmaze\/shows\/(\d+)\/episodes$/);
  62. if (em) return (fake.tvmaze.episodes || {})[em[1]] ? json(200, fake.tvmaze.episodes[em[1]].map(e => ({ type: 'regular', summary: '<p>tvmaze</p>', ...e }))) : json(404, { name: 'Not Found', status: 404 });
  63. const sm = url.pathname.match(/^\/tvmaze\/shows\/(\d+)$/);
  64. if (sm && url.searchParams.get('embed') === 'episodes') {
  65. const eps = (fake.tvmaze.episodes || {})[sm[1]];
  66. return eps ? json(200, { id: Number(sm[1]), name: 'fake TVmaze show ' + sm[1], summary: (fake.tvmaze.summaries || {})[sm[1]] ?? null, status: (fake.tvmaze.statuses || {})[sm[1]] ?? null, type: (fake.tvmaze.types || {})[sm[1]] ?? null,
  67. _embedded: { episodes: eps.map(e => ({ type: 'regular', summary: '<p>tvmaze</p>', ...e })) } }) : json(404, { name: 'Not Found', status: 404 });
  68. }
  69. return sm && !(fake.tvmaze.missing || []).includes(Number(sm[1])) ? json(200, { id: Number(sm[1]), name: 'fake TVmaze show ' + sm[1], status: (fake.tvmaze.statuses || {})[sm[1]] ?? null, type: (fake.tvmaze.types || {})[sm[1]] ?? null }) : json(404, { name: 'Not Found', status: 404 });
  70. }
  71. if (url.pathname === '/3/search/multi') {
  72. fake.searchRequests.push({ path: url.pathname + url.search, authorization: req.headers['authorization'] || null });
  73. // like the real one, every title result carries `adult` (false unless the fixture says otherwise, mission 054)
  74. const results = (fake.search[(url.searchParams.get('query') || '').toLowerCase()] || []).map(r => r.media_type === 'person' || 'adult' in r ? r : { ...r, adult: false });
  75. res.writeHead(200, { 'content-type': 'application/json' });
  76. return res.end(JSON.stringify({ page: 1, results, total_pages: 1, total_results: results.length }));
  77. }
  78. // the search page's small posters (w92, loaded by the BROWSER from TMDB's image host) — kept out of `requests` too
  79. if (/^\/t\/p\/w92\/[a-z0-9]+\.png$/.test(url.pathname)) { fake.thumbRequests.push(url.pathname); res.writeHead(200, { 'content-type': 'image/png' }); return res.end(PNG); }
  80. // tracker.worldapi.org#16: the person page's fetch (kept out of `requests`, like the search's) — `personDelayMs` slows it
  81. // down so the gate sees the page's "loading" state
  82. const pm = url.pathname.match(/^\/3\/person\/(\d+)$/);
  83. if (pm || /^\/t\/p\/w185\/[a-z0-9]+\.png$/.test(url.pathname)) {
  84. fake.personRequests.push({ path: url.pathname + url.search, authorization: req.headers['authorization'] || null });
  85. const answerPerson = () => {
  86. if (!pm) { res.writeHead(200, { 'content-type': 'image/png' }); return res.end(PNG); }
  87. const pr = fake.persons[pm[1]];
  88. if (!pr) { res.writeHead(404, { 'content-type': 'application/json' }); return res.end('{"status_code":34,"status_message":"The resource you requested could not be found."}'); }
  89. const { combined_credits, ...out } = pr;
  90. if ((url.searchParams.get('append_to_response') || '').split(',').includes('combined_credits')) out.combined_credits = combined_credits || { cast: [], crew: [] };
  91. res.writeHead(200, { 'content-type': 'application/json' });
  92. res.end(JSON.stringify(out));
  93. };
  94. if (pm && fake.personDelayMs > 0) return setTimeout(answerPerson, fake.personDelayMs);
  95. return answerPerson();
  96. }
  97. fake.requests.push({ path: url.pathname + url.search, authorization: req.headers['authorization'] || null, at: Date.now() });
  98. const answer = () => {
  99. const ch = url.pathname.match(/^\/3\/(tv|movie)\/changes$/);
  100. if (ch) {
  101. if (fake.changesFail) { res.writeHead(503, { 'content-type': 'application/json' }); return res.end('{"status_code":11}'); }
  102. const all = fake.changes[ch[1]] || [], size = fake.changesPageSize, page = Number(url.searchParams.get('page') || 1);
  103. const results = all.slice((page - 1) * size, page * size).map(id => ({ id, adult: false }));
  104. res.writeHead(200, { 'content-type': 'application/json' });
  105. return res.end(JSON.stringify({ results, page, total_pages: Math.max(1, Math.ceil(all.length / size)), total_results: all.length }));
  106. }
  107. const appended = (url.searchParams.get('append_to_response') || '').split(',').filter(Boolean);
  108. const mv = url.pathname.match(/^\/3\/movie\/(\d+)$/);
  109. if (mv && fake.movies[mv[1]]) {
  110. const m = fake.movies[mv[1]];
  111. const out = { id: m.id, title: m.title, adult: m.adult ?? false, poster_path: m.poster_path, release_date: m.release_date, overview: m.overview, genres: m.genres,
  112. homepage: m.homepage, tagline: m.tagline, status: m.status, backdrop_path: m.backdrop_path ?? null, runtime: m.runtime ?? 0 };
  113. if (appended.includes('external_ids')) out.external_ids = m.external_ids || {};
  114. if (appended.includes('credits')) out.credits = m.credits || { cast: [], crew: [] };
  115. if (m.belongs_to_collection !== undefined) out.belongs_to_collection = m.belongs_to_collection;
  116. res.writeHead(200, { 'content-type': 'application/json' });
  117. return res.end(JSON.stringify(out));
  118. }
  119. const cm = url.pathname.match(/^\/3\/collection\/(\d+)$/);
  120. if (cm && fake.collections[cm[1]]) {
  121. res.writeHead(200, { 'content-type': 'application/json' });
  122. return res.end(JSON.stringify(fake.collections[cm[1]]));
  123. }
  124. let m = url.pathname.match(/^\/3\/tv\/(\d+)$/);
  125. if (m && fake.shows[m[1]]) {
  126. const s = fake.shows[m[1]];
  127. const out = details(s);
  128. if (appended.includes('external_ids')) out.external_ids = s.external_ids || {};
  129. if (appended.includes('aggregate_credits')) out.aggregate_credits = s.aggregate_credits || { cast: [], crew: [] };
  130. for (const part of appended) {
  131. const sm = part.match(/^season\/(\d+)$/);
  132. const season = sm && s.seasons.find(x => x.season_number === Number(sm[1]));
  133. if (season) out[part] = { id: season.id, season_number: season.season_number, name: season.name, overview: season.overview || '', air_date: season.air_date,
  134. episodes: season.episodes.map(e => ({ id: e.id, season_number: season.season_number, episode_number: e.episode_number, name: e.name, overview: e.overview || '', air_date: e.air_date })) };
  135. }
  136. res.writeHead(200, { 'content-type': 'application/json' });
  137. return res.end(JSON.stringify(out));
  138. }
  139. // mission 032 (tracker#33): w780 = a backdrop the sync takes as the poster when TMDB has none
  140. if (/^\/t\/p\/w(342|780)\/[a-z0-9]+\.png$/.test(url.pathname)) { res.writeHead(200, { 'content-type': 'image/png' }); return res.end(PNG); }
  141. res.writeHead(404, { 'content-type': 'application/json' });
  142. res.end('{"status_code":34,"status_message":"The resource you requested could not be found."}');
  143. };
  144. if (fake.delayMs > 0) setTimeout(answer, fake.delayMs); else answer();
  145. });
  146. await new Promise((ok, fail) => { server.once('error', fail); server.listen(port, '127.0.0.1', ok); });
  147. fake.stop = () => new Promise(r => server.close(() => r()));
  148. return fake;
  149. }

Branches

Latest commits

  • 8dd423f7README: login.js stays by caramboleyo's explicit rulemre
  • d8df1493tracker: standby service on port 45018 and a gap-free hand-over in deploy.sh step 4mre
  • 36dd1686ident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • ff9b838etracker: the Ended status pill uses the same red as layouts (pill danger); gate updatedmre
  • 40d9719eTP2: LOG line and report for the tracker pillsmre
  • ab3f2ba5tracker: status, genres, TMDB/IMDb/TVDB/TVmaze links and list kinds use the theme's pill; dense season list with the season check centred on its title line; gates for bothmre
  • 521061d6tracker header on phones: signed in, the brand fits whole at 360 and 390 px (tighter gaps and side paddings, slightly smaller brand, narrow screens and signed in only); mobile gate checks itmre
  • 18114a53tracker: franchises gate waits for the signed-out selector instead of the removed Log in buttonmre
  • 08561d73ident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • 59ef1e4atests/browser: repair 'done' check counts the 404 titles the first run already finished (race: failed=1 when Bulk Film 79 ran before the restart)mre
  • 5925fc4dreports/MK-mobile.md: rebase update, gate countsmre
  • 6adbc7f0extlink badges: background-clip after the background shorthand (it reset the clip: the pills were 44 px tall); gates check the lookmre
  • 8d3b0f20widget: the franchise link's 44 px tap area no longer overlaps the Prequel/Sequel rowmre
  • 1d98dcfdbrowser gate: the badges' size check reads the padding box (the 44 px tap area is transparent border)mre
  • 2f9e29ffreports/MK-mobile.md, deploy.sh GATES: tests/mobile.mjs, theme check markermre
  • 7cfc8ab5a season of more than 150 episodes starts closed on its title page; the phone gate checks itmre
  • 59095c59tests/mobile.mjs: the phone gate (390 px touch, tap targets, /franchises paging)mre
  • 105309detap targets: every row link, the TMDB/IMDb badges, the widget links, the franchise names and the login-failed link are 44 px high on a phonemre
  • f0b86c8efranchises: 40 loose timelines per page (/franchises/page/N) and a merge sort for the names (1,546 timelines: 20 s and 54,000 px before)mre
  • b9e841a7Merge branch 'sy-sync'mre