gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmaind2e6d26bMerge branch 'records-park55' into mainTrackermain/tests/warmstart.mjs

6.4 KB

  1. // tests/warmstart.mjs — THE GATE of the progressive start (mission T17, boot time): the server listens BEFORE the start-up scan
  2. // (lib/bootscan.hl) is done. TRACKER_WARM_SYNC_MS=0 + TRACKER_WARM_HOLD_MS=4000 make the window deterministic on the fixture storage:
  3. // for 4 s after "listening" nothing is scanned. Proves, with real HTTP requests to the running server:
  4. // - during the window: `/` and `/movies` and `/search/x` answer 200 with the "starting up" note (no list), the personal pages and
  5. // /settings answer 200 without it, a short id answers 503 (Retry-After), the search face finds nothing and imports nothing
  6. // - after the log line "boot scan: done": no note anywhere, `/` lists the fixture titles, a short id answers 301, the search finds
  7. // the fixture show, the jobs started (the short-id backfill ran: "short ids done")
  8. // On the OLD code (no note, no 503) the first block fails — `TRACKER_APP_DIR=<old tree> node tests/warmstart.mjs` shows it.
  9. //
  10. // node tests/warmstart.mjs (TRACKER_GATE_PORT, default 8748)
  11. import { spawn, execFileSync } from 'node:child_process';
  12. import { checkServerExit } from './identkit.mjs';
  13. import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
  14. import { dirname, join, resolve } from 'node:path';
  15. import { fileURLToPath } from 'node:url';
  16. const HERE = dirname(fileURLToPath(import.meta.url));
  17. const APP = process.env.TRACKER_APP_DIR ? resolve(process.env.TRACKER_APP_DIR) : resolve(HERE, '..');
  18. const PORT = Number(process.env.TRACKER_GATE_PORT || 8748);
  19. const BASE = `http://127.0.0.1:${PORT}`;
  20. const SCRATCH = join(resolve(HERE, '..'), '.scratch', 'warmstart');
  21. const STORE = join(SCRATCH, 'store'), MPACKDB = join(STORE, 'mpackdb'), SESSIONS = join(SCRATCH, 'sessions');
  22. rmSync(SCRATCH, { recursive: true, force: true });
  23. mkdirSync(MPACKDB, { recursive: true }); mkdirSync(SESSIONS, { recursive: true });
  24. let failures = 0, passes = 0;
  25. const check = (label, ok, detail = '') => { console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`); if (ok) passes++; else failures++; };
  26. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  27. const get = async (path) => { const r = await fetch(BASE + path, { redirect: 'manual' }); return { status: r.status, retry: r.headers.get('retry-after'), body: await r.text() }; };
  28. const NOTE = /id="warming"/;
  29. let server, log = '';
  30. try {
  31. const seedOut = execFileSync(join(APP, 'bin/hybriel'), ['tests/seed-show.hl'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: MPACKDB } }).toString();
  32. check('seed: the fixture titles were written', seedOut.includes('gate-test-show'), seedOut);
  33. writeFileSync(join(STORE, 'old-short-ids.json'), JSON.stringify({ sh1: '100jh' }));
  34. 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',
  35. TRACKER_URL: BASE, TRACKER_SYNC: '0', TRACKER_ART: '0', TRACKER_PHOTOS: '0', TRACKER_BACKFILL: '0', TRACKER_KINDS: '0', TRACKER_COLLECTIONS: '0', TRACKER_FRANCHISE_SEED: '0', TRACKER_REPAIR: '0', TRACKER_CREDITS: '0',
  36. TRACKER_OLD_SHORT_IDS: join(STORE, 'old-short-ids.json'), TRACKER_WARM_SYNC_MS: '0', TRACKER_WARM_HOLD_MS: '4000' }, stdio: ['ignore', 'pipe', 'pipe'] });
  37. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  38. let up = false;
  39. for (let i = 0; i < 600 && !up; i++) { checkServerExit(server, 'tracker', log); try { up = (await fetch(BASE + '/')).ok; } catch { await sleep(250); } }
  40. check('the server answers (a cold start compiles first)', up, log);
  41. const t0 = Date.now();
  42. // ---- the window: the server listens, the scan has not started ----
  43. const home = await get('/'), movies = await get('/movies'), search = await get('/search/gate'), show = await get('/series/gate-test-show');
  44. check('window: / answers 200 with the "starting up" note', home.status === 200 && NOTE.test(home.body) && /starting up/.test(home.body), `${home.status} ${home.body.slice(0, 200)}`);
  45. check('window: /movies, /search/<text> and a title page answer 200 with the note', [movies, search, show].every(r => r.status === 200 && NOTE.test(r.body)), JSON.stringify([movies, search, show].map(r => r.status + String(NOTE.test(r.body)))));
  46. const settings = await get('/settings'), myUnwatched = await get('/my/unwatched'), myMovies = await get('/my/movies');
  47. check('window: /settings and the personal pages answer 200 WITHOUT the note (they need none of the scan)', [settings, myUnwatched, myMovies].every(r => r.status === 200 && !NOTE.test(r.body)), JSON.stringify([settings, myUnwatched, myMovies].map(r => r.status + String(NOTE.test(r.body)))));
  48. const sid = await get('/abcde');
  49. check('window: a short id answers 503 + Retry-After (it may be one the scan has not read yet), not 404', sid.status === 503 && sid.retry === '30', `${sid.status} ${sid.retry}`);
  50. check('window: the log says the scan goes on after the server listens, no scan line yet', /boot scan: listening first/.test(log) && !/boot scan: \d+ titles/.test(log), log);
  51. // ---- after the hold: the clock scans, then everything is there ----
  52. for (let i = 0; i < 400 && !/short ids done|short ids: nothing/.test(log); i++) await sleep(100);
  53. check('the scan finished by itself, then the jobs started (log: boot scan: done … short ids done)', /boot scan: done in \d+ ms/.test(log) && /short ids done/.test(log) && Date.now() - t0 >= 3000, log);
  54. const home2 = await get('/'), movies2 = await get('/movies'), series2 = await get('/series'), found = await get('/search/gate%20test');
  55. check('after: no note on / /movies /search', [home2, movies2, found].every(r => r.status === 200 && !NOTE.test(r.body)), JSON.stringify([home2, movies2, found].map(r => r.status + String(NOTE.test(r.body)))));
  56. check('after: /series lists the fixture series, the search finds it', /Gate Test Show/.test(series2.body) && /gate-test-show/.test(found.body), JSON.stringify([/Gate Test Show/.test(series2.body), /gate-test-show/.test(found.body)]));
  57. const known = await get('/100jh');
  58. check('after: the OLD short id of the fixture show is kept and answers 301 to its page', known.status === 301, `${known.status}`);
  59. check('after: an unknown short id is a 404 again', (await get('/abcde')).status === 404);
  60. } catch (e) {
  61. check('no exception', false, String(e && e.stack || e));
  62. } finally {
  63. if (server) { server.kill('SIGTERM'); await sleep(500); }
  64. rmSync(SCRATCH, { recursive: true, force: true });
  65. }
  66. console.log(`\n${passes} passed, ${failures} failed`);
  67. process.exit(failures ? 1 : 0);

Branches

Latest commits

  • d2e6d26bMerge branch 'records-park55' into mainTracker
  • f567f025|||PR records: park #55, no Claude workers ruleTracker
  • c21aff6bMerge branch 'records-hm55c' into mainTracker
  • 9ba258d3|||PR records: HM55b resultTracker
  • 64f2d300Merge branch 'records-hm55b2' into mainTracker
  • ae3b80dc|||PR records: HM55b briefTracker
  • 7ef3cb3bMerge branch 'records-st55' into mainTracker
  • fec2e080|||PR records: STATUS HM55Tracker
  • 8e174918Merge branch 'records-hm55b' into mainTracker
  • b1ecee57|||PR records: HM55 stateTracker
  • 28eab08cMerge branch 'records-hm55' into mainTracker
  • d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
  • 3059f86cMerge branch 'records-design-rule' into mainTracker
  • 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
  • d1390692Merge branch 'records-dp75b' into mainTracker
  • a4d1a7d2|||PR records: later steps checked, branch auditTracker
  • e070e16fMerge branch 'records-dp75' into mainTracker
  • 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
  • bfc4ea4dMerge branch 'ap62' into mainTracker
  • 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker