Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CursorProvider.test.ts

843 lines26.6 KB

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 getCursorFallbackModels,
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 };
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 };
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("getCursorFallbackModels", () => {
479 it("does not publish any built-in cursor models before ACP discovery", () => {
480 expect(
481 getCursorFallbackModels({
482 customModels: ["internal/cursor-model"],
483 }).map((model) => model.slug),
484 ).toEqual(["internal/cursor-model"]);
485 });
486});
487​
488describe("buildCursorProviderSnapshot", () => {
489 it("downgrades ready status to warning when ACP model discovery times out", () => {
490 expect(
491 buildCursorProviderSnapshot({
492 checkedAt: "2026-01-01T00:00:00.000Z",
493 cursorSettings: baseCursorSettings,
494 parsed: {
495 version: "2026.04.09-f2b0fcd",
496 status: "ready",
497 auth: { status: "authenticated", type: "Team", label: "Cursor Team Subscription" },
498 },
499 discoveryWarning: "Cursor ACP model discovery timed out after 15000ms.",
500 }),
501 ).toMatchObject({
502 status: "warning",
503 message: "Cursor ACP model discovery timed out after 15000ms.",
504 models: [],
505 });
506 });
507​
508 it("preserves provider error state while appending discovery warnings", () => {
509 expect(
510 buildCursorProviderSnapshot({
511 checkedAt: "2026-01-01T00:00:00.000Z",
512 cursorSettings: {
513 ...baseCursorSettings,
514 customModels: ["claude-sonnet-4-6"],
515 },
516 parsed: {
517 version: "2026.04.09-f2b0fcd",
518 status: "error",
519 auth: { status: "unauthenticated" },
520 message: "Cursor Agent is not authenticated. Run `agent login` and try again.",
521 },
522 discoveryWarning: cursorAcpDiscoveryFailedMessage,
523 }),
524 ).toMatchObject({
525 status: "error",
526 message: `Cursor Agent is not authenticated. Run \`agent login\` and try again. ${cursorAcpDiscoveryFailedMessage}`,
527 models: [
528 {
529 slug: "claude-sonnet-4-6",
530 isCustom: true,
531 },
532 ],
533 });
534 });
535});
536​
537describe("buildCursorCapabilitiesFromConfigOptions", () => {
538 it("derives model capabilities from parameterized Cursor ACP config options", () => {
539 expect(buildCursorCapabilitiesFromConfigOptions(parameterizedGpt54ConfigOptions)).toEqual(
540 createModelCapabilities({
541 optionDescriptors: [
542 selectDescriptor("reasoning", "Reasoning", [
543 { id: "low", label: "Low" },
544 { id: "medium", label: "Medium", isDefault: true },
545 { id: "high", label: "High" },
546 { id: "xhigh", label: "Extra High" },
547 ]),
548 selectDescriptor("contextWindow", "Context", [
549 { id: "272k", label: "272K", isDefault: true },
550 { id: "1m", label: "1M" },
551 ]),
552 booleanDescriptor("fastMode", "Fast", false),
553 ],
554 }),
555 );
556 });
557​
558 it("detects boolean thinking toggles from model_config options", () => {
559 expect(buildCursorCapabilitiesFromConfigOptions(parameterizedClaudeConfigOptions)).toEqual(
560 createModelCapabilities({
561 optionDescriptors: [
562 selectDescriptor("reasoning", "Reasoning", [
563 { id: "low", label: "Low" },
564 { id: "medium", label: "Medium" },
565 { id: "high", label: "High", isDefault: true },
566 ]),
567 booleanDescriptor("thinking", "Thinking", true),
568 ],
569 }),
570 );
571 });
572​
573 it("prefers the newer model_option effort control over legacy thought_level", () => {
574 expect(
575 buildCursorCapabilitiesFromConfigOptions(parameterizedClaudeModelOptionConfigOptions),
576 ).toEqual(
577 createModelCapabilities({
578 optionDescriptors: [
579 selectDescriptor("reasoning", "Effort", [
580 { id: "low", label: "Low" },
581 { id: "medium", label: "Medium" },
582 { id: "high", label: "High" },
583 { id: "max", label: "Max", isDefault: true },
584 ]),
585 booleanDescriptor("fastMode", "Fast", true),
586 booleanDescriptor("thinking", "Thinking", true),
587 ],
588 }),
589 );
590 });
591});
592​
593describe("checkCursorProviderStatus", () => {
594 it("reports the install docs when the Cursor CLI command is missing", async () => {
595 const provider = await runNode(
596 checkCursorProviderStatus({
597 enabled: true,
598 binaryPath: missingCursorBinaryPath,
599 apiEndpoint: "",
600 customModels: [],
601 }),
602 );
603​
604 expect(provider).toMatchObject({
605 installed: false,
606 status: "error",
607 auth: { status: "unknown" },
608 message: cursorCliCommandMissingMessage,
609 });
610 });
611​
612 it("passes the injected environment to ACP model discovery", async () => {
613 const { requestLogPath, wrapperPath } = await runNode(makeProviderStatusEnvFixture());
614​
615 const provider = await runNode(
616 checkCursorProviderStatus(
617 {
618 enabled: true,
619 binaryPath: wrapperPath,
620 apiEndpoint: "",
621 customModels: [],
622 },
623 {
624 ...process.env,
625 T3_ACP_REQUEST_LOG_PATH: requestLogPath,
626 },
627 ),
628 );
629​
630 expect(provider.models.map((model) => model.slug)).toEqual([
631 "default",
632 "composer-2",
633 "gpt-5.4",
634 "claude-opus-4-6",
635 ]);
636 await expect(runNode(waitForFileContent(requestLogPath))).resolves.toContain("initialize");
637 });
638});
639​
640describe("discoverCursorModelsViaAcp", () => {
641 it("keeps the ACP probe runtime alive long enough to discover models", async () => {
642 const wrapperPath = await runNode(makeMockAgentWrapper());
643​
644 const models = await runNode(
645 discoverCursorModelsViaAcp({
646 enabled: true,
647 binaryPath: wrapperPath,
648 apiEndpoint: "",
649 customModels: [],
650 }).pipe(Effect.scoped),
651 );
652​
653 expect(models.map((model) => model.slug)).toEqual([
654 "default",
655 "composer-2",
656 "gpt-5.4",
657 "claude-opus-4-6",
658 ]);
659 });
660​
661 it.skipIf(windowsHost)("closes the ACP probe runtime after discovery completes", async () => {
662 const { exitLogPath, wrapperPath } = await runNode(
663 makeExitLogFixture("cursor-provider-exit-log-"),
664 );
665​
666 await runNode(
667 discoverCursorModelsViaAcp({
668 enabled: true,
669 binaryPath: wrapperPath,
670 apiEndpoint: "",
671 customModels: [],
672 }),
673 );
674​
675 const exitLog = await runNode(waitForFileContent(exitLogPath));
676 expect(exitLog).toContain("SIGTERM");
677 });
678});
679​
680describe("parseCursorAboutOutput", () => {
681 it("parses json about output and forwards subscription metadata", () => {
682 expect(
683 parseCursorAboutOutput({
684 code: 0,
685 stdout: JSON.stringify({
686 cliVersion: "2026.04.09-f2b0fcd",
687 subscriptionTier: "Team",
688 userEmail: "jmarminge@gmail.com",
689 }),
690 stderr: "",
691 }),
692 ).toEqual({
693 version: "2026.04.09-f2b0fcd",
694 status: "ready",
695 auth: {
696 status: "authenticated",
697 email: "jmarminge@gmail.com",
698 type: "Team",
699 label: "Cursor Team Subscription",
700 },
701 });
702 });
703​
704 it("treats json about output with a logged-out email as unauthenticated", () => {
705 expect(
706 parseCursorAboutOutput({
707 code: 0,
708 stdout: JSON.stringify({
709 cliVersion: "2026.04.09-f2b0fcd",
710 subscriptionTier: "Team",
711 userEmail: "Not logged in",
712 }),
713 stderr: "",
714 }),
715 ).toEqual({
716 version: "2026.04.09-f2b0fcd",
717 status: "error",
718 auth: {
719 status: "unauthenticated",
720 },
721 message: "Cursor Agent is not authenticated. Run `agent login` and try again.",
722 });
723 });
724​
725 it("treats json about output with a null email as unauthenticated", () => {
726 expect(
727 parseCursorAboutOutput({
728 code: 0,
729 stdout: JSON.stringify({
730 cliVersion: "2026.04.09-f2b0fcd",
731 subscriptionTier: null,
732 userEmail: null,
733 }),
734 stderr: "",
735 }),
736 ).toEqual({
737 version: "2026.04.09-f2b0fcd",
738 status: "error",
739 auth: {
740 status: "unauthenticated",
741 },
742 message: "Cursor Agent is not authenticated. Run `agent login` and try again.",
743 });
744 });
745});
746​
747describe("Cursor parameterized model picker preview gating", () => {
748 it("parses Cursor CLI version dates from build versions", () => {
749 expect(parseCursorVersionDate("2026.04.08-c4e73a3")).toBe(20260408);
750 expect(parseCursorVersionDate("2026.04.09")).toBe(20260409);
751 expect(parseCursorVersionDate("not-a-version")).toBeUndefined();
752 });
753​
754 it("parses the Cursor CLI channel from cli-config.json", () => {
755 expect(parseCursorCliConfigChannel('{ "channel": "lab" }')).toBe("lab");
756 expect(parseCursorCliConfigChannel('{ "channel": "stable" }')).toBe("stable");
757 expect(parseCursorCliConfigChannel('{ "version": 1 }')).toBeUndefined();
758 expect(parseCursorCliConfigChannel("not-json")).toBeUndefined();
759 });
760​
761 it("returns no warning when the preview requirements are met", () => {
762 expect(
763 getCursorParameterizedModelPickerUnsupportedMessage({
764 version: "2026.04.08-c4e73a3",
765 channel: "lab",
766 }),
767 ).toBeUndefined();
768 });
769​
770 it("explains when the Cursor Agent version is too old", () => {
771 expect(
772 getCursorParameterizedModelPickerUnsupportedMessage({
773 version: "2026.04.07-c4e73a3",
774 channel: "lab",
775 }),
776 ).toContain("too old");
777 });
778​
779 it("explains when the Cursor Agent channel is not lab", () => {
780 expect(
781 getCursorParameterizedModelPickerUnsupportedMessage({
782 version: "2026.04.08-c4e73a3",
783 channel: "stable",
784 }),
785 ).toContain("lab channel");
786 });
787});
788​
789describe("resolveCursorAcpBaseModelId", () => {
790 it("drops bracket traits without rewriting raw ACP model ids", () => {
791 expect(resolveCursorAcpBaseModelId("gpt-5.4[reasoning=medium,context=272k]")).toBe("gpt-5.4");
792 expect(resolveCursorAcpBaseModelId("gpt-5.4-medium-fast")).toBe("gpt-5.4-medium-fast");
793 expect(resolveCursorAcpBaseModelId("claude-4.6-opus-high-thinking")).toBe(
794 "claude-4.6-opus-high-thinking",
795 );
796 expect(resolveCursorAcpBaseModelId("composer-2")).toBe("composer-2");
797 expect(resolveCursorAcpBaseModelId("auto")).toBe("auto");
798 });
799});
800​
801describe("resolveCursorAcpConfigUpdates", () => {
802 it("maps Cursor model options onto separate ACP config option updates", () => {
803 expect(
804 resolveCursorAcpConfigUpdates(parameterizedGpt54ConfigOptions, [
805 { id: "reasoning", value: "xhigh" },
806 { id: "fastMode", value: true },
807 { id: "contextWindow", value: "1m" },
808 ]),
809 ).toEqual([
810 { configId: "reasoning", value: "extra-high" },
811 { configId: "context", value: "1m" },
812 { configId: "fast", value: "true" },
813 ]);
814 });
815​
816 it("maps boolean thinking toggles when the model exposes them separately", () => {
817 expect(
818 resolveCursorAcpConfigUpdates(parameterizedClaudeConfigOptions, [
819 { id: "thinking", value: false },
820 ]),
821 ).toEqual([{ configId: "thinking", value: false }]);
822 });
823​
824 it("maps explicit fastMode: false so the adapter can clear a prior fast selection", () => {
825 expect(
826 resolveCursorAcpConfigUpdates(parameterizedGpt54ConfigOptions, [
827 { id: "fastMode", value: false },
828 ]),
829 ).toEqual([{ configId: "fast", value: "false" }]);
830 });
831​
832 it("writes Cursor effort changes through the newer model_option config when available", () => {
833 expect(
834 resolveCursorAcpConfigUpdates(parameterizedClaudeModelOptionConfigOptions, [
835 { id: "reasoning", value: "max" },
836 { id: "thinking", value: false },
837 ]),
838 ).toEqual([
839 { configId: "effort", value: "max" },
840 { configId: "thinking", value: "false" },
841 ]);
842 });
843});