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

appSettings.test.ts

222 lines7.2 KB

1import { Schema } from "effect";
2import { describe, expect, it } from "vitest";
3​
4import {
5 AppSettingsSchema,
6 DEFAULT_TIMESTAMP_FORMAT,
7 getAppModelOptions,
8 getCustomModelOptionsByProvider,
9 getCustomModelsByProvider,
10 getCustomModelsForProvider,
11 getDefaultCustomModelsForProvider,
12 MODEL_PROVIDER_SETTINGS,
13 normalizeCustomModelSlugs,
14 patchCustomModels,
15 resolveAppModelSelection,
16} from "./appSettings";
17​
18describe("normalizeCustomModelSlugs", () => {
19 it("normalizes aliases, removes built-ins, and deduplicates values", () => {
20 expect(
21 normalizeCustomModelSlugs([
22 " custom/internal-model ",
23 "gpt-5.3-codex",
24 "5.3",
25 "custom/internal-model",
26 "",
27 null,
28 ]),
29 ).toEqual(["custom/internal-model"]);
30 });
31​
32 it("normalizes provider-specific aliases for claude", () => {
33 expect(normalizeCustomModelSlugs(["sonnet"], "claudeAgent")).toEqual([]);
34 expect(normalizeCustomModelSlugs(["claude/custom-sonnet"], "claudeAgent")).toEqual([
35 "claude/custom-sonnet",
36 ]);
37 });
38});
39​
40describe("getAppModelOptions", () => {
41 it("appends saved custom models after the built-in options", () => {
42 const options = getAppModelOptions("codex", ["custom/internal-model"]);
43​
44 expect(options.map((option) => option.slug)).toEqual([
45 "gpt-5.4",
46 "gpt-5.4-mini",
47 "gpt-5.3-codex",
48 "gpt-5.3-codex-spark",
49 "gpt-5.2-codex",
50 "gpt-5.2",
51 "custom/internal-model",
52 ]);
53 });
54​
55 it("keeps the currently selected custom model available even if it is no longer saved", () => {
56 const options = getAppModelOptions("codex", [], "custom/selected-model");
57​
58 expect(options.at(-1)).toEqual({
59 slug: "custom/selected-model",
60 name: "custom/selected-model",
61 isCustom: true,
62 });
63 });
64 it("keeps a saved custom provider model available as an exact slug option", () => {
65 const options = getAppModelOptions("claudeAgent", ["claude/custom-opus"], "claude/custom-opus");
66​
67 expect(options.some((option) => option.slug === "claude/custom-opus" && option.isCustom)).toBe(
68 true,
69 );
70 });
71});
72​
73describe("resolveAppModelSelection", () => {
74 it("preserves saved custom model slugs instead of falling back to the default", () => {
75 expect(
76 resolveAppModelSelection(
77 "codex",
78 { codex: ["galapagos-alpha"], claudeAgent: [] },
79 "galapagos-alpha",
80 ),
81 ).toBe("galapagos-alpha");
82 });
83​
84 it("falls back to the provider default when no model is selected", () => {
85 expect(resolveAppModelSelection("codex", { codex: [], claudeAgent: [] }, "")).toBe("gpt-5.4");
86 });
87​
88 it("resolves display names through the shared resolver", () => {
89 expect(resolveAppModelSelection("codex", { codex: [], claudeAgent: [] }, "GPT-5.3 Codex")).toBe(
90 "gpt-5.3-codex",
91 );
92 });
93​
94 it("resolves aliases through the shared resolver", () => {
95 expect(resolveAppModelSelection("claudeAgent", { codex: [], claudeAgent: [] }, "sonnet")).toBe(
96 "claude-sonnet-4-6",
97 );
98 });
99​
100 it("resolves transient selected custom models included in app model options", () => {
101 expect(
102 resolveAppModelSelection("codex", { codex: [], claudeAgent: [] }, "custom/selected-model"),
103 ).toBe("custom/selected-model");
104 });
105});
106​
107describe("timestamp format defaults", () => {
108 it("defaults timestamp format to locale", () => {
109 expect(DEFAULT_TIMESTAMP_FORMAT).toBe("locale");
110 });
111});
112​
113describe("provider-specific custom models", () => {
114 it("includes provider-specific custom slugs in non-codex model lists", () => {
115 const claudeOptions = getAppModelOptions("claudeAgent", ["claude/custom-opus"]);
116​
117 expect(claudeOptions.some((option) => option.slug === "claude/custom-opus")).toBe(true);
118 });
119});
120​
121describe("provider-indexed custom model settings", () => {
122 const settings = {
123 customCodexModels: ["custom/codex-model"],
124 customClaudeModels: ["claude/custom-opus"],
125 } as const;
126​
127 it("exports one provider config per provider", () => {
128 expect(MODEL_PROVIDER_SETTINGS.map((config) => config.provider)).toEqual([
129 "codex",
130 "claudeAgent",
131 ]);
132 });
133​
134 it("reads custom models for each provider", () => {
135 expect(getCustomModelsForProvider(settings, "codex")).toEqual(["custom/codex-model"]);
136 expect(getCustomModelsForProvider(settings, "claudeAgent")).toEqual(["claude/custom-opus"]);
137 });
138​
139 it("reads default custom models for each provider", () => {
140 const defaults = {
141 customCodexModels: ["default/codex-model"],
142 customClaudeModels: ["claude/default-opus"],
143 } as const;
144​
145 expect(getDefaultCustomModelsForProvider(defaults, "codex")).toEqual(["default/codex-model"]);
146 expect(getDefaultCustomModelsForProvider(defaults, "claudeAgent")).toEqual([
147 "claude/default-opus",
148 ]);
149 });
150​
151 it("patches custom models for codex", () => {
152 expect(patchCustomModels("codex", ["custom/codex-model"])).toEqual({
153 customCodexModels: ["custom/codex-model"],
154 });
155 });
156​
157 it("patches custom models for claude", () => {
158 expect(patchCustomModels("claudeAgent", ["claude/custom-opus"])).toEqual({
159 customClaudeModels: ["claude/custom-opus"],
160 });
161 });
162​
163 it("builds a complete provider-indexed custom model record", () => {
164 expect(getCustomModelsByProvider(settings)).toEqual({
165 codex: ["custom/codex-model"],
166 claudeAgent: ["claude/custom-opus"],
167 });
168 });
169​
170 it("builds provider-indexed model options including custom models", () => {
171 const modelOptionsByProvider = getCustomModelOptionsByProvider(settings);
172​
173 expect(
174 modelOptionsByProvider.codex.some((option) => option.slug === "custom/codex-model"),
175 ).toBe(true);
176 expect(
177 modelOptionsByProvider.claudeAgent.some((option) => option.slug === "claude/custom-opus"),
178 ).toBe(true);
179 });
180​
181 it("normalizes and deduplicates custom model options per provider", () => {
182 const modelOptionsByProvider = getCustomModelOptionsByProvider({
183 customCodexModels: [" custom/codex-model ", "gpt-5.4", "custom/codex-model"],
184 customClaudeModels: [" sonnet ", "claude/custom-opus", "claude/custom-opus"],
185 });
186​
187 expect(
188 modelOptionsByProvider.codex.filter((option) => option.slug === "custom/codex-model"),
189 ).toHaveLength(1);
190 expect(modelOptionsByProvider.codex.some((option) => option.slug === "gpt-5.4")).toBe(true);
191 expect(
192 modelOptionsByProvider.claudeAgent.filter((option) => option.slug === "claude/custom-opus"),
193 ).toHaveLength(1);
194 expect(
195 modelOptionsByProvider.claudeAgent.some((option) => option.slug === "claude-sonnet-4-6"),
196 ).toBe(true);
197 });
198});
199​
200describe("AppSettingsSchema", () => {
201 it("fills decoding defaults for persisted settings that predate newer keys", () => {
202 const decode = Schema.decodeSync(Schema.fromJsonString(AppSettingsSchema));
203​
204 expect(
205 decode(
206 JSON.stringify({
207 codexBinaryPath: "/usr/local/bin/codex",
208 confirmThreadDelete: false,
209 }),
210 ),
211 ).toMatchObject({
212 codexBinaryPath: "/usr/local/bin/codex",
213 codexHomePath: "",
214 defaultThreadEnvMode: "local",
215 confirmThreadDelete: false,
216 enableAssistantStreaming: false,
217 timestampFormat: DEFAULT_TIMESTAMP_FORMAT,
218 customCodexModels: [],
219 customClaudeModels: [],
220 });
221 });
222});