Open History to see the last commit
1import * as Effect from "effect/Effect";
2import type * as EffectAcpSchema from "effect-acp/schema";
3import { describe, expect, it } from "vite-plus/test";
4
5import { applyCursorAcpModelSelection, buildCursorAcpSpawnInput } from "./CursorAcpSupport.ts";
6
7const parameterizedGpt54ConfigOptions: ReadonlyArray<EffectAcpSchema.SessionConfigOption> = [
8 {
9 id: "model",
10 name: "Model",
11 category: "model",
12 type: "select",
13 currentValue: "gpt-5.4-medium-fast",
14 options: [{ value: "gpt-5.4-medium-fast", name: "GPT-5.4" }],
15 },
16 {
17 id: "reasoning",
18 name: "Reasoning",
19 category: "thought_level",
20 type: "select",
21 currentValue: "medium",
22 options: [
23 { value: "low", name: "Low" },
24 { value: "medium", name: "Medium" },
25 { value: "high", name: "High" },
26 { value: "extra-high", name: "Extra High" },
27 ],
28 },
29 {
30 id: "context",
31 name: "Context",
32 category: "model_config",
33 type: "select",
34 currentValue: "272k",
35 options: [
36 { value: "272k", name: "272K" },
37 { value: "1m", name: "1M" },
38 ],
39 },
40 {
41 id: "fast",
42 name: "Fast",
43 category: "model_config",
44 type: "select",
45 currentValue: "false",
46 options: [
47 { value: "false", name: "Off" },
48 { value: "true", name: "Fast" },
49 ],
50 },
51];
52
53describe("buildCursorAcpSpawnInput", () => {
54 it("builds the default Cursor ACP command", () => {
55 expect(buildCursorAcpSpawnInput(undefined, "/tmp/project")).toEqual({
56 command: "cursor-agent",
57 args: ["acp"],
58 cwd: "/tmp/project",
59 });
60 });
61
62 it("includes the configured api endpoint when present", () => {
63 expect(
64 buildCursorAcpSpawnInput(
65 {
66 binaryPath: "/usr/local/bin/agent",
67 apiEndpoint: "http://localhost:3000",
68 },
69 "/tmp/project",
70 ),
71 ).toEqual({
72 command: "/usr/local/bin/agent",
73 args: ["-e", "http://localhost:3000", "acp"],
74 cwd: "/tmp/project",
75 });
76 });
77
78 it("forces approval in full-access mode", () => {
79 expect(buildCursorAcpSpawnInput(undefined, "/tmp/project", undefined, "full-access")).toEqual({
80 command: "cursor-agent",
81 args: ["--force", "acp"],
82 cwd: "/tmp/project",
83 });
84 });
85
86 it("uses Cursor auto-review in auto mode", () => {
87 expect(buildCursorAcpSpawnInput(undefined, "/tmp/project", undefined, "auto")).toEqual({
88 command: "cursor-agent",
89 args: ["--auto-review", "acp"],
90 cwd: "/tmp/project",
91 });
92 });
93
94 it.each(["approval-required", "auto-accept-edits"] as const)(
95 "does not relax approval in %s mode",
96 (runtimeMode) => {
97 expect(buildCursorAcpSpawnInput(undefined, "/tmp/project", undefined, runtimeMode)).toEqual({
98 command: "cursor-agent",
99 args: ["acp"],
100 cwd: "/tmp/project",
101 });
102 },
103 );
104});
105
106describe("applyCursorAcpModelSelection", () => {
107 it("sets the base model before applying separate config options", async () => {
108 const calls: Array<
109 | { readonly type: "model"; readonly value: string }
110 | { readonly type: "config"; readonly configId: string; readonly value: string | boolean }
111 > = [];
112
113 const runtime = {
114 getConfigOptions: Effect.succeed(parameterizedGpt54ConfigOptions),
115 setModel: (value: string) =>
116 Effect.sync(() => {
117 calls.push({ type: "model", value });
118 }),
119 setConfigOption: (configId: string, value: string | boolean) =>
120 Effect.sync(() => {
121 calls.push({ type: "config", configId, value });
122 }),
123 };
124
125 await Effect.runPromise(
126 applyCursorAcpModelSelection({
127 runtime,
128 model: "gpt-5.4-medium-fast[reasoning=medium,context=272k]",
129 selections: [
130 { id: "reasoning", value: "xhigh" },
131 { id: "contextWindow", value: "1m" },
132 { id: "fastMode", value: true },
133 ],
134 mapError: ({ step, configId, cause }) =>
135 step === "set-config-option"
136 ? `failed to set config option ${configId}: ${cause.message}`
137 : `failed to set model: ${cause.message}`,
138 }),
139 );
140
141 expect(calls).toEqual([
142 { type: "model", value: "gpt-5.4-medium-fast" },
143 { type: "config", configId: "reasoning", value: "extra-high" },
144 { type: "config", configId: "context", value: "1m" },
145 { type: "config", configId: "fast", value: "true" },
146 ]);
147 });
148});