Open History to see the last commit
1import "../../index.css";
2
3import {
4 type ModelSelection,
5 ClaudeModelOptions,
6 CodexModelOptions,
7 DEFAULT_MODEL_BY_PROVIDER,
8 DEFAULT_SERVER_SETTINGS,
9 EnvironmentId,
10 type ServerProvider,
11 ThreadId,
12} from "@t3tools/contracts";
13import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime";
14import { page } from "vitest/browser";
15import { useCallback } from "react";
16import { afterEach, describe, expect, it, vi } from "vitest";
17import { render } from "vitest-browser-react";
18
19import { TraitsPicker } from "./TraitsPicker";
20import {
21 COMPOSER_DRAFT_STORAGE_KEY,
22 ComposerThreadDraftState,
23 useComposerDraftStore,
24 useComposerThreadDraft,
25 useEffectiveComposerModelState,
26} from "../../composerDraftStore";
27import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
28
29// ── Claude TraitsPicker tests ─────────────────────────────────────────
30
31const LOCAL_ENVIRONMENT_ID = EnvironmentId.makeUnsafe("environment-local");
32const CLAUDE_THREAD_ID = ThreadId.makeUnsafe("thread-claude-traits");
33const CLAUDE_THREAD_REF = scopeThreadRef(LOCAL_ENVIRONMENT_ID, CLAUDE_THREAD_ID);
34const CLAUDE_THREAD_KEY = scopedThreadKey(CLAUDE_THREAD_REF);
35const CODEX_THREAD_ID = ThreadId.makeUnsafe("thread-codex-traits");
36const CODEX_THREAD_REF = scopeThreadRef(LOCAL_ENVIRONMENT_ID, CODEX_THREAD_ID);
37const CODEX_THREAD_KEY = scopedThreadKey(CODEX_THREAD_REF);
38const TEST_PROVIDERS: ReadonlyArray<ServerProvider> = [
39 {
40 provider: "codex",
41 enabled: true,
42 installed: true,
43 version: "0.1.0",
44 status: "ready",
45 auth: { status: "authenticated" },
46 checkedAt: "2026-01-01T00:00:00.000Z",
47 models: [
48 {
49 slug: "gpt-5.4",
50 name: "GPT-5.4",
51 isCustom: false,
52 capabilities: {
53 reasoningEffortLevels: [
54 { value: "xhigh", label: "Extra High" },
55 { value: "high", label: "High", isDefault: true },
56 ],
57 supportsFastMode: true,
58 supportsThinkingToggle: false,
59 contextWindowOptions: [],
60 promptInjectedEffortLevels: [],
61 },
62 },
63 ],
64 },
65 {
66 provider: "claudeAgent",
67 enabled: true,
68 installed: true,
69 version: "0.1.0",
70 status: "ready",
71 auth: { status: "authenticated" },
72 checkedAt: "2026-01-01T00:00:00.000Z",
73 models: [
74 {
75 slug: "claude-opus-4-6",
76 name: "Claude Opus 4.6",
77 isCustom: false,
78 capabilities: {
79 reasoningEffortLevels: [
80 { value: "low", label: "Low" },
81 { value: "medium", label: "Medium" },
82 { value: "high", label: "High", isDefault: true },
83 { value: "max", label: "Max" },
84 { value: "ultrathink", label: "Ultrathink" },
85 ],
86 supportsFastMode: true,
87 supportsThinkingToggle: false,
88 contextWindowOptions: [],
89 promptInjectedEffortLevels: ["ultrathink"],
90 },
91 },
92 {
93 slug: "claude-sonnet-4-6",
94 name: "Claude Sonnet 4.6",
95 isCustom: false,
96 capabilities: {
97 reasoningEffortLevels: [
98 { value: "low", label: "Low" },
99 { value: "medium", label: "Medium" },
100 { value: "high", label: "High", isDefault: true },
101 { value: "ultrathink", label: "Ultrathink" },
102 ],
103 supportsFastMode: false,
104 supportsThinkingToggle: false,
105 contextWindowOptions: [],
106 promptInjectedEffortLevels: ["ultrathink"],
107 },
108 },
109 {
110 slug: "claude-haiku-4-5",
111 name: "Claude Haiku 4.5",
112 isCustom: false,
113 capabilities: {
114 reasoningEffortLevels: [],
115 supportsFastMode: false,
116 supportsThinkingToggle: true,
117 contextWindowOptions: [],
118 promptInjectedEffortLevels: [],
119 },
120 },
121 ],
122 },
123];
124
125function ClaudeTraitsPickerHarness(props: {
126 model: string;
127 fallbackModelSelection: ModelSelection | null;
128 triggerVariant?: "ghost" | "outline";
129}) {
130 const prompt = useComposerThreadDraft(CLAUDE_THREAD_REF).prompt;
131 const setPrompt = useComposerDraftStore((store) => store.setPrompt);
132 const { modelOptions, selectedModel } = useEffectiveComposerModelState({
133 threadRef: CLAUDE_THREAD_REF,
134 providers: TEST_PROVIDERS,
135 selectedProvider: "claudeAgent",
136 threadModelSelection: props.fallbackModelSelection,
137 projectModelSelection: null,
138 settings: {
139 ...DEFAULT_SERVER_SETTINGS,
140 ...DEFAULT_CLIENT_SETTINGS,
141 },
142 });
143 const handlePromptChange = useCallback(
144 (nextPrompt: string) => {
145 setPrompt(CLAUDE_THREAD_REF, nextPrompt);
146 },
147 [setPrompt],
148 );
149
150 return (
151 <TraitsPicker
152 provider="claudeAgent"
153 models={TEST_PROVIDERS[1]!.models}
154 threadRef={CLAUDE_THREAD_REF}
155 model={selectedModel ?? props.model}
156 prompt={prompt}
157 modelOptions={modelOptions?.claudeAgent}
158 onPromptChange={handlePromptChange}
159 triggerVariant={props.triggerVariant}
160 />
161 );
162}
163
164async function mountClaudePicker(props?: {
165 model?: string;
166 prompt?: string;
167 options?: ClaudeModelOptions;
168 fallbackModelOptions?: {
169 effort?: "low" | "medium" | "high" | "max" | "ultrathink";
170 thinking?: boolean;
171 fastMode?: boolean;
172 } | null;
173 skipDraftModelOptions?: boolean;
174 triggerVariant?: "ghost" | "outline";
175}) {
176 const model = props?.model ?? "claude-opus-4-6";
177 const claudeOptions = !props?.skipDraftModelOptions ? props?.options : undefined;
178 const draftsByThreadKey: Record<string, ComposerThreadDraftState> = {
179 [CLAUDE_THREAD_KEY]: {
180 prompt: props?.prompt ?? "",
181 images: [],
182 nonPersistedImageIds: [],
183 persistedAttachments: [],
184 terminalContexts: [],
185 modelSelectionByProvider: props?.skipDraftModelOptions
186 ? {}
187 : {
188 claudeAgent: {
189 provider: "claudeAgent",
190 model,
191 ...(claudeOptions && Object.keys(claudeOptions).length > 0
192 ? { options: claudeOptions }
193 : {}),
194 },
195 },
196 activeProvider: "claudeAgent",
197 runtimeMode: null,
198 interactionMode: null,
199 },
200 };
201 useComposerDraftStore.setState({
202 draftsByThreadKey,
203 draftThreadsByThreadKey: {},
204 logicalProjectDraftThreadKeyByLogicalProjectKey: {},
205 });
206 const host = document.createElement("div");
207 document.body.append(host);
208 const fallbackModelSelection =
209 props?.fallbackModelOptions !== undefined
210 ? ({
211 provider: "claudeAgent",
212 model,
213 ...(props.fallbackModelOptions ? { options: props.fallbackModelOptions } : {}),
214 } satisfies ModelSelection)
215 : null;
216 const screen = await render(
217 <ClaudeTraitsPickerHarness
218 model={model}
219 fallbackModelSelection={fallbackModelSelection}
220 {...(props?.triggerVariant ? { triggerVariant: props.triggerVariant } : {})}
221 />,
222 { container: host },
223 );
224
225 const cleanup = async () => {
226 await screen.unmount();
227 host.remove();
228 };
229
230 return {
231 [Symbol.asyncDispose]: cleanup,
232 cleanup,
233 };
234}
235
236describe("TraitsPicker (Claude)", () => {
237 afterEach(() => {
238 document.body.innerHTML = "";
239 useComposerDraftStore.setState({
240 draftsByThreadKey: {},
241 draftThreadsByThreadKey: {},
242 logicalProjectDraftThreadKeyByLogicalProjectKey: {},
243 stickyModelSelectionByProvider: {},
244 });
245 });
246
247 it("shows fast mode controls for Opus", async () => {
248 await using _ = await mountClaudePicker();
249
250 await page.getByRole("button").click();
251
252 await vi.waitFor(() => {
253 const text = document.body.textContent ?? "";
254 expect(text).toContain("Fast Mode");
255 expect(text).toContain("off");
256 expect(text).toContain("on");
257 });
258 });
259
260 it("hides fast mode controls for non-Opus models", async () => {
261 await using _ = await mountClaudePicker({ model: "claude-sonnet-4-6" });
262
263 await page.getByRole("button").click();
264
265 await vi.waitFor(() => {
266 expect(document.body.textContent ?? "").not.toContain("Fast Mode");
267 });
268 });
269
270 it("shows only the provided effort options", async () => {
271 await using _ = await mountClaudePicker({
272 model: "claude-sonnet-4-6",
273 });
274
275 await page.getByRole("button").click();
276
277 await vi.waitFor(() => {
278 const text = document.body.textContent ?? "";
279 expect(text).toContain("Low");
280 expect(text).toContain("Medium");
281 expect(text).toContain("High");
282 expect(text).not.toContain("Max");
283 expect(text).toContain("Ultrathink");
284 });
285 });
286
287 it("shows a th inking on/off dropdown for Haiku", async () => {
288 await using _ = await mountClaudePicker({
289 model: "claude-haiku-4-5",
290 options: { thinking: true },
291 });
292
293 await vi.waitFor(() => {
294 expect(document.body.textContent ?? "").toContain("Thinking On");
295 });
296 await page.getByRole("button").click();
297
298 await vi.waitFor(() => {
299 const text = document.body.textContent ?? "";
300 expect(text).toContain("Thinking");
301 expect(text).toContain("On (default)");
302 expect(text).toContain("Off");
303 });
304 });
305
306 it("shows prompt-controlled Ultrathink state with selectable effort controls", async () => {
307 await using _ = await mountClaudePicker({
308 model: "claude-opus-4-6",
309 options: { effort: "high" },
310 prompt: "Ultrathink:\nInvestigate this",
311 });
312
313 await vi.waitFor(() => {
314 expect(document.body.textContent ?? "").toContain("Ultrathink");
315 expect(document.body.textContent ?? "").not.toContain("Ultrathink · Prompt");
316 });
317 await page.getByRole("button").click();
318
319 await vi.waitFor(() => {
320 const text = document.body.textContent ?? "";
321 expect(text).toContain("Effort");
322 expect(text).not.toContain("ultrathink");
323 });
324 });
325
326 it("warns when ultrathink appears in prompt body text", async () => {
327 await using _ = await mountClaudePicker({
328 model: "claude-opus-4-6",
329 options: { effort: "high" },
330 prompt: "Ultrathink:\nplease ultrathink about this problem",
331 });
332
333 await page.getByRole("button").click();
334
335 await vi.waitFor(() => {
336 const text = document.body.textContent ?? "";
337 expect(text).toContain(
338 'Your prompt contains "ultrathink" in the text. Remove it to change effort.',
339 );
340 });
341 });
342
343 it("persists sticky claude model options when traits change", async () => {
344 await using _ = await mountClaudePicker({
345 model: "claude-opus-4-6",
346 options: { effort: "medium", fastMode: false },
347 });
348
349 await page.getByRole("button").click();
350 await page.getByRole("menuitemradio", { name: "Max" }).click();
351
352 expect(
353 useComposerDraftStore.getState().stickyModelSelectionByProvider.claudeAgent,
354 ).toMatchObject({
355 provider: "claudeAgent",
356 options: {
357 effort: "max",
358 },
359 });
360 });
361
362 it("accepts outline trigger styling", async () => {
363 await using _ = await mountClaudePicker({
364 triggerVariant: "outline",
365 });
366
367 const button = document.querySelector("button");
368 if (!(button instanceof HTMLButtonElement)) {
369 throw new Error("Expected traits trigger button to be rendered.");
370 }
371 expect(button.className).toContain("border-input");
372 expect(button.className).toContain("bg-popover");
373 });
374});
375
376// ── Codex TraitsPicker tests ──────────────────────────────────────────
377
378async function mountCodexPicker(props: { model?: string; options?: CodexModelOptions }) {
379 const model = props.model ?? DEFAULT_MODEL_BY_PROVIDER.codex;
380 const draftsByThreadKey: Record<string, ComposerThreadDraftState> = {
381 [CODEX_THREAD_KEY]: {
382 prompt: "",
383 images: [],
384 nonPersistedImageIds: [],
385 persistedAttachments: [],
386 terminalContexts: [],
387 modelSelectionByProvider: {
388 codex: {
389 provider: "codex",
390 model,
391 ...(props.options ? { options: props.options } : {}),
392 },
393 },
394 activeProvider: "codex",
395 runtimeMode: null,
396 interactionMode: null,
397 },
398 };
399
400 useComposerDraftStore.setState({
401 draftsByThreadKey,
402 draftThreadsByThreadKey: {},
403 logicalProjectDraftThreadKeyByLogicalProjectKey: {
404 "environment-local:project-codex-traits": CODEX_THREAD_KEY,
405 },
406 });
407 const host = document.createElement("div");
408 document.body.append(host);
409 const screen = await render(
410 <TraitsPicker
411 provider="codex"
412 models={TEST_PROVIDERS[0]!.models}
413 threadRef={CODEX_THREAD_REF}
414 model={props.model ?? DEFAULT_MODEL_BY_PROVIDER.codex}
415 prompt=""
416 modelOptions={props.options}
417 onPromptChange={() => {}}
418 />,
419 { container: host },
420 );
421
422 const cleanup = async () => {
423 await screen.unmount();
424 host.remove();
425 };
426
427 return {
428 [Symbol.asyncDispose]: cleanup,
429 cleanup,
430 };
431}
432
433describe("TraitsPicker (Codex)", () => {
434 afterEach(() => {
435 document.body.innerHTML = "";
436 localStorage.removeItem(COMPOSER_DRAFT_STORAGE_KEY);
437 useComposerDraftStore.setState({
438 draftsByThreadKey: {},
439 draftThreadsByThreadKey: {},
440 logicalProjectDraftThreadKeyByLogicalProjectKey: {},
441 stickyModelSelectionByProvider: {},
442 });
443 });
444
445 it("shows fast mode controls", async () => {
446 await using _ = await mountCodexPicker({
447 options: { fastMode: false },
448 });
449
450 await page.getByRole("button").click();
451
452 await vi.waitFor(() => {
453 const text = document.body.textContent ?? "";
454 expect(text).toContain("Fast Mode");
455 expect(text).toContain("off");
456 expect(text).toContain("on");
457 });
458 });
459
460 it("shows Fast in the trigger label when fast mode is active", async () => {
461 await using _ = await mountCodexPicker({
462 options: { fastMode: true },
463 });
464
465 await vi.waitFor(() => {
466 expect(document.body.textContent ?? "").toContain("High · Fast");
467 });
468 });
469
470 it("shows only the provided effort options", async () => {
471 await using _ = await mountCodexPicker({
472 options: { fastMode: false },
473 });
474
475 await page.getByRole("button").click();
476
477 await vi.waitFor(() => {
478 const text = document.body.textContent ?? "";
479 expect(text).toContain("Extra High");
480 expect(text).toContain("High");
481 expect(text).not.toContain("Low");
482 expect(text).not.toContain("Medium");
483 });
484 });
485
486 it("persists sticky codex model options when traits change", async () => {
487 await using _ = await mountCodexPicker({
488 options: { fastMode: false },
489 });
490
491 await page.getByRole("button").click();
492 await page.getByRole("menuitemradio", { name: "on" }).click();
493
494 expect(useComposerDraftStore.getState().stickyModelSelectionByProvider.codex).toMatchObject({
495 provider: "codex",
496 options: { fastMode: true },
497 });
498 });
499});