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

CursorAcpExtension.test.ts

108 lines3.0 KB

1import { describe, expect, it } from "vitest";
2​
3import {
4 extractAskQuestions,
5 extractPlanMarkdown,
6 extractTodosAsPlan,
7} from "./CursorAcpExtension.ts";
8​
9describe("CursorAcpExtension", () => {
10 it("extracts ask-question prompts from the real Cursor ACP payload shape", () => {
11 const questions = extractAskQuestions({
12 toolCallId: "ask-1",
13 title: "Need input",
14 questions: [
15 {
16 id: "language",
17 prompt: "Which language should I use?",
18 options: [
19 { id: "ts", label: "TypeScript" },
20 { id: "rs", label: "Rust" },
21 ],
22 allowMultiple: false,
23 },
24 ],
25 });
26​
27 expect(questions).toEqual([
28 {
29 id: "language",
30 header: "Question",
31 question: "Which language should I use?",
32 multiSelect: false,
33 options: [
34 { label: "TypeScript", description: "TypeScript" },
35 { label: "Rust", description: "Rust" },
36 ],
37 },
38 ]);
39 });
40​
41 it("defaults ask-question multi-select to false when Cursor omits allowMultiple", () => {
42 const questions = extractAskQuestions({
43 toolCallId: "ask-2",
44 questions: [
45 {
46 id: "mode",
47 prompt: "Which mode should I use?",
48 options: [
49 { id: "agent", label: "Agent" },
50 { id: "plan", label: "Plan" },
51 ],
52 },
53 ],
54 });
55​
56 expect(questions).toEqual([
57 {
58 id: "mode",
59 header: "Question",
60 question: "Which mode should I use?",
61 multiSelect: false,
62 options: [
63 { label: "Agent", description: "Agent" },
64 { label: "Plan", description: "Plan" },
65 ],
66 },
67 ]);
68 });
69​
70 it("extracts plan markdown from the real Cursor create-plan payload shape", () => {
71 const planMarkdown = extractPlanMarkdown({
72 toolCallId: "plan-1",
73 name: "Refactor parser",
74 overview: "Tighten ACP parsing",
75 plan: "# Plan\n\n1. Add schemas\n2. Remove casts",
76 todos: [
77 { id: "t1", content: "Add schemas", status: "in_progress" },
78 { id: "t2", content: "Remove casts", status: "pending" },
79 ],
80 isProject: false,
81 });
82​
83 expect(planMarkdown).toBe("# Plan\n\n1. Add schemas\n2. Remove casts");
84 });
85​
86 it("projects todo updates into a plan shape and drops invalid entries", () => {
87 expect(
88 extractTodosAsPlan({
89 toolCallId: "todos-1",
90 todos: [
91 { id: "1", content: "Inspect state", status: "completed" },
92 { id: "2", content: " Apply fix ", status: "in_progress" },
93 { id: "3", title: "Fallback title", status: "pending" },
94 { id: "4", content: "Unknown status", status: "weird_status" },
95 { id: "5", content: " " },
96 ],
97 merge: true,
98 }),
99 ).toEqual({
100 plan: [
101 { step: "Inspect state", status: "completed" },
102 { step: "Apply fix", status: "inProgress" },
103 { step: "Fallback title", status: "pending" },
104 { step: "Unknown status", status: "pending" },
105 ],
106 });
107 });
108});