Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import * as NodeOS from "node:os";
4import * as NodePath from "node:path";
5import { expect, it } from "@effect/vitest";
6import { ProviderInstanceId } from "@t3tools/contracts";
7import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
8import * as Effect from "effect/Effect";
9import * as FileSystem from "effect/FileSystem";
10import * as Layer from "effect/Layer";
11import { HttpClient } from "effect/unstable/http";
12import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
13
14import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts";
15import { ServerConfig } from "../../config.ts";
16import { ServerSettingsService } from "../../serverSettings.ts";
17import { NoOpProviderEventLoggers, ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts";
18import { CursorDriver } from "./CursorDriver.ts";
19
20const testLayer = ServerConfig.layerTest(process.cwd(), {
21 prefix: "t3-cursor-driver-copy-command-",
22}).pipe(
23 Layer.provideMerge(NodeServices.layer),
24 Layer.provideMerge(ServerSettingsService.layerTest()),
25 Layer.provideMerge(
26 Layer.mock(BackgroundPolicy.BackgroundPolicy)({
27 shouldRunScopeWork: () => Effect.succeed(false),
28 }),
29 ),
30 Layer.provideMerge(Layer.succeed(ProviderEventLoggers, NoOpProviderEventLoggers)),
31 Layer.provideMerge(
32 Layer.succeed(
33 HttpClient.HttpClient,
34 HttpClient.make(() => Effect.die("Disabled Cursor must not make an HTTP request")),
35 ),
36 ),
37);
38
39// The `#!/bin/sh` stub below cannot be resolved as an executable on Windows.
40const windowsHost = HostProcessPlatform.defaultValue() === "win32";
41
42it.layer(testLayer)("CursorDriver", (it) => {
43 it.effect.skipIf(windowsHost)(
44 "quotes a configured executable path in the copyable update command",
45 () =>
46 Effect.gen(function* () {
47 const fs = yield* FileSystem.FileSystem;
48 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cursor-driver-" });
49 const binaryPath = NodePath.join(tempDir, "Cursor Tools", "bin", "cursor-agent");
50 yield* fs.makeDirectory(NodePath.dirname(binaryPath), { recursive: true });
51 yield* fs.writeFileString(binaryPath, "#!/bin/sh\n");
52 yield* fs.chmod(binaryPath, 0o755);
53
54 const instance = yield* CursorDriver.create({
55 instanceId: ProviderInstanceId.make("cursor-copy-command"),
56 displayName: "Cursor test",
57 enabled: false,
58 environment: [],
59 config: { ...CursorDriver.defaultConfig(), binaryPath },
60 });
61
62 const capabilities = yield* instance.snapshot.resolveMaintenance();
63 expect(capabilities.update).toMatchObject({
64 command: `'${binaryPath}' update`,
65 executable: binaryPath,
66 args: ["update"],
67 });
68 expect((yield* instance.snapshot.refresh).status).toBe("disabled");
69 }).pipe(
70 Effect.provideService(
71 ChildProcessSpawner.ChildProcessSpawner,
72 ChildProcessSpawner.make(() => Effect.die("Disabled Cursor must not spawn a process")),
73 ),
74 Effect.scoped,
75 ),
76 );
77
78 it.effect("stays manual-only when the configured executable does not exist", () =>
79 Effect.gen(function* () {
80 const instance = yield* CursorDriver.create({
81 instanceId: ProviderInstanceId.make("cursor-missing"),
82 displayName: "Cursor test",
83 enabled: false,
84 environment: [],
85 config: {
86 ...CursorDriver.defaultConfig(),
87 binaryPath: NodePath.join(NodeOS.tmpdir(), "t3-cursor-missing", "cursor-agent"),
88 },
89 });
90 expect((yield* instance.snapshot.resolveMaintenance()).update).toBeNull();
91 }).pipe(
92 Effect.provideService(
93 ChildProcessSpawner.ChildProcessSpawner,
94 ChildProcessSpawner.make(() => Effect.die("Disabled Cursor must not spawn a process")),
95 ),
96 Effect.scoped,
97 ),
98 );
99});