Open History to see the last commit
1import {
2 DEFAULT_MODEL_BY_PROVIDER,
3 EnvironmentId,
4 ModelSelection,
5 ThreadId,
6} from "@t3tools/contracts";
7import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime";
8import "../../index.css";
9
10import { page } from "vitest/browser";
11import { afterEach, describe, expect, it, vi } from "vitest";
12import { render } from "vitest-browser-react";
13
14import { CompactComposerControlsMenu } from "./CompactComposerControlsMenu";
15import { TraitsMenuContent } from "./TraitsPicker";
16import { useComposerDraftStore } from "../../composerDraftStore";
17
18const LOCAL_ENVIRONMENT_ID = EnvironmentId.make("environment-local");
19
20async function mountMenu(props?: { modelSelection?: ModelSelection; prompt?: string }) {
21 const threadId = ThreadId.make("thread-compact-menu");
22 const threadRef = scopeThreadRef(LOCAL_ENVIRONMENT_ID, threadId);
23 const threadKey = scopedThreadKey(threadRef);
24 const provider = props?.modelSelection?.provider ?? "claudeAgent";
25 const model = props?.modelSelection?.model ?? DEFAULT_MODEL_BY_PROVIDER[provider];
26
27 useComposerDraftStore.setState({
28 draftsByThreadKey: {
29 [threadKey]: {
30 prompt: props?.prompt ?? "",
31 images: [],
32 nonPersistedImageIds: [],
33 persistedAttachments: [],
34 terminalContexts: [],
35 modelSelectionByProvider: {
36 [provider]: {
37 provider,
38 model,
39 ...(props?.modelSelection?.options ? { options: props.modelSelection.options } : {}),
40 },
41 },
42 activeProvider: provider,
43 runtimeMode: null,
44 interactionMode: null,
45 },
46 },
47 draftThreadsByThreadKey: {},
48 logicalProjectDraftThreadKeyByLogicalProjectKey: {},
49 });
50 const host = document.createElement("div");
51 document.body.append(host);
52 const onPromptChange = vi.fn();
53 const providerOptions = props?.modelSelection?.options;
54 const models =
55 provider === "claudeAgent"
56 ? [
57 {
58 slug: "claude-opus-4-6",
59 name: "Claude Opus 4.6",
60 isCustom: false,
61 capabilities: {
62 reasoningEffortLevels: [
63 { value: "low", label: "Low" },
64 { value: "medium", label: "Medium" },
65 { value: "high", label: "High", isDefault: true },
66 { value: "max", label: "Max" },
67 { value: "ultrathink", label: "Ultrathink" },
68 ],
69 supportsFastMode: true,
70 supportsThinkingToggle: false,
71 contextWindowOptions: [],
72 promptInjectedEffortLevels: ["ultrathink"],
73 },
74 },
75 {
76 slug: "claude-haiku-4-5",
77 name: "Claude Haiku 4.5",
78 isCustom: false,
79 capabilities: {
80 reasoningEffortLevels: [],
81 supportsFastMode: false,
82 supportsThinkingToggle: true,
83 contextWindowOptions: [],
84 promptInjectedEffortLevels: [],
85 },
86 },
87 {
88 slug: "claude-sonnet-4-6",
89 name: "Claude Sonnet 4.6",
90 isCustom: false,
91 capabilities: {
92 reasoningEffortLevels: [
93 { value: "low", label: "Low" },
94 { value: "medium", label: "Medium" },
95 { value: "high", label: "High", isDefault: true },
96 { value: "ultrathink", label: "Ultrathink" },
97 ],
98 supportsFastMode: false,
99 supportsThinkingToggle: false,
100 contextWindowOptions: [],
101 promptInjectedEffortLevels: ["ultrathink"],
102 },
103 },
104 ]
105 : [
106 {
107 slug: "gpt-5.4",
108 name: "GPT-5.4",
109 isCustom: false,
110 capabilities: {
111 reasoningEffortLevels: [
112 { value: "xhigh", label: "Extra High" },
113 { value: "high", label: "High", isDefault: true },
114 ],
115 supportsFastMode: true,
116 supportsThinkingToggle: false,
117 contextWindowOptions: [],
118 promptInjectedEffortLevels: [],
119 },
120 },
121 ];
122 const screen = await render(
123 <CompactComposerControlsMenu
124 activePlan={false}
125 interactionMode="default"
126 planSidebarLabel="Plan"
127 planSidebarOpen={false}
128 runtimeMode="approval-required"
129 showInteractionModeToggle
130 traitsMenuContent={
131 <TraitsMenuContent
132 provider={provider}
133 models={models}
134 threadRef={threadRef}
135 model={model}
136 prompt={props?.prompt ?? ""}
137 modelOptions={providerOptions}
138 onPromptChange={onPromptChange}
139 />
140 }
141 onToggleInteractionMode={vi.fn()}
142 onTogglePlanSidebar={vi.fn()}
143 onRuntimeModeChange={vi.fn()}
144 />,
145 { container: host },
146 );
147
148 const cleanup = async () => {
149 await screen.unmount();
150 host.remove();
151 };
152
153 return {
154 [Symbol.asyncDispose]: cleanup,
155 cleanup,
156 };
157}
158
159describe("CompactComposerControlsMenu", () => {
160 afterEach(() => {
161 document.body.innerHTML = "";
162 useComposerDraftStore.setState({
163 draftsByThreadKey: {},
164 draftThreadsByThreadKey: {},
165 logicalProjectDraftThreadKeyByLogicalProjectKey: {},
166 stickyModelSelectionByProvider: {},
167 });
168 });
169
170 it("shows fast mode controls for Opus", async () => {
171 await using _ = await mountMenu({
172 modelSelection: { provider: "claudeAgent", model: "claude-opus-4-6" },
173 });
174
175 await page.getByLabelText("More composer controls").click();
176
177 await vi.waitFor(() => {
178 const text = document.body.textContent ?? "";
179 expect(text).toContain("Fast Mode");
180 expect(text).toContain("off");
181 expect(text).toContain("on");
182 });
183 });
184
185 it("hides fast mode controls for non-Opus Claude models", async () => {
186 await using _ = await mountMenu({
187 modelSelection: { provider: "claudeAgent", model: "claude-sonnet-4-6" },
188 });
189
190 await page.getByLabelText("More composer controls").click();
191
192 await vi.waitFor(() => {
193 expect(document.body.textContent ?? "").not.toContain("Fast Mode");
194 });
195 });
196
197 it("shows only the provided effort options", async () => {
198 await using _ = await mountMenu({
199 modelSelection: { provider: "claudeAgent", model: "claude-sonnet-4-6" },
200 });
201
202 await page.getByLabelText("More composer controls").click();
203
204 await vi.waitFor(() => {
205 const text = document.body.textContent ?? "";
206 expect(text).toContain("Low");
207 expect(text).toContain("Medium");
208 expect(text).toContain("High");
209 expect(text).not.toContain("Max");
210 expect(text).toContain("Ultrathink");
211 });
212 });
213
214 it("shows a Claude thinking on/off section for Haiku", async () => {
215 await using _ = await mountMenu({
216 modelSelection: {
217 provider: "claudeAgent",
218 model: "claude-haiku-4-5",
219 options: { thinking: true },
220 },
221 });
222
223 await page.getByLabelText("More composer controls").click();
224
225 await vi.waitFor(() => {
226 const text = document.body.textContent ?? "";
227 expect(text).toContain("Thinking");
228 expect(text).toContain("On (default)");
229 expect(text).toContain("Off");
230 });
231 });
232
233 it("shows prompt-controlled Ultrathink state with selectable effort controls", async () => {
234 await using _ = await mountMenu({
235 modelSelection: {
236 provider: "claudeAgent",
237 model: "claude-opus-4-6",
238 options: { effort: "high" },
239 },
240 prompt: "Ultrathink:\nInvestigate this",
241 });
242
243 await page.getByLabelText("More composer controls").click();
244
245 await vi.waitFor(() => {
246 const text = document.body.textContent ?? "";
247 expect(text).toContain("Effort");
248 expect(text).not.toContain("ultrathink");
249 });
250 });
251
252 it("warns when ultrathink appears in prompt body text", async () => {
253 await using _ = await mountMenu({
254 modelSelection: {
255 provider: "claudeAgent",
256 model: "claude-opus-4-6",
257 options: { effort: "high" },
258 },
259 prompt: "Ultrathink:\nplease ultrathink about this problem",
260 });
261
262 await page.getByLabelText("More composer controls").click();
263
264 await vi.waitFor(() => {
265 const text = document.body.textContent ?? "";
266 expect(text).toContain(
267 'Your prompt contains "ultrathink" in the text. Remove it to change effort.',
268 );
269 });
270 });
271
272 it("can hide the interaction mode section", async () => {
273 const host = document.createElement("div");
274 document.body.append(host);
275 const screen = await render(
276 <CompactComposerControlsMenu
277 activePlan={false}
278 interactionMode="default"
279 planSidebarLabel="Plan"
280 planSidebarOpen={false}
281 runtimeMode="approval-required"
282 showInteractionModeToggle={false}
283 onToggleInteractionMode={vi.fn()}
284 onTogglePlanSidebar={vi.fn()}
285 onRuntimeModeChange={vi.fn()}
286 />,
287 { container: host },
288 );
289
290 await page.getByLabelText("More composer controls").click();
291
292 await vi.waitFor(() => {
293 const text = document.body.textContent ?? "";
294 expect(text).not.toContain("Mode");
295 expect(text).not.toContain("Chat");
296 expect(text).not.toContain("Plan");
297 expect(text).toContain("Access");
298 expect(text).toContain("Supervised");
299 expect(text).toContain("Full access");
300 });
301
302 await screen.unmount();
303 host.remove();
304 });
305});