Open History to see the last commit
1import { describe, expect, it } from "vitest";
2import {
3 CURSOR_MODEL_FAMILY_OPTIONS,
4 CURSOR_REASONING_OPTIONS,
5 DEFAULT_MODEL,
6 DEFAULT_MODEL_BY_PROVIDER,
7 DEFAULT_REASONING_EFFORT_BY_PROVIDER,
8 MODEL_OPTIONS,
9 MODEL_OPTIONS_BY_PROVIDER,
10 REASONING_EFFORT_OPTIONS_BY_PROVIDER,
11} from "../../contracts/src";
12
13import {
14 getDefaultModel,
15 getDefaultReasoningEffort,
16 getCursorModelFamilyOptions,
17 getModelOptions,
18 getReasoningEffortOptions,
19 normalizeModelSlug,
20 parseCursorModelSelection,
21 resolveCursorModelFromSelection,
22 resolveModelSlug,
23 resolveModelSlugForProvider,
24} from "./model";
25
26describe("normalizeModelSlug", () => {
27 it("maps known aliases to canonical slugs", () => {
28 expect(normalizeModelSlug("5.3")).toBe("gpt-5.3-codex");
29 expect(normalizeModelSlug("gpt-5.3")).toBe("gpt-5.3-codex");
30 });
31
32 it("returns null for empty or missing values", () => {
33 expect(normalizeModelSlug("")).toBeNull();
34 expect(normalizeModelSlug(" ")).toBeNull();
35 expect(normalizeModelSlug(null)).toBeNull();
36 expect(normalizeModelSlug(undefined)).toBeNull();
37 });
38
39 it("preserves non-aliased model slugs", () => {
40 expect(normalizeModelSlug("gpt-5.2")).toBe("gpt-5.2");
41 expect(normalizeModelSlug("gpt-5.2-codex")).toBe("gpt-5.2-codex");
42 });
43
44 it("uses provider-specific aliases", () => {
45 expect(normalizeModelSlug("sonnet", "claudeCode")).toBe("claude-sonnet-4-6");
46 expect(normalizeModelSlug("opus-4.6", "claudeCode")).toBe("claude-opus-4-6");
47 expect(normalizeModelSlug("claude-haiku-4-5-20251001", "claudeCode")).toBe(
48 "claude-haiku-4-5",
49 );
50 expect(normalizeModelSlug("composer", "cursor")).toBe("composer-1.5");
51 expect(normalizeModelSlug("gpt-5.3-codex-spark", "cursor")).toBe(
52 "gpt-5.3-codex-spark-preview",
53 );
54 expect(normalizeModelSlug("gemini-3.1", "cursor")).toBe("gemini-3.1");
55 expect(normalizeModelSlug("claude-4.6-sonnet-thinking", "cursor")).toBe(
56 "sonnet-4.6-thinking",
57 );
58 });
59});
60
61describe("resolveModelSlug", () => {
62 it("returns default only when the model is missing", () => {
63 expect(resolveModelSlug(undefined)).toBe(DEFAULT_MODEL);
64 expect(resolveModelSlug(null)).toBe(DEFAULT_MODEL);
65 });
66
67 it("preserves unknown custom models", () => {
68 expect(resolveModelSlug("gpt-4.1")).toBe(DEFAULT_MODEL);
69 expect(resolveModelSlug("custom/internal-model")).toBe(DEFAULT_MODEL);
70 });
71
72 it("resolves only supported model options", () => {
73 for (const model of MODEL_OPTIONS) {
74 expect(resolveModelSlug(model.slug)).toBe(model.slug);
75 }
76 });
77
78 it("supports provider-aware resolution", () => {
79 expect(resolveModelSlugForProvider("claudeCode", undefined)).toBe(
80 DEFAULT_MODEL_BY_PROVIDER.claudeCode,
81 );
82 expect(resolveModelSlugForProvider("claudeCode", "sonnet")).toBe("claude-sonnet-4-6");
83 expect(resolveModelSlugForProvider("claudeCode", "gpt-5.3-codex")).toBe(
84 DEFAULT_MODEL_BY_PROVIDER.claudeCode,
85 );
86 expect(resolveModelSlugForProvider("cursor", undefined)).toBe(
87 DEFAULT_MODEL_BY_PROVIDER.cursor,
88 );
89 expect(resolveModelSlugForProvider("cursor", "composer")).toBe("composer-1.5");
90 expect(resolveModelSlugForProvider("cursor", "gpt-5.3-codex-high-fast")).toBe(
91 "gpt-5.3-codex-high-fast",
92 );
93 expect(resolveModelSlugForProvider("cursor", "claude-sonnet-4-6")).toBe(
94 DEFAULT_MODEL_BY_PROVIDER.cursor,
95 );
96 });
97
98 it("keeps codex defaults for backward compatibility", () => {
99 expect(getDefaultModel()).toBe(DEFAULT_MODEL);
100 expect(getModelOptions()).toEqual(MODEL_OPTIONS);
101 expect(getModelOptions("claudeCode")).toEqual(MODEL_OPTIONS_BY_PROVIDER.claudeCode);
102 expect(getModelOptions("cursor")).toEqual(MODEL_OPTIONS_BY_PROVIDER.cursor);
103 expect(getCursorModelFamilyOptions()).toEqual(CURSOR_MODEL_FAMILY_OPTIONS);
104 });
105});
106
107describe("cursor model selection", () => {
108 it("includes the expected cursor reasoning levels and families", () => {
109 expect(CURSOR_REASONING_OPTIONS).toEqual(["low", "normal", "high", "xhigh"]);
110 expect(getCursorModelFamilyOptions().map((option) => option.slug)).toContain("gpt-5.3-codex");
111 expect(getCursorModelFamilyOptions().map((option) => option.slug)).toContain("opus-4.6");
112 });
113
114 it("parses codex reasoning and fast mode variants", () => {
115 expect(parseCursorModelSelection("gpt-5.3-codex-high-fast")).toEqual({
116 family: "gpt-5.3-codex",
117 reasoning: "high",
118 fast: true,
119 thinking: false,
120 });
121 expect(parseCursorModelSelection("gpt-5.2-codex")).toEqual(
122 parseCursorModelSelection(DEFAULT_MODEL_BY_PROVIDER.cursor),
123 );
124 });
125
126 it("parses and resolves thinking variants", () => {
127 expect(parseCursorModelSelection("sonnet-4.6-thinking")).toEqual({
128 family: "sonnet-4.6",
129 reasoning: "normal",
130 fast: false,
131 thinking: true,
132 });
133 expect(
134 resolveCursorModelFromSelection({
135 family: "sonnet-4.6",
136 thinking: true,
137 }),
138 ).toBe("sonnet-4.6-thinking");
139 });
140
141 it("resolves codex family selections into concrete model ids", () => {
142 expect(
143 resolveCursorModelFromSelection({
144 family: "gpt-5.3-codex",
145 reasoning: "xhigh",
146 fast: true,
147 }),
148 ).toBe("gpt-5.3-codex-xhigh-fast");
149 });
150});
151
152describe("getReasoningEffortOptions", () => {
153 it("returns codex reasoning options for codex", () => {
154 expect(getReasoningEffortOptions("codex")).toEqual(
155 REASONING_EFFORT_OPTIONS_BY_PROVIDER.codex,
156 );
157 });
158
159 it("returns no reasoning options for claudeCode", () => {
160 expect(getReasoningEffortOptions("claudeCode")).toEqual([]);
161 });
162
163 it("returns no reasoning options for cursor", () => {
164 expect(getReasoningEffortOptions("cursor")).toEqual([]);
165 });
166});
167
168describe("getDefaultReasoningEffort", () => {
169 it("returns provider-scoped defaults", () => {
170 expect(getDefaultReasoningEffort("codex")).toBe(
171 DEFAULT_REASONING_EFFORT_BY_PROVIDER.codex,
172 );
173 expect(getDefaultReasoningEffort("claudeCode")).toBe(
174 DEFAULT_REASONING_EFFORT_BY_PROVIDER.claudeCode,
175 );
176 expect(getDefaultReasoningEffort("cursor")).toBe(
177 DEFAULT_REASONING_EFFORT_BY_PROVIDER.cursor,
178 );
179 });
180});