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

CursorProvider.test.ts

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