|
1 | | -import { mkdtemp, rm, writeFile } from "node:fs/promises"; |
| 1 | +import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; |
2 | 2 | import { tmpdir } from "node:os"; |
3 | 3 | import { join } from "node:path"; |
4 | 4 | import { RpcClient } from "@earendil-works/pi-coding-agent"; |
5 | | -import { describe, expect, it } from "vitest"; |
| 5 | +import { describe, expect, it, vi } from "vitest"; |
6 | 6 | import { createPiRpcClient } from "./rpc-client"; |
7 | 7 |
|
8 | 8 | describe("createPiRpcClient", () => { |
@@ -31,6 +31,37 @@ describe("createPiRpcClient", () => { |
31 | 31 | ).toBeUndefined(); |
32 | 32 | }); |
33 | 33 |
|
| 34 | + it("runs the RPC host with Electron's Node mode enabled", async () => { |
| 35 | + const directory = await mkdtemp(join(tmpdir(), "pi-electron-node-mode-")); |
| 36 | + const hostPath = join(directory, "host.mjs"); |
| 37 | + const capturePath = join(directory, "capture.txt"); |
| 38 | + await writeFile( |
| 39 | + hostPath, |
| 40 | + ` |
| 41 | +import { closeSync, writeFileSync } from "node:fs"; |
| 42 | +
|
| 43 | +closeSync(3); |
| 44 | +writeFileSync(${JSON.stringify(capturePath)}, process.env.ELECTRON_RUN_AS_NODE ?? ""); |
| 45 | +process.stdin.resume(); |
| 46 | +`, |
| 47 | + ); |
| 48 | + const client = createPiRpcClient({ |
| 49 | + cliPath: hostPath, |
| 50 | + cwd: directory, |
| 51 | + providerOptions: { apiKey: "proxy-key" }, |
| 52 | + }); |
| 53 | + |
| 54 | + try { |
| 55 | + await client.start(); |
| 56 | + await vi.waitFor(async () => { |
| 57 | + await expect(readFile(capturePath, "utf8")).resolves.toBe("1"); |
| 58 | + }); |
| 59 | + } finally { |
| 60 | + await client.stop(); |
| 61 | + await rm(directory, { recursive: true }); |
| 62 | + } |
| 63 | + }); |
| 64 | + |
34 | 65 | it("uses the private host channel without changing Pi RPC", async () => { |
35 | 66 | const directory = await mkdtemp(join(tmpdir(), "pi-host-channel-")); |
36 | 67 | const hostPath = join(directory, "host.mjs"); |
|
0 commit comments