tracker
All repositories: gitoria
5.8 KB
// tests/identkit.mjs — helpers for tickets' tests that need a REAL ident (ticket #7): a// throw-away ident instance from ident's code (a COPY without .env, storage, sessions — so it// can never send mail: codes go to IDENT_MAIL_SINK), its accounts, a registered app, and the// ident side of the two login flows. Never the live ident, never the dev server on :8351.//// const id = await startIdent({ identDir, workDir, port }) // copies the code, starts it// const alice = await id.signIn('[email protected]') // → { cookie } (identsid=…)// const app = await id.registerApp(alice, 'tickets', [origin]) // → { key, secret }// const code = await id.selectorCode(alice, app, origin) // one-time code (the selector's path)// const pid = await id.exchange(app, code) // → the per-app identity id// id.stop()import { spawn } from 'node:child_process';import { cpSync, mkdirSync, readFileSync, rmSync, existsSync, writeFileSync } from 'node:fs';import { join } from 'node:path';const sleep = (ms) => new Promise(r => setTimeout(r, ms));const J = JSON.stringify;// the ident code, copied without anything that holds secrets or dataconst SKIP = new Set(['.env', 'storage', '.sessions', '.scratch', 'server.log', 'server.pid', 'testapp', '.git']);export function copyIdent(identDir, to) {rmSync(to, { recursive: true, force: true });mkdirSync(to, { recursive: true });cpSync(identDir, to, { recursive: true, filter: (src) => {const rel = src.slice(identDir.length).replace(/^\/+/, '');if (rel === '') return true;return !SKIP.has(rel.split('/')[0]);} });if (existsSync(join(to, '.env'))) throw new Error('identkit: a .env was copied — refusing to start');}export async function startIdent({ identDir, workDir, port }) {const code = join(workDir, 'ident-code');const data = join(workDir, 'ident-data');copyIdent(identDir, code);rmSync(data, { recursive: true, force: true });mkdirSync(data, { recursive: true });const sink = join(data, 'mail.txt');writeFileSync(sink, '');const base = `http://127.0.0.1:${port}`;let log = '';const proc = spawn(join(code, 'bin/hybriel'), ['project.hl'], {cwd: code,env: { ...process.env, IDENT_PORT: String(port), IDENT_STORAGE: join(data, 'mpackdb'), IDENT_SESSIONS: join(data, 'sessions') + '/',IDENT_MAIL_SINK: sink, IDENT_IP_LIMIT: '1000', IDENT_IP_DAY_LIMIT: '1000', IDENT_WATCH: '0', HL_HOST: '127.0.0.1',SMTP_HOST: '', SMTP_USER: '', SMTP_PASSWORD: '' },stdio: ['ignore', 'pipe', 'pipe'],});proc.stdout.on('data', d => log += d); proc.stderr.on('data', d => log += d);let up = false;for (let i = 0; i < 80 && !up; i++) { try { const r = await fetch(base + '/'); up = r.ok; } catch {} if (!up) await sleep(250); }if (!up) throw new Error('ident did not come up\n' + log);let emitI = 0;const emit = async (event, payload, cookie) => {const r = await fetch(base + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', ...(cookie ? { cookie } : {}) }, body: J({ t: 'emit', i: ++emitI, event, payload }) });const setCookie = (r.headers.get('set-cookie') || '').split(';')[0];const t = await r.text();let j = null; try { j = JSON.parse(t); } catch {}return { value: j && j.value, raw: t, setCookie };};const lastCode = (email) => {const lines = readFileSync(sink, 'utf8').trim().split('\n').filter(l => l.startsWith(email + ' '));return lines.length ? lines[lines.length - 1].split(' ')[1] : null;};return {base, sink, lastCode, log: () => log, proc,// an ident account signed in over the REST carrier (the first login creates it)async signIn(email) {const c = await fetch(base + '/api/code', { method: 'POST', headers: { 'content-type': 'application/json' }, body: J({ email }) });if (c.status !== 200) throw new Error('ident code refused: ' + c.status + ' ' + await c.text());const v = await emit('verifyCode', [email, lastCode(email), 'Europe/Vienna']);if (!v.value || !v.value.account || !v.setCookie) throw new Error('ident sign-in failed: ' + v.raw);return { email, cookie: v.setCookie };},async registerApp(who, name, origins) {const r = await emit('appCreate', [{ name, origins }], who.cookie);if (!r.value || !r.value.secret) throw new Error('appCreate failed: ' + r.raw);return { key: r.value.app.apiKey, secret: r.value.secret, raw: r.value };},// the selector's path without a browser: the identities (as the page at `origin` asks) → choose → codeasync selectorCode(who, app, origin, identityName = null) {const l = await fetch(base + '/api/selector/identities?key=' + app.key, { headers: { origin, cookie: who.cookie } });const lj = await l.json();if (!lj.identities || !lj.identities.length) throw new Error('no identities: ' + J(lj));const pick = identityName ? lj.identities.find(i => i.name === identityName) : lj.identities[0];const c = await fetch(base + '/api/selector/choose?key=' + app.key, { method: 'POST', headers: { origin, cookie: who.cookie, 'content-type': 'application/json' }, body: J({ identity: pick.id }) });const cj = await c.json();if (!cj.code) throw new Error('choose failed: ' + J(cj));return cj.code;},async exchange(app, code) {const r = await fetch(base + '/api/exchange', { method: 'POST', headers: { 'content-type': 'application/json' }, body: J({ key: app.key, secret: app.secret, code }) });const j = await r.json();if (!j.identity) throw new Error('exchange failed: ' + J(j));return j.identity;},async stop() {try { proc.kill('SIGTERM'); } catch {}await new Promise(r => { if (proc.exitCode !== null || proc.signalCode !== null) return r(); proc.once('exit', r); setTimeout(r, 3000); });},};}
Branches
- mainmain branch
Latest commits
- b8bd1157tracker#14: README + STATUS (search, real-data numbers, gate, merge notes)mre
- 65c694a8tracker#14: search — header magnifier, /search/<text> (in-memory word-prefix index over titles + people), Fetch from web (TMDB search/multi, ours left out), Add = import via syncShow; gate +25 checks, real-data scriptmre
- cbdc4ea7tracker#12: link icons TMDB/IMDb/TVDB/TVmaze; sync fills missing ids (TVmaze lookup); movies fetched via /movie/mre
- b105bcd8tracker#11: Hybriel master ff51cf46 (checks no longer vanish), mobile-first styles, carets, follow button, sign-in modal, inverted check, orange castmre
- 31b758aatracker#10: installable app (manifest, service worker, offline shell), own icon + faviconmre
- 2fa9d997tracker#9: TMDB sync (followed shows: seasons, episodes, posters), tools/sync-tmdb.hl + daily run 04:00 UTC, fake TMDB in gatemre
- 49e1f61edeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
- 54070a4etracker#8: /my/unwatched + /my/schedule (301 from old), S01E01, title (year), 1 episode, watched-set lookup (unwatched 15s -> 1s)mre
- 3251488atracker#7: /my/shows (followed shows, newest follow first, poster, title, last watched SxxEyy); gate can take screenshots (TRACKER_GATE_SHOTS)mre
- 44b7d9f9tracker#6: /schedule — upcoming episodes of followed shows, soonest firstmre
- 91c9fc8ctracker#5: /unwatched — unwatched released episodes of followed shows, newest firstmre
- a97c0295tracker#4: show page /shows/:slug (header, seasons, episodes, watch checks) + tools/relink-episode-seasons.hlmre
- 05f407c5tracker: no border on any button except inverted ones (Log out, ident status and identities too); header brand weight 100mre
- 17375427tracker#2: tools/migrate.hl + tools/verify.hl — old MongoDB data into mpackdb with new idsmre
- 31aac936tracker#3: no border on the header and on filled buttons; inverted buttons keep theirsmre
- 2ad9d29ctracker#1: login exactly like calendar (identity selector in the header, empty homepage)mre
- 3691e176tracker#1: empty tracker with the ident login (state of 2026-09-27)mre