Open History to see the last commit
1import { describe, expect, it } from "@effect/vitest";
2
3import { ACP_SESSION_MODE_OPTION_ID, acpProviderOptionDescriptors } from "./sessionConfig.ts";
4
5describe("acpProviderOptionDescriptors", () => {
6 it("maps non-model select options and excludes model and collaboration categories", () => {
7 const descriptors = acpProviderOptionDescriptors({
8 configOptions: [
9 {
10 id: "model",
11 name: "Model",
12 category: "model",
13 type: "select",
14 currentValue: "gpt-5.6-sol",
15 options: [{ value: "gpt-5.6-sol", name: "GPT-5.6-Sol" }],
16 },
17 {
18 id: "collaboration_mode",
19 name: "Collaboration mode",
20 category: "collaboration_mode",
21 type: "select",
22 currentValue: "default",
23 options: [
24 { value: "default", name: "Default" },
25 { value: "plan", name: "Plan" },
26 ],
27 },
28 {
29 id: "reasoning_effort",
30 name: "Reasoning effort",
31 category: "thought_level",
32 type: "select",
33 currentValue: "medium",
34 options: [
35 { value: "low", name: "Low" },
36 { value: "medium", name: "Medium", description: "Balanced" },
37 ],
38 },
39 {
40 id: "permission_mode",
41 name: "Permission mode",
42 category: "mode",
43 type: "select",
44 currentValue: "default",
45 options: [
46 { value: "default", name: "Default" },
47 { value: "bypass", name: "Bypass" },
48 ],
49 },
50 ],
51 modeState: undefined,
52 });
53
54 expect(descriptors).toEqual([
55 {
56 id: "reasoning_effort",
57 label: "Reasoning effort",
58 type: "select",
59 options: [
60 { id: "low", label: "Low" },
61 { id: "medium", label: "Medium", description: "Balanced" },
62 ],
63 currentValue: "medium",
64 role: "reasoning",
65 },
66 {
67 id: "permission_mode",
68 label: "Permission mode",
69 type: "select",
70 options: [
71 { id: "default", label: "Default" },
72 { id: "bypass", label: "Bypass" },
73 ],
74 currentValue: "default",
75 role: "mode",
76 },
77 ]);
78 });
79
80 it("flattens grouped select choices and drops empty or duplicate values", () => {
81 const descriptors = acpProviderOptionDescriptors({
82 configOptions: [
83 {
84 id: "sandbox",
85 name: "Sandbox",
86 type: "select",
87 currentValue: "workspace",
88 options: [
89 {
90 groupId: "standard",
91 name: "Standard",
92 options: [
93 { value: "workspace", name: "Workspace" },
94 { value: " ", name: "Blank" },
95 ],
96 },
97 {
98 groupId: "extra",
99 name: "Extra",
100 options: [
101 { value: "workspace", name: "Duplicate" },
102 { value: "full", name: "Full" },
103 ],
104 },
105 ],
106 },
107 ],
108 modeState: undefined,
109 });
110
111 expect(descriptors).toEqual([
112 {
113 id: "sandbox",
114 label: "Sandbox",
115 type: "select",
116 options: [
117 { id: "workspace", label: "Workspace" },
118 { id: "full", label: "Full" },
119 ],
120 currentValue: "workspace",
121 },
122 ]);
123 });
124
125 it("synthesizes a mode descriptor for agents without a mode config option", () => {
126 const descriptors = acpProviderOptionDescriptors({
127 configOptions: [],
128 modeState: {
129 currentModeId: "safe",
130 availableModes: [
131 { id: "safe", name: "Safe" },
132 { id: "yolo", name: "YOLO", description: "No approvals" },
133 ],
134 },
135 });
136
137 expect(descriptors).toEqual([
138 {
139 id: ACP_SESSION_MODE_OPTION_ID,
140 label: "Mode",
141 description: "Session mode advertised by the ACP agent.",
142 type: "select",
143 options: [
144 { id: "safe", label: "Safe" },
145 { id: "yolo", label: "YOLO", description: "No approvals" },
146 ],
147 currentValue: "safe",
148 role: "mode",
149 },
150 ]);
151 });
152
153 it("suppresses the synthetic mode descriptor when modes duplicate a config option", () => {
154 const descriptors = acpProviderOptionDescriptors({
155 configOptions: [
156 {
157 id: "thinking",
158 name: "Thinking",
159 category: "thought_level",
160 type: "select",
161 currentValue: "medium",
162 options: [
163 { value: "off", name: "Thinking: off" },
164 { value: "medium", name: "Thinking: medium" },
165 ],
166 },
167 ],
168 modeState: {
169 currentModeId: "medium",
170 availableModes: [
171 { id: "off", name: "Thinking: off" },
172 { id: "medium", name: "Thinking: medium" },
173 ],
174 },
175 });
176
177 expect(descriptors.map((descriptor) => descriptor.id)).toEqual(["thinking"]);
178 });
179
180 it("does not let an unrelated select option hide the session modes API", () => {
181 const descriptors = acpProviderOptionDescriptors({
182 configOptions: [
183 {
184 id: "unrelated",
185 name: "Unrelated",
186 type: "select",
187 currentValue: "safe",
188 options: [
189 { value: "safe", name: "Safe" },
190 { value: "yolo", name: "YOLO" },
191 ],
192 },
193 ],
194 modeState: {
195 currentModeId: "safe",
196 availableModes: [
197 { id: "safe", name: "Safe" },
198 { id: "yolo", name: "YOLO" },
199 ],
200 },
201 });
202
203 expect(descriptors.map((descriptor) => descriptor.id)).toEqual([
204 "unrelated",
205 ACP_SESSION_MODE_OPTION_ID,
206 ]);
207 });
208
209 it("preserves canonical opaque option values and omits values the wire would mutate", () => {
210 const exactValue = "value:with:opaque-markers";
211 const descriptors = acpProviderOptionDescriptors({
212 configOptions: [
213 {
214 id: "opaque",
215 name: "Opaque",
216 type: "select",
217 currentValue: exactValue,
218 options: [
219 { value: exactValue, name: "Exact" },
220 { value: " value with spaces ", name: "Would be trimmed" },
221 { value: "x".repeat(257), name: "Too long" },
222 ],
223 },
224 ],
225 modeState: undefined,
226 });
227
228 expect(descriptors[0]).toMatchObject({
229 id: "opaque",
230 currentValue: exactValue,
231 options: [{ id: exactValue, label: "Exact" }],
232 });
233 });
234});