mirror of
https://github.com/earendil-works/pi.git
synced 2026-06-18 15:54:04 +08:00
e007fcd0d2
closes #4764
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { afterEach, describe, expect, test } from "vitest";
|
|
import { RpcClient } from "../src/modes/rpc/rpc-client.ts";
|
|
|
|
const tempDirs: string[] = [];
|
|
|
|
function writeChildScript(contents: string): string {
|
|
const dir = mkdtempSync(join(tmpdir(), "pi-rpc-client-exit-"));
|
|
tempDirs.push(dir);
|
|
const path = join(dir, "child.mjs");
|
|
writeFileSync(path, contents);
|
|
return path;
|
|
}
|
|
|
|
afterEach(() => {
|
|
for (const dir of tempDirs.splice(0)) {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
describe("RpcClient child process failures", () => {
|
|
test("rejects an in-flight request when the child process exits", async () => {
|
|
const client = new RpcClient({
|
|
cliPath: writeChildScript(`
|
|
process.stdin.once("data", () => {
|
|
process.exit(43);
|
|
});
|
|
process.stdin.resume();
|
|
`),
|
|
});
|
|
|
|
await client.start();
|
|
|
|
await expect(client.getCommands()).rejects.toThrow(/Agent process exited \(code=43 signal=null\)/);
|
|
});
|
|
});
|