Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import type { ProviderOptionDescriptor } from "@t3tools/contracts";
3import { buildTraitsTriggerDisplay } from "./TraitsPicker";
4
5function selectDescriptor(
6 id: string,
7 options: ReadonlyArray<{ id: string; label: string }>,
8 currentValue: string,
9): Extract<ProviderOptionDescriptor, { type: "select" }> {
10 return { id, label: id, type: "select", options: [...options], currentValue };
11}
12
13function fastModeDescriptor(
14 currentValue: boolean,
15): Extract<ProviderOptionDescriptor, { type: "boolean" }> {
16 return { id: "fastMode", label: "Fast Mode", type: "boolean", currentValue };
17}
18
19const EFFORT = selectDescriptor(
20 "effort",
21 [
22 { id: "high", label: "High" },
23 { id: "max", label: "Max" },
24 ],
25 "high",
26);
27const CONTEXT_WINDOW = selectDescriptor(
28 "contextWindow",
29 [
30 { id: "200k", label: "200k" },
31 { id: "1m", label: "1M" },
32 ],
33 "1m",
34);
35
36function display(descriptors: ReadonlyArray<ProviderOptionDescriptor>, fastModeEnabled: boolean) {
37 return buildTraitsTriggerDisplay({
38 descriptors,
39 primarySelectDescriptorId: "effort",
40 ultrathinkPromptControlled: false,
41 fastModeEnabled,
42 });
43}
44
45describe("buildTraitsTriggerDisplay", () => {
46 it("omits fast mode from the label entirely when it is off", () => {
47 expect(display([EFFORT, fastModeDescriptor(false), CONTEXT_WINDOW], false)).toEqual({
48 label: "High · 1M",
49 showFastModeIcon: false,
50 });
51 });
52
53 it("shows the bolt instead of a text label when fast mode is on", () => {
54 expect(display([EFFORT, fastModeDescriptor(true), CONTEXT_WINDOW], true)).toEqual({
55 label: "High · 1M",
56 showFastModeIcon: true,
57 });
58 });
59
60 it("keeps non-fastMode booleans as text labels", () => {
61 const thinking: Extract<ProviderOptionDescriptor, { type: "boolean" }> = {
62 id: "thinking",
63 label: "Thinking",
64 type: "boolean",
65 currentValue: true,
66 };
67 expect(display([EFFORT, thinking], false)).toEqual({
68 label: "High · Thinking On",
69 showFastModeIcon: false,
70 });
71 });
72
73 it("falls back to a text label when fast mode is the only trait", () => {
74 expect(display([fastModeDescriptor(true)], true)).toEqual({
75 label: "Fast",
76 showFastModeIcon: false,
77 });
78 expect(display([fastModeDescriptor(false)], false)).toEqual({
79 label: "Normal",
80 showFastModeIcon: false,
81 });
82 });
83
84 it("stays blank when descriptors resolve to no label and there is no fast mode", () => {
85 // A select with neither a currentValue nor an isDefault option yields no
86 // label. Without a fastMode descriptor present that must stay blank rather
87 // than falling through to a bogus "Normal".
88 const unresolved: Extract<ProviderOptionDescriptor, { type: "select" }> = {
89 id: "effort",
90 label: "effort",
91 type: "select",
92 options: [
93 { id: "low", label: "Low" },
94 { id: "high", label: "High" },
95 ],
96 };
97 expect(display([unresolved], false)).toEqual({ label: "", showFastModeIcon: false });
98 });
99
100 it("still renders the prompt-controlled ultrathink label alongside the bolt", () => {
101 expect(
102 buildTraitsTriggerDisplay({
103 descriptors: [EFFORT, fastModeDescriptor(true)],
104 primarySelectDescriptorId: "effort",
105 ultrathinkPromptControlled: true,
106 fastModeEnabled: true,
107 }),
108 ).toEqual({ label: "Ultrathink", showFastModeIcon: true });
109 });
110});