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
Latest commits
- a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmre
- 17f031f0gitoria#34: private repos, organizations, members, move tool, gatemre
- 71b69343gitoria#23: the sidebar's Repositories link was a 404 after any in-page navigation (static menu re-evaluated publicUrl in the browser); the menu is an instance property now; gate taps it after a tab, folder, filemre
- 90b4f728gitoria#25: restore the homepage cache and the parsed-blocks cache (they store data under immutable keys, no HTML); the page key, the framework readme key and the textHash key stay removedmre
- a487248cgitoria#25: remove every cache that hid the page build (page key, Markdown render key, homepage cache, parsed-blocks cache) and the gate that only tested themmre
- 12f2f4fegitoria: re-vendor Hybriel set-day27b, a startup fault in on Error exits 1mre
- c21c084egitoria: write the standby service out in full so the boot gate can read the main servicemre
- e307d69agitoria: say what is per process during the hand-overmre
- f0cbe6a6gitoria: standby service on port 45014 and a deploy that hands over through it without a gapmre
- 727cd083gitoria#25: README: vendor notes for Hybriel c1b1010f and the page cachemre
- 61b72dedgitoria#25: re-vendor Hybriel master c1b1010f (W149 page cache), key the repo Readme page by slug and main commit, extend the readme-cache gatemre
- 5b0b4b9ereadme-cache gate: use the security gate's ports when no own ports are givenmre
- bc8f20d9gitoria#25: re-vendor Hybriel c09538bb with the W141 render cache, cache the homepage per commit, add the readme-cache gatemre
- 9feebbd3Re-vendor Hybriel to ded47c13 (W145: Firefox start script fix)mre
- 28ed41e5gitoria#24: one sign-in comes from hl:web batch 20, the /session/share workaround is gonemre
- 3b2669e4gs: drop the unbuildable legacy check, fix pwa fetchmre
- 2a2fdd77gs: C2 check before cookie experimentsmre
- 76e0587aWIP gs 2mre
- a80da7bdWIP gs: security gate for lazy sessions, g24 browser checksmre
- 23fb05d8re-vendor Hybriel aaa39e69 (hl:web batch 20: login emit and Sessions.mint, tab follows a login, signed-in session cookie wins among duplicates and is re-issued with the Domain, W85 faster render, lazy sessions)mre