import * as NodeServices from "@effect/platform-node/NodeServices"; import { assert, it } from "@effect/vitest"; import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import { vi } from "vite-plus/test"; import * as NodePtyAdapter from "./NodePtyAdapter.ts"; import * as PtyAdapter from "./PtyAdapter.ts"; const spawn = vi.fn(() => ({ pid: 42, write: vi.fn(), resize: vi.fn(), kill: vi.fn(), onData: vi.fn(() => ({ dispose: vi.fn() })), onExit: vi.fn(() => ({ dispose: vi.fn() })), })); vi.mock("node-pty", () => ({ spawn })); const testLayer = NodePtyAdapter.layer.pipe( Layer.provide( Layer.mergeAll( NodeServices.layer, Layer.succeed(HostProcessPlatform, "win32"), Layer.succeed(HostProcessArchitecture, "x64"), ), ), ); it.effect("spawns through the public adapter with the provided host references", () => Effect.gen(function* () { const adapter = yield* PtyAdapter.PtyAdapter; const process = yield* adapter.spawn({ shell: "powershell.exe", args: ["-NoLogo"], cwd: "C:\\workspace", cols: 120, rows: 40, env: {}, }); assert.equal(process.pid, 42); assert.equal(spawn.mock.calls.length, 1); assert.deepEqual(spawn.mock.calls[0], [ "powershell.exe", ["-NoLogo"], { cwd: "C:\\workspace", cols: 120, rows: 40, env: {}, name: "xterm-color", }, ]); }).pipe(Effect.provide(testLayer)), );