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

sessionConfig.test.ts

210 lines5.8 KB

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 modeState: undefined,
41 });
42​
43 expect(descriptors).toEqual([
44 {
45 id: "reasoning_effort",
46 label: "Reasoning effort",
47 type: "select",
48 options: [
49 { id: "low", label: "Low" },
50 { id: "medium", label: "Medium", description: "Balanced" },
51 ],
52 currentValue: "medium",
53 },
54 ]);
55 });
56​
57 it("flattens grouped select choices and drops empty or duplicate values", () => {
58 const descriptors = acpProviderOptionDescriptors({
59 configOptions: [
60 {
61 id: "sandbox",
62 name: "Sandbox",
63 type: "select",
64 currentValue: "workspace",
65 options: [
66 {
67 groupId: "standard",
68 name: "Standard",
69 options: [
70 { value: "workspace", name: "Workspace" },
71 { value: " ", name: "Blank" },
72 ],
73 },
74 {
75 groupId: "extra",
76 name: "Extra",
77 options: [
78 { value: "workspace", name: "Duplicate" },
79 { value: "full", name: "Full" },
80 ],
81 },
82 ],
83 },
84 ],
85 modeState: undefined,
86 });
87​
88 expect(descriptors).toEqual([
89 {
90 id: "sandbox",
91 label: "Sandbox",
92 type: "select",
93 options: [
94 { id: "workspace", label: "Workspace" },
95 { id: "full", label: "Full" },
96 ],
97 currentValue: "workspace",
98 },
99 ]);
100 });
101​
102 it("synthesizes a mode descriptor for agents without a mode config option", () => {
103 const descriptors = acpProviderOptionDescriptors({
104 configOptions: [],
105 modeState: {
106 currentModeId: "safe",
107 availableModes: [
108 { id: "safe", name: "Safe" },
109 { id: "yolo", name: "YOLO", description: "No approvals" },
110 ],
111 },
112 });
113​
114 expect(descriptors).toEqual([
115 {
116 id: ACP_SESSION_MODE_OPTION_ID,
117 label: "Mode",
118 description: "Session mode advertised by the ACP agent.",
119 type: "select",
120 options: [
121 { id: "safe", label: "Safe" },
122 { id: "yolo", label: "YOLO", description: "No approvals" },
123 ],
124 currentValue: "safe",
125 },
126 ]);
127 });
128​
129 it("suppresses the synthetic mode descriptor when modes duplicate a config option", () => {
130 const descriptors = acpProviderOptionDescriptors({
131 configOptions: [
132 {
133 id: "thinking",
134 name: "Thinking",
135 category: "thought_level",
136 type: "select",
137 currentValue: "medium",
138 options: [
139 { value: "off", name: "Thinking: off" },
140 { value: "medium", name: "Thinking: medium" },
141 ],
142 },
143 ],
144 modeState: {
145 currentModeId: "medium",
146 availableModes: [
147 { id: "off", name: "Thinking: off" },
148 { id: "medium", name: "Thinking: medium" },
149 ],
150 },
151 });
152​
153 expect(descriptors.map((descriptor) => descriptor.id)).toEqual(["thinking"]);
154 });
155​
156 it("does not let an unrelated select option hide the session modes API", () => {
157 const descriptors = acpProviderOptionDescriptors({
158 configOptions: [
159 {
160 id: "unrelated",
161 name: "Unrelated",
162 type: "select",
163 currentValue: "safe",
164 options: [
165 { value: "safe", name: "Safe" },
166 { value: "yolo", name: "YOLO" },
167 ],
168 },
169 ],
170 modeState: {
171 currentModeId: "safe",
172 availableModes: [
173 { id: "safe", name: "Safe" },
174 { id: "yolo", name: "YOLO" },
175 ],
176 },
177 });
178​
179 expect(descriptors.map((descriptor) => descriptor.id)).toEqual([
180 "unrelated",
181 ACP_SESSION_MODE_OPTION_ID,
182 ]);
183 });
184​
185 it("preserves canonical opaque option values and omits values the wire would mutate", () => {
186 const exactValue = "value:with:opaque-markers";
187 const descriptors = acpProviderOptionDescriptors({
188 configOptions: [
189 {
190 id: "opaque",
191 name: "Opaque",
192 type: "select",
193 currentValue: exactValue,
194 options: [
195 { value: exactValue, name: "Exact" },
196 { value: " value with spaces ", name: "Would be trimmed" },
197 { value: "x".repeat(257), name: "Too long" },
198 ],
199 },
200 ],
201 modeState: undefined,
202 });
203​
204 expect(descriptors[0]).toMatchObject({
205 id: "opaque",
206 currentValue: exactValue,
207 options: [{ id: exactValue, label: "Exact" }],
208 });
209 });
210});