gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitbb2ebc67bb2ebc67log: #64 live, #53 mergedmrebb2ebc67/tests/tmdbfix.mjs

9.2 KB

  1. // tests/tmdbfix.mjs — tools/tmdb-fix.hl against a fake TMDB (tracker#36, mission T36). A fresh gate storage (tests/seed-tmdbfix.hl) with a
  2. // title for every group; checks: the dry run plans exactly the right changes and changes NOTHING; the apply fixes years and switches ids
  3. // with the watches / follows / seasons / episodes still on the record; ambiguous, taken, no-year and translated titles stay as they
  4. // were; a second apply and a second dry run change / plan nothing. No real token, no real TMDB.
  5. // STORAGE=/abs/new/dir PORT=8767 node tests/tmdbfix.mjs (STORAGE: a scratch dir the gate fills, never live data)
  6. import http from 'node:http';
  7. import fs from 'node:fs';
  8. import { spawn } from 'node:child_process';
  9. const PORT = Number(process.env.PORT || 8767), STORAGE = process.env.STORAGE, TOOL = process.env.TOOL || 'tools/tmdb-fix.hl';
  10. if (!STORAGE || !STORAGE.startsWith('/')) { console.log('set STORAGE (absolute, a scratch dir)'); process.exit(2); }
  11. fs.rmSync(STORAGE, { recursive: true, force: true }); fs.mkdirSync(STORAGE, { recursive: true });
  12. const movie = (id, title, date, extra = {}) => ({ id, title, original_title: title, release_date: date, ...extra });
  13. const tv = (id, name, date) => ({ id, name, original_name: name, first_air_date: date });
  14. const DB = {
  15. '/3/movie/101': movie(101, 'Year Missing', '2008-05-01'), '/3/movie/102': movie(102, 'Other Year', '2008-01-01'),
  16. '/3/movie/103': movie(103, 'Uebersetzt', '2010-03-03'), '/3/movie/109': movie(109, 'Gone Taken', '2016-06-06'),
  17. '/3/movie/110': movie(110, 'Other Thing', '2020-02-02'), '/3/movie/111': movie(111, 'Fine', '2005-05-05'),
  18. '/3/movie/204': movie(204, 'Gone Unique', '2015-04-04'), '/3/tv/305': tv(305, 'Gone Series', '2011-01-01'),
  19. };
  20. const SEARCH = {
  21. '/3/search/movie|Gone Unique': [movie(204, 'Gone Unique', '2015-04-04'), movie(205, 'Gone Unique', '2001-01-01'), movie(299, 'Gone Unique Returns', '2015-09-09')],
  22. '/3/search/movie|Gone Many': [movie(206, 'Gone Many', '2012-01-01'), movie(207, 'Gone Many', '2012-12-12')],
  23. '/3/search/movie|Gone Other Year': [movie(208, 'Gone Other Year', '2014-01-01')],
  24. '/3/search/movie|Gone Taken': [movie(109, 'Gone Taken', '2016-06-06')],
  25. '/3/search/tv|Gone Series': [tv(305, 'Gone Series', '2011-01-01'), tv(306, 'Gone Series Kids', '2011-02-02')],
  26. };
  27. let seen = [];
  28. const server = http.createServer((req, res) => {
  29. const u = new URL(req.url, 'http://x'); seen.push(u.pathname + (u.pathname.includes('search') ? '?' + u.searchParams.get('query') : ''));
  30. const send = (code, body) => { res.writeHead(code, { 'content-type': 'application/json' }); res.end(JSON.stringify(body)); };
  31. if (u.pathname.includes('/search/')) return send(200, { page: 1, results: SEARCH[u.pathname + '|' + u.searchParams.get('query')] || [] });
  32. return DB[u.pathname] ? send(200, DB[u.pathname]) : send(404, { status_code: 34 });
  33. });
  34. await new Promise(r => server.listen(PORT, '127.0.0.1', r));
  35. const run = (file, args, extraEnv = {}) => new Promise((resolve) => {
  36. seen = []; let out = '';
  37. const p = spawn('./bin/hybriel', [file, ...args], { env: { ...process.env, TMDB_READ_TOKEN: 'fake-token', TMDB_BASE_URL: `http://127.0.0.1:${PORT}/3`, TRACKER_STORAGE: STORAGE, ...extraEnv } });
  38. p.stdout.on('data', d => out += d); p.stderr.on('data', d => out += d);
  39. p.on('close', code => resolve({ code, out, seen: [...seen] }));
  40. });
  41. let pass = 0, fail = 0;
  42. const check = (name, ok, extra = '') => { ok ? pass++ : fail++; console.log((ok ? 'PASS ' : 'FAIL ') + name + (ok ? '' : ' — ' + String(extra).slice(0, 700))); };
  43. const peek = async () => { const r = await run('tests/peek-tmdbfix.hl', []); const shows = {}; const rest = []; for (const l of r.out.split('\n')) { if (l.startsWith('show ')) { const j = JSON.parse(l.slice(5)); shows[j.slug] = j; } else if (l.trim()) rest.push(l); } return { shows, rest: rest.sort() }; };
  44. try {
  45. const seed = await run('tests/seed-tmdbfix.hl', []);
  46. check('seeded', /seeded/.test(seed.out), seed.out);
  47. const before = await peek();
  48. const plan = STORAGE + '.plan.tsv';
  49. const dry = await run(TOOL, ['--dry-run', '--plan-out', plan]);
  50. const has = (s) => dry.out.includes(s);
  51. check('dry run exits 0 and ends with the totals', dry.code == 0 && /done: asked=\d+ ok=\d+ group1=2 \(year fixes=2 nothing-to-take=0\) group2=1 group3=6 \(switch=2 listed=4\) group4=1/.test(dry.out), dry.out);
  52. check('year missing → TMDB year planned', /fix-year .*Year-Missing.*year \? → 2008/.test(dry.out), dry.out);
  53. check('other year, same name → TMDB year planned', /fix-year .*Other-Year.*year 2002 → 2008/.test(dry.out), dry.out);
  54. check('gone id with ONE same-name same-year result → switch planned (the wrong-year and other-name results do not count)', /fix-tmdb .*Gone-Unique.*tmdb 104 → 204/.test(dry.out), dry.out);
  55. check('gone series → switch planned via the TV search', /fix-tmdb tv .*Gone-Series.*tmdb 105 → 305/.test(dry.out), dry.out);
  56. check('two results with the same name and year → listed, not switched', /list-3 .*Gone-Many.*several TMDB results.*206 "Gone Many" \(2012\); 207/.test(dry.out) && !has('106 →'), dry.out);
  57. check('only another year → listed, not switched', /list-3 .*Gone-Other-Year.*no TMDB result with this name and year/.test(dry.out), dry.out);
  58. check('the one result is an id another record of ours already has → listed, not switched', /list-3 .*Gone-Taken .*already ours at \/movies\/Gone-Taken-2/.test(dry.out) || /list-3 .*Gone-Taken tmdb.*already ours/.test(dry.out), dry.out);
  59. check('no year of ours → no search, listed', /list-3 .*Gone-No-Year.*no year to search with/.test(dry.out) && !dry.seen.some(s => s.includes('Gone No Year')), dry.out + JSON.stringify(dry.seen));
  60. check('translation (same year, other name) → left, listed as leave-2', /leave-2 .*Translated/.test(dry.out) && !/fix-.*Translated/.test(dry.out), dry.out);
  61. check('both differ → list-4 only', /list-4 .*Both-Differ/.test(dry.out) && !/fix-.*Both-Differ/.test(dry.out), dry.out);
  62. check('a fine title is not mentioned', !dry.out.includes('/Fine ') && !dry.out.includes('/movies/Fine"'), dry.out);
  63. const afterDry = await peek();
  64. check('the dry run changed NOTHING', JSON.stringify(afterDry) == JSON.stringify(before), JSON.stringify(afterDry.shows));
  65. check('the plan file has the 4 changes', fs.readFileSync(plan, 'utf8').trim().split('\n').length == 4, fs.readFileSync(plan, 'utf8'));
  66. const ap = await run(TOOL, ['--apply', plan]);
  67. check('apply: 4 applied (2 years, 2 ids), nothing skipped or failed', /apply\) done: planned=4 applied=4 \(year=2 tmdb=2\) skipped=0 failed=0/.test(ap.out), ap.out);
  68. const after = await peek();
  69. const S = after.shows, B = before.shows;
  70. check('year missing: year 2008, no migratedYear', S['Year-Missing'].year == 2008 && S['Year-Missing'].migratedYear == null, JSON.stringify(S['Year-Missing']));
  71. check('other year: year 2008, the old 2002 kept in migratedYear', S['Other-Year'].year == 2008 && S['Other-Year'].migratedYear == 2002, JSON.stringify(S['Other-Year']));
  72. check('release follows TMDB: Other Year 2008-01-01 (old 2002-03-04 kept in migratedRelease), Year Missing 2008-05-01 (nothing old to keep)', S['Other-Year'].release == '2008-01-01' && S['Other-Year'].migratedRelease == '2002-03-04' && S['Year-Missing'].release == '2008-05-01' && S['Year-Missing'].migratedRelease == null, JSON.stringify([S['Other-Year'], S['Year-Missing']]));
  73. check('movie id switched, old id kept, the 404 marker cleared', S['Gone-Unique'].tmdbId == 204 && S['Gone-Unique'].tmdbIdWas == 104 && S['Gone-Unique'].adultCheck == null, JSON.stringify(S['Gone-Unique']));
  74. check('series id switched, old id kept', S['Gone-Series'].tmdbId == 305 && S['Gone-Series'].tmdbIdWas == 105, JSON.stringify(S['Gone-Series']));
  75. check('the record ids are unchanged (nothing re-created)', Object.keys(S).every(k => S[k].id == B[k].id) && Object.keys(S).length == Object.keys(B).length, JSON.stringify(Object.keys(S)));
  76. check('watches, follows, seasons and episodes are exactly as before (the switched movie and series keep theirs)', JSON.stringify(after.rest) == JSON.stringify(before.rest) && after.rest.some(l => l.startsWith('watch wEp1')) && after.rest.some(l => l.startsWith('follow fMovie')), JSON.stringify(after.rest));
  77. const untouched = ['Translated', 'Gone-Many', 'Gone-Other-Year', 'Gone-Taken', 'Gone-Taken-2', 'Both-Differ', 'Fine', 'Gone-No-Year'];
  78. check('every other title is exactly as before', untouched.every(k => JSON.stringify(S[k]) == JSON.stringify(B[k])), untouched.filter(k => JSON.stringify(S[k]) != JSON.stringify(B[k])).join());
  79. const ap2 = await run(TOOL, ['--apply', plan]);
  80. check('a second apply changes nothing (idempotent)', /planned=4 applied=0 \(year=0 tmdb=0\) skipped=4 failed=0/.test(ap2.out), ap2.out);
  81. const again = await run(TOOL, ['--dry-run']);
  82. check('a second dry run plans no change and lists only what is left for the creator', !/^fix-/m.test(again.out) && /group1=0 .*group2=1 group3=4 \(switch=0 listed=4\) group4=1/.test(again.out), again.out);
  83. check('and still changes nothing', JSON.stringify(await peek()) == JSON.stringify(after));
  84. const refuse = await run(TOOL, []);
  85. check('without --dry-run / --apply the tool refuses', /REFUSED/.test(refuse.out) && refuse.code == 2, refuse.out);
  86. } finally { server.close(); }
  87. console.log(`tmdbfix: ${pass} pass, ${fail} fail`); process.exit(fail ? 1 : 0);

Branches

Latest commits

  • bb2ebc67log: #64 live, #53 mergedmre
  • 27cde42fMerge hm53-dom: tracker#53 inputs bound to membersmre
  • 2156cc7flog: HM54 reviewmre
  • 9fb82efclog: HM54 gap, fill continuesmre
  • b632eb8dlog: HM53 done, HM54 startedmre
  • ccb1a263tracker#53: bind editor drafts and use key event focus targetmre
  • 3356fcfclog: #52 blocked, HM53 startedmre
  • 833dcfc9Merge hm52-search: report only, tracker#52 blocked by framework gapmre
  • 73010cc0HM52: report replace-navigation search draft regressionmre
  • 1742e92bstatus: DP64 and HM52 runningmre
  • 29ad5b58log: #64 merged, DP64 and HM52 startedmre
  • fafddbf9Merge hm64-catalog: tracker#64 catalog from packed entriesmre
  • b2e2206dlog: #63 livemre
  • 5831e0e0log: HM64 donemre
  • 4042b923Flatten catalog membership rows into paired slotsmre
  • ea8a759elog: #61 #62 live, DP63 and HM64 startedmre
  • 40439456Merge hm63-searchtext: tracker#63 packed search textmre
  • b7e6b48ePack normalized search text behind numeric offsetsmre
  • b35f53e1log: DP62 stale runtime decisionmre
  • f9593602log: Apollo deploy rule correctionmre