/** * Test fixture: run ONE remote primitive from its own process, the way a hook * does. * * The remote-ops bridge blocks its caller in `spawnSync` while celilo's event * loop answers the socket, so the asking half can never share a process with * the broker — in production it never does. A test that calls a bridged * primitive in the broker's own process deadlocks: the loop that must accept * the connection is the loop spawnSync is blocking. This fixture is what * keeps the test topology honest. * * One instruction on argv[2] (JSON), one result line on stdout. */ import { installAuthorizedKey, probeHttp, remoteExec, serviceCtl, streamBackup, streamRestore, } from '@celilo/capabilities'; const instruction = JSON.parse(process.argv[2] ?? '{}') as { op: string; target: { ipv4_address: string; user?: string; port?: number; identityFile?: string }; command?: string; unit?: string; action?: 'restart'; producerCommand?: string; consumerCommand?: string; localPath?: string; password?: string; opts?: { timeoutMs?: number; input?: string; env?: Record }; }; let result: unknown; switch (instruction.op) { case 'remoteExec': result = remoteExec(instruction.target, instruction.command ?? '', instruction.opts ?? {}); break; case 'serviceCtl': result = serviceCtl( instruction.target, instruction.unit ?? '', instruction.action ?? 'restart', ); break; case 'streamBackup': result = streamBackup( instruction.target, instruction.producerCommand ?? '', instruction.localPath ?? '', ); break; case 'streamRestore': result = streamRestore( instruction.target, instruction.localPath ?? '', instruction.consumerCommand ?? '', ); break; case 'installAuthorizedKey': result = installAuthorizedKey(instruction.target, instruction.password ?? ''); break; case 'probeHttpRefused': result = await probeHttp(instruction.target, { port: 80 }, async () => { throw new Error('fetch must not run for a refused target'); }); break; case 'probeHttpAllowed': result = await probeHttp( instruction.target, { port: 80 }, async () => new Response('ok', { status: 200 }), ); break; default: throw new Error(`unknown op '${instruction.op}'`); } console.log(JSON.stringify(result));