Open History to see the last commit
1import "../../index.css";
2
3import { ProjectId, ThreadId } from "@t3tools/contracts";
4import { page } from "vitest/browser";
5import { afterEach, describe, expect, it, vi } from "vitest";
6import { render } from "vitest-browser-react";
7
8import { CodexTraitsPicker } from "./CodexTraitsPicker";
9import { COMPOSER_DRAFT_STORAGE_KEY, useComposerDraftStore } from "../../composerDraftStore";
10
11async function mountPicker(props: {
12 reasoningEffort?: "low" | "medium" | "high" | "xhigh";
13 fastModeEnabled: boolean;
14}) {
15 const threadId = ThreadId.makeUnsafe("thread-codex-traits");
16 const draftsByThreadId = {} as ReturnType<
17 typeof useComposerDraftStore.getState
18 >["draftsByThreadId"];
19 draftsByThreadId[threadId] = {
20 prompt: "",
21 images: [],
22 nonPersistedImageIds: [],
23 persistedAttachments: [],
24 terminalContexts: [],
25 provider: "codex",
26 model: null,
27 modelOptions: {
28 codex: {
29 ...(props.reasoningEffort ? { reasoningEffort: props.reasoningEffort } : {}),
30 ...(props.fastModeEnabled ? { fastMode: true } : {}),
31 },
32 },
33 runtimeMode: null,
34 interactionMode: null,
35 };
36 useComposerDraftStore.setState({
37 draftsByThreadId,
38 draftThreadsByThreadId: {},
39 projectDraftThreadIdByProjectId: {
40 [ProjectId.makeUnsafe("project-codex-traits")]: threadId,
41 },
42 });
43 const host = document.createElement("div");
44 document.body.append(host);
45 const screen = await render(<CodexTraitsPicker threadId={threadId} />, { container: host });
46
47 return {
48 cleanup: async () => {
49 await screen.unmount();
50 host.remove();
51 },
52 };
53}
54
55describe("CodexTraitsPicker", () => {
56 afterEach(() => {
57 document.body.innerHTML = "";
58 localStorage.removeItem(COMPOSER_DRAFT_STORAGE_KEY);
59 useComposerDraftStore.setState({
60 draftsByThreadId: {},
61 draftThreadsByThreadId: {},
62 projectDraftThreadIdByProjectId: {},
63 });
64 });
65
66 it("shows fast mode controls", async () => {
67 const mounted = await mountPicker({
68 fastModeEnabled: false,
69 });
70
71 try {
72 await page.getByRole("button").click();
73
74 await vi.waitFor(() => {
75 const text = document.body.textContent ?? "";
76 expect(text).toContain("Fast Mode");
77 expect(text).toContain("off");
78 expect(text).toContain("on");
79 });
80 } finally {
81 await mounted.cleanup();
82 }
83 });
84
85 it("shows Fast in the trigger label when fast mode is active", async () => {
86 const mounted = await mountPicker({
87 fastModeEnabled: true,
88 });
89
90 try {
91 await vi.waitFor(() => {
92 expect(document.body.textContent ?? "").toContain("High · Fast");
93 });
94 } finally {
95 await mounted.cleanup();
96 }
97 });
98
99 it("shows only the provided effort options", async () => {
100 const mounted = await mountPicker({
101 fastModeEnabled: false,
102 });
103
104 try {
105 await page.getByRole("button").click();
106
107 await vi.waitFor(() => {
108 const text = document.body.textContent ?? "";
109 expect(text).toContain("Low");
110 expect(text).toContain("Medium");
111 expect(text).toContain("High");
112 expect(text).toContain("Extra High");
113 });
114 } finally {
115 await mounted.cleanup();
116 }
117 });
118
119 it("hydrates legacy codex persisted state into modelOptions through the picker", async () => {
120 const threadId = ThreadId.makeUnsafe("thread-codex-legacy");
121 localStorage.setItem(
122 COMPOSER_DRAFT_STORAGE_KEY,
123 JSON.stringify({
124 state: {
125 draftsByThreadId: {
126 [threadId]: {
127 prompt: "",
128 attachments: [],
129 provider: "codex",
130 model: "gpt-5.3-codex",
131 effort: "xhigh",
132 codexFastMode: true,
133 serviceTier: "fast",
134 },
135 },
136 draftThreadsByThreadId: {},
137 projectDraftThreadIdByProjectId: {},
138 },
139 version: 1,
140 }),
141 );
142 useComposerDraftStore.setState({
143 draftsByThreadId: {},
144 draftThreadsByThreadId: {},
145 projectDraftThreadIdByProjectId: {},
146 });
147
148 const host = document.createElement("div");
149 document.body.append(host);
150 const screen = await render(<CodexTraitsPicker threadId={threadId} />, { container: host });
151
152 try {
153 await useComposerDraftStore.persist.rehydrate();
154
155 await vi.waitFor(() => {
156 expect(document.body.textContent ?? "").toContain("Extra High · Fast");
157 expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.modelOptions).toEqual({
158 codex: {
159 reasoningEffort: "xhigh",
160 fastMode: true,
161 },
162 });
163 });
164 } finally {
165 await screen.unmount();
166 host.remove();
167 }
168 });
169});