Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { ProviderDriverKind, type ProviderOptionDescriptor } from "@t3tools/contracts";
3import { buildTraitsTriggerDisplay } from "./TraitsPicker";
4
5function selectDescriptor(
6 id: string,
7 options: ReadonlyArray<{ id: string; label: string; isDefault?: boolean }>,
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 "reasoningEffort",
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
36const CODEX = ProviderDriverKind.make("codex");
37
38function display(descriptors: ReadonlyArray<ProviderOptionDescriptor>) {
39 return buildTraitsTriggerDisplay({
40 provider: CODEX,
41 descriptors,
42 primarySelectDescriptorId: "reasoningEffort",
43 ultrathinkPromptControlled: false,
44 });
45}
46
47describe("buildTraitsTriggerDisplay", () => {
48 it("omits fast mode from the label entirely when it is off", () => {
49 expect(display([EFFORT, fastModeDescriptor(false), CONTEXT_WINDOW])).toEqual({
50 label: "High · 1M",
51 showFastModeIcon: false,
52 });
53 });
54
55 it("shows the bolt instead of a text label when fast mode is on", () => {
56 expect(display([EFFORT, fastModeDescriptor(true), CONTEXT_WINDOW])).toEqual({
57 label: "High · 1M",
58 showFastModeIcon: true,
59 });
60 });
61
62 it("renders Codex's Standard and Fast service tiers as fast mode", () => {
63 const serviceTier = selectDescriptor(
64 "serviceTier",
65 [
66 { id: "default", label: "Standard", isDefault: true },
67 { id: "priority", label: "Fast" },
68 ],
69 "default",
70 );
71
72 expect(display([EFFORT, serviceTier])).toEqual({
73 label: "High",
74 showFastModeIcon: false,
75 });
76 expect(display([EFFORT, { ...serviceTier, currentValue: "priority" }])).toEqual({
77 label: "High",
78 showFastModeIcon: true,
79 });
80 });
81
82 it("keeps non-fastMode booleans as text labels", () => {
83 const thinking: Extract<ProviderOptionDescriptor, { type: "boolean" }> = {
84 id: "thinking",
85 label: "Thinking",
86 type: "boolean",
87 currentValue: true,
88 };
89 expect(display([EFFORT, thinking])).toEqual({
90 label: "High · Thinking On",
91 showFastModeIcon: false,
92 });
93 });
94
95 it("falls back to a text label when fast mode is the only trait", () => {
96 expect(display([fastModeDescriptor(true)])).toEqual({
97 label: "Fast",
98 showFastModeIcon: false,
99 });
100 expect(display([fastModeDescriptor(false)])).toEqual({
101 label: "Normal",
102 showFastModeIcon: false,
103 });
104 });
105
106 it("stays blank when descriptors resolve to no label and there is no fast mode", () => {
107 // A select with neither a currentValue nor an isDefault option yields no
108 // label. Without a fastMode descriptor present that must stay blank rather
109 // than falling through to a bogus "Normal".
110 const unresolved: Extract<ProviderOptionDescriptor, { type: "select" }> = {
111 id: "effort",
112 label: "effort",
113 type: "select",
114 options: [
115 { id: "low", label: "Low" },
116 { id: "high", label: "High" },
117 ],
118 };
119 expect(display([unresolved])).toEqual({ label: "", showFastModeIcon: false });
120 });
121
122 it("still renders the prompt-controlled ultrathink label alongside the bolt", () => {
123 expect(
124 buildTraitsTriggerDisplay({
125 provider: CODEX,
126 descriptors: [EFFORT, fastModeDescriptor(true)],
127 primarySelectDescriptorId: "reasoningEffort",
128 ultrathinkPromptControlled: true,
129 }),
130 ).toEqual({ label: "Ultrathink", showFastModeIcon: true });
131 });
132});