gitoria
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
- 4f47843egate: ticket links use the tickets short URL (/<slug>/<n>, tickets#25)mre
- 86605446mission 002 (code order) 4/4: README file map + import order + 'Same output' test + gate run with a tickets HEAD copy, STATUS (entry, lessons), LOG, report; tests/realdata-baseline.mjs + realdata-compare.py (a cleanup answers the same on live data: pages, modules, API, git over HTTPS and SSH, faces), tests/letcount.pymre
- cc7bf7bamission 002 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (289 lets → plain declarations; 213 left: 125 reassigned, 88 loop-bound; no member/import/param clash). gates 200/0, 46/0, 44/0; real-data reads + writes identical (browser modules: var → const only)mre
- 090a20c6mission 002 (code order) 2/4: one lib/ file per topic — git.hl split into git (calls, branches, init, temp folder) / homepage / code / pulls / releases (+ git-helpers: paths, ids, |||PR/|||RL markers); repos-helpers, tickets-helpers, transport-helpers; util.hl = localtime + env, storage dir, addresses, lists, text checks, one newest-first sort (was 3 copies); the function routes out of project.hl into lib/api.hl (thin; plumbing in api-helpers.hl), sshgate.hl folded into api.hl + sshkeys.hl keyLine + repos.hl mayPush; 'Make main' and the merge answer out of the faces (code.hl makeMain, pulls.hl pullsView), one login helper (users.hl userOfLoginCode); project.hl is the map. Session-writing routes get &req + &server.sessions. gates 200/0, 46/0, 44/0; real-data identical except /login/failed now shows the parked reason for a browser that already had a session (the old copy-of-req lost it)mre
- 110c2799mission 002 (code order) 1/4: .hl files out of the root — lib/ (api, git, localtime, markdown, repos, sshgate, sshkeys, tickets, tokens, transport, users), components/styles.hl; jsoncheck.hl removed (imported nowhere); import paths only. gates 200/0, 46/0, 44/0; real-data reads + writes identicalmre
- fdfb4b1bgitoria: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gates 200/0, 46/0, 44/0mre
- 5b46ac84antcolony#40: LOG.md — missions 069/072 are antcolony missions (report paths on Byrodin)mre
- 5602ff41gitoria: Hybriel master 190aa11d (fc838894 GC correctness, #127 mountKids by reference, #126, #48) — tracker README flat; gates 200/0, 46/0, 44/0mre
- e85eaf01gitoria: 069 round 2 — hybriel 1a096ad3 not adopted (Markdown SSR still grows); browser gate waits for the server-side logout before restartmre
- 09ce4f3fgitoria: mission 069 re-vendor hybriel 8efba065 stopped (big SSR pages grow + slow down); lambda audit clean; old vendor keptmre
- 3dc43108antcolony#40: mission references point to the moved missionsmre
- 8d9450fdantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
- 205d5fe4gitoria: Hybriel master ff51cf46; ssh keys/tokens no double rows (session sync); gates follow #20mre
- 9b27cb26gitoria#21: installable app (manifest, service worker, offline start page), own iconmre
- 68dcb603deploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
- e2deed6dgitoria#20: "Add code" only on the Code page of an empty repository, no collapsiblemre
- 8bb97ffddeploy.sh: never send .git or .gitignore to Byrodinmre
- fd981932State of 2026-09-27; bin/ no longer tracked (Hybriel commit is in README)mre
- 4a2d7125initial commitmre