Open History to see the last commit
1import * as NodeOS from "node:os";
2
3import * as NodeServices from "@effect/platform-node/NodeServices";
4import type * as Crypto from "effect/Crypto";
5import * as Effect from "effect/Effect";
6import * as FileSystem from "effect/FileSystem";
7import * as Path from "effect/Path";
8import type * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
9import { describe, expect, it } from "vite-plus/test";
10import type * as EffectAcpSchema from "effect-acp/schema";
11import type { CursorSettings } from "@t3tools/contracts";
12import { createModelCapabilities } from "@t3tools/shared/model";
13
14import {
15 buildCursorProviderSnapshot,
16 buildCursorCapabilitiesFromConfigOptions,
17 checkCursorProviderStatus,
18 discoverCursorModelsViaAcp,
19 makeCursorModelDiscovery,
20 getCursorParameterizedModelPickerUnsupportedMessage,
21 parseCursorAboutOutput,
22 parseCursorCliConfigChannel,
23 parseCursorVersionDate,
24 resolveCursorAcpBaseModelId,
25 resolveCursorAcpConfigUpdates,
26} from "./CursorProvider.ts";
27import {
28 discoverCursorSkills,
29 hasCursorSkillMention,
30 probeCursorSkills,
31 rewriteCursorSkillMentions,
32} from "../Drivers/CursorSkills.ts";
33import { execScriptSource, writeFakeCli } from "../../testUtils/fakeCli.ts";
34import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
35
36const runNode = <A, E>(
37 effect: Effect.Effect<
38 A,
39 E,
40 ChildProcessSpawner.ChildProcessSpawner | Crypto.Crypto | FileSystem.FileSystem | Path.Path
41 >,
42): Promise<A> => Effect.runPromise(effect.pipe(Effect.provide(NodeServices.layer)));
43
44// Closing the probe kills the agent with SIGTERM; Windows terminates the
45// process instead, so the mock never sees a signal to log.
46const windowsHost = HostProcessPlatform.defaultValue() === "win32";
47
48const resolveMockAgentPath = Effect.fn("resolveMockAgentPath")(function* () {
49 const path = yield* Path.Path;
50 return yield* path.fromFileUrl(new URL("../../../scripts/acp-mock-agent.ts", import.meta.url));
51});
52
53function selectDescriptor(
54 id: string,
55 label: string,
56 options: ReadonlyArray<{ id: string; label: string; isDefault?: boolean }>,
57) {
58 return {
59 id,
60 label,
61 type: "select" as const,
62 options: [...options],
63 ...(options.find((option) => option.isDefault)?.id
64 ? { currentValue: options.find((option) => option.isDefault)?.id }
65 : {}),
66 };
67}
68
69function booleanDescriptor(id: string, label: string, currentValue?: boolean) {
70 return {
71 id,
72 label,
73 type: "boolean" as const,
74 ...(typeof currentValue === "boolean" ? { currentValue } : {}),
75 };
76}
77
78const makeMockAgentWrapper = Effect.fn("makeMockAgentWrapper")(function* (
79 extraEnv?: Record<string, string>,
80) {
81 const fileSystem = yield* FileSystem.FileSystem;
82 const mockAgentPath = yield* resolveMockAgentPath();
83 const dir = yield* fileSystem.makeTempDirectory({
84 directory: NodeOS.tmpdir(),
85 prefix: "cursor-provider-mock-",
86 });
87 return writeFakeCli({
88 directory: dir,
89 name: "fake-agent",
90 env: extraEnv ?? {},
91 source: execScriptSource({ scriptPath: mockAgentPath }),
92 });
93});
94
95const makeMockAgentWithAboutWrapper = Effect.fn("makeMockAgentWithAboutWrapper")(function* () {
96 const fileSystem = yield* FileSystem.FileSystem;
97 const mockAgentPath = yield* resolveMockAgentPath();
98 const dir = yield* fileSystem.makeTempDirectory({
99 directory: NodeOS.tmpdir(),
100 prefix: "cursor-provider-about-mock-",
101 });
102 return writeFakeCli({
103 directory: dir,
104 name: "fake-agent",
105 source: [
106 'if (process.argv[2] === "about") {',
107 ' process.stdout.write("CLI Version 2026.04.09-f2b0fcd\\n");',
108 ' process.stdout.write("User Email cursor@example.com\\n");',
109 " process.exit(0);",
110 "}",
111 execScriptSource({ scriptPath: mockAgentPath }),
112 ].join("\n"),
113 });
114});
115
116const waitForFileContent = Effect.fn("waitForFileContent")(function* (
117 filePath: string,
118 attempts = 40,
119) {
120 const fileSystem = yield* FileSystem.FileSystem;
121 for (let attempt = 0; attempt < attempts; attempt += 1) {
122 const content = yield* fileSystem
123 .readFileString(filePath)
124 .pipe(Effect.catch(() => Effect.void));
125 if (content !== undefined) {
126 if (content.trim().length > 0) {
127 return content;
128 }
129 }
130 yield* Effect.sleep("50 millis");
131 }
132 return yield* Effect.die(`Timed out waiting for file content at ${filePath}`);
133});
134
135const makeProviderStatusEnvFixture = Effect.fn("makeProviderStatusEnvFixture")(function* () {
136 const fileSystem = yield* FileSystem.FileSystem;
137 const path = yield* Path.Path;
138 const tempDir = yield* fileSystem.makeTempDirectory({
139 directory: NodeOS.tmpdir(),
140 prefix: "cursor-provider-status-env-",
141 });
142 return {
143 requestLogPath: path.join(tempDir, "requests.ndjson"),
144 wrapperPath: yield* makeMockAgentWithAboutWrapper(),
145 };
146});
147
148const makeExitLogFixture = Effect.fn("makeExitLogFixture")(function* (prefix: string) {
149 const fileSystem = yield* FileSystem.FileSystem;
150 const path = yield* Path.Path;
151 const tempDir = yield* fileSystem.makeTempDirectory({
152 directory: NodeOS.tmpdir(),
153 prefix,
154 });
155 const exitLogPath = path.join(tempDir, "exit.log");
156 return {
157 exitLogPath,
158 wrapperPath: yield* makeMockAgentWrapper({
159 T3_ACP_EXIT_LOG_PATH: exitLogPath,
160 }),
161 };
162});
163
164const parameterizedGpt54ConfigOptions = [
165 {
166 type: "select",
167 currentValue: "gpt-5.4-medium-fast",
168 options: [{ name: "GPT-5.4", value: "gpt-5.4-medium-fast" }],
169 category: "model",
170 id: "model",
171 name: "Model",
172 },
173 {
174 type: "select",
175 currentValue: "medium",
176 options: [
177 { name: "None", value: "none" },
178 { name: "Low", value: "low" },
179 { name: "Medium", value: "medium" },
180 { name: "High", value: "high" },
181 { name: "Extra High", value: "extra-high" },
182 ],
183 category: "thought_level",
184 id: "reasoning",
185 name: "Reasoning",
186 },
187 {
188 type: "select",
189 currentValue: "272k",
190 options: [
191 { name: "272K", value: "272k" },
192 { name: "1M", value: "1m" },
193 ],
194 category: "model_config",
195 id: "context",
196 name: "Context",
197 },
198 {
199 type: "select",
200 currentValue: "false",
201 options: [
202 { name: "Off", value: "false" },
203 { name: "Fast", value: "true" },
204 ],
205 category: "model_config",
206 id: "fast",
207 name: "Fast",
208 },
209] satisfies ReadonlyArray<EffectAcpSchema.SessionConfigOption>;
210
211const parameterizedClaudeConfigOptions = [
212 {
213 type: "select",
214 currentValue: "claude-4.6-opus-high-thinking",
215 options: [{ name: "Opus 4.6", value: "claude-4.6-opus-high-thinking" }],
216 category: "model",
217 id: "model",
218 name: "Model",
219 },
220 {
221 type: "select",
222 currentValue: "high",
223 options: [
224 { name: "Low", value: "low" },
225 { name: "Medium", value: "medium" },
226 { name: "High", value: "high" },
227 ],
228 category: "thought_level",
229 id: "reasoning",
230 name: "Reasoning",
231 },
232 {
233 type: "boolean",
234 currentValue: true,
235 category: "model_config",
236 id: "thinking",
237 name: "Thinking",
238 },
239] satisfies ReadonlyArray<EffectAcpSchema.SessionConfigOption>;
240
241const parameterizedClaudeModelOptionConfigOptions = [
242 {
243 type: "select",
244 currentValue: "claude-opus-4-6",
245 options: [{ name: "Opus 4.6", value: "claude-opus-4-6" }],
246 category: "model",
247 id: "model",
248 name: "Model",
249 },
250 {
251 type: "select",
252 currentValue: "high",
253 options: [
254 { name: "Low", value: "low" },
255 { name: "Medium", value: "medium" },
256 { name: "High", value: "high" },
257 ],
258 category: "thought_level",
259 id: "reasoning",
260 name: "Reasoning",
261 },
262 {
263 type: "select",
264 currentValue: "max",
265 options: [
266 { name: "Low", value: "low" },
267 { name: "Medium", value: "medium" },
268 { name: "High", value: "high" },
269 { name: "Max", value: "max" },
270 ],
271 category: "model_option",
272 id: "effort",
273 name: "Effort",
274 },
275 {
276 type: "select",
277 currentValue: "true",
278 options: [
279 { name: "Off", value: "false" },
280 { name: "Fast", value: "true" },
281 ],
282 category: "model_config",
283 id: "fast",
284 name: "Fast",
285 },
286 {
287 type: "select",
288 currentValue: "true",
289 options: [
290 { name: "Off", value: "false" },
291 { name: ":icon-brain:", value: "true" },
292 ],
293 category: "model_config",
294 id: "thinking",
295 name: "Thinking",
296 },
297] satisfies ReadonlyArray<EffectAcpSchema.SessionConfigOption>;
298
299const baseCursorSettings: CursorSettings = {
300 enabled: true,
301 binaryPath: "cursor-agent",
302 apiEndpoint: "",
303 customModels: [],
304};
305const cursorAcpDiscoveryFailedMessage = [
306 "Cursor ACP model discovery failed.",
307 "Cursor CLI setup may be incomplete; install or enable the Cursor CLI, restart T3 Code, and try again.",
308 "See https://cursor.com/docs/cli/installation.",
309 "Check server logs for ACP details.",
310].join(" ");
311const missingCursorBinaryPath = "/definitely/not/installed/t3-cursor-agent";
312const cursorCliCommandMissingMessage = [
313 `Cursor CLI command \`${missingCursorBinaryPath}\` was not found.`,
314 `Install or enable the Cursor CLI, make sure \`${missingCursorBinaryPath}\` is on PATH, then restart T3 Code.`,
315 "See https://cursor.com/docs/cli/installation.",
316].join(" ");
317
318describe("Cursor skills", () => {
319 it("discovers recursive project skills with project precedence", async () =>
320 await runNode(
321 Effect.gen(function* () {
322 const fileSystem = yield* FileSystem.FileSystem;
323 const path = yield* Path.Path;
324 const userHome = yield* fileSystem.makeTempDirectory({
325 directory: NodeOS.tmpdir(),
326 prefix: "cursor-skills-home-",
327 });
328 const workspace = yield* fileSystem.makeTempDirectory({
329 directory: NodeOS.tmpdir(),
330 prefix: "cursor-skills-workspace-",
331 });
332 const writeSkill = Effect.fn("writeCursorSkill")(function* (
333 root: string,
334 name: string,
335 contents: string,
336 ) {
337 const skillDirectory = path.join(root, name);
338 yield* fileSystem.makeDirectory(skillDirectory, { recursive: true });
339 yield* fileSystem.writeFileString(path.join(skillDirectory, "SKILL.md"), contents);
340 });
341
342 yield* writeSkill(
343 path.join(userHome, ".cursor", "skills"),
344 "review",
345 "---\ndescription: user review\n---\n",
346 );
347 yield* writeSkill(
348 path.join(workspace, ".agents", "skills", "nested"),
349 "review",
350 "---\nname: Review changes\ndescription: project review\n---\n",
351 );
352 yield* writeSkill(
353 path.join(workspace, ".cursor", "skills"),
354 "internal",
355 "---\nuser-invocable: false\n---\n",
356 );
357 yield* writeSkill(
358 path.join(workspace, ".cursor", "skills"),
359 "oversized",
360 "x".repeat(1_000_001),
361 );
362 yield* fileSystem.makeDirectory(path.join(userHome, ".codex"), { recursive: true });
363 yield* fileSystem.writeFileString(
364 path.join(userHome, ".codex", "skills"),
365 "not a directory",
366 );
367
368 const skills = yield* discoverCursorSkills(workspace, { HOME: userHome });
369 expect(skills).toEqual([
370 {
371 name: "internal",
372 path: path.join(workspace, ".cursor", "skills", "internal", "SKILL.md"),
373 scope: "project",
374 enabled: true,
375 userInvocable: false,
376 },
377 {
378 name: "oversized",
379 path: path.join(workspace, ".cursor", "skills", "oversized", "SKILL.md"),
380 scope: "project",
381 enabled: true,
382 },
383 {
384 name: "review",
385 displayName: "Review changes",
386 description: "project review",
387 path: path.join(workspace, ".agents", "skills", "nested", "review", "SKILL.md"),
388 scope: "project",
389 enabled: true,
390 },
391 ]);
392 expect(
393 (yield* probeCursorSkills(workspace, { HOME: userHome }).pipe(Effect.result))._tag,
394 ).toBe("Failure");
395 }),
396 ));
397
398 it("treats a symlinked skill outside the root as a package boundary", async () =>
399 await runNode(
400 Effect.gen(function* () {
401 const fileSystem = yield* FileSystem.FileSystem;
402 const path = yield* Path.Path;
403 const userHome = yield* fileSystem.makeTempDirectory({
404 directory: NodeOS.tmpdir(),
405 prefix: "cursor-skills-home-",
406 });
407 const workspace = yield* fileSystem.makeTempDirectory({
408 directory: NodeOS.tmpdir(),
409 prefix: "cursor-skills-workspace-",
410 });
411 const library = yield* fileSystem.makeTempDirectory({
412 directory: NodeOS.tmpdir(),
413 prefix: "cursor-skills-library-",
414 });
415 const writeSkill = Effect.fn("writeCursorSkill")(function* (
416 directory: string,
417 contents: string,
418 ) {
419 yield* fileSystem.makeDirectory(directory, { recursive: true });
420 yield* fileSystem.writeFileString(path.join(directory, "SKILL.md"), contents);
421 });
422
423 // A skill package managed in a config repo and installed by symlink.
424 // Its own SKILL.md must be discovered under the link name, but nothing
425 // below the target may be walked.
426 yield* writeSkill(path.join(library, "shared-review"), "---\ndescription: shared\n---\n");
427 yield* writeSkill(path.join(library, "shared-review", "hidden"), "---\n---\n");
428 const root = path.join(workspace, ".cursor", "skills");
429 yield* fileSystem.makeDirectory(root, { recursive: true });
430 yield* fileSystem.symlink(path.join(library, "shared-review"), path.join(root, "review"));
431
432 const skills = yield* discoverCursorSkills(workspace, { HOME: userHome });
433 expect(skills).toEqual([
434 {
435 name: "review",
436 description: "shared",
437 path: path.join(root, "review", "SKILL.md"),
438 scope: "project",
439 enabled: true,
440 },
441 ]);
442 expect(
443 (yield* probeCursorSkills(workspace, { HOME: userHome }).pipe(Effect.result))._tag,
444 ).toBe("Success");
445 }),
446 ));
447
448 it("rewrites only discovered skill mentions into Cursor slash invocations", () => {
449 expect(hasCursorSkillMention("use $Review_Pr:V2 here")).toBe(true);
450 expect(hasCursorSkillMention("please $review this")).toBe(true);
451 expect(
452 rewriteCursorSkillMentions("use $review, keep $HOME and 5$review", new Set(["review"])),
453 ).toBe("use $review, keep $HOME and 5$review");
454 expect(rewriteCursorSkillMentions("please $review this", new Set(["review"]))).toBe(
455 "please /review this",
456 );
457 });
458
459 it("detects and invokes digit-leading Cursor skills without rewriting money", () => {
460 const names = new Set(["2spec", "20k", "100M", "1e6"]);
461 // Repeated presence checks must not carry a global-regex cursor.
462 expect(hasCursorSkillMention("use $2spec here")).toBe(true);
463 expect(hasCursorSkillMention("use $2spec here")).toBe(true);
464 expect(rewriteCursorSkillMentions("use $2spec here", names)).toBe("use /2spec here");
465 expect(rewriteCursorSkillMentions("use $2spec here", new Set())).toBe("use $2spec here");
466 for (const text of [
467 "pay $20 tomorrow",
468 "budget $20k here",
469 "cost $100M total",
470 "limit $1e6 here",
471 ]) {
472 expect(hasCursorSkillMention(text)).toBe(false);
473 expect(rewriteCursorSkillMentions(text, names)).toBe(text);
474 }
475 });
476});
477
478describe("buildCursorProviderSnapshot", () => {
479 it("downgrades ready status to warning when ACP model discovery times out", () => {
480 expect(
481 buildCursorProviderSnapshot({
482 checkedAt: "2026-01-01T00:00:00.000Z",
483 cursorSettings: baseCursorSettings,
484 parsed: {
485 version: "2026.04.09-f2b0fcd",
486 status: "ready",
487 auth: { status: "authenticated", type: "Team", label: "Cursor Team Subscription" },
488 },
489 discoveryWarning: "Cursor ACP model discovery timed out after 15000ms.",
490 }),
491 ).toMatchObject({
492 status: "warning",
493 message: "Cursor ACP model discovery timed out after 15000ms.",
494 models: [],
495 supportsConversationRollback: false,
496 });
497 });
498
499 it("preserves provider error state while appending discovery warnings", () => {
500 expect(
501 buildCursorProviderSnapshot({
502 checkedAt: "2026-01-01T00:00:00.000Z",
503 cursorSettings: {
504 ...baseCursorSettings,
505 customModels: ["claude-sonnet-4-6"],
506 },
507 parsed: {
508 version: "2026.04.09-f2b0fcd",
509 status: "error",
510 auth: { status: "unauthenticated" },
511 message: "Cursor Agent is not authenticated. Run `agent login` and try again.",
512 },
513 discoveryWarning: cursorAcpDiscoveryFailedMessage,
514 }),
515 ).toMatchObject({
516 status: "error",
517 message: `Cursor Agent is not authenticated. Run \`agent login\` and try again. ${cursorAcpDiscoveryFailedMessage}`,
518 models: [
519 {
520 slug: "claude-sonnet-4-6",
521 isCustom: true,
522 },
523 ],
524 });
525 });
526});
527
528describe("buildCursorCapabilitiesFromConfigOptions", () => {
529 it("derives model capabilities from parameterized Cursor ACP config options", () => {
530 expect(buildCursorCapabilitiesFromConfigOptions(parameterizedGpt54ConfigOptions)).toEqual(
531 createModelCapabilities({
532 optionDescriptors: [
533 selectDescriptor("reasoning", "Reasoning", [
534 { id: "low", label: "Low" },
535 { id: "medium", label: "Medium", isDefault: true },
536 { id: "high", label: "High" },
537 { id: "xhigh", label: "Extra High" },
538 ]),
539 selectDescriptor("contextWindow", "Context", [
540 { id: "272k", label: "272K", isDefault: true },
541 { id: "1m", label: "1M" },
542 ]),
543 booleanDescriptor("fastMode", "Fast", false),
544 ],
545 }),
546 );
547 });
548
549 it("detects boolean thinking toggles from model_config options", () => {
550 expect(buildCursorCapabilitiesFromConfigOptions(parameterizedClaudeConfigOptions)).toEqual(
551 createModelCapabilities({
552 optionDescriptors: [
553 selectDescriptor("reasoning", "Reasoning", [
554 { id: "low", label: "Low" },
555 { id: "medium", label: "Medium" },
556 { id: "high", label: "High", isDefault: true },
557 ]),
558 booleanDescriptor("thinking", "Thinking", true),
559 ],
560 }),
561 );
562 });
563
564 it("prefers the newer model_option effort control over legacy thought_level", () => {
565 expect(
566 buildCursorCapabilitiesFromConfigOptions(parameterizedClaudeModelOptionConfigOptions),
567 ).toEqual(
568 createModelCapabilities({
569 optionDescriptors: [
570 selectDescriptor("reasoning", "Effort", [
571 { id: "low", label: "Low" },
572 { id: "medium", label: "Medium" },
573 { id: "high", label: "High" },
574 { id: "max", label: "Max", isDefault: true },
575 ]),
576 booleanDescriptor("fastMode", "Fast", true),
577 booleanDescriptor("thinking", "Thinking", true),
578 ],
579 }),
580 );
581 });
582});
583
584describe("checkCursorProviderStatus", () => {
585 it("reports the install docs when the Cursor CLI command is missing", async () => {
586 const provider = await runNode(
587 checkCursorProviderStatus({
588 enabled: true,
589 binaryPath: missingCursorBinaryPath,
590 apiEndpoint: "",
591 customModels: [],
592 }),
593 );
594
595 expect(provider).toMatchObject({
596 installed: false,
597 status: "error",
598 auth: { status: "unknown" },
599 message: cursorCliCommandMissingMessage,
600 });
601 });
602
603 it("passes the injected environment to ACP model discovery", async () => {
604 const { requestLogPath, wrapperPath } = await runNode(makeProviderStatusEnvFixture());
605
606 const provider = await runNode(
607 checkCursorProviderStatus(
608 {
609 enabled: true,
610 binaryPath: wrapperPath,
611 apiEndpoint: "",
612 customModels: [],
613 },
614 {
615 ...process.env,
616 T3_ACP_REQUEST_LOG_PATH: requestLogPath,
617 },
618 ),
619 );
620
621 expect(provider.models.map((model) => model.slug)).toEqual([
622 "default",
623 "composer-2",
624 "gpt-5.4",
625 "claude-opus-4-6",
626 ]);
627 await expect(runNode(waitForFileContent(requestLogPath))).resolves.toContain("initialize");
628 });
629});
630
631describe("discoverCursorModelsViaAcp", () => {
632 it("reuses successful discovery until the CLI version or account changes", async () => {
633 await runNode(
634 Effect.gen(function* () {
635 const { requestLogPath, wrapperPath } = yield* makeProviderStatusEnvFixture();
636 const fileSystem = yield* FileSystem.FileSystem;
637 const settings = {
638 enabled: true,
639 binaryPath: wrapperPath,
640 apiEndpoint: "",
641 customModels: [],
642 };
643 const discover = yield* makeCursorModelDiscovery(settings, {
644 ...process.env,
645 T3_ACP_REQUEST_LOG_PATH: requestLogPath,
646 });
647 const about = {
648 version: "2026.08.11",
649 auth: { status: "authenticated" as const, label: "first@example.test" },
650 };
651 const first = yield* discover(about);
652 expect(first.length).toBeGreaterThan(0);
653 yield* fileSystem.writeFileString(requestLogPath, "");
654 expect(yield* discover(about)).toEqual(first);
655 expect(yield* fileSystem.readFileString(requestLogPath)).toBe("");
656 yield* discover({ ...about, version: "2026.08.12" });
657 expect(yield* fileSystem.readFileString(requestLogPath)).toContain("initialize");
658 yield* fileSystem.writeFileString(requestLogPath, "");
659 yield* discover({
660 version: "2026.08.12",
661 auth: { ...about.auth, label: "second@example.test" },
662 });
663 expect(yield* fileSystem.readFileString(requestLogPath)).toContain("initialize");
664 }),
665 );
666 });
667
668 it("keeps the ACP probe runtime alive long enough to discover models", async () => {
669 const wrapperPath = await runNode(makeMockAgentWrapper());
670
671 const models = await runNode(
672 discoverCursorModelsViaAcp({
673 enabled: true,
674 binaryPath: wrapperPath,
675 apiEndpoint: "",
676 customModels: [],
677 }).pipe(Effect.scoped),
678 );
679
680 expect(models.map((model) => model.slug)).toEqual([
681 "default",
682 "composer-2",
683 "gpt-5.4",
684 "claude-opus-4-6",
685 ]);
686 });
687
688 it.skipIf(windowsHost)("closes the ACP probe runtime after discovery completes", async () => {
689 const { exitLogPath, wrapperPath } = await runNode(
690 makeExitLogFixture("cursor-provider-exit-log-"),
691 );
692
693 await runNode(
694 discoverCursorModelsViaAcp({
695 enabled: true,
696 binaryPath: wrapperPath,
697 apiEndpoint: "",
698 customModels: [],
699 }),
700 );
701
702 const exitLog = await runNode(waitForFileContent(exitLogPath));
703 expect(exitLog).toContain("SIGTERM");
704 });
705});
706
707describe("parseCursorAboutOutput", () => {
708 it("parses json about output and forwards subscription metadata", () => {
709 expect(
710 parseCursorAboutOutput({
711 code: 0,
712 stdout: JSON.stringify({
713 cliVersion: "2026.04.09-f2b0fcd",
714 subscriptionTier: "Team",
715 userEmail: "jmarminge@gmail.com",
716 }),
717 stderr: "",
718 }),
719 ).toEqual({
720 version: "2026.04.09-f2b0fcd",
721 status: "ready",
722 auth: {
723 status: "authenticated",
724 email: "jmarminge@gmail.com",
725 type: "Team",
726 label: "Cursor Team Subscription",
727 },
728 });
729 });
730
731 it("treats json about output with a logged-out email as unauthenticated", () => {
732 expect(
733 parseCursorAboutOutput({
734 code: 0,
735 stdout: JSON.stringify({
736 cliVersion: "2026.04.09-f2b0fcd",
737 subscriptionTier: "Team",
738 userEmail: "Not logged in",
739 }),
740 stderr: "",
741 }),
742 ).toEqual({
743 version: "2026.04.09-f2b0fcd",
744 status: "error",
745 auth: {
746 status: "unauthenticated",
747 },
748 message: "Cursor Agent is not authenticated. Run `agent login` and try again.",
749 });
750 });
751
752 it("treats json about output with a null email as unauthenticated", () => {
753 expect(
754 parseCursorAboutOutput({
755 code: 0,
756 stdout: JSON.stringify({
757 cliVersion: "2026.04.09-f2b0fcd",
758 subscriptionTier: null,
759 userEmail: null,
760 }),
761 stderr: "",
762 }),
763 ).toEqual({
764 version: "2026.04.09-f2b0fcd",
765 status: "error",
766 auth: {
767 status: "unauthenticated",
768 },
769 message: "Cursor Agent is not authenticated. Run `agent login` and try again.",
770 });
771 });
772});
773
774describe("Cursor parameterized model picker preview gating", () => {
775 it("parses Cursor CLI version dates from build versions", () => {
776 expect(parseCursorVersionDate("2026.04.08-c4e73a3")).toBe(20260408);
777 expect(parseCursorVersionDate("2026.04.09")).toBe(20260409);
778 expect(parseCursorVersionDate("not-a-version")).toBeUndefined();
779 });
780
781 it("parses the Cursor CLI channel from cli-config.json", () => {
782 expect(parseCursorCliConfigChannel('{ "channel": "lab" }')).toBe("lab");
783 expect(parseCursorCliConfigChannel('{ "channel": "stable" }')).toBe("stable");
784 expect(parseCursorCliConfigChannel('{ "version": 1 }')).toBeUndefined();
785 expect(parseCursorCliConfigChannel("not-json")).toBeUndefined();
786 });
787
788 it("returns no warning when the preview requirements are met", () => {
789 expect(
790 getCursorParameterizedModelPickerUnsupportedMessage({
791 version: "2026.04.08-c4e73a3",
792 channel: "lab",
793 }),
794 ).toBeUndefined();
795 });
796
797 it("explains when the Cursor Agent version is too old", () => {
798 expect(
799 getCursorParameterizedModelPickerUnsupportedMessage({
800 version: "2026.04.07-c4e73a3",
801 channel: "lab",
802 }),
803 ).toContain("too old");
804 });
805
806 it("explains when the Cursor Agent channel is not lab", () => {
807 expect(
808 getCursorParameterizedModelPickerUnsupportedMessage({
809 version: "2026.04.08-c4e73a3",
810 channel: "stable",
811 }),
812 ).toContain("lab channel");
813 });
814});
815
816describe("resolveCursorAcpBaseModelId", () => {
817 it("drops bracket traits without rewriting raw ACP model ids", () => {
818 expect(resolveCursorAcpBaseModelId("gpt-5.4[reasoning=medium,context=272k]")).toBe("gpt-5.4");
819 expect(resolveCursorAcpBaseModelId("gpt-5.4-medium-fast")).toBe("gpt-5.4-medium-fast");
820 expect(resolveCursorAcpBaseModelId("claude-4.6-opus-high-thinking")).toBe(
821 "claude-4.6-opus-high-thinking",
822 );
823 expect(resolveCursorAcpBaseModelId("composer-2")).toBe("composer-2");
824 expect(resolveCursorAcpBaseModelId("auto")).toBe("auto");
825 });
826});
827
828describe("resolveCursorAcpConfigUpdates", () => {
829 it("maps Cursor model options onto separate ACP config option updates", () => {
830 expect(
831 resolveCursorAcpConfigUpdates(parameterizedGpt54ConfigOptions, [
832 { id: "reasoning", value: "xhigh" },
833 { id: "fastMode", value: true },
834 { id: "contextWindow", value: "1m" },
835 ]),
836 ).toEqual([
837 { configId: "reasoning", value: "extra-high" },
838 { configId: "context", value: "1m" },
839 { configId: "fast", value: "true" },
840 ]);
841 });
842
843 it("maps boolean thinking toggles when the model exposes them separately", () => {
844 expect(
845 resolveCursorAcpConfigUpdates(parameterizedClaudeConfigOptions, [
846 { id: "thinking", value: false },
847 ]),
848 ).toEqual([{ configId: "thinking", value: false }]);
849 });
850
851 it("maps explicit fastMode: false so the adapter can clear a prior fast selection", () => {
852 expect(
853 resolveCursorAcpConfigUpdates(parameterizedGpt54ConfigOptions, [
854 { id: "fastMode", value: false },
855 ]),
856 ).toEqual([{ configId: "fast", value: "false" }]);
857 });
858
859 it("writes Cursor effort changes through the newer model_option config when available", () => {
860 expect(
861 resolveCursorAcpConfigUpdates(parameterizedClaudeModelOptionConfigOptions, [
862 { id: "reasoning", value: "max" },
863 { id: "thinking", value: false },
864 ]),
865 ).toEqual([
866 { configId: "effort", value: "max" },
867 { configId: "thinking", value: "false" },
868 ]);
869 });
870});