gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitac2c4e3fac2c4e3fident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mreac2c4e3f/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

  • ac2c4e3fident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • b279f536theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 2b01515ctests/ticketskit: a failed start kills the tickets server (own process group); stop() kills the groupmre
  • 109cfc5ctests/ticketskit: keep the rotated session cookie of the tickets login (tickets ST2 session rotation)mre
  • 7eb6be27sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • b3911918reports/MG-mobile.md: 404 fixed, rebased gatesMG
  • 9da65b42tests/browser.mjs: 404 checks (host, no hydration wait)MG
  • 00517fafgitoria: shell 404 page for unknown paths (catch-all route, status 404, JSON 404 under /api), 390 gate checksMG
  • d9e977f0reports/MG-mobile.md, LOGMG
  • 2f2725actests/browser.mjs: commit-row check (one row, centred date)MG
  • 4df1ea01tests/browser.mjs: MG phone checks (list first, no dead strip, one branch heading, tab grid, commit rows, PR title row, ticket columns, wrapping commands)MG
  • c52424e9gitoria mobile: repo list before the forms, 3x2 tab grid, no duplicate branch heading, ordered commit rows, aligned ticket rows, pull title on its own row, wrapping clone commands, no dead strip under formsMG
  • 3a95252dG3: cache parsed README blocks by sha256 of the text (bounded LRU), reportmre
  • 570138cddeploy: security gate (tests/security.mjs)mre
  • da6b20fcgitoria SG: security audit fixes (uploadMax 0, Secure cookie on https, session rotation at login, nosniff on function routes, no identity in page data) + tests/security.mjs gate + reportmre
  • f98c981fgitoria B1: report wordingmre
  • c6364cedgitoria B1: compact Markdown blocks (one kind flag per block/span, empty and false fields omitted); same rendered HTML, page values -67%mre
  • cd99d2feWIP gitoria#22: always render the repo level's slot (missing-repo boot hang), pages render nothing without a repo; hydration diagnosis in reports/G2-hydrate.mdmre
  • e5404b9breport: commit idsmre
  • 63cfa21ereports/G2-repotabs.mdmre