kunibert
All repositories: gitoria
2.8 KB
import http from 'node:http';import net from 'node:net';import { spawn } from 'node:child_process';import { mkdir, writeFile, copyFile } from 'node:fs/promises';import path from 'node:path';import { fileURLToPath } from 'node:url';const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..');const bin = process.env.HL_BIN || path.join(root, 'native/zig-out/bin/hybriel');const work = process.env.TMPDIR;if (!work) throw new Error('set TMPDIR to scratch');const sockets = new Set();const web = http.createServer((req, res) => {const code = Number(req.url.slice(1));res.writeHead(code, { 'content-type': 'application/json', date: 'fixed', connection: 'close' });res.end(JSON.stringify({ code }));});const slow = net.createServer(s => { sockets.add(s); s.on('close', () => sockets.delete(s)); });function listen(s, port) { return new Promise((r, j) => { s.once('error', j); s.listen(port, '127.0.0.1', r); }); }function run(args) {return new Promise((resolve, reject) => {const p = spawn(args[0], args.slice(1), { cwd: root, env: process.env });let out = '', err = '';p.stdout.on('data', s => out += s); p.stderr.on('data', s => err += s);p.on('error', reject); p.on('close', code => code ? reject(new Error(`${args.join(' ')} exit ${code}\n${out}${err}`)) : resolve(out));});}try {const probe = net.createServer(); await listen(probe, 32262); await new Promise(r => probe.close(r));await listen(web, 32260); await listen(slow, 32261);const fixture = path.join(root, 'plugins/fetch/tests/try_fetch.hl');const native = await run([bin, fixture]);await run([bin, '--native', fixture, '-o', path.join(work, 'try-fetch')]);const compiled = await run([path.join(work, 'try-fetch')]);const jsdir = path.join(work, 'try-fetch-js'); await mkdir(jsdir, { recursive: true });await writeFile(path.join(jsdir, 'package.json'), '{"type":"module"}');await run([bin, '--js', '--entry', fixture, '-o', path.join(jsdir, 'probe.mjs')]);await writeFile(path.join(jsdir, 'hl-runtime.js'), await run([bin, '--js-runtime']));await mkdir(path.join(jsdir, 'hl-modules'), { recursive: true });await copyFile(path.join(root, 'plugins/fetch/server.js'), path.join(jsdir, 'hl-modules/fetch.js'));const js = await run(['node', path.join(jsdir, 'probe.mjs')]);if (native !== compiled || native !== js) throw new Error(`different answers\nrun:${native}\nnative:${compiled}\njs:${js}`);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);console.log('PASS 4 scenarios, identical run/native/JS answers\n' + native);} finally {for (const s of sockets) s.destroy();await Promise.all([web, slow].map(s => new Promise(r => s.listening ? s.close(r) : r())));}
Branches
Latest commits
- a6577aaeRecords: #14 live, #16 startedmre
- 0382238bStart fresh on Review again and name vendored pathsKunibert
- 5608c6f1Records: kunibert#13 vendored paths livemre
- 8840771dExclude vendored findings from app verdictsKunibert
- 6aa65353Records: jukebox connected, first reviewmre
- ad8011cfRecords: neutral ticket rule, jukeboxmre
- ca5f31dfPrompt: neutral reviewer identitymre
- b241d9c8Records: Anton tryParse noteKunibert
- 42cc1bc0Records: K12 doneKunibert
- 9e6039eeRecords: gates K11, K12Kunibert
- 59b8fe83Use Hybriel day39 helpersKunibert
- c2e393a2Records: K12 startedKunibert
- 00696678Records: Anton day39 notemre
- 070e01a4Records: parkmre
- bf8af0dcRecords: v1.4 checkedmre
- 44af321bRecords: contract v1.4mre
- 310f3fd0Records: outdated semanticsmre
- 268ebfe6Records: #11 proven live and closedmre
- 88e8aad3Records: K11 verified and deployedmre
- cd4cb09cNo review and status error when the model's tools did not run (kunibert#11)Kunibert