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

sessionConfig.test.ts

263 lines7.2 KB

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