gitoria
All repositories: gitoria
5.2 KB
// tests/firefox.mjs — a REAL Firefox for the gate (mission 033: the creator uses Firefox and saw full page loads).// Headless Firefox driven over WebDriver BiDi (Firefox's own protocol, `--remote-debugging-port`, ws …/session), no// driver or npm package. Host names are mapped to 127.0.0.1 with the pref `network.dns.localDomains` (exact names).// Clicks are REAL pointer input (input.performActions), not element.click().// const ff = await launchFirefox({ port: 8730, hosts: ['gitoria.test', 'alpha.gitoria.test'] });// await ff.goto(url); await ff.click('#navcode'); await ff.waitFor('expr'); await ff.evaluate('expr'); await ff.close();import { spawn } from 'node:child_process';import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';const sleep = (ms) => new Promise(r => setTimeout(r, ms));export async function launchFirefox({ port, hosts = [], bin = process.env.HL_FIREFOX || '/usr/bin/firefox' }) {const profile = mkdtempSync(join(tmpdir(), 'gitoria-ff-'));writeFileSync(join(profile, 'user.js'), [`user_pref("network.dns.localDomains", ${JSON.stringify(hosts.join(','))});`,'user_pref("browser.shell.checkDefaultBrowser", false);','user_pref("datareporting.policy.dataSubmissionEnabled", false);','user_pref("toolkit.telemetry.reportingpolicy.firstRun", false);','user_pref("browser.aboutwelcome.enabled", false);','user_pref("network.proxy.type", 0);',].join('\n') + '\n');const proc = spawn(bin, ['--headless', '--no-remote', '--profile', profile, `--remote-debugging-port=${port}`, 'about:blank'], { stdio: ['ignore', 'pipe', 'pipe'] });let out = '';proc.stdout.on('data', d => out += d); proc.stderr.on('data', d => out += d);let ws = null;for (let i = 0; i < 80 && !ws; i++) {await sleep(250);if (!/WebDriver BiDi listening/.test(out)) continue;ws = await new Promise((res) => { const w = new WebSocket(`ws://127.0.0.1:${port}/session`); w.onopen = () => res(w); w.onerror = () => res(null); });}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)); }let next = 0; const pending = new Map();const errors = [];ws.onmessage = (ev) => {const m = JSON.parse(ev.data);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; }if (m.method === 'log.entryAdded' && m.params && m.params.level === 'error') errors.push(m.params.text || '');};const send = (method, params = {}) => new Promise((res, rej) => { const id = ++next; pending.set(id, { res, rej }); ws.send(JSON.stringify({ id, method, params })); });await send('session.new', { capabilities: {} });await send('session.subscribe', { events: ['log.entryAdded'] });const tree = await send('browsingContext.getTree', {});const context = tree.contexts[0].context;const evaluate = async (expression) => {const r = await send('script.evaluate', { expression, target: { context }, awaitPromise: true, resultOwnership: 'none' });if (r.type === 'exception') throw new Error('evaluate: ' + (r.exceptionDetails && r.exceptionDetails.text));// primitives only (string, number, boolean, null): an expression that wants to hand back more returns JSON.stringify(…)const v = r.result; return v && 'value' in v && typeof v.value !== 'object' ? v.value : null;};const waitFor = async (expression, { timeout = 15000, label = expression } = {}) => {const end = Date.now() + timeout;while (Date.now() < end) { try { const v = await evaluate(expression); if (v) return v; } catch {} await sleep(100); }throw new Error('firefox waitFor timed out: ' + label);};return {context, errors,evaluate,waitFor,goto: (url) => send('browsingContext.navigate', { context, url, wait: 'complete' }),setCookie: (name, value, domain) => send('storage.setCookie', { cookie: { name, value: { type: 'string', value }, domain, path: '/' } }),async click(selector, { timeout = 15000 } = {}) {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 });const { x, y } = JSON.parse(box);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 }] }] });},async close() {try { await send('session.end', {}); } catch {}try { ws.close(); } catch {}try { proc.kill('SIGTERM'); } catch {}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); });rmSync(profile, { recursive: true, force: true });},};}
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
- 1c3fa842gitoria#45 #47: worker briefsmre
- 0a46bf7dgitoria#47: apps API contract v1.3 (status read route, statuses + required on the pull)mre
- 3373f7c3gitoria#38: push API contract v1.2.1, reviews, worker briefs and logmre
- 34143d2cgitoria#46: closing brace of appComments lost in the mergemre
- 54927c9cgitoria#46: PR statuses and required checks before merge (merge w46-status)mre
- 187e1871gitoria#46: badges without decorative bordersmre
- 6b022798gitoria#46: tests/status.mjs in GATESmre
- c6162f00gitoria#46: status badges on /pulls, Required before merge in Settingsmre
- e5a0b64egitoria#46: PUT statuses/<sha>, required contexts block the merge on the servermre
- 26a140e3gitoria#44: reviews, inline threads, replies, conversation for apps (merge w44-reviews)mre
- 888dbf87gitoria#44: unknown API paths answer the contract's JSON 404 and sit above the page routesmre
- ea587d90gitoria#44: reviews with inline threads, replies, resolve and the PR conversation for apps (lib/reviews.hl, tests/reviews.mjs)mre
- 49533a50gitoria#43: signed events to connected apps (merge w43-events)mre
- 1a1e87d5gitoria#43: the sender never writes the apps row; Settings shows the newest deliverymre
- cd442066gitoria#43: app-auth unit test reads the apps table from its new filemre
- 5dccbe38gitoria#43: in-flight rows are left alone by the other process; gate in deploy.sh; READMEmre
- 8c8805f3merge main (gitoria#42), delivery log and redelivery routes, sweep fixmre
- 5a996ea8gitoria#42: short-lived app tokens, read-only git fetch with them (merge w42-app-token)mre
- afdb0cbfgitoria#43: rename the moved helper (name clash in the browser build)mre
- 15e01e94gitoria#43: tests/events.mjs and its probemre