gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchw53-pulls-speed-pr80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymrew53-pulls-speed-pr/tests/push.mjs

24.1 KB

  1. import { requiredPort, requiredPortRange } from './gate-ports.mjs';
  2. // tests/push.mjs — THE GATE OF PUSH AND PULL (ticket gitoria#7). Its own gitoria server + its own ident (copy, mail sink),
  3. // a real Chrome for everything visible (create a repo, the "add code" box, access tokens), and the REAL `git` binary for
  4. // clone / push / fetch over HTTP against the repo address <slug>.gitoria.test (git's http.curloptResolve maps it to 127.0.0.1).
  5. // node tests/push.mjs (GITORIA_GATE_PORT 8700, GITORIA_GATE_IDENT_PORT 8701, GITORIA_GATE_CHROME "8703-8707")
  6. import { spawn } from 'node:child_process';
  7. import { request as httpRequest, createServer } from 'node:http';
  8. import { rmSync, mkdirSync, writeFileSync, existsSync, readFileSync } from 'node:fs';
  9. import { dirname, join, resolve } from 'node:path';
  10. import { fileURLToPath } from 'node:url';
  11. import { randomBytes } from 'node:crypto';
  12. import { launchBrowser } from './cdp.mjs';
  13. import { startIdent } from './identkit.mjs';
  14. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  15. const HERE = dirname(fileURLToPath(import.meta.url));
  16. const APP = resolve(HERE, '..');
  17. const BIN = join(APP, 'bin/hybriel');
  18. const PORT = requiredPort('GITORIA_GATE_PORT');
  19. const IDENT_PORT = requiredPort('GITORIA_GATE_IDENT_PORT');
  20. const PROXY = requiredPort('GITORIA_GATE_PROXY'); // stands in for nginx: buffers a chunked request body and sends it with a length
  21. const [CH_FROM, CH_TO] = requiredPortRange('GITORIA_GATE_CHROME');
  22. const API = `http://127.0.0.1:${PORT}`;
  23. const BASE = `http://gitoria.test:${PORT}`;
  24. const IDENT_B = `http://ident.gitoria.test:${IDENT_PORT}`;
  25. const REPO = (slug) => `http://${slug}.gitoria.test:${PORT}`;
  26. const hreq = (method, path, host, headers = {}, body = null) => new Promise((res, rej) => {
  27. const rq = httpRequest({ host: '127.0.0.1', port: PORT, path, method, headers: { host, ...headers } }, (r) => { let b = ''; r.setEncoding('utf8'); r.on('data', d => b += d); r.on('end', () => res({ status: r.statusCode, headers: r.headers, body: b })); });
  28. rq.on('error', rej); if (body) { rq.setHeader('content-length', Buffer.byteLength(body)); rq.write(body); } rq.end();
  29. });
  30. process.env.HL_CHROME_ARGS = '--host-resolver-rules=MAP *.gitoria.test 127.0.0.1, MAP gitoria.test 127.0.0.1';
  31. const SCRATCH = join(APP, '.scratch');
  32. const STORE = join(SCRATCH, 'push-store');
  33. const WORK = join(STORE, 'work');
  34. 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')));
  35. rmSync(STORE, { recursive: true, force: true });
  36. mkdirSync(WORK, { recursive: true });
  37. const J2 = JSON.stringify;
  38. const sh = (expr) => `(() => { const h = document.querySelector('#selector'); const r = h && h.shadowRoot; if (!r) return null; return (${expr}); })()`;
  39. async function shClick(page, inner, name = null) {
  40. const find = `(() => { const h = document.querySelector('#selector'); const r = h && h.shadowRoot; if (!r) return null; const el = ${name === null ? `r.querySelector(${J2(inner)})` : `[...r.querySelectorAll(${J2(inner)})].find(b => b.textContent === ${J2(name)})`}; if (!el) return null; const b = el.getBoundingClientRect(); return b.width > 0 ? { x: b.x + b.width / 2, y: b.y + b.height / 2 } : null; })()`;
  41. const box = await page.waitFor(find, { label: 'selector ' + inner });
  42. const at = { x: Math.round(box.x), y: Math.round(box.y), button: 'left', clickCount: 1 };
  43. await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', ...at, buttons: 0 });
  44. await page.send('Input.dispatchMouseEvent', { type: 'mousePressed', ...at, buttons: 1 });
  45. await page.send('Input.dispatchMouseEvent', { type: 'mouseReleased', ...at, buttons: 0 });
  46. }
  47. // the header's selector (the only sign-in): choose the first identity
  48. async function selectorLogin(page) {
  49. await shClick(page, '#choose');
  50. await page.waitFor(sh(`r.querySelectorAll('[part~="identity"]').length > 0`), { label: 'selector list' });
  51. await shClick(page, '[part~="identity"]', 'Default');
  52. }
  53. let failures = 0, passes = 0;
  54. function check(label, ok, detail = '') {
  55. console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`);
  56. if (ok) passes++; else failures++;
  57. }
  58. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  59. const J = JSON.stringify;
  60. let pageA = null;
  61. let log = '', server = null, ident = null, proxy = null;
  62. function startProxy() {
  63. proxy = createServer((req, res) => {
  64. const parts = []; req.on('data', d => parts.push(d));
  65. req.on('end', () => {
  66. const body = Buffer.concat(parts);
  67. const headers = { ...req.headers }; delete headers['transfer-encoding']; headers['content-length'] = String(body.length);
  68. const up = httpRequest({ host: '127.0.0.1', port: PORT, path: req.url, method: req.method, headers }, (r) => { res.writeHead(r.statusCode, r.headers); r.pipe(res); });
  69. up.on('error', () => { res.writeHead(502); res.end(); });
  70. up.end(body);
  71. });
  72. });
  73. proxy.listen(PROXY, '127.0.0.1');
  74. }
  75. const browsers = [];
  76. function startServer(extraEnv = {}) {
  77. server = spawn(BIN, ['project.hl'], {
  78. cwd: APP,
  79. env: { ...process.env, GITORIA_PORT: String(PORT), GITORIA_STORAGE: join(STORE, 'mpackdb'), GITORIA_SESSIONS: join(STORE, 'sessions') + '/', GITORIA_WATCH: '0', GITORIA_GIT: join(STORE, 'git'),
  80. GITORIA_PUBLIC_URL: BASE, IDENT_URL: IDENT_B, IDENT_EXCHANGE_URL: ident.base, GITORIA_TICKETS_URL: 'http://127.0.0.1:1', ...extraEnv },
  81. stdio: ['ignore', 'pipe', 'pipe'],
  82. });
  83. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  84. }
  85. async function serverUp() {
  86. for (let i = 0; i < 480; i++) { try { const r = await fetch(API + '/api/repos'); if (r.ok) return; } catch {} await sleep(250); }
  87. throw new Error('gitoria did not come up\n' + log);
  88. }
  89. async function stopServer() {
  90. if (!server) return;
  91. try { server.kill('SIGTERM'); } catch {}
  92. await new Promise(r => { if (server.exitCode !== null || server.signalCode !== null) return r(); server.once('exit', r); setTimeout(r, 3000); });
  93. server = null;
  94. }
  95. function patient(page) {
  96. const waitFor = page.waitFor.bind(page);
  97. page.waitFor = (expr, o = {}) => waitFor(expr, { ...o, timeout: (o.timeout || 10000) * 3 });
  98. const goto = page.goto.bind(page);
  99. page.goto = (url, o = {}) => goto(url, { ...o, timeout: (o.timeout || 15000) * 3 });
  100. return page;
  101. }
  102. const hydrated = (page) => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { label: 'page hydrated' });
  103. const txt = (page, sel) => page.evaluate(`(document.querySelector(${J(sel)}) || {}).textContent || null`);
  104. const has = (page, sel) => page.evaluate(`!!document.querySelector(${J(sel)})`);
  105. // THE SHELL (gitoria#23, the theme's header): "Log out" sits in the user menu's dropdown, on a phone "Log in with ident" in the
  106. // ident dropdown — a person opens it first; a target that already shows is clicked straight away (as tests/browser.mjs)
  107. async function clickInMenu(page, sel, toggle) {
  108. const shows = `(() => { const e = document.querySelector(${J(sel)}); return !!e && e.getBoundingClientRect().width > 0; })()`;
  109. await page.waitForSelector(sel);
  110. if (!(await page.evaluate(shows)) && await has(page, toggle)) { await page.click(toggle); await page.waitFor(shows, { label: 'menu open for ' + sel }); }
  111. await page.click(sel);
  112. }
  113. const noOverflow = (page) => page.evaluate('document.documentElement.scrollWidth <= window.innerWidth');
  114. // the real git client. HOST = the repo address mapped to 127.0.0.1; credentials in the URL when given
  115. const GIT_ENV = { ...process.env, GIT_TERMINAL_PROMPT: '0', GIT_CONFIG_NOSYSTEM: '1', HOME: WORK, LC_ALL: 'C' };
  116. function git(cwd, args, slug, extra = {}) {
  117. const pre = slug ? ['-c', `http.curloptResolve=${slug}.gitoria.test:${extra.port || PROXY}:127.0.0.1`] : [];
  118. const { port: _p, ...envExtra } = extra;
  119. // async: the proxy of this gate lives in this process, a blocking spawnSync would starve it
  120. return new Promise((res) => {
  121. const c = spawn('git', [...pre, '-c', 'user.name=Gate', '-c', '[email protected]', '-c', 'init.defaultBranch=main', ...args], { cwd, env: { ...GIT_ENV, ...envExtra } });
  122. let out = ''; c.stdout.on('data', d => out += d); c.stderr.on('data', d => out += d);
  123. const t = setTimeout(() => c.kill('SIGKILL'), 120000);
  124. c.on('close', (code) => { clearTimeout(t); res({ code, out }); });
  125. });
  126. }
  127. const urlOf = (slug, user, pass, port = PROXY) => `http://${user ? `${user}:${pass}@` : ''}${slug}.gitoria.test:${port}/${slug}.git`;
  128. try {
  129. ident = await startIdent({ identDir: IDENT_DIR, workDir: join(STORE, 'ident'), port: IDENT_PORT });
  130. const alice = await ident.signIn('[email protected]');
  131. const bob = await ident.signIn('[email protected]');
  132. const APPKEY = await ident.registerApp(alice, 'gitoria (push gate)', [BASE]);
  133. startServer({ IDENT_API_KEY: APPKEY.key, IDENT_API_SECRET: APPKEY.secret });
  134. await serverUp();
  135. startProxy();
  136. // ---- alice in Chrome: log in, name, create an empty repo --------------------------------------------------
  137. const b = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });
  138. browsers.push(b);
  139. const A = patient(await b.newPage());
  140. pageA = A;
  141. const [ck, cv] = alice.cookie.split('=');
  142. await A.send('Network.enable');
  143. await A.send('Network.setCookie', { name: ck, value: cv, url: IDENT_B + '/' });
  144. await A.goto(BASE + '/');
  145. await A.waitForSelector('#selector');
  146. await hydrated(A);
  147. check('tokens: signed out, the main page offers no token form', !(await has(A, '#tokenform')));
  148. await selectorLogin(A);
  149. await A.waitForSelector('#nameform');
  150. await hydrated(A);
  151. await A.type('#displayname', 'alice');
  152. await A.click('#namesave');
  153. await A.waitFor('!document.querySelector("#nameform") && !!document.querySelector("#createform")', { label: 'named' });
  154. await A.type('#slug', 'gamma');
  155. await A.type('#description', 'pushed to');
  156. await A.click('#createsave');
  157. await A.waitForSelector('#created');
  158. // ---- the "add code" box of an EMPTY repo (gitoria#20: plain text, only on the Code page) ---------------------
  159. await A.goto(REPO('gamma') + '/code');
  160. await A.waitFor('!!document.querySelector("#addcode")', { label: 'add code box' });
  161. const url = urlOf('gamma', null, null, PORT);
  162. check('empty repo: the "add code" box is plain text (no <details>/<summary>)', await A.evaluate('document.querySelector("#addcode").tagName !== "DETAILS" && !document.querySelector("#addcode summary")'));
  163. check('empty repo: the clone command names the repo address', (await txt(A, '#clonecommand')) === 'git clone ' + url, await txt(A, '#clonecommand'));
  164. const nc = await txt(A, '#newcommands');
  165. check('empty repo: the new-project commands are complete', nc.split('\n').length === 6 && /^git init -b main$/m.test(nc) && nc.includes(`git remote add origin ${url}`) && /git push -u origin main$/.test(nc), nc);
  166. check('empty repo: the existing-project commands are complete', (await txt(A, '#existingcommands')) === `git remote add origin ${url}\ngit branch -M main\ngit push -u origin main`, await txt(A, '#existingcommands'));
  167. check('empty repo: the box links to the access tokens on the main address', (await A.evaluate('document.querySelector("#totokens").getAttribute("href")')) === BASE + '/#tokens');
  168. const first = (await hreq('GET', '/code', `gamma.gitoria.test:${PORT}`)).body;
  169. check('empty repo: the box is in the FIRST html of /code (no script needed)', /id="addcode"/.test(first) && first.includes(`git clone ${url}`), first.slice(first.indexOf('id="addcode"'), first.indexOf('id="addcode"') + 200));
  170. const other = await A.evaluate('1'); // keep the page alive
  171. await A.goto(REPO('nothere') + '/');
  172. await A.waitFor('!!document.querySelector("#missing")');
  173. check('unknown address: no "add code" box', !(await has(A, '#addcode')));
  174. // ---- the token, made in the browser -------------------------------------------------------------------------
  175. await A.goto(BASE + '/');
  176. await A.waitFor('!!document.querySelector("#tokenform")', { label: 'token form' });
  177. await hydrated(A);
  178. check('tokens: logged in, "You have no tokens yet"', await has(A, '#notokens'));
  179. await A.click('#tokensave');
  180. await sleep(300);
  181. await A.type('#tokenname', 'laptop');
  182. await A.click('#tokensave');
  183. await A.waitFor('!!document.querySelector("#tokensecret")', { label: 'token shown' });
  184. const TOKEN = (await txt(A, '#tokensecret')).trim();
  185. check('tokens: a token is shown once (gtr_ + 40 hex), listed by its name', /^gtr_[0-9a-f]{40}$/.test(TOKEN) && (await txt(A, '#tokenlist')).includes('laptop') && !(await has(A, '#notokens')), TOKEN);
  186. const stored = readFileSync(join(STORE, 'mpackdb', readdirOf(join(STORE, 'mpackdb')).find(n => n.startsWith('tokens.'))), 'latin1');
  187. // hybriel 64527baa: the face's ack syncs `tokens` from the server; the new row must not be listed twice
  188. check('tokens: the first token is listed ONCE', (await A.evaluate('document.querySelectorAll("#tokenlist li").length')) === 1, await txt(A, '#tokenlist'));
  189. check('tokens: only the hash is stored, never the token', !stored.includes(TOKEN.slice(4)), 'the token text is in the table file');
  190. await A.type('#tokenname', 'second');
  191. await A.click('#tokensave');
  192. await A.waitFor('document.querySelectorAll("#tokenlist li").length === 2', { label: 'two tokens' });
  193. const SECOND = (await txt(A, '#tokensecret')).trim();
  194. check('tokens: a second token replaces the shown secret', /^gtr_[0-9a-f]{40}$/.test(SECOND) && SECOND !== TOKEN, J({ TOKEN, SECOND }));
  195. // ---- real git: clone the empty repo, push, clone, fetch, push again ---------------------------------------------
  196. const W = (n) => join(WORK, n);
  197. let g = await git(WORK, ['clone', urlOf('gamma'), 'first'], 'gamma');
  198. check('git: cloning the empty repo works (an empty repository)', g.code === 0 && /empty repository/.test(g.out), J(g));
  199. writeFileSync(join(W('first'), 'README.md'), '# gamma\n\nPushed with **git**.\n');
  200. writeFileSync(join(W('first'), 'big.bin'), randomBytes(4000000));
  201. await git(W('first'), ['add', '.']); await git(W('first'), ['commit', '-qm', 'first commit']);
  202. g = await git(W('first'), ['push', 'origin', 'main'], 'gamma');
  203. check('git: a push without credentials is refused and says how to get a token', g.code !== 0 && /terminal prompts disabled|could not read Username|401/.test(g.out) && g.out.length > 0, g.out);
  204. const rawNo = await hreq('POST', '/gamma.git/git-receive-pack', `gamma.gitoria.test:${PORT}`, {}, '0000');
  205. check('git: the push endpoint answers 401 with a Basic challenge and the hint', rawNo.status === 401 && /Basic/.test(rawNo.headers['www-authenticate'] || '') && /token/.test(rawNo.body), J(rawNo));
  206. g = await git(W('first'), ['push', urlOf('gamma', 'alice', 'gtr_' + '0'.repeat(40)), 'main'], 'gamma');
  207. check('git: a token nobody made is refused', g.code !== 0 && /Authentication failed|not valid|401/.test(g.out), g.out);
  208. // bob logs in through his own ident identity: another user's token must not push to alice's repo
  209. const bobCode = await ident.selectorCode(bob, APPKEY, BASE);
  210. const bl = await fetch(API + '/login/callback?ident_code=' + bobCode, { redirect: 'manual' });
  211. const bobCookie = (bl.headers.get('set-cookie') || '').split(';')[0];
  212. const bobName = await fetch(API + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', cookie: bobCookie }, body: J({ t: 'emit', i: 1, event: 'gitoriaSaveName', payload: ['bob'] }) });
  213. const bt = await fetch(API + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', cookie: bobCookie }, body: J({ t: 'emit', i: 2, event: 'gitoriaMakeToken', payload: ['bobs'] }) });
  214. const BOBTOKEN = (JSON.parse(await bt.text()).value || {}).token;
  215. check('tokens: bob makes his own token (a face, own session)', /^gtr_[0-9a-f]{40}$/.test(BOBTOKEN || ''), String(BOBTOKEN));
  216. g = await git(W('first'), ['push', urlOf('gamma', 'bob', BOBTOKEN), 'main'], 'gamma');
  217. check('git: another user\'s token may not push — only the owner may', g.code !== 0 && /only the owner|403/.test(g.out), g.out);
  218. g = await git(W('first'), ['push', urlOf('gamma', 'alice', TOKEN), 'main'], 'gamma');
  219. check('git: the owner pushes with the token (a 4 MB pack too)', g.code === 0 && /main -> main/.test(g.out), g.out);
  220. g = await git(WORK, ['clone', '-q', urlOf('gamma'), 'second'], 'gamma');
  221. check('git: a clone needs no login (public read) and has the pushed commit and file', g.code === 0 && readFileSync(join(W('second'), 'README.md'), 'utf8').includes('Pushed with') && readFileSync(join(W('second'), 'big.bin')).equals(readFileSync(join(W('first'), 'big.bin'))), g.out);
  222. check('git: the bare repo on the server holds the commit', await (await git(W('first'), ['--git-dir', join(STORE, 'git', 'gamma.git'), 'log', '--format=%s'])).out.trim() === 'first commit');
  223. // hybriel#89: hl:http1 reads a chunked request body — a big push straight to the server (no proxy) works (was a 411 before)
  224. writeFileSync(join(W('first'), 'direct.bin'), randomBytes(4000000));
  225. await git(W('first'), ['add', '.']); await git(W('first'), ['commit', '-qm', 'direct push']);
  226. g = await git(W('first'), ['-c', 'http.postBuffer=65536', 'push', urlOf('gamma', 'alice', TOKEN, PORT), 'main'], 'gamma', { port: PORT });
  227. check('git: a big push straight to hl:http1 (chunked, no proxy) works (hybriel#89)', g.code === 0 && /main -> main/.test(g.out) && (await git(W('first'), ['--git-dir', join(STORE, 'git', 'gamma.git'), 'log', '-1', '--format=%s'])).out.trim() === 'direct push', g.out);
  228. // a fetch with many local commits sends a gzip-compressed request
  229. for (let i = 0; i < 300; i++) { await git(W('second'), ['commit', '-q', '--allow-empty', '-m', 'local ' + i]); }
  230. writeFileSync(join(W('first'), 'more.txt'), 'more\n'); await git(W('first'), ['add', '.']); await git(W('first'), ['commit', '-qm', 'second commit']);
  231. g = await git(W('first'), ['push', urlOf('gamma', 'alice', TOKEN), 'main'], 'gamma');
  232. check('git: a second push (fast-forward) works', g.code === 0, g.out);
  233. g = await git(W('second'), ['fetch', 'origin'], 'gamma');
  234. check('git: a fetch with 300 unpushed local commits (gzip request) works', g.code === 0, g.out);
  235. g = await git(W('second'), ['pull', '--no-rebase', '--no-edit', 'origin', 'main'], 'gamma');
  236. check('git: pull merges the new commit', g.code === 0 && existsSync(join(W('second'), 'more.txt')), g.out);
  237. g = await git(W('first'), ['-c', 'protocol.version=0', 'ls-remote', urlOf('gamma')], 'gamma');
  238. check('git: protocol v0 works too', g.code === 0 && /refs\/heads\/main/.test(g.out), g.out);
  239. g = await git(W('first'), ['-c', 'protocol.version=2', 'ls-remote', urlOf('gamma')], 'gamma');
  240. check('git: protocol v2 works', g.code === 0 && /refs\/heads\/main/.test(g.out), g.out);
  241. // ---- odd requests ---------------------------------------------------------------------------------------------
  242. const st = async (path, o = {}) => (await hreq(o.method || 'GET', path, `gamma.gitoria.test:${PORT}`, o.headers || {}, o.body)).status;
  243. check('transport: dumb-protocol / unknown service → 403', (await st('/gamma.git/info/refs')) === 403 && (await st('/gamma.git/info/refs?service=git-evil')) === 403);
  244. check('transport: another repo name in the path / an unknown repo → 404', (await st('/beta.git/info/refs?service=git-upload-pack')) === 404 && (await st('/gamma/info/refs?service=git-upload-pack')) === 404);
  245. check('transport: wrong methods → 405', (await st('/gamma.git/git-upload-pack')) === 405 && (await st('/gamma.git/info/refs?service=git-upload-pack', { method: 'POST' })) === 405);
  246. check('transport: the main address has no git', (await hreq('GET', '/gamma.git/info/refs?service=git-upload-pack', `gitoria.test:${PORT}`)).status === 404);
  247. check('transport: a Basic header that is not base64 is just "no credentials" → 401', (await st('/gamma.git/git-receive-pack', { method: 'POST', body: '0000', headers: { authorization: 'Basic $(touch /tmp/pwned)' } })) === 401 && !existsSync('/tmp/pwned'));
  248. check('transport: no temp files left behind', !existsSync(join(STORE, 'git', '.tmp')) || readdirOf(join(STORE, 'git', '.tmp')).length === 0, J(readdirOf(join(STORE, 'git', '.tmp'))));
  249. // ---- the box on a repo with code; the pushed code shows; remove a token -----------------------------------------
  250. await A.goto(REPO('gamma') + '/');
  251. await A.waitFor('!!document.querySelector("#homepage")', { label: 'README of the pushed code' });
  252. check('pushed code: the Readme page shows the pushed README', /Pushed with/.test(await txt(A, '#homepage')));
  253. check('pushed code: no "add code" box on the Readme', !(await has(A, '#addcode')));
  254. await A.goto(REPO('gamma') + '/code');
  255. await A.waitFor('!!document.querySelector("#crumbs")', { label: '/code' });
  256. check('pushed code: /code has no "add code" box once there is a commit (gitoria#20)', !(await has(A, '#addcode')));
  257. await A.goto(BASE + '/');
  258. await A.waitFor('document.querySelectorAll("#tokenlist li").length === 2', { label: 'tokens after reload' });
  259. await hydrated(A);
  260. check('tokens: the list survives a reload; the secret is not shown again', !(await has(A, '#tokensecret')));
  261. await A.evaluate('document.querySelector("#tokenlist li .removetoken").click()');
  262. await A.waitFor('document.querySelectorAll("#tokenlist li").length === 1', { label: 'one token removed' });
  263. const gone = (await txt(A, '#tokenlist')).includes('laptop') ? 'laptop' : 'second';
  264. // removed one is the newest = "second"
  265. g = await git(W('first'), ['push', urlOf('gamma', 'alice', SECOND), 'main'], 'gamma');
  266. check('tokens: a removed token stops working at once', g.code !== 0 && /not valid|Authentication failed|401/.test(g.out) && gone === 'laptop', g.out + ' / left: ' + gone);
  267. g = await git(W('first'), ['push', urlOf('gamma', 'alice', TOKEN), 'main'], 'gamma');
  268. check('tokens: the other token still works', g.code === 0, g.out);
  269. await A.evaluate('document.querySelector("#tokenlist li .removetoken").click()');
  270. await A.waitFor('!document.querySelector("#tokenlist li") && !!document.querySelector("#notokens")', { label: 'all removed' });
  271. await clickInMenu(A, '#logout', 'button.user-toggle');
  272. await A.waitFor('!document.querySelector("#tokenform")', { label: 'token form gone at logout' });
  273. check('tokens: logout hides the token form', !(await has(A, '#tokenform')) && !(await has(A, '#tokensecret')));
  274. // face forgery
  275. const fk = await fetch(API + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json' }, body: J({ t: 'emit', i: 3, event: 'gitoriaMakeToken', payload: ['x', { user: { id: 'y' } }] }) });
  276. check('tokens: a forged session argument makes no token', !/gtr_/.test(await fk.text()));
  277. // layout
  278. for (const [w, name] of [[390, 'phone'], [1280, 'wide']]) {
  279. await A.send('Emulation.setDeviceMetricsOverride', { width: w, height: 900, deviceScaleFactor: 1, mobile: w < 600 });
  280. await A.goto(REPO('gamma') + '/code');
  281. await A.waitFor('!!document.querySelector("#crumbs")');
  282. check(`layout ${w}px: the pushed repo's code page has no horizontal overflow`, await noOverflow(A));
  283. const { data } = await A.send('Page.captureScreenshot', { format: 'png', captureBeyondViewport: true });
  284. writeFileSync(join(SCRATCH, `push-${name}.png`), Buffer.from(data, 'base64'));
  285. }
  286. const problems = A.problems().filter(m => !/favicon|ERR_|Failed to load resource/.test(m.text));
  287. check('browser: no console errors', problems.length === 0, problems.map(m => m.text).join(' | '));
  288. check('server log: no error other than absorbed ones', !/error(?!: absorbed)/i.test(log.replace(/error absorbed[^\n]*/g, '')), log.split('\n').filter(l => /error/i.test(l)).slice(0, 5).join(' | '));
  289. } catch (e) {
  290. failures++;
  291. console.log('FAIL gate crashed — ' + (e && e.stack || e));
  292. if (pageA) { try { console.log('DOM: ' + (await pageA.evaluate('document.querySelector("#tokens") ? document.querySelector("#tokens").outerHTML.slice(0, 1500) : location.href'))); } catch {} }
  293. if (pageA) console.log('page problems: ' + J(pageA.problems().map(m => m.text.slice(0, 300))));
  294. } finally {
  295. for (const b of browsers) { try { await b.close(); } catch {} }
  296. if (proxy) proxy.close();
  297. await stopServer();
  298. if (ident) await ident.stop();
  299. writeFileSync(join(SCRATCH, 'push-server.log'), log);
  300. console.log(`${passes} passed, ${failures} failed`);
  301. process.exit(failures ? 1 : 0);
  302. }
  303. function readdirOf(d) { try { return require_readdir(d); } catch { return []; } }
  304. import { readdirSync as require_readdir } from 'node:fs';

Branches

Latest commits

  • 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
  • 2a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre
  • 83f0c953Report person approval verificationmre
  • 3ae94b86Record browser failures and verify owned tab cleanupmre
  • 54eec687Gate person approvals and merge alternativesmre
  • 12b08829Add person approvals for pull request headsmre
  • 55c84779Merge branch 'gp-gate-ports' into mainGitoria
  • 57af42bbREADME: point to deploy.sh for the port listmre
  • d63375d2README: gate commands with explicit portsmre
  • feeaa701|||PR gates: explicit ports only, deploy.sh passes themmre
  • 6cc1f943Merge branch 'records-1112' into mainGitoria
  • 9448c438|||PR records: LOG, missions and reports since 11-09mre
  • 6dc08a8eMerge branch 'p51-public-pr-reads' into mainGitoria
  • 7b88cfe0Type publicReaderOfRequest parameters (L10)Gitoria
  • 2a4b3dc1|||PR Anonymous reads of public repos' pulls and statusesmre
  • 21b2c141Merge branch 's25-no-session-on-login-error' into mainGitoria