| 7 | import { IpcAdapter } from "../src/runtime/adapters/ipc.js"; |
| 8 | |
| 9 | async function withCapturedIpc( |
| 10 | run: (sent: unknown[]) => Promise<void> | void, |
| 11 | ): Promise<void> { |
| 12 | const processWithSend = process as NodeJS.Process & { |
| 13 | send?: (message: unknown) => boolean; |
| 14 | }; |
| 15 | const hadSend = Object.prototype.hasOwnProperty.call(processWithSend, "send"); |
| 16 | const originalSend = processWithSend.send; |
| 17 | const sent: unknown[] = []; |
| 18 | |
| 19 | processWithSend.send = (message: unknown) => { |
| 20 | sent.push(message); |
| 21 | return true; |
| 22 | }; |
| 23 | |
| 24 | try { |
| 25 | await run(sent); |
| 26 | } finally { |
| 27 | if (hadSend) { |
| 28 | processWithSend.send = originalSend; |
| 29 | } else { |
| 30 | delete processWithSend.send; |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | test("ipc send_message handles slash commands before prompting the agent", async () => { |
| 36 | await withCapturedIpc(async (sent) => { |