Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

TraitsPicker.test.ts

157 lines4.7 KB

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 };
12​
13function fastModeDescriptor(
14 currentValue: boolean,
15): Extract<ProviderOptionDescriptor, { type: "boolean" }> {
16 return { id: "fastMode", label: "Fast Mode", type: "boolean", currentValue };
18​
19function serviceTierDescriptor(
20 currentValue: "default" | "priority" | "flex",
21): Extract<ProviderOptionDescriptor, { type: "select" }> {
22 return {
23 id: "serviceTier",
24 label: "Service Tier",
25 type: "select",
26 options: [
27 { id: "default", label: "Standard", isDefault: true },
28 { id: "priority", label: "Fast" },
29 { id: "flex", label: "Flex" },
30 ],
31 currentValue,
32 };
34​
35const EFFORT = selectDescriptor(
36 "reasoningEffort",
37 [
38 { id: "high", label: "High" },
39 { id: "max", label: "Max" },
40 ],
41 "high",
42);
43const CONTEXT_WINDOW = selectDescriptor(
44 "contextWindow",
45 [
46 { id: "200k", label: "200k" },
47 { id: "1m", label: "1M" },
48 ],
49 "1m",
50);
51​
52const CODEX = ProviderDriverKind.make("codex");
53​
54function display(descriptors: ReadonlyArray<ProviderOptionDescriptor>) {
55 return buildTraitsTriggerDisplay({
56 provider: CODEX,
57 descriptors,
58 primarySelectDescriptorId: "reasoningEffort",
59 ultrathinkPromptControlled: false,
60 });
62​
63describe("buildTraitsTriggerDisplay", () => {
64 it("omits fast mode from the label entirely when it is off", () => {
65 expect(display([EFFORT, fastModeDescriptor(false), CONTEXT_WINDOW])).toEqual({
66 label: "High · 1M",
67 showFastModeIcon: false,
68 });
69 });
70​
71 it("shows the bolt instead of a text label when fast mode is on", () => {
72 expect(display([EFFORT, fastModeDescriptor(true), CONTEXT_WINDOW])).toEqual({
73 label: "High · 1M",
74 showFastModeIcon: true,
75 });
76 });
77​
78 it("treats Codex standard and fast service tiers as fast mode states", () => {
79 expect(display([EFFORT, serviceTierDescriptor("default")])).toEqual({
80 label: "High",
81 showFastModeIcon: false,
82 });
83 expect(display([EFFORT, serviceTierDescriptor("priority")])).toEqual({
84 label: "High",
85 showFastModeIcon: true,
86 });
87 });
88​
89 it("keeps other Codex service tiers in the label", () => {
90 expect(display([EFFORT, serviceTierDescriptor("flex")])).toEqual({
91 label: "High · Flex",
92 showFastModeIcon: false,
93 });
94 });
95​
96 it("keeps the Codex service tier readable when it is the only trait", () => {
97 expect(display([serviceTierDescriptor("default")])).toEqual({
98 label: "Standard",
99 showFastModeIcon: false,
100 });
101 expect(display([serviceTierDescriptor("priority")])).toEqual({
102 label: "Fast",
103 showFastModeIcon: false,
104 });
105 });
106​
107 it("keeps non-fastMode booleans as text labels", () => {
108 const thinking: Extract<ProviderOptionDescriptor, { type: "boolean" }> = {
109 id: "thinking",
110 label: "Thinking",
111 type: "boolean",
112 currentValue: true,
113 };
114 expect(display([EFFORT, thinking])).toEqual({
115 label: "High · Thinking On",
116 showFastModeIcon: false,
117 });
118 });
119​
120 it("falls back to a text label when fast mode is the only trait", () => {
121 expect(display([fastModeDescriptor(true)])).toEqual({
122 label: "Fast",
123 showFastModeIcon: false,
124 });
125 expect(display([fastModeDescriptor(false)])).toEqual({
126 label: "Normal",
127 showFastModeIcon: false,
128 });
129 });
130​
131 it("stays blank when descriptors resolve to no label and there is no fast mode", () => {
132 // A select with neither a currentValue nor an isDefault option yields no
133 // label. Without a fastMode descriptor present that must stay blank rather
134 // than falling through to a bogus "Normal".
135 const unresolved: Extract<ProviderOptionDescriptor, { type: "select" }> = {
136 id: "effort",
137 label: "effort",
138 type: "select",
139 options: [
140 { id: "low", label: "Low" },
141 { id: "high", label: "High" },
142 ],
143 };
144 expect(display([unresolved])).toEqual({ label: "", showFastModeIcon: false });
145 });
146​
147 it("still renders the prompt-controlled ultrathink label alongside the bolt", () => {
148 expect(
149 buildTraitsTriggerDisplay({
150 provider: CODEX,
151 descriptors: [EFFORT, fastModeDescriptor(true)],
152 primarySelectDescriptorId: "reasoningEffort",
153 ultrathinkPromptControlled: true,
154 }),
155 ).toEqual({ label: "Ultrathink", showFastModeIcon: true });
156 });
157});