| ... | ... | @@ -21,15 +21,50 @@ const spawn = vi.fn(() => ({ |
| 21 | 21 | |
| 22 | 22 | vi.mock("node-pty", () => ({ spawn })); |
| 23 | 23 | |
| 24 | | const testLayer = NodePtyAdapter.layer.pipe( |
| 25 | | Layer.provide( |
| 26 | | Layer.mergeAll( |
| 27 | | NodeServices.layer, |
| 28 | | Layer.succeed(HostProcessPlatform, "win32"), |
| 29 | | Layer.succeed(HostProcessArchitecture, "x64"), |
| 24 | const makeTestLayer = (platform: NodeJS.Platform = "win32") => |
| 25 | NodePtyAdapter.layer.pipe( |
| 26 | Layer.provide( |
| 27 | Layer.mergeAll( |
| 28 | NodeServices.layer, |
| 29 | Layer.succeed(HostProcessPlatform, platform), |
| 30 | Layer.succeed(HostProcessArchitecture, "x64"), |
| 31 | ), |
| 30 | 32 | ), |
| 31 | | ), |
| 32 | | ); |
| 33 | ); |
| 34 | |
| 35 | const testLayer = makeTestLayer(); |
| 36 | |
| 37 | for (const platform of ["win32", "linux", "darwin"] as const) { |
| 38 | it.effect(`terminates through node-pty using ${platform} semantics`, () => |
| 39 | Effect.gen(function* () { |
| 40 | const adapter = yield* PtyAdapter.PtyAdapter; |
| 41 | const process = yield* adapter.spawn({ |
| 42 | shell: "test-shell", |
| 43 | cwd: ".", |
| 44 | cols: 80, |
| 45 | rows: 24, |
| 46 | env: {}, |
| 47 | }); |
| 48 | const nativeProcess = spawn.mock.results.at(-1)!.value; |
| 49 | nativeProcess.kill.mockImplementation((signal?: string) => { |
| 50 | if (platform === "win32" && signal) { |
| 51 | throw new Error("Signals not supported on windows."); |
| 52 | } |
| 53 | }); |
| 54 | |
| 55 | process.kill("SIGTERM"); |
| 56 | process.kill("SIGKILL"); |
| 57 | process.kill(); |
| 58 | |
| 59 | assert.deepEqual( |
| 60 | nativeProcess.kill.mock.calls, |
| 61 | platform === "win32" |
| 62 | ? [[undefined], [undefined], [undefined]] |
| 63 | : [["SIGTERM"], ["SIGKILL"], [undefined]], |
| 64 | ); |
| 65 | }).pipe(Effect.provide(makeTestLayer(platform))), |
| 66 | ); |
| 67 | } |
| 33 | 68 | |
| 34 | 69 | it.effect("spawns through the public adapter with the provided host references", () => |
| 35 | 70 | Effect.gen(function* () { |