gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit77829b7377829b73gitoria#43: signed events to connected apps (deliveries table, sender timer, pull_request events, ping)mre77829b73/tests/firefox.mjs

5.2 KB

  1. // tests/firefox.mjs — a REAL Firefox for the gate (mission 033: the creator uses Firefox and saw full page loads).
  2. // Headless Firefox driven over WebDriver BiDi (Firefox's own protocol, `--remote-debugging-port`, ws …/session), no
  3. // driver or npm package. Host names are mapped to 127.0.0.1 with the pref `network.dns.localDomains` (exact names).
  4. // Clicks are REAL pointer input (input.performActions), not element.click().
  5. // const ff = await launchFirefox({ port: 8730, hosts: ['gitoria.test', 'alpha.gitoria.test'] });
  6. // await ff.goto(url); await ff.click('#navcode'); await ff.waitFor('expr'); await ff.evaluate('expr'); await ff.close();
  7. import { spawn } from 'node:child_process';
  8. import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
  9. import { tmpdir } from 'node:os';
  10. import { join } from 'node:path';
  11. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  12. export async function launchFirefox({ port, hosts = [], bin = process.env.HL_FIREFOX || '/usr/bin/firefox' }) {
  13. const profile = mkdtempSync(join(tmpdir(), 'gitoria-ff-'));
  14. writeFileSync(join(profile, 'user.js'), [
  15. `user_pref("network.dns.localDomains", ${JSON.stringify(hosts.join(','))});`,
  16. 'user_pref("browser.shell.checkDefaultBrowser", false);',
  17. 'user_pref("datareporting.policy.dataSubmissionEnabled", false);',
  18. 'user_pref("toolkit.telemetry.reportingpolicy.firstRun", false);',
  19. 'user_pref("browser.aboutwelcome.enabled", false);',
  20. 'user_pref("network.proxy.type", 0);',
  21. ].join('\n') + '\n');
  22. const proc = spawn(bin, ['--headless', '--no-remote', '--profile', profile, `--remote-debugging-port=${port}`, 'about:blank'], { stdio: ['ignore', 'pipe', 'pipe'] });
  23. let out = '';
  24. proc.stdout.on('data', d => out += d); proc.stderr.on('data', d => out += d);
  25. let ws = null;
  26. for (let i = 0; i < 80 && !ws; i++) {
  27. await sleep(250);
  28. if (!/WebDriver BiDi listening/.test(out)) continue;
  29. ws = await new Promise((res) => { const w = new WebSocket(`ws://127.0.0.1:${port}/session`); w.onopen = () => res(w); w.onerror = () => res(null); });
  30. }
  31. if (!ws) { try { proc.kill('SIGKILL'); } catch {} rmSync(profile, { recursive: true, force: true }); throw new Error('firefox did not open BiDi\n' + out.slice(-800)); }
  32. let next = 0; const pending = new Map();
  33. const errors = [];
  34. ws.onmessage = (ev) => {
  35. const m = JSON.parse(ev.data);
  36. if (m.id != null && pending.has(m.id)) { const p = pending.get(m.id); pending.delete(m.id); m.type === 'error' ? p.rej(new Error(m.error + ': ' + m.message)) : p.res(m.result); return; }
  37. if (m.method === 'log.entryAdded' && m.params && m.params.level === 'error') errors.push(m.params.text || '');
  38. };
  39. const send = (method, params = {}) => new Promise((res, rej) => { const id = ++next; pending.set(id, { res, rej }); ws.send(JSON.stringify({ id, method, params })); });
  40. await send('session.new', { capabilities: {} });
  41. await send('session.subscribe', { events: ['log.entryAdded'] });
  42. const tree = await send('browsingContext.getTree', {});
  43. const context = tree.contexts[0].context;
  44. const evaluate = async (expression) => {
  45. const r = await send('script.evaluate', { expression, target: { context }, awaitPromise: true, resultOwnership: 'none' });
  46. if (r.type === 'exception') throw new Error('evaluate: ' + (r.exceptionDetails && r.exceptionDetails.text));
  47. // primitives only (string, number, boolean, null): an expression that wants to hand back more returns JSON.stringify(…)
  48. const v = r.result; return v && 'value' in v && typeof v.value !== 'object' ? v.value : null;
  49. };
  50. const waitFor = async (expression, { timeout = 15000, label = expression } = {}) => {
  51. const end = Date.now() + timeout;
  52. while (Date.now() < end) { try { const v = await evaluate(expression); if (v) return v; } catch {} await sleep(100); }
  53. throw new Error('firefox waitFor timed out: ' + label);
  54. };
  55. return {
  56. context, errors,
  57. evaluate,
  58. waitFor,
  59. goto: (url) => send('browsingContext.navigate', { context, url, wait: 'complete' }),
  60. setCookie: (name, value, domain) => send('storage.setCookie', { cookie: { name, value: { type: 'string', value }, domain, path: '/' } }),
  61. async click(selector, { timeout = 15000 } = {}) {
  62. const box = await waitFor(`(() => { const el = document.querySelector(${JSON.stringify(selector)}); if (!el) return null; el.scrollIntoView({ block: 'center' }); const b = el.getBoundingClientRect(); return b.width ? JSON.stringify({ x: Math.round(b.left + b.width / 2), y: Math.round(b.top + b.height / 2) }) : null; })()`, { timeout, label: 'click ' + selector });
  63. const { x, y } = JSON.parse(box);
  64. await send('input.performActions', { context, actions: [{ type: 'pointer', id: 'mouse', parameters: { pointerType: 'mouse' }, actions: [{ type: 'pointerMove', x, y }, { type: 'pointerDown', button: 0 }, { type: 'pointerUp', button: 0 }] }] });
  65. },
  66. async close() {
  67. try { await send('session.end', {}); } catch {}
  68. try { ws.close(); } catch {}
  69. try { proc.kill('SIGTERM'); } catch {}
  70. await new Promise(r => { if (proc.exitCode !== null || proc.signalCode !== null) return r(); proc.once('exit', r); setTimeout(() => { try { proc.kill('SIGKILL'); } catch {} r(); }, 4000); });
  71. rmSync(profile, { recursive: true, force: true });
  72. },
  73. };
  74. }

Branches

Latest commits

  • 77829b73gitoria#43: signed events to connected apps (deliveries table, sender timer, pull_request events, ping)mre
  • 1997e77dgitoria#40: stable PR numbers, refs/pull/N/head, ssh pushes reach the app (merge w40-pr-number)mre
  • 9364fb16gitoria#40: ssh pushes call /__git/pushed before and after (ensurePulls, notifyPush, syncPulls); gate over the sshd imagemre
  • fdb9ed28gitoria#41: repo owners can connect an app (merge w41-apps-connect)mre
  • 2ef23df0gitoria#40: the browser gate reads the title without the #Nmre
  • 9af07ecegitoria#41: connect an app to a repo (apps table, connect flow, manual add, allow-list, settings)mre
  • b9137ff0gitoria#40: pull requests are stored with a number, refs/pull/N/head, syncPulls and pullObject; /pulls shows #Nmre
  • 06d622daown image tag gitoria-runtime:debian12 for gitoria and standby (shared tag lost git)mre
  • 20caa33agitoria#37: media queries in the language's @media block (minWidth = '60rem') in list, codebrowser and repomre
  • c4175e6dgitoria: a startup error prints its message before exit 1 (hybriel#247)mre
  • c50d17efKeep function-route not-found style in shared stylesheetmre
  • e42d78d3Preserve ticket state CSS and document function-route style gapmre
  • c6b7154eWIP gitoria#26: move styles into nested component blocksmre
  • 77a2c31cgitoria#31: plain declarations instead of needless let in lib/ and tools/ (103 let removed, 137 kept because reassigned); no other changemre
  • 4b98ab62gitoria: an ident access key (idt_) works as the git password; read key clones only, bad key 401, ident down 503 (ident#27); gate tests/ident-access-gitoria.mjs in deploy.shmre
  • 1185f686gitoria#36: a failed return from tickets shows a note on the settings page and leaves one log line per outcome; no code is exchangedmre
  • 5d2c385agitoria: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 71+5 failing → 76 passed; deploy.sh runs tests/private.mjs toomre
  • 241ef3f9deploy.sh: rebuild the sshd image before up -d (GO34c)mre
  • 821cdbb1gitoria#34b: styles, create-repo tool, docs, push/ssh gates sign in through the selector, shots scriptmre
  • a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmre