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

CompactComposerControlsMenu.browser.tsx

308 lines9.1 KB

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