gitoria
All repositories: gitoria
4.7 KB
// tests/ticketskit.mjs — a throw-away tickets.worldapi.org for the gate (ticket gitoria#10): tickets' code// COPIED without .env / storage / sessions (never the live one, never its data), started on its own port and// storage, logged in through the gate's ident, with an API token for the tickets user "gitoria".// const t = await startTickets({ ticketsDir, workDir, port, ident, identAlice }) // → { base, token, stop(), api(path) }import { spawn } from 'node:child_process';import { cpSync, mkdirSync, rmSync, existsSync } from 'node:fs';import { join } from 'node:path';const sleep = (ms) => new Promise(r => setTimeout(r, ms));const J = JSON.stringify;const SKIP = new Set(['.env', 'storage', '.sessions', '.scratch', 'server.log', 'server.pid', 'testapp', '.git', 'tests', 'import']);// the server and anything it started: its own process group (spawned detached), by the saved numeric pidfunction killTree(proc) { try { process.kill(-proc.pid, 'SIGKILL'); } catch { try { proc.kill('SIGKILL'); } catch {} } }export async function startTickets({ ticketsDir, workDir, port, ident, who, origins = '' }) {const code = join(workDir, 'tickets-code');const data = join(workDir, 'tickets-data');rmSync(workDir, { recursive: true, force: true });mkdirSync(code, { recursive: true });mkdirSync(data, { recursive: true });cpSync(ticketsDir, code, { recursive: true, filter: (src) => {const rel = src.slice(ticketsDir.length).replace(/^\/+/, '');return rel === '' || !SKIP.has(rel.split('/')[0]);} });if (existsSync(join(code, '.env'))) throw new Error('ticketskit: a .env was copied — refusing to start');const base = `http://127.0.0.1:${port}`;const app = await ident.registerApp(who, 'tickets (gitoria gate)', [base]);let log = '';const proc = spawn(join(code, 'bin/hybriel'), ['project.hl'], {cwd: code,env: { ...process.env, TICKETS_PORT: String(port), TICKETS_STORAGE: join(data, 'mpackdb'), TICKETS_SESSIONS: join(data, 'sessions') + '/', TICKETS_WATCH: '0',HL_HOST: '127.0.0.1', IDENT_URL: ident.base, IDENT_EXCHANGE_URL: ident.base, TICKETS_PUBLIC_URL: base, IDENT_API_KEY: app.key, IDENT_API_SECRET: app.secret, TICKETS_CREATOR_IDENTITY: '', TICKETS_CONNECT_ORIGINS: origins },stdio: ['ignore', 'pipe', 'pipe'], detached: true,});proc.stdout.on('data', d => log += d); proc.stderr.on('data', d => log += d);// any failure while starting kills the server again (a crashed gate left it listening, 2026-10-23)let token = null, cookie = '';try {let up = false;// tickets on native Hybriel compiles cold for ~25 s (hybriel#148): wait up to 120 sfor (let i = 0; i < 480 && !up; i++) { try { up = (await fetch(base + "/api/projects")).ok; } catch {} if (!up) await sleep(250); }if (!up) throw new Error('tickets did not come up\n' + log);// the user "gitoria": the login button's server half, a display name, an API tokenconst first = await fetch(base + '/');cookie = (first.headers.get('set-cookie') || '').split(';')[0];const cb = await fetch(base + '/login/callback?ident_code=' + await ident.selectorCode(who, app, base), { headers: { cookie }, redirect: 'manual' });if (cb.status !== 302) throw new Error('tickets login failed: ' + cb.status);// a login gets a NEW session id (tickets mission ST, session fixation): like a browser, keep the cookie the login setconst rotated = (cb.headers.get('set-cookie') || '').split(';')[0];if (rotated) cookie = rotated;let n = 0;const emit = async (event, payload) => {const r = await fetch(base + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', cookie }, body: J({ t: 'emit', i: ++n, event, payload }) });const t = await r.text(); let j = null; try { j = JSON.parse(t); } catch {}return { raw: t, value: j && j.value };};const nm = await emit('saveDisplayName', ['gitoria']);if (!nm.value || nm.value.name !== 'gitoria') throw new Error('tickets name failed: ' + nm.raw);const tk = await emit('tokenCreate', ['gitoria gate']);token = tk.value && tk.value.token;if (!/^tkt_[0-9a-f]{48}$/.test(token || '')) throw new Error('tickets token failed: ' + tk.raw);} catch (e) { killTree(proc); throw e; }return {base, token, cookie, log: () => log,async api(path, headers = {}) { const r = await fetch(base + path, { headers }); const t = await r.text(); let j = null; try { j = JSON.parse(t); } catch {} return { status: r.status, json: j }; },async stop() {try { process.kill(-proc.pid, 'SIGTERM'); } catch { 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
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- cb634512log: 2026-11-08 keyed lists livemre
- 07c98d4aLists: keyed rows with @id, remove(id) and one whole-list assignment instead of hand-rebuilt loopsmre
- 0db0d81elog: 2026-11-08 day52 live, W30 startedmre
- b05f6d92tests/status: the gate's 3 s app token expired during the restart; it lives 60 s like status-keyedmre
- 1e8f4f0avendor: Hybriel set-day52 (fault-path leak fix #335, keyed rows #331)mre
- f5f0fb7blog: 2026-11-08 day50/#29 live, H25 correction, V52 startedmre
- dc77fb95main: offline note from __hlOnline, tick removed (#29)mre
- 37a86d93tests/reviews: seeded fake hook's DNS failures are not server errors (flaky gate)mre
- 07ab845bvendor: Hybriel set-day50 (run() leak fix #335)mre
- 71b2fa4blog: hybriel#335mre
- bd94cc7elog: #25 cause found (run() leak)mre
- 565cb508log: H25 round 1mre
- 90a0af84log: H25 startedmre
- 87bd53b8mission H25mre
- 71a746cflog: day48 livemre
- bf568e14log: V48 mergedmre
- 09955dedMerge v48: Hybriel set-day48, theme layouts ce4a0bamre
- f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
- 5d0834e7log: Apollo model rulemre
- fe8e5bd5log: #25 sample, V48 missionmre