gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit1e8f4f0a1e8f4f0avendor: Hybriel set-day52 (fault-path leak fix #335, keyed rows #331)mre1e8f4f0a/tests/push.mjs

24.1 KB

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

Branches

Latest commits

  • 1e8f4f0avendor: Hybriel set-day52 (fault-path leak fix #335, keyed rows #331)mre
  • f5f0fb7blog: 2026-11-08 day50/#29 live, H25 correction, V52 startedmre
  • dc77fb95main: offline note from __hlOnline, tick removed (#29)mre
  • 37a86d93tests/reviews: seeded fake hook's DNS failures are not server errors (flaky gate)mre
  • 07ab845bvendor: Hybriel set-day50 (run() leak fix #335)mre
  • 71b2fa4blog: hybriel#335mre
  • bd94cc7elog: #25 cause found (run() leak)mre
  • 565cb508log: H25 round 1mre
  • 90a0af84log: H25 startedmre
  • 87bd53b8mission H25mre
  • 71a746cflog: day48 livemre
  • bf568e14log: V48 mergedmre
  • 09955dedMerge v48: Hybriel set-day48, theme layouts ce4a0bamre
  • f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
  • 5d0834e7log: Apollo model rulemre
  • fe8e5bd5log: #25 sample, V48 missionmre
  • 8580c5d9log: theme fix from Atlasmre
  • 46823d93log: Apollo budget correctionmre
  • f6d32341log: Apollo on budget and #25 nextmre
  • d7184f53log: batch live, #25 evidencemre