Files
stack/agents/darkwing/work/queue-54-review/r1/probes/probe-node.mjs
T
jason.woltjeandClaude Opus 5.5 8a3ded5335 review(row54): round 1 packet, changes (darkwing)
Review of #1543 candidate dba2429e: gate green with Docker, 31 mutants
(26 killed), Node, import and Chromium probes. Posted as comment 27186.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-10 15:47:54 -05:00

58 lines
4.4 KiB
JavaScript

// Row 54 round 1 node probes (Darkwing). Run with WT=<candidate worktree>.
import { mkdtempSync, writeFileSync, mkdirSync, realpathSync, rmSync } from 'node:fs';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
const WT = process.env.WT;
const { redactor, queueReader, consoleReads, businessId } = await import(`${WT}/packages/webui/src/reads.mjs`);
const { startServer } = await import(`${WT}/packages/webui/src/serve.mjs`);
const { startTimeOf, hostFile } = await import(`${WT}/packages/cli/src/host.mjs`);
const out = (k, v) => console.log(`${k}: ${JSON.stringify(v)}`);
// P2: the redactor on shapes its tests don't use.
const r = redactor({ configDir: '/home/u/.config/mosaic-dev', dataRoot: '/home/u/.mosaic-dev' });
for (const s of [
'config:/home/u/secret/x.token', 'open "/home/u/secret/x.token"', 'path</home/u/x>', 'see file:///home/u/x.token', 'at ~/secret/x.token',
'in ./secret/x.token', 'C:\\Users\\u\\x.token', 'url https://discord.com/channels/123456789012345678/223456789012345678',
'id:123456789012345678', 'id_123456789012345678', 'n=1234567890123456', 'a 21-digit 123456789012345678901 run',
'tab\t/home/u/x', '/home/u/.config/mosaic-dev', '/home/u/.config/mosaic-dev/', '/home/u/.mosaic-dev.bak/x', '[/home/u/x]', '{/home/u/x}',
]) out(`P2 ${JSON.stringify(s)}`, r(s));
// P4: the queue child's timeout and output cap, with a stand-in reader script.
const base = realpathSync(mkdtempSync(join(tmpdir(), 'dw-r54-')));
const fake = (name, body) => { const root = join(base, name); mkdirSync(join(root, 'packages/webui/src'), { recursive: true }); writeFileSync(join(root, 'packages/webui/src/queue-read.mjs'), body); return root; };
const settle = async (p) => { const t = Date.now(); try { const v = await p; return { ok: true, ms: Date.now() - t, rows: v.rows?.length }; } catch (e) { return { ok: false, ms: Date.now() - t, code: e.code, message: e.message }; } };
out('P4a hang, timeout 500ms', await settle(queueReader({ root: fake('hang', 'setInterval(()=>{},1000)'), timeoutMs: 500 })()));
out('P4b 64 KiB out, cap 1 KiB', await settle(queueReader({ root: fake('big', 'process.stdout.write("x".repeat(65536))'), maxBytes: 1024 })()));
out('P4c exit 2 with a path on stderr', await settle(consoleReads({ root: fake('two', `process.stderr.write("refused at ${base}/q.json");process.exit(2)`) }).queue()));
out('P4d exit 0, bad shape', await settle(queueReader({ root: fake('shape', 'console.log(JSON.stringify({rows:{}}))') })()));
out('P4e killed by a signal', await settle(queueReader({ root: fake('sig', 'process.kill(process.pid,"SIGKILL")') })()));
// P5: the business id from the bus host state: none, stale, live, malformed.
const dataRoot = join(base, 'data'); mkdirSync(join(dataRoot, 'bus-host'), { recursive: true });
const id = () => { try { return businessId({ dataRoot }); } catch (e) { return `${e.code}: ${e.message}`; } };
out('P5a no host file', id());
writeFileSync(hostFile(dataRoot), JSON.stringify({ pid: process.pid, startTime: 'not-the-start', business: 'stale-biz' }));
out('P5b stale host file', id());
writeFileSync(hostFile(dataRoot), JSON.stringify({ pid: process.pid, startTime: startTimeOf(process.pid), business: 'live-biz' }));
out('P5c live host file', id());
writeFileSync(hostFile(dataRoot), '{');
out('P5d malformed host file', id());
// P3: Host and Origin on the new routes, and HEAD.
const server = await startServer({ port: 0, reads: consoleReads({ root: fake('two2', 'process.exit(2)') }) });
const port = server.address().port;
const { request } = await import('node:http');
const call = (path, method = 'GET', headers = {}) => new Promise(res => { const q = request({ host: '127.0.0.1', port, path, method, headers }, s => { let b = ''; s.on('data', c => b += c); s.on('end', () => res(`${s.statusCode} ${b.slice(0, 80)}`)); }); q.end(); });
for (const p of ['/api/queue', '/api/queue/1', '/api/business', '/api/settings']) {
out(`P3 ${p} Host evil`, await call(p, 'GET', { host: 'evil.example' }));
out(`P3 ${p} Host 127.0.0.1:other`, await call(p, 'GET', { host: '127.0.0.1:1' }));
out(`P3 ${p} Origin evil`, await call(p, 'GET', { origin: 'http://evil.example' }));
out(`P3 ${p} HEAD`, await call(p, 'HEAD'));
out(`P3 ${p} OPTIONS`, await call(p, 'OPTIONS'));
}
out('P3 /api/queue/ empty id', await call('/api/queue/'));
out('P3 /api/queue/1?x', await call('/api/queue/1?x=1'));
out('P3 /api/queue%2F1', await call('/api/queue%2F1'));
server.close();
rmSync(base, { recursive: true, force: true });