gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitce08920dce08920dMerge branch 'w52c-header-phone' into mainGitoriace08920d/plugins/fetch/tests/try-fetch.mjs

2.8 KB

  1. import http from 'node:http';
  2. import net from 'node:net';
  3. import { spawn } from 'node:child_process';
  4. import { mkdir, writeFile, copyFile } from 'node:fs/promises';
  5. import path from 'node:path';
  6. import { fileURLToPath } from 'node:url';
  7. const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..');
  8. const bin = process.env.HL_BIN || path.join(root, 'native/zig-out/bin/hybriel');
  9. const work = process.env.TMPDIR;
  10. if (!work) throw new Error('set TMPDIR to scratch');
  11. const sockets = new Set();
  12. const web = http.createServer((req, res) => {
  13. const code = Number(req.url.slice(1));
  14. res.writeHead(code, { 'content-type': 'application/json', date: 'fixed', connection: 'close' });
  15. res.end(JSON.stringify({ code }));
  16. });
  17. const slow = net.createServer(s => { sockets.add(s); s.on('close', () => sockets.delete(s)); });
  18. function listen(s, port) { return new Promise((r, j) => { s.once('error', j); s.listen(port, '127.0.0.1', r); }); }
  19. function run(args) {
  20. return new Promise((resolve, reject) => {
  21. const p = spawn(args[0], args.slice(1), { cwd: root, env: process.env });
  22. let out = '', err = '';
  23. p.stdout.on('data', s => out += s); p.stderr.on('data', s => err += s);
  24. p.on('error', reject); p.on('close', code => code ? reject(new Error(`${args.join(' ')} exit ${code}\n${out}${err}`)) : resolve(out));
  25. });
  26. }
  27. try {
  28. const probe = net.createServer(); await listen(probe, 32262); await new Promise(r => probe.close(r));
  29. await listen(web, 32260); await listen(slow, 32261);
  30. const fixture = path.join(root, 'plugins/fetch/tests/try_fetch.hl');
  31. const native = await run([bin, fixture]);
  32. await run([bin, '--native', fixture, '-o', path.join(work, 'try-fetch')]);
  33. const compiled = await run([path.join(work, 'try-fetch')]);
  34. const jsdir = path.join(work, 'try-fetch-js'); await mkdir(jsdir, { recursive: true });
  35. await writeFile(path.join(jsdir, 'package.json'), '{"type":"module"}');
  36. await run([bin, '--js', '--entry', fixture, '-o', path.join(jsdir, 'probe.mjs')]);
  37. await writeFile(path.join(jsdir, 'hl-runtime.js'), await run([bin, '--js-runtime']));
  38. await mkdir(path.join(jsdir, 'hl-modules'), { recursive: true });
  39. await copyFile(path.join(root, 'plugins/fetch/server.js'), path.join(jsdir, 'hl-modules/fetch.js'));
  40. const js = await run(['node', path.join(jsdir, 'probe.mjs')]);
  41. if (native !== compiled || native !== js) throw new Error(`different answers\nrun:${native}\nnative:${compiled}\njs:${js}`);
  42. if (!native.includes('connection refused') || !native.includes('timed out') || !native.includes('true true true true true true {"code":200} 200') || !native.includes('true true true true true true {"code":404} 404')) throw new Error(native);
  43. console.log('PASS 4 scenarios, identical run/native/JS answers\n' + native);
  44. } finally {
  45. for (const s of sockets) s.destroy();
  46. await Promise.all([web, slow].map(s => new Promise(r => s.listening ? s.close(r) : r())));
  47. }

Branches

Latest commits

  • ce08920dMerge branch 'w52c-header-phone' into mainGitoria
  • 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
  • e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
  • c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
  • 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
  • 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