tracker
All repositories: gitoria
6.3 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 { 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++) { 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
- 944ad51eSK: report reports/SK-sec.md, LOGsk
- 415487c1SK: import budget per user + id type check, gate checkssk
- 7b8a4f74security audit SK: nosniff + image sandbox headers, face id checks, adult follow, login budget + new session at login, guest-link budget, tests/security.mjssk
- f0f26c5areports: T18 section (gates, boot-gate, 3x3 table, search + short-id compare)mre
- 2a8682a1deploy.sh GATES: tests/warmstart.mjsmre
- 3761338breports/T17-boot.md: handoff (phase table, fix, numbers so far, open proof)mre
- 52e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre
- c87149e8tests/warmstart.mjs: the progressive start proven over HTTP (note in the window, 503 short id, after: everything); bootBeginmre
- 593a6350boot: resumable start-up scan, the server listens first (T17)mre
- be4890a0reports: H2 hydration audit (no test change needed)mre
- 1f9c8bf4re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- c1df88eddocker-compose: HL_GC_TABLE_LOAD=62 (tracker mission 048, T16 real-data numbers)mre
- d0a82867mission 048: report, LOG (HL_GC_TABLE_LOAD=62 measured)mre
- 2d4be66fre-vendor Hybriel 5df4eb7e (GC: HL_GC_TABLE_LOAD knob, mission 406)mre
- 99e7c8b9tests: realdata-m035-radii, repro-t38, realdata-060-backfill ports from env (REAL_PORT, REAL_CHROME, REPRO_CHROME), defaults unchangedmre
- 4625aa22re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
- a6dfd6ecdeploy: person-lookup gate (tracker#46)mre
- 33ad4bd5Merge commit 'f57f64f'mre
- 7d38cec4docker-compose: nofile 65536 (default soft 1024 refused boot: errno 24 in fs.listDir, Hybriel 528bc89f)mre
- f57f64f0mission 046: report, LOGmre