tracker
All repositories: gitoria
6.4 KB
// tests/warmstart.mjs — THE GATE of the progressive start (mission T17, boot time): the server listens BEFORE the start-up scan// (lib/bootscan.hl) is done. TRACKER_WARM_SYNC_MS=0 + TRACKER_WARM_HOLD_MS=4000 make the window deterministic on the fixture storage:// for 4 s after "listening" nothing is scanned. Proves, with real HTTP requests to the running server:// - during the window: `/` and `/movies` and `/search/x` answer 200 with the "starting up" note (no list), the personal pages and// /settings answer 200 without it, a short id answers 503 (Retry-After), the search face finds nothing and imports nothing// - after the log line "boot scan: done": no note anywhere, `/` lists the fixture titles, a short id answers 301, the search finds// the fixture show, the jobs started (the short-id backfill ran: "short ids done")// On the OLD code (no note, no 503) the first block fails — `TRACKER_APP_DIR=<old tree> node tests/warmstart.mjs` shows it.//// node tests/warmstart.mjs (TRACKER_GATE_PORT, default 8748)import { spawn, execFileSync } from 'node:child_process';import { checkServerExit } from './identkit.mjs';import { mkdirSync, rmSync, writeFileSync } from 'node:fs';import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';const HERE = dirname(fileURLToPath(import.meta.url));const APP = process.env.TRACKER_APP_DIR ? resolve(process.env.TRACKER_APP_DIR) : resolve(HERE, '..');const PORT = Number(process.env.TRACKER_GATE_PORT || 8748);const BASE = `http://127.0.0.1:${PORT}`;const SCRATCH = join(resolve(HERE, '..'), '.scratch', 'warmstart');const STORE = join(SCRATCH, 'store'), MPACKDB = join(STORE, 'mpackdb'), SESSIONS = join(SCRATCH, 'sessions');rmSync(SCRATCH, { recursive: true, force: true });mkdirSync(MPACKDB, { recursive: true }); mkdirSync(SESSIONS, { recursive: true });let failures = 0, passes = 0;const check = (label, ok, detail = '') => { console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`); if (ok) passes++; else failures++; };const sleep = (ms) => new Promise(r => setTimeout(r, ms));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() }; };const NOTE = /id="warming"/;let server, log = '';try {const seedOut = execFileSync(join(APP, 'bin/hybriel'), ['tests/seed-show.hl'], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: MPACKDB } }).toString();check('seed: the fixture titles were written', seedOut.includes('gate-test-show'), seedOut);writeFileSync(join(STORE, 'old-short-ids.json'), JSON.stringify({ sh1: '100jh' }));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',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',TRACKER_OLD_SHORT_IDS: join(STORE, 'old-short-ids.json'), TRACKER_WARM_SYNC_MS: '0', TRACKER_WARM_HOLD_MS: '4000' }, stdio: ['ignore', 'pipe', 'pipe'] });server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);let up = false;for (let i = 0; i < 600 && !up; i++) { checkServerExit(server, 'tracker', log); try { up = (await fetch(BASE + '/')).ok; } catch { await sleep(250); } }check('the server answers (a cold start compiles first)', up, log);const t0 = Date.now();// ---- the window: the server listens, the scan has not started ----const home = await get('/'), movies = await get('/movies'), search = await get('/search/gate'), show = await get('/series/gate-test-show');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)}`);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)))));const settings = await get('/settings'), myUnwatched = await get('/my/unwatched'), myMovies = await get('/my/movies');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)))));const sid = await get('/abcde');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}`);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);// ---- after the hold: the clock scans, then everything is there ----for (let i = 0; i < 400 && !/short ids done|short ids: nothing/.test(log); i++) await sleep(100);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);const home2 = await get('/'), movies2 = await get('/movies'), series2 = await get('/series'), found = await get('/search/gate%20test');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)))));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)]));const known = await get('/100jh');check('after: the OLD short id of the fixture show is kept and answers 301 to its page', known.status === 301, `${known.status}`);check('after: an unknown short id is a 404 again', (await get('/abcde')).status === 404);} catch (e) {check('no exception', false, String(e && e.stack || e));} finally {if (server) { server.kill('SIGTERM'); await sleep(500); }rmSync(SCRATCH, { recursive: true, force: true });}console.log(`\n${passes} passed, ${failures} failed`);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