tracker
All repositories: gitoria
9.2 KB
// 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// title for every group; checks: the dry run plans exactly the right changes and changes NOTHING; the apply fixes years and switches ids// with the watches / follows / seasons / episodes still on the record; ambiguous, taken, no-year and translated titles stay as they// were; a second apply and a second dry run change / plan nothing. No real token, no real TMDB.// STORAGE=/abs/new/dir PORT=8767 node tests/tmdbfix.mjs (STORAGE: a scratch dir the gate fills, never live data)import http from 'node:http';import fs from 'node:fs';import { spawn } from 'node:child_process';const PORT = Number(process.env.PORT || 8767), STORAGE = process.env.STORAGE, TOOL = process.env.TOOL || 'tools/tmdb-fix.hl';if (!STORAGE || !STORAGE.startsWith('/')) { console.log('set STORAGE (absolute, a scratch dir)'); process.exit(2); }fs.rmSync(STORAGE, { recursive: true, force: true }); fs.mkdirSync(STORAGE, { recursive: true });const movie = (id, title, date, extra = {}) => ({ id, title, original_title: title, release_date: date, ...extra });const tv = (id, name, date) => ({ id, name, original_name: name, first_air_date: date });const DB = {'/3/movie/101': movie(101, 'Year Missing', '2008-05-01'), '/3/movie/102': movie(102, 'Other Year', '2008-01-01'),'/3/movie/103': movie(103, 'Uebersetzt', '2010-03-03'), '/3/movie/109': movie(109, 'Gone Taken', '2016-06-06'),'/3/movie/110': movie(110, 'Other Thing', '2020-02-02'), '/3/movie/111': movie(111, 'Fine', '2005-05-05'),'/3/movie/204': movie(204, 'Gone Unique', '2015-04-04'), '/3/tv/305': tv(305, 'Gone Series', '2011-01-01'),};const SEARCH = {'/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')],'/3/search/movie|Gone Many': [movie(206, 'Gone Many', '2012-01-01'), movie(207, 'Gone Many', '2012-12-12')],'/3/search/movie|Gone Other Year': [movie(208, 'Gone Other Year', '2014-01-01')],'/3/search/movie|Gone Taken': [movie(109, 'Gone Taken', '2016-06-06')],'/3/search/tv|Gone Series': [tv(305, 'Gone Series', '2011-01-01'), tv(306, 'Gone Series Kids', '2011-02-02')],};let seen = [];const server = http.createServer((req, res) => {const u = new URL(req.url, 'http://x'); seen.push(u.pathname + (u.pathname.includes('search') ? '?' + u.searchParams.get('query') : ''));const send = (code, body) => { res.writeHead(code, { 'content-type': 'application/json' }); res.end(JSON.stringify(body)); };if (u.pathname.includes('/search/')) return send(200, { page: 1, results: SEARCH[u.pathname + '|' + u.searchParams.get('query')] || [] });return DB[u.pathname] ? send(200, DB[u.pathname]) : send(404, { status_code: 34 });});await new Promise(r => server.listen(PORT, '127.0.0.1', r));const run = (file, args, extraEnv = {}) => new Promise((resolve) => {seen = []; let out = '';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 } });p.stdout.on('data', d => out += d); p.stderr.on('data', d => out += d);p.on('close', code => resolve({ code, out, seen: [...seen] }));});let pass = 0, fail = 0;const check = (name, ok, extra = '') => { ok ? pass++ : fail++; console.log((ok ? 'PASS ' : 'FAIL ') + name + (ok ? '' : ' — ' + String(extra).slice(0, 700))); };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() }; };try {const seed = await run('tests/seed-tmdbfix.hl', []);check('seeded', /seeded/.test(seed.out), seed.out);const before = await peek();const plan = STORAGE + '.plan.tsv';const dry = await run(TOOL, ['--dry-run', '--plan-out', plan]);const has = (s) => dry.out.includes(s);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);check('year missing → TMDB year planned', /fix-year .*Year-Missing.*year \? → 2008/.test(dry.out), dry.out);check('other year, same name → TMDB year planned', /fix-year .*Other-Year.*year 2002 → 2008/.test(dry.out), dry.out);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);check('gone series → switch planned via the TV search', /fix-tmdb tv .*Gone-Series.*tmdb 105 → 305/.test(dry.out), dry.out);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);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);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);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));check('translation (same year, other name) → left, listed as leave-2', /leave-2 .*Translated/.test(dry.out) && !/fix-.*Translated/.test(dry.out), dry.out);check('both differ → list-4 only', /list-4 .*Both-Differ/.test(dry.out) && !/fix-.*Both-Differ/.test(dry.out), dry.out);check('a fine title is not mentioned', !dry.out.includes('/Fine ') && !dry.out.includes('/movies/Fine"'), dry.out);const afterDry = await peek();check('the dry run changed NOTHING', JSON.stringify(afterDry) == JSON.stringify(before), JSON.stringify(afterDry.shows));check('the plan file has the 4 changes', fs.readFileSync(plan, 'utf8').trim().split('\n').length == 4, fs.readFileSync(plan, 'utf8'));const ap = await run(TOOL, ['--apply', plan]);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);const after = await peek();const S = after.shows, B = before.shows;check('year missing: year 2008, no migratedYear', S['Year-Missing'].year == 2008 && S['Year-Missing'].migratedYear == null, JSON.stringify(S['Year-Missing']));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']));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']]));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']));check('series id switched, old id kept', S['Gone-Series'].tmdbId == 305 && S['Gone-Series'].tmdbIdWas == 105, JSON.stringify(S['Gone-Series']));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)));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));const untouched = ['Translated', 'Gone-Many', 'Gone-Other-Year', 'Gone-Taken', 'Gone-Taken-2', 'Both-Differ', 'Fine', 'Gone-No-Year'];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());const ap2 = await run(TOOL, ['--apply', plan]);check('a second apply changes nothing (idempotent)', /planned=4 applied=0 \(year=0 tmdb=0\) skipped=4 failed=0/.test(ap2.out), ap2.out);const again = await run(TOOL, ['--dry-run']);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);check('and still changes nothing', JSON.stringify(await peek()) == JSON.stringify(after));const refuse = await run(TOOL, []);check('without --dry-run / --apply the tool refuses', /REFUSED/.test(refuse.out) && refuse.code == 2, refuse.out);} finally { server.close(); }console.log(`tmdbfix: ${pass} pass, ${fail} fail`); process.exit(fail ? 1 : 0);
Branches
Latest commits
- 3c95f7f3log: DP62 and HM63 startedmre
- 9c4397c9mission HM63mre
- 8dfe42c8mission DP62mre
- e347fef4Merge rv44: tracker#61 #62 on Hybriel day44mre
- 8274bcf1log: RV44 done, deploy held for the usage windowmre
- 1ef7a3b1RV44: report day44 gates and migration/restart proofsmre
- a5f62f6cRV44: re-vendor Hybriel set day44 (source 222edef7, bin 4f0f263e)mre
- 6159a248Merge branch 'hm62-personindex' into rv44mre
- a8923d93log: RV44 startedmre
- cf28cf77mission RV44mre
- 585782dfLog: tracker#60 Chrome look, STATUS rewrittenmre
- 147d0172conductor: caramboleyo is the user, not owner/creatorApollo
- 21dd0cfblog: #60 live measurement, reviewmre
- 7793cf94HM62b report: person indexes with fixed mpackdbmre
- b4c8d3a9Document tracker#62 fixed-index migration and GC proofmre
- 09d66ed5status: #60 livemre
- 4171672flog: #60 livemre
- f52862a2log: HM62b startedmre
- 88fde2c4mission HM62bmre
- a722e526log: #62 blocked by hybriel#317mre