gitoria
All repositories: gitoria
8.7 KB
import { requiredPort, requiredPortRange } from './gate-ports.mjs';// 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 required, GITORIA_PRIV_IDENT_PORT required)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 CHROME = requiredPortRange('GITORIA_PRIV_CHROME');const PORT = requiredPort('GITORIA_PRIV_PORT'), IDENT_PORT = requiredPort('GITORIA_PRIV_IDENT_PORT');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: CHROME });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
Latest commits
- fe209ffeMerge branch 'w56-owner-members' into mainGitoria
- fa0754c8|||PR repository owner transfer and members API (#55)mre
- 8862e537Merge branch 'w55-rename-org' into mainGitoria
- 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
- 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
- 499f25f2Review fixes for the Settings organization move (#53)mre
- ed3b922b|||PR move a repository into an organization in Settings (#53)mre
- 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
- 9f7ce8d8Preserve rename compatibility and live page titlesmre
- c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
- ce08920dMerge branch 'w52c-header-phone' into mainGitoria
- 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
- e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
- c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
- 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
- 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
- 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
- 155861f6Merge branch 'w52-person-approval' into mainGitoria
- b5435de8|||PR person approvals: second Kunibert round (#52)mre
- 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre