Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 CursorListAvailableModelsResponse,
5 extractAskQuestions,
6 extractPlanMarkdown,
7 extractTodosAsPlan,
8} from "./CursorAcpExtension.ts";
9
10describe("CursorAcpExtension", () => {
11 it("extracts ask-question prompts from the real Cursor ACP payload shape", () => {
12 const questions = extractAskQuestions({
13 toolCallId: "ask-1",
14 title: "Need input",
15 questions: [
16 {
17 id: "language",
18 prompt: "Which language should I use?",
19 options: [
20 { id: "ts", label: "TypeScript" },
21 { id: "rs", label: "Rust" },
22 ],
23 allowMultiple: false,
24 },
25 ],
26 });
27
28 expect(questions).toEqual([
29 {
30 id: "language",
31 header: "Question",
32 question: "Which language should I use?",
33 multiSelect: false,
34 options: [
35 { label: "TypeScript", description: "TypeScript" },
36 { label: "Rust", description: "Rust" },
37 ],
38 },
39 ]);
40 });
41
42 it("defaults ask-question multi-select to false when Cursor omits allowMultiple", () => {
43 const questions = extractAskQuestions({
44 toolCallId: "ask-2",
45 questions: [
46 {
47 id: "mode",
48 prompt: "Which mode should I use?",
49 options: [
50 { id: "agent", label: "Agent" },
51 { id: "plan", label: "Plan" },
52 ],
53 },
54 ],
55 });
56
57 expect(questions).toEqual([
58 {
59 id: "mode",
60 header: "Question",
61 question: "Which mode should I use?",
62 multiSelect: false,
63 options: [
64 { label: "Agent", description: "Agent" },
65 { label: "Plan", description: "Plan" },
66 ],
67 },
68 ]);
69 });
70
71 it("extracts plan markdown from the real Cursor create-plan payload shape", () => {
72 const planMarkdown = extractPlanMarkdown({
73 toolCallId: "plan-1",
74 name: "Refactor parser",
75 overview: "Tighten ACP parsing",
76 plan: "# Plan\n\n1. Add schemas\n2. Remove casts",
77 todos: [
78 { id: "t1", content: "Add schemas", status: "in_progress" },
79 { id: "t2", content: "Remove casts", status: "pending" },
80 ],
81 isProject: false,
82 });
83
84 expect(planMarkdown).toBe("# Plan\n\n1. Add schemas\n2. Remove casts");
85 });
86
87 it("projects todo updates into a plan shape and drops invalid entries", () => {
88 expect(
89 extractTodosAsPlan({
90 toolCallId: "todos-1",
91 todos: [
92 { id: "1", content: "Inspect state", status: "completed" },
93 { id: "2", content: " Apply fix ", status: "in_progress" },
94 { id: "3", title: "Fallback title", status: "pending" },
95 { id: "4", content: "Unknown status", status: "weird_status" },
96 { id: "5", content: " " },
97 ],
98 merge: true,
99 }),
100 ).toEqual({
101 plan: [
102 { step: "Inspect state", status: "completed" },
103 { step: "Apply fix", status: "inProgress" },
104 { step: "Fallback title", status: "pending" },
105 { step: "Unknown status", status: "pending" },
106 ],
107 });
108 });
109
110 it("falls back to the title when content is present but blank", () => {
111 expect(
112 extractTodosAsPlan({
113 toolCallId: "todos-2",
114 todos: [
115 { id: "1", content: "", title: "Titled step", status: "pending" },
116 { id: "2", content: " ", title: "Whitespace content", status: "in_progress" },
117 { id: "3", content: "", title: "", status: "pending" },
118 ],
119 merge: true,
120 }),
121 ).toEqual({
122 plan: [
123 { step: "Titled step", status: "pending" },
124 { step: "Whitespace content", status: "inProgress" },
125 ],
126 });
127 });
128
129 it("decodes Cursor list_available_models responses with per-model config options", () => {
130 const decoded = CursorListAvailableModelsResponse.make({
131 models: [
132 {
133 value: "gpt-5.4",
134 name: "GPT-5.4",
135 configOptions: [
136 {
137 id: "reasoning",
138 name: "Reasoning",
139 category: "thought_level",
140 type: "select",
141 currentValue: "medium",
142 options: [
143 { value: "low", name: "Low" },
144 { value: "medium", name: "Medium" },
145 ],
146 },
147 ],
148 },
149 ],
150 });
151
152 expect(decoded.models[0]?.configOptions?.[0]?.id).toBe("reasoning");
153 });
154});