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