gitoria
All repositories: gitoria
8.6 KB
// tests/shots-go34.mjs (not a gate: makes the 390 / 1280 screenshots of the GO34 pages into SHOTS_DIR and prints the tap/field measurements) — was tests/private.mjs — GATE OF PRIVATE REPOS AND ORGANIZATIONS (ticket gitoria#34, GO34). Real HTTP against a real local gitoria + its own ident// (tests/identkit.mjs), the real `git` binary for clone / push, the move tool (tools/move-repo.hl) on a copy. A private repo, and every repo of a// private organization, does not exist for anybody who is not in it: homepage list, repo page, every code path, API, git over HTTP, the ssh// access check. An organization's address lists its repos and /<repo>/… behave like repo pages. A public repo is unchanged.// node tests/private.mjs (GITORIA_PRIV_PORT default 8744, GITORIA_PRIV_IDENT_PORT default 8743)import { spawn, execFileSync } from 'node:child_process';import { request } from 'node:http';import { mkdirSync, rmSync, writeFileSync, existsSync, readdirSync } from 'node:fs';import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { startIdent } from './identkit.mjs';import { launchBrowser } from './cdp.mjs';if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';const HERE = dirname(fileURLToPath(import.meta.url));const APP = resolve(HERE, '..');const PORT = Number(process.env.GITORIA_PRIV_PORT || 8744), IDENT_PORT = Number(process.env.GITORIA_PRIV_IDENT_PORT || 8743);const IDENT_DIR = process.env.GITORIA_GATE_IDENT_DIR || [resolve(APP, '../ident.worldapi.org'), '/media/STORAGE/projects/WorldAPI/ident.worldapi.org'].find(d => existsSync(join(d, 'project.hl')));const STORE = join(APP, '.scratch/shots-store');const OUT = process.env.SHOTS_DIR || join(STORE, 'shots');const SSH_SECRET = 'sshsecret-for-the-private-gate';const J = JSON.stringify, sleep = (ms) => new Promise(r => setTimeout(r, ms));let passes = 0, failures = 0;const check = (label, ok, detail = '') => { console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`); if (ok) passes++; else failures++; };function raw(method, path, { host = `localhost:${PORT}`, headers = {}, body = null, cookie = null } = {}) {return new Promise((res, rej) => {const h = { host, ...headers }; if (cookie) h.cookie = cookie;if (body !== null) h['content-length'] = Buffer.byteLength(body);const r = request({ host: '127.0.0.1', port: PORT, method, path, headers: h }, (m) => { const c = []; m.on('data', d => c.push(d)); m.on('end', () => res({ status: m.statusCode, headers: m.headers, body: Buffer.concat(c).toString('latin1') })); });r.on('error', rej); if (body !== null) r.write(body); r.end();});}const get = (path, o = {}) => raw('GET', path, o);const g404 = (r) => r.status === 404 || /No such repository/.test(r.body);const at = (label, path = '/', o = {}) => get(path, { host: `${label}.localhost:${PORT}`, ...o });let server = null, log = '';function startServer(env) {log = '';const p = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, stdio: ['ignore', 'pipe', 'pipe'],env: { ...process.env, GITORIA_PORT: String(PORT), GITORIA_WATCH: '0', GITORIA_PUBLIC_URL: `http://localhost:${PORT}`, GITORIA_SSH_SECRET: SSH_SECRET, GITORIA_TICKETS_URL: 'http://127.0.0.1:1', ...env } });p.stdout.on('data', d => log += d); p.stderr.on('data', d => log += d);server = p; return p;}async function up() { for (let i = 0; i < 960; i++) { try { if ((await get('/api/repos')).status === 200) return; } catch {} await sleep(250); } throw new Error('gitoria did not come up\n' + log); }const stop = async () => { if (server) { const p = server; server = null; p.kill(); await new Promise(r => p.once('exit', r)); } };let ident;try {rmSync(STORE, { recursive: true, force: true }); mkdirSync(STORE, { recursive: true }); mkdirSync(OUT, { recursive: true });ident = await startIdent({ identDir: IDENT_DIR, workDir: join(STORE, 'ident'), port: IDENT_PORT });const alice = await ident.signIn('[email protected]'), bob = await ident.signIn('[email protected]'), carol = await ident.signIn('[email protected]');const BASE = `http://localhost:${PORT}`;const app = await ident.registerApp(alice, 'gitoria (private gate)', [BASE]);const ENV = { GITORIA_STORAGE: join(STORE, 'mpackdb'), GITORIA_SESSIONS: join(STORE, 'sessions') + '/', GITORIA_GIT: join(STORE, 'git'), IDENT_URL: ident.base, IDENT_EXCHANGE_URL: ident.base, IDENT_API_KEY: app.key, IDENT_API_SECRET: app.secret };startServer(ENV); await up();const cookieOf = (r) => (r.headers['set-cookie'] || []).map(c => c.split(';')[0])[0] || null;const login = async (who) => {const ck = cookieOf(await get('/'));const code = await ident.selectorCode(who, app, BASE);const cb = await get('/login/callback?ident_code=' + code + '&next=%2F', { cookie: ck });return { cookie: cookieOf(cb) || ck };};let n = 0;const face = async (who, event, payload) => {const r = await raw('POST', '/__hl/emit', { headers: { 'content-type': 'application/json' }, cookie: who && who.cookie, body: J({ t: 'emit', i: ++n, event, payload }) });let j = null; try { j = JSON.parse(r.body); } catch {}return { status: r.status, value: j && j.value, error: j && j.error };};const A = await login(alice), B = await login(bob), C = await login(carol);await face(A, 'gitoriaSaveName', ['Alice']); await face(B, 'gitoriaSaveName', ['Bob']); await face(C, 'gitoriaSaveName', ['Carol']);const tok = async (who, name) => (await face(who, 'gitoriaMakeToken', [name])).value.token;const tA = await tok(A, 'a'), tB = await tok(B, 'b'), tC = await tok(C, 'c');const W = join(STORE, 'work'); mkdirSync(W, { recursive: true });const genv = { ...process.env, GIT_TERMINAL_PROMPT: '0', GIT_CONFIG_GLOBAL: '/dev/null', GIT_AUTHOR_NAME: 'a', GIT_AUTHOR_EMAIL: 'a@a', GIT_COMMITTER_NAME: 'a', GIT_COMMITTER_EMAIL: 'a@a' };const g = (...a) => execFileSync('git', a, { cwd: W, encoding: 'utf8', env: genv, stdio: ['ignore', 'pipe', 'pipe'] });g('init', '-q', '-b', 'main'); writeFileSync(join(W, 'README.md'), '# Hidden tool\n\nA private tool.\n'); g('add', '-A'); g('commit', '-q', '-m', 'init');await face(A, 'gitoriaCreateOrg', ['acme', true]);await face(A, 'gitoriaCreateRepo', ['tool', 'the private tool of acme', 'acme', false]);await face(A, 'gitoriaCreateRepo', ['second', 'another one', 'acme', false]);g('push', '-q', `http://u:${tA}@acme.localhost:${PORT}/tool.git`, 'main');await face(A, 'gitoriaChangeMember', ['acme/tool', 'Bob', true]);const b = await launchBrowser({ debugPortRange: [8750, 8757] });try {const page = await b.newPage();await page.send('Network.enable');const as = async (who, host) => {await page.send('Network.deleteCookies', { name: 'gitoriasid', domain: host.split(':')[0] }).catch(() => {});if (who) { const [ck, cv] = who.cookie.split('='); await page.send('Network.setCookie', { name: ck, value: cv, url: `http://${host}/` }); }};const list = [['org-owner', A, 'acme.localhost', '/'], ['repo-owner', A, 'acme.localhost', '/tool'], ['repo-signedout', null, 'acme.localhost', '/tool'], ['org-signedout', null, 'acme.localhost', '/'],['settings-owner', A, 'acme.localhost', '/tool/settings'], ['home-create', A, 'localhost', '/']];for (const [w, h] of [[390, 844], [1280, 900]]) {await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: w < 600 });for (const [name, who, host, path] of list) {const hp = `${host}:${PORT}`;await as(who, hp);await page.goto(`http://${hp}${path}`);await sleep(2500);const m = await page.evaluate(`(() => { const out = { sw: document.documentElement.scrollWidth, small: [] }; for (const e of document.querySelectorAll('a, button, input, select')) { const r = e.getBoundingClientRect(); if (r.width > 0 && (r.height < 44) && getComputedStyle(e).display !== 'inline') out.small.push(e.tagName + '#' + e.id + ' ' + Math.round(r.width) + 'x' + Math.round(r.height)); if ((e.tagName === 'INPUT' || e.tagName === 'SELECT') && r.width > 0 && parseFloat(getComputedStyle(e).fontSize) < 16) out.small.push('font<16 ' + e.id); } out.small = out.small.slice(0, 12); return out; })()`);const { data } = await page.send('Page.captureScreenshot', { format: 'png', captureBeyondViewport: true });writeFileSync(join(OUT, `${name}-${w}.png`), Buffer.from(data, 'base64'));console.log(name, w, JSON.stringify(m));}}} finally { await b.close().catch(() => {}); }} finally {await stop().catch(() => {});try { ident && ident.stop && await ident.stop(); } catch {}process.exit(0);}
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
- 26117255|||PR apps API: review comments on files with spaces in their namemre
- b8796cecMerge branch 'f1-broken-json' into mainGitoria
- 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
- f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
- 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
- 16a3530fMerge branch 'heap-revert' into mainGitoria
- 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
- 13f0c342Merge branch 'hl25-records' into mainGitoria
- a002ecb7|||PR records: HL25 report, heap helper, logmre
- 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
- fefaedd2log: tracker PR-only, HL25 startedmre
- 21aa57calog: parkmre
- e9f950a8reports: G25c soakmre
- a7783686log: deploy 9f41ffcmre
- 9f41ffc1log: W30b mergedmre
- bef635c1Merge branch 'w30b'mre
- 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
- c4f6d9e3reports: G25c growth huntmre
- b88e39f1log: privacy cleanup donemre
- bfd7826ddocs: neutral example organisation namemre