components
All repositories: gitoria
4.1 KB
// #285: exercise real sockets through the run form and a native executable.import { spawn, execFileSync } from 'node:child_process';import { once } from 'node:events';import { mkdtempSync, rmSync, readlinkSync } from 'node:fs';import { tmpdir } from 'node:os';import { resolve, join, dirname } from 'node:path';import { fileURLToPath } from 'node:url';import assert from 'node:assert/strict';const here = dirname(fileURLToPath(import.meta.url));const root = resolve(here, '../../..');const bin = process.env.HL_BIN || join(root, 'native/zig-out/bin/hybriel');const fixture = join(here, 'on-error-answers.hl');const port = Number(process.env.HL_TEST_PORT || 31910);const work = mkdtempSync(join(tmpdir(), 'on-error-answers-'));let checks = 0;const sleep = ms => new Promise(r => setTimeout(r, ms));try {const native = join(work, 'server');execFileSync(bin, ['--native', fixture, '-o', native, '--quiet'], { cwd: root, timeout: 180000 });for (const [name, cmd, args] of [['run', bin, [fixture]], ['native', native, []]]) {const child = spawn(cmd, args, { cwd: root, env: { ...process.env, HL_TEST_PORT: String(port) }, stdio: ['ignore', 'pipe', 'pipe'] });const exited = once(child, 'exit');let log = '';child.stdout.on('data', d => { log += d });child.stderr.on('data', d => { log += d });const request = async path => {const r = await fetch(`http://127.0.0.1:${port}${path}`, { signal: AbortSignal.timeout(3000) });return { status: r.status, body: await r.text(), type: r.headers.get('content-type'), fallback: r.headers.get('x-fallback') };};try {let up = false;for (let i = 0; i < 150; i++) {if (child.exitCode !== null) break;try { if ((await request('/health')).body === 'healthy') { up = true; break } } catch {}await sleep(100);}assert.ok(up, `${name} failed to boot: ${log}`);for (const [path, status, body, type] of [['/text', 200, 'fallback', 'text/plain'],['/json', 200, '{"ok":true,"items":[1,2]}', 'application/json'],['/status', 503, 'unavailable', null],['/bytes', 200, 'raw', 'application/octet-stream'],['/empty', 200, '', 'text/plain'],['/false', 200, 'false', 'application/json'],['/zero', 200, '0', 'application/json'],['/sent', 202, 'sent', null],]) {const r = await request(path);assert.equal(r.status, status, `${name} ${path}`);assert.equal(r.body, body, `${name} ${path}`);if (type) assert.ok(r.type?.startsWith(type), `${name} ${path} content type: ${r.type}`);if (path === '/status') assert.equal(r.fallback, 'yes');checks++;}for (const path of ['/null', '/none']) {const r = await request(path);assert.equal(r.status, 500);assert.match(r.body, /route:/);assert.match(r.body, /on-error-answers.hl:/);checks++;}assert.equal((await request('/health')).body, 'healthy');assert.doesNotMatch(log, /UNREACHABLE/);assert.equal((log.match(/^hook$/gm) || []).length, 10);assert.equal((log.match(/^handled$/gm) || []).length, 10);checks++;await request('/fatal').catch(() => {});const [code] = await Promise.race([exited, sleep(5000).then(() => { throw new Error('fatal handler did not stop') })]);assert.equal(code, 1, log);assert.match(log, /error-handler-fault/);checks++;console.log(`${name}: 12/12`);} finally {if (child.exitCode === null && child.signalCode === null) {// Only our child, and verify its cwd before signalling it.const sockets = execFileSync('ss', ['-ltnp', `sport = :${port}`], { encoding: 'utf8' });if (sockets.includes('LISTEN')) assert.ok(sockets.includes(`pid=${child.pid},`), 'listener belongs to our child');let cwd;try { cwd = readlinkSync(`/proc/${child.pid}/cwd`) }catch (e) { if (e.code !== 'ENOENT') throw e }if (cwd !== undefined) { assert.equal(cwd, root); child.kill('SIGTERM') }await exited;}}}console.log(`on-error-answers: ${checks}/24`);} finally { rmSync(work, { recursive: true, force: true }) }
Branches
Latest commits
- b7e11e3bvirtual-list: the first resetKey is the baseline, so centerId and scrollTop keep their place at mount; gate for itAtlas
- 7e428ba6Re-vendor Hybriel day72 (day73 withdrawn: minifier breaks write sets)Atlas
- a06fc778Reset virtual-list window when the host changes resetKeyAtlas
- 3aab598cRe-vendor complete Hybriel day73 set for virtual-list resetAtlas
- 337ca075MD1 gate check measures frames in the page, not milliseconds from outside, and takes the middle load (components#30)mre
- f5f131c5Record AP29 autoplay comparisons and passing gatesmre
- 51c38187Gate media autoplay on first load and after client mountmre
- a3f2223dRecord successful B44 deployment and live proofmre
- 06c1e021Record passing B44 browser rerunmre
- c9861533Record B44 component proof and browser gate blockermre
- 1b7413beIgnore detached media events and space demo option outputsmre
- ca3b4959Re-vendor complete Hybriel plugins and runtime to day44mre
- df9e7df9Last-item checks run in the browser gate (components#26 fixed on day41); media-player loop is a plain Booleanmre
- 895a5afcRe-vendor complete Hybriel plugins and runtime to day41mre
- 16006bb3Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
- 88397fc3Re-vendor complete Hybriel plugins and runtime to day39mre
- 9b872cedRecord IC28 deployment and live icon verificationmre
- 46fefaa7Count the icons entry in the offline home-page checkmre
- c7e14cabRecord IC28 rerun and unchanged-main baseline comparisonmre
- 5e090ffdRecord IC28 review evidence and gate resultsmre