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

CursorProvider.test.ts

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