|
| 1 | +import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 2 | +import { expect, it } from "@effect/vitest"; |
| 3 | +import { ProviderInstanceId } from "@t3tools/contracts"; |
| 4 | +import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; |
| 5 | +import * as Effect from "effect/Effect"; |
| 6 | +import * as Layer from "effect/Layer"; |
| 7 | +import { HttpClient } from "effect/unstable/http"; |
| 8 | +import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner"; |
| 9 | + |
| 10 | +import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts"; |
| 11 | +import { ServerConfig } from "../../config.ts"; |
| 12 | +import { ServerSettingsService } from "../../serverSettings.ts"; |
| 13 | +import { NoOpProviderEventLoggers, ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts"; |
| 14 | +import { CursorDriver } from "./CursorDriver.ts"; |
| 15 | + |
| 16 | +const testLayer = ServerConfig.layerTest(process.cwd(), { |
| 17 | + prefix: "t3-cursor-driver-copy-command-", |
| 18 | +}).pipe( |
| 19 | + Layer.provideMerge(NodeServices.layer), |
| 20 | + Layer.provideMerge(ServerSettingsService.layerTest()), |
| 21 | + Layer.provideMerge( |
| 22 | + Layer.mock(BackgroundPolicy.BackgroundPolicy)({ |
| 23 | + shouldRunScopeWork: () => Effect.succeed(false), |
| 24 | + }), |
| 25 | + ), |
| 26 | + Layer.provideMerge(Layer.succeed(ProviderEventLoggers, NoOpProviderEventLoggers)), |
| 27 | + Layer.provideMerge( |
| 28 | + Layer.succeed( |
| 29 | + HttpClient.HttpClient, |
| 30 | + HttpClient.make(() => Effect.die("Disabled Cursor must not make an HTTP request")), |
| 31 | + ), |
| 32 | + ), |
| 33 | +); |
| 34 | + |
| 35 | +it.layer(testLayer)("CursorDriver", (it) => { |
| 36 | + it.effect("formats a copied update command for the injected Windows environment", () => |
| 37 | + Effect.gen(function* () { |
| 38 | + const binaryPath = "C:\\Users\\Example User\\.local\\bin\\cursor-agent.exe"; |
| 39 | + const instance = yield* CursorDriver.create({ |
| 40 | + instanceId: ProviderInstanceId.make("cursor-copy-command"), |
| 41 | + displayName: "Cursor test", |
| 42 | + enabled: false, |
| 43 | + environment: [], |
| 44 | + config: { ...CursorDriver.defaultConfig(), binaryPath }, |
| 45 | + }); |
| 46 | + |
| 47 | + expect(instance.snapshot.maintenanceCapabilities.update).toMatchObject({ |
| 48 | + command: `& '${binaryPath}' update`, |
| 49 | + executable: binaryPath, |
| 50 | + args: ["update"], |
| 51 | + }); |
| 52 | + expect((yield* instance.snapshot.refresh).status).toBe("disabled"); |
| 53 | + }).pipe( |
| 54 | + Effect.provideService(HostProcessPlatform, "win32"), |
| 55 | + Effect.provideService( |
| 56 | + ChildProcessSpawner.ChildProcessSpawner, |
| 57 | + ChildProcessSpawner.make(() => Effect.die("Disabled Cursor must not spawn a process")), |
| 58 | + ), |
| 59 | + Effect.scoped, |
| 60 | + ), |
| 61 | + ); |
| 62 | +}); |
0 commit comments