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
- 097c52baStyle the login error through its View idmre
- c6d9c86aOwn the not-found code rule in its componentmre
- 055424c2Record W61 replacement theme gates, sidebar repro and baselinemre
- 2ed09441Use layouts theme 17e0f03 for W61 compatibilitymre
- b8609a91Merge branch 'main' into w61-stylemre
- 4639caf7Report W61 theme startup blocker and day39 Style probemre
- 81f0a0bbREADME: two caches were restored by 90b4f72; log W62mre
- 4a3f557eImport layouts theme ebd00b6 for W61 (startup blocked)mre
- ab12a257Merge W62: #25 commit page measurements and proc repromre
- 41323e49gitoria#25: measure commit request costs and reproduce blocking process waitsmre
- 53ca42b2log: W60 merged, W61 W62 startedmre
- 80870a33mission W61: style passmre
- 560fd208Merge W60: helpers, bound forms, login in topics, two form fixes (gitoria#28 #32 #33)mre
- ac5ba6a4log: W60, #25 measuredmre
- 220f6342W60: record corrected form proof, full AE and remaining gapsmre
- 7e31cac5gitoria#28: restrict reply form layout to reply formsmre
- ae373cfdgitoria#28: keep each reply draft in its thread componentmre
- eeeebd5agitoria: insert a newly created organization oncemre
- 34d2d5cagitoria: clear the bound public-key textarea after creationmre
- 119e54c0W60: restore conductor-owned tracking filesmre