gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchl33-thinecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mrel33-thin/plugins/http1/tests/on-error-answers.mjs

4.1 KB

  1. // #285: exercise real sockets through the run form and a native executable.
  2. import { spawn, execFileSync } from 'node:child_process';
  3. import { once } from 'node:events';
  4. import { mkdtempSync, rmSync, readlinkSync } from 'node:fs';
  5. import { tmpdir } from 'node:os';
  6. import { resolve, join, dirname } from 'node:path';
  7. import { fileURLToPath } from 'node:url';
  8. import assert from 'node:assert/strict';
  9. const here = dirname(fileURLToPath(import.meta.url));
  10. const root = resolve(here, '../../..');
  11. const bin = process.env.HL_BIN || join(root, 'native/zig-out/bin/hybriel');
  12. const fixture = join(here, 'on-error-answers.hl');
  13. const port = Number(process.env.HL_TEST_PORT || 31910);
  14. const work = mkdtempSync(join(tmpdir(), 'on-error-answers-'));
  15. let checks = 0;
  16. const sleep = ms => new Promise(r => setTimeout(r, ms));
  17. try {
  18. const native = join(work, 'server');
  19. execFileSync(bin, ['--native', fixture, '-o', native, '--quiet'], { cwd: root, timeout: 180000 });
  20. for (const [name, cmd, args] of [['run', bin, [fixture]], ['native', native, []]]) {
  21. const child = spawn(cmd, args, { cwd: root, env: { ...process.env, HL_TEST_PORT: String(port) }, stdio: ['ignore', 'pipe', 'pipe'] });
  22. const exited = once(child, 'exit');
  23. let log = '';
  24. child.stdout.on('data', d => { log += d });
  25. child.stderr.on('data', d => { log += d });
  26. const request = async path => {
  27. const r = await fetch(`http://127.0.0.1:${port}${path}`, { signal: AbortSignal.timeout(3000) });
  28. return { status: r.status, body: await r.text(), type: r.headers.get('content-type'), fallback: r.headers.get('x-fallback') };
  29. };
  30. try {
  31. let up = false;
  32. for (let i = 0; i < 150; i++) {
  33. if (child.exitCode !== null) break;
  34. try { if ((await request('/health')).body === 'healthy') { up = true; break } } catch {}
  35. await sleep(100);
  36. }
  37. assert.ok(up, `${name} failed to boot: ${log}`);
  38. for (const [path, status, body, type] of [
  39. ['/text', 200, 'fallback', 'text/plain'],
  40. ['/json', 200, '{"ok":true,"items":[1,2]}', 'application/json'],
  41. ['/status', 503, 'unavailable', null],
  42. ['/bytes', 200, 'raw', 'application/octet-stream'],
  43. ['/empty', 200, '', 'text/plain'],
  44. ['/false', 200, 'false', 'application/json'],
  45. ['/zero', 200, '0', 'application/json'],
  46. ['/sent', 202, 'sent', null],
  47. ]) {
  48. const r = await request(path);
  49. assert.equal(r.status, status, `${name} ${path}`);
  50. assert.equal(r.body, body, `${name} ${path}`);
  51. if (type) assert.ok(r.type?.startsWith(type), `${name} ${path} content type: ${r.type}`);
  52. if (path === '/status') assert.equal(r.fallback, 'yes');
  53. checks++;
  54. }
  55. for (const path of ['/null', '/none']) {
  56. const r = await request(path);
  57. assert.equal(r.status, 500);
  58. assert.match(r.body, /route:/);
  59. assert.match(r.body, /on-error-answers.hl:/);
  60. checks++;
  61. }
  62. assert.equal((await request('/health')).body, 'healthy');
  63. assert.doesNotMatch(log, /UNREACHABLE/);
  64. assert.equal((log.match(/^hook$/gm) || []).length, 10);
  65. assert.equal((log.match(/^handled$/gm) || []).length, 10);
  66. checks++;
  67. await request('/fatal').catch(() => {});
  68. const [code] = await Promise.race([exited, sleep(5000).then(() => { throw new Error('fatal handler did not stop') })]);
  69. assert.equal(code, 1, log);
  70. assert.match(log, /error-handler-fault/);
  71. checks++;
  72. console.log(`${name}: 12/12`);
  73. } finally {
  74. if (child.exitCode === null && child.signalCode === null) {
  75. // Only our child, and verify its cwd before signalling it.
  76. const sockets = execFileSync('ss', ['-ltnp', `sport = :${port}`], { encoding: 'utf8' });
  77. if (sockets.includes('LISTEN')) assert.ok(sockets.includes(`pid=${child.pid},`), 'listener belongs to our child');
  78. let cwd;
  79. try { cwd = readlinkSync(`/proc/${child.pid}/cwd`) }
  80. catch (e) { if (e.code !== 'ENOENT') throw e }
  81. if (cwd !== undefined) { assert.equal(cwd, root); child.kill('SIGTERM') }
  82. await exited;
  83. }
  84. }
  85. }
  86. console.log(`on-error-answers: ${checks}/24`);
  87. } finally { rmSync(work, { recursive: true, force: true }) }

Branches

Latest commits

  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre
  • 6dea1c60Merge branch 'r35-day72' into mainTickets
  • 7bcfdc22|||PR drop worker edits to conductor recordsmre
  • 2617b6ee|||PR dialogs: host flag cleared on close, dialog gate (tickets#40)mre
  • 6e701371|||PR record partial day72 dialog validationmre
  • b9fb9a91|||PR bind ticket dialog visibility to member flagsmre
  • 0788e65f|||PR re-vendor Hybriel day72mre
  • e2a6bdcfMerge branch 'records-t35' into mainTickets
  • d8d54df1|||PR records: R35 day72 + #40mre
  • 8a7f475aMerge branch 'records-t33' into mainTickets
  • e685d0c2|||PR records: PROCEDURES merge callmre
  • b42aff2b|||PR records: GO 2026-11-23, workers L33 O34, PROCEDURES.mdmre
  • ed091d44Merge branch 'records' into mainTickets
  • 180c0cdb|||PR records: ticket move live (M32), hybriel#439mre
  • 497cae7bMerge branch 'm32-move' into mainTickets
  • 772e0696|||PR Allow project admins to move tickets between their projectsmre
  • be92a560Merge branch 'records' into mainTickets
  • 0daf2ea8|||PR records: PR-only workflow, #50 donemre
  • 0185d0b6Log PR 1 deploymre
  • f5bf16e2Mission 031: deploy PR 1mre