|
1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
2 | | -import { ProviderDriverKind, type ProviderOptionDescriptor } from "@t3tools/contracts"; |
3 | | -import { buildTraitsTriggerDisplay, buildUnavailableModelOptionDescriptors } from "./TraitsPicker"; |
| 2 | +import { |
| 3 | + ProviderDriverKind, |
| 4 | + type ProviderOptionDescriptor, |
| 5 | + type ServerProviderModel, |
| 6 | +} from "@t3tools/contracts"; |
| 7 | +import { |
| 8 | + getReasoningLevelChange, |
| 9 | + buildTraitsTriggerDisplay, |
| 10 | + buildUnavailableModelOptionDescriptors, |
| 11 | +} from "./TraitsPicker"; |
4 | 12 |
|
5 | 13 | function selectDescriptor( |
6 | 14 | id: string, |
@@ -188,3 +196,106 @@ describe("buildUnavailableModelOptionDescriptors", () => { |
188 | 196 | ]); |
189 | 197 | }); |
190 | 198 | }); |
| 199 | + |
| 200 | +describe("reasoning level shortcuts", () => { |
| 201 | + const modelWith = ( |
| 202 | + descriptors: ReadonlyArray<ProviderOptionDescriptor>, |
| 203 | + ): ReadonlyArray<ServerProviderModel> => [ |
| 204 | + { |
| 205 | + slug: "test-model", |
| 206 | + name: "Test", |
| 207 | + isCustom: false, |
| 208 | + capabilities: { optionDescriptors: descriptors }, |
| 209 | + }, |
| 210 | + ]; |
| 211 | + const options = [ |
| 212 | + { id: "low", label: "Low" }, |
| 213 | + { id: "high", label: "High", isDefault: true }, |
| 214 | + { id: "ultrathink", label: "Ultrathink" }, |
| 215 | + ]; |
| 216 | + const input = { |
| 217 | + provider: CODEX, |
| 218 | + model: "test-model", |
| 219 | + models: modelWith([ |
| 220 | + { ...selectDescriptor("effort", options, "high"), promptInjectedValues: ["ultrathink"] }, |
| 221 | + fastModeDescriptor(false), |
| 222 | + ]), |
| 223 | + modelOptions: [{ id: "fastMode", value: true }], |
| 224 | + prompt: "Solve this", |
| 225 | + planModeEnabled: false, |
| 226 | + direction: -1 as const, |
| 227 | + }; |
| 228 | + |
| 229 | + it("steps from the default, skips unsupported levels, and preserves other traits", () => { |
| 230 | + expect( |
| 231 | + getReasoningLevelChange({ |
| 232 | + ...input, |
| 233 | + models: modelWith([ |
| 234 | + { id: "effort", label: "Effort", type: "select", options }, |
| 235 | + fastModeDescriptor(false), |
| 236 | + ]), |
| 237 | + }), |
| 238 | + ).toEqual({ |
| 239 | + prompt: "Solve this", |
| 240 | + modelOptions: [ |
| 241 | + { id: "effort", value: "low" }, |
| 242 | + { id: "fastMode", value: true }, |
| 243 | + ], |
| 244 | + }); |
| 245 | + }); |
| 246 | + |
| 247 | + it("stops at both ends", () => { |
| 248 | + expect( |
| 249 | + getReasoningLevelChange({ ...input, modelOptions: [{ id: "effort", value: "low" }] }), |
| 250 | + ).toBeNull(); |
| 251 | + expect( |
| 252 | + getReasoningLevelChange({ ...input, prompt: "Ultrathink:\nSolve this", direction: 1 }), |
| 253 | + ).toBeNull(); |
| 254 | + }); |
| 255 | + |
| 256 | + it("enters and leaves prompt-controlled ultrathink", () => { |
| 257 | + const increased = getReasoningLevelChange({ ...input, direction: 1 }); |
| 258 | + expect(increased).toEqual({ prompt: "Ultrathink:\nSolve this" }); |
| 259 | + expect(getReasoningLevelChange({ ...input, prompt: increased!.prompt })).toEqual({ |
| 260 | + prompt: "Solve this", |
| 261 | + modelOptions: [ |
| 262 | + { id: "effort", value: "high" }, |
| 263 | + { id: "fastMode", value: true }, |
| 264 | + ], |
| 265 | + }); |
| 266 | + expect( |
| 267 | + getReasoningLevelChange({ ...input, prompt: "Please ultrathink about this" }), |
| 268 | + ).toBeNull(); |
| 269 | + }); |
| 270 | + |
| 271 | + it("changes only the prompt when enabling ultrathink, and preserves slash commands", () => { |
| 272 | + expect(getReasoningLevelChange({ ...input, prompt: "", direction: 1 })).toEqual({ |
| 273 | + prompt: "Ultrathink:\n", |
| 274 | + }); |
| 275 | + expect(getReasoningLevelChange({ ...input, prompt: "/review", direction: 1 })).toEqual({ |
| 276 | + prompt: "/review", |
| 277 | + }); |
| 278 | + }); |
| 279 | + |
| 280 | + it.each(["reasoningEffort", "effort", "variant"])("supports the %s descriptor", (id) => { |
| 281 | + expect( |
| 282 | + getReasoningLevelChange({ |
| 283 | + ...input, |
| 284 | + models: modelWith([selectDescriptor(id, options, "high")]), |
| 285 | + })?.modelOptions, |
| 286 | + ).toEqual([{ id, value: "low" }]); |
| 287 | + }); |
| 288 | + |
| 289 | + it.each(["agent", "contextWindow"])("does not step through %s options", (id) => { |
| 290 | + expect( |
| 291 | + getReasoningLevelChange({ |
| 292 | + ...input, |
| 293 | + models: modelWith([selectDescriptor(id, options, "high")]), |
| 294 | + }), |
| 295 | + ).toBeNull(); |
| 296 | + }); |
| 297 | + |
| 298 | + it("does nothing when the model is unavailable", () => { |
| 299 | + expect(getReasoningLevelChange({ ...input, models: [] })).toBeNull(); |
| 300 | + }); |
| 301 | +}); |
0 commit comments