|
1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
2 | 2 |
|
3 | | -import type { ModelCapabilities } from "@t3tools/contracts"; |
| 3 | +import { |
| 4 | + ProviderInstanceId, |
| 5 | + type ModelCapabilities, |
| 6 | + type ModelSelection, |
| 7 | +} from "@t3tools/contracts"; |
4 | 8 |
|
5 | | -import { applyProviderOptionSelection, resolveProviderOptionDescriptors } from "./providerOptions"; |
| 9 | +import { |
| 10 | + applyProviderOptionSelection, |
| 11 | + composerModelOptionSummary, |
| 12 | + resolveProviderOptionDescriptors, |
| 13 | +} from "./providerOptions"; |
6 | 14 |
|
7 | 15 | const CODEX_CAPABILITIES: ModelCapabilities = { |
8 | 16 | optionDescriptors: [ |
@@ -62,3 +70,185 @@ describe("mobile provider options", () => { |
62 | 70 | ]); |
63 | 71 | }); |
64 | 72 | }); |
| 73 | + |
| 74 | +describe("composer model option summary", () => { |
| 75 | + const selection: ModelSelection = { |
| 76 | + instanceId: ProviderInstanceId.make("test-provider"), |
| 77 | + model: "custom-model-with-a-long-name", |
| 78 | + }; |
| 79 | + function summary( |
| 80 | + capabilities: ModelCapabilities | null = CODEX_CAPABILITIES, |
| 81 | + selected = selection, |
| 82 | + reported?: ModelSelection, |
| 83 | + provider = "codex", |
| 84 | + ) { |
| 85 | + return composerModelOptionSummary({ |
| 86 | + provider, |
| 87 | + descriptors: resolveProviderOptionDescriptors({ |
| 88 | + capabilities, |
| 89 | + selections: selected.options, |
| 90 | + }), |
| 91 | + selection: selected, |
| 92 | + reportedSelection: reported, |
| 93 | + }); |
| 94 | + } |
| 95 | + |
| 96 | + it("shows the effective default reasoning and hides standard speed", () => { |
| 97 | + expect(summary()).toEqual({ reasoningLabel: "Medium", speedLabel: undefined }); |
| 98 | + }); |
| 99 | + |
| 100 | + it("shows a selected reasoning label and Codex fast tier", () => { |
| 101 | + expect( |
| 102 | + summary(CODEX_CAPABILITIES, { |
| 103 | + ...selection, |
| 104 | + options: [ |
| 105 | + { id: "reasoningEffort", value: "high" }, |
| 106 | + { id: "serviceTier", value: "priority" }, |
| 107 | + ], |
| 108 | + }), |
| 109 | + ).toEqual({ reasoningLabel: "High", speedLabel: "Fast" }); |
| 110 | + }); |
| 111 | + |
| 112 | + it.each(["reasoningEffort", "reasoning", "effort", "variant", "thinking"])( |
| 113 | + "uses advertised reasoning labels for %s", |
| 114 | + (id) => { |
| 115 | + const capabilities: ModelCapabilities = { |
| 116 | + optionDescriptors: [ |
| 117 | + { |
| 118 | + id, |
| 119 | + label: "Reasoning", |
| 120 | + type: "select", |
| 121 | + options: [{ id: "xhigh", label: "Extra High", isDefault: true }], |
| 122 | + }, |
| 123 | + ], |
| 124 | + }; |
| 125 | + const selected = { ...selection, options: [{ id, value: "xhigh" }] }; |
| 126 | + expect(summary(capabilities, selected)).toEqual({ |
| 127 | + reasoningLabel: "Extra High", |
| 128 | + speedLabel: undefined, |
| 129 | + }); |
| 130 | + }, |
| 131 | + ); |
| 132 | + |
| 133 | + it.each(["claudeAgent", "cursor", "opencode"])( |
| 134 | + "shows and clears boolean fast mode for %s", |
| 135 | + (provider) => { |
| 136 | + const capabilities: ModelCapabilities = { |
| 137 | + optionDescriptors: [{ id: "fastMode", label: "Fast Mode", type: "boolean" }], |
| 138 | + }; |
| 139 | + for (const value of [true, false]) { |
| 140 | + expect( |
| 141 | + summary( |
| 142 | + capabilities, |
| 143 | + { ...selection, options: [{ id: "fastMode", value }] }, |
| 144 | + undefined, |
| 145 | + provider, |
| 146 | + ), |
| 147 | + ).toEqual({ reasoningLabel: undefined, speedLabel: value ? "Fast" : undefined }); |
| 148 | + } |
| 149 | + }, |
| 150 | + ); |
| 151 | + |
| 152 | + it("uses matching provider-reported options when no explicit override exists", () => { |
| 153 | + const reported: ModelSelection = { |
| 154 | + ...selection, |
| 155 | + options: [ |
| 156 | + { id: "reasoningEffort", value: "high" }, |
| 157 | + { id: "serviceTier", value: "priority" }, |
| 158 | + ], |
| 159 | + }; |
| 160 | + expect(summary(CODEX_CAPABILITIES, selection, reported)).toEqual({ |
| 161 | + reasoningLabel: "High", |
| 162 | + speedLabel: "Fast", |
| 163 | + }); |
| 164 | + expect( |
| 165 | + summary( |
| 166 | + CODEX_CAPABILITIES, |
| 167 | + { |
| 168 | + ...selection, |
| 169 | + options: [ |
| 170 | + { id: "reasoningEffort", value: "medium" }, |
| 171 | + { id: "serviceTier", value: "default" }, |
| 172 | + ], |
| 173 | + }, |
| 174 | + reported, |
| 175 | + ), |
| 176 | + ).toEqual({ reasoningLabel: "Medium", speedLabel: undefined }); |
| 177 | + for (const other of [ |
| 178 | + { ...reported, model: "other-model" }, |
| 179 | + { ...reported, instanceId: ProviderInstanceId.make("other-provider") }, |
| 180 | + ]) { |
| 181 | + expect(summary(CODEX_CAPABILITIES, selection, other)).toEqual({ |
| 182 | + reasoningLabel: "Medium", |
| 183 | + speedLabel: undefined, |
| 184 | + }); |
| 185 | + } |
| 186 | + }); |
| 187 | + |
| 188 | + it("does not turn unsupported or unrelated options into indicators", () => { |
| 189 | + const selected: ModelSelection = { |
| 190 | + ...selection, |
| 191 | + options: [ |
| 192 | + { id: "reasoningEffort", value: "high" }, |
| 193 | + { id: "fastMode", value: true }, |
| 194 | + ], |
| 195 | + }; |
| 196 | + expect(summary(null, selected)).toEqual({ reasoningLabel: undefined, speedLabel: undefined }); |
| 197 | + expect(summary({ optionDescriptors: [] }, selected)).toEqual({ |
| 198 | + reasoningLabel: undefined, |
| 199 | + speedLabel: undefined, |
| 200 | + }); |
| 201 | + expect( |
| 202 | + summary({ |
| 203 | + optionDescriptors: [ |
| 204 | + { |
| 205 | + id: "contextWindow", |
| 206 | + label: "Context Window", |
| 207 | + type: "select", |
| 208 | + options: [{ id: "expanded", label: "Expanded", isDefault: true }], |
| 209 | + }, |
| 210 | + ], |
| 211 | + }), |
| 212 | + ).toEqual({ reasoningLabel: undefined, speedLabel: undefined }); |
| 213 | + }); |
| 214 | + |
| 215 | + it("recognizes only advertised Codex fast and ultrafast tiers", () => { |
| 216 | + const capabilities: ModelCapabilities = { |
| 217 | + optionDescriptors: [ |
| 218 | + { |
| 219 | + id: "serviceTier", |
| 220 | + label: "Service Tier", |
| 221 | + type: "select", |
| 222 | + options: [ |
| 223 | + { id: "default", label: "Standard", isDefault: true }, |
| 224 | + { id: "priority", label: "Fast" }, |
| 225 | + { id: "ultrafast", label: "Ultrafast" }, |
| 226 | + { id: "flex", label: "Flex" }, |
| 227 | + ], |
| 228 | + }, |
| 229 | + ], |
| 230 | + }; |
| 231 | + for (const [value, expected] of [ |
| 232 | + ["default", undefined], |
| 233 | + ["priority", "Fast"], |
| 234 | + ["ultrafast", "Ultrafast"], |
| 235 | + ["flex", undefined], |
| 236 | + ["unknown", undefined], |
| 237 | + ] as const) { |
| 238 | + const selected = { ...selection, options: [{ id: "serviceTier", value }] }; |
| 239 | + expect(summary(capabilities, selected).speedLabel).toBe(expected); |
| 240 | + expect(summary(capabilities, selected, undefined, "cursor").speedLabel).toBeUndefined(); |
| 241 | + } |
| 242 | + }); |
| 243 | + |
| 244 | + it("shows boolean thinking independently of speed", () => { |
| 245 | + const capabilities: ModelCapabilities = { |
| 246 | + optionDescriptors: [{ id: "thinking", label: "Thinking", type: "boolean" }], |
| 247 | + }; |
| 248 | + for (const value of [true, false]) { |
| 249 | + expect(summary(capabilities, { ...selection, options: [{ id: "thinking", value }] })).toEqual( |
| 250 | + { reasoningLabel: value ? "Thinking" : "No thinking", speedLabel: undefined }, |
| 251 | + ); |
| 252 | + } |
| 253 | + }); |
| 254 | +}); |
0 commit comments