gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit55c8477955c84779Merge branch 'gp-gate-ports' into mainGitoria55c84779/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

  • 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
  • 9448c438|||PR records: LOG, missions and reports since 11-09mre
  • 6dc08a8eMerge branch 'p51-public-pr-reads' into mainGitoria
  • 7b88cfe0Type publicReaderOfRequest parameters (L10)Gitoria
  • 2a4b3dc1|||PR Anonymous reads of public repos' pulls and statusesmre
  • 21b2c141Merge branch 's25-no-session-on-login-error' into mainGitoria
  • 698458e2|||PR No session for cookieless login errors: READMEmre
  • cce7b785|||PR No session for cookieless login errorsmre
  • 678d6303Merge branch 'v59' into mainGitoria
  • 5803cf4f|||PR vendor: Hybriel set-day59 and GC budget 32 MiBmre
  • 9eff6627Merge branch 'f2-api-bugs' into mainGitoria
  • 26117255|||PR apps API: review comments on files with spaces in their namemre
  • b8796cecMerge branch 'f1-broken-json' into mainGitoria
  • 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
  • f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
  • 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre