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

DevinProvider.test.ts

364 lines13.0 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 buildDevinModelsFromPayload,
5 inferDevinContextWindowTokens,
6 parseDevinHumanModelList,
7 parseDevinModelUid,
8} from "./DevinProvider.ts";
9​
10describe("buildDevinModelsFromPayload", () => {
11 it("maps families, marks adaptive as default, and removes duplicate ids", () => {
12 const models = buildDevinModelsFromPayload({
13 families: [
14 {
15 family_label: "Devin",
16 family_uid: "devin",
17 variants: [
18 { model_uid: "adaptive", label: "Adaptive" },
19 { model_uid: "claude-sonnet-4-6", label: "Claude Sonnet 4.6" },
20 ],
21 },
22 {
23 family_label: "Duplicate",
24 family_uid: "duplicate",
25 variants: [{ model_uid: "adaptive", label: "Adaptive again" }],
26 },
27 ],
28 });
29​
30 expect(
31 models.map(({ slug, name, subProvider, isDefault }) => ({
32 slug,
33 name,
34 subProvider,
35 isDefault,
36 })),
37 ).toEqual([
38 { slug: "adaptive", name: "Adaptive", subProvider: "Devin", isDefault: true },
39 {
40 slug: "claude-sonnet-4-6",
41 name: "Claude Sonnet 4.6",
42 subProvider: "Devin",
43 isDefault: undefined,
44 },
45 ]);
46 });
47​
48 it("populates per-model input capabilities from the known mapping", () => {
49 const models = buildDevinModelsFromPayload({
50 families: [
51 {
52 family_label: "Devin",
53 family_uid: "devin",
54 variants: [
55 { model_uid: "adaptive", label: "Adaptive" },
56 { model_uid: "claude-sonnet-4-6", label: "Claude Sonnet 4.6" },
57 ],
58 },
59 ],
60 });
61​
62 const adaptive = models.find((model) => model.slug === "adaptive");
63 // Devin models accept images and files but not audio.
64 expect(adaptive?.capabilities?.inputImages).not.toBe(false);
65 expect(adaptive?.capabilities?.inputFiles).not.toBe(false);
66 expect(adaptive?.capabilities?.inputAudio).toBe(false);
67​
68 // An unmapped slug keeps the permissive default (no capability fields set).
69 const unmapped = models.find((model) => model.slug === "claude-sonnet-4-6");
70 expect(unmapped?.capabilities?.inputImages).toBeUndefined();
71 expect(unmapped?.capabilities?.inputAudio).toBeUndefined();
72 expect(unmapped?.capabilities?.inputFiles).toBeUndefined();
73 });
74​
75 it("groups reasoning variants into one model with a reasoning option descriptor", () => {
76 const models = buildDevinModelsFromPayload({
77 families: [
78 {
79 family_label: "Claude Opus 5",
80 family_uid: "claude-opus-5",
81 variants: [
82 { model_uid: "claude-opus-5-low", label: "Claude Opus 5 Low" },
83 { model_uid: "claude-opus-5-medium", label: "Claude Opus 5 Medium" },
84 { model_uid: "claude-opus-5-high", label: "Claude Opus 5 High" },
85 ],
86 },
87 ],
88 });
89​
90 expect(models.map((m) => m.slug)).toEqual(["claude-opus-5"]);
91 const grouped = models[0]!;
92 expect(grouped.name).toBe("Claude Opus 5");
93 const descriptor = grouped.capabilities?.optionDescriptors?.[0];
94 expect(descriptor?.type).toBe("select");
95 expect(descriptor?.id).toBe("reasoning");
96 const options = descriptor?.type === "select" ? descriptor.options : undefined;
97 expect(options?.map((o) => ({ id: o.id, label: o.label, isDefault: o.isDefault }))).toEqual([
98 { id: "low", label: "Low", isDefault: undefined },
99 { id: "medium", label: "Medium", isDefault: true },
100 { id: "high", label: "High", isDefault: undefined },
101 ]);
102 });
103​
104 it("groups speed-tier variants into one model with a speed option", () => {
105 const models = buildDevinModelsFromPayload({
106 families: [
107 {
108 family_label: "Claude Opus 5",
109 family_uid: "claude-opus-5",
110 variants: [
111 { model_uid: "claude-opus-5-medium", label: "Claude Opus 5 Medium" },
112 { model_uid: "claude-opus-5-low", label: "Claude Opus 5 Low" },
113 { model_uid: "claude-opus-5-medium-fast", label: "Claude Opus 5 Medium Fast" },
114 { model_uid: "claude-opus-5-low-fast", label: "Claude Opus 5 Low Fast" },
115 ],
116 },
117 ],
118 });
119​
120 const slugs = models.map((m) => m.slug);
121 expect(slugs).toEqual(["claude-opus-5"]);
122 const descriptors = models[0]!.capabilities?.optionDescriptors ?? [];
123 const speedDescriptor = descriptors.find((d) => d.id === "speed");
124 expect(speedDescriptor?.type).toBe("select");
125 expect(
126 speedDescriptor?.type === "select" ? speedDescriptor.options.map((o) => o.id) : [],
127 ).toEqual(["standard", "fast"]);
128 });
129​
130 it("groups uppercase enum-style variants and defaults to medium", () => {
131 const models = buildDevinModelsFromPayload({
132 families: [
133 {
134 family_label: "GPT 5.2",
135 family_uid: "gpt-5-2",
136 variants: [
137 { model_uid: "MODEL_GPT_5_2_LOW", label: "GPT 5.2 Low" },
138 { model_uid: "MODEL_GPT_5_2_MEDIUM", label: "GPT 5.2 Medium" },
139 { model_uid: "MODEL_GPT_5_2_HIGH", label: "GPT 5.2 High" },
140 ],
141 },
142 ],
143 });
144​
145 expect(models.map((m) => m.slug)).toEqual(["MODEL_GPT_5_2"]);
146 const upperDescriptor = models[0]!.capabilities?.optionDescriptors?.[0];
147 const upperOptions = upperDescriptor?.type === "select" ? upperDescriptor.options : undefined;
148 expect(upperOptions?.find((o) => o.id === "medium")?.isDefault).toBe(true);
149 });
150​
151 it("keeps GLM reasoning limited to none, high, and max across context windows", () => {
152 const models = buildDevinModelsFromPayload({
153 families: [
154 {
155 family_label: "GLM-5.2",
156 family_uid: "glm-5.2",
157 variants: [
158 { model_uid: "glm-5-2", label: "GLM-5.2 High" },
159 { model_uid: "glm-5-2-max", label: "GLM-5.2 Max" },
160 { model_uid: "glm-5-2-1m", label: "GLM-5.2 High 1M" },
161 { model_uid: "glm-5-2-max-1m", label: "GLM-5.2 Max 1M" },
162 { model_uid: "glm-5-2-none", label: "GLM-5.2 No Thinking" },
163 { model_uid: "glm-5-2-none-1m", label: "GLM-5.2 No Thinking 1M" },
164 ],
165 },
166 ],
167 });
168 expect(models).toHaveLength(1);
169 expect(models[0]?.name).toBe("GLM-5.2");
170 const descriptors = models[0]?.capabilities?.optionDescriptors ?? [];
171 const reasoning = descriptors.find((descriptor) => descriptor.id === "reasoning");
172 expect(
173 reasoning?.type === "select" ? reasoning.options.map((option) => option.id) : [],
174 ).toEqual(["none", "high", "max"]);
175 expect(
176 reasoning?.type === "select"
177 ? reasoning.options.find((option) => option.isDefault)?.id
178 : undefined,
179 ).toBe("high");
180 const context = descriptors.find((descriptor) => descriptor.id === "contextWindow");
181 expect(context?.type === "select" ? context.options.map((option) => option.id) : []).toEqual([
182 "200k",
183 "1m",
184 ]);
185 expect(
186 context?.type === "select"
187 ? context.options.find((option) => option.isDefault)?.id
188 : undefined,
189 ).toBe("200k");
190 });
191​
192 it("groups opaque private UIDs under their family and preserves concrete reasoning UIDs", () => {
193 const models = buildDevinModelsFromPayload({
194 families: [
195 {
196 family_label: "Claude Sonnet 4.5",
197 family_uid: "claude-sonnet-4.5",
198 variants: [
199 { model_uid: "MODEL_PRIVATE_2", label: "Claude Sonnet 4.5" },
200 { model_uid: "MODEL_PRIVATE_3", label: "Claude Sonnet 4.5 Thinking" },
201 ],
202 },
203 ],
204 });
205​
206 expect(models).toHaveLength(1);
207 expect(models[0]?.slug).toBe("MODEL_PRIVATE_2");
208 const reasoning = models[0]?.capabilities?.optionDescriptors?.find(
209 (descriptor) => descriptor.id === "reasoning",
210 );
211 expect(reasoning?.type === "select" ? reasoning.options : []).toEqual([
212 { id: "none", label: "None", isDefault: true },
213 { id: "__uid:MODEL_PRIVATE_3", label: "Thinking" },
214 ]);
215 });
216​
217 it("leaves unrelated models without a reasoning suffix as standalone variants", () => {
218 const models = buildDevinModelsFromPayload({
219 families: [
220 {
221 family_label: "Misc",
222 family_uid: "misc",
223 variants: [
224 { model_uid: "kimi-k2-6", label: "Kimi K2.6" },
225 { model_uid: "claude-opus-4-6-1m", label: "Claude Opus 4.6 1M" },
226 ],
227 },
228 ],
229 });
230​
231 expect(models.map((m) => m.slug)).toEqual(["kimi-k2-6", "claude-opus-4-6-1m"]);
232 for (const model of models) {
233 expect(model.capabilities?.optionDescriptors).toEqual([]);
234 }
235 });
236​
237 it("keeps explicit context metadata when the JSON catalog omits UID suffixes", () => {
238 const models = buildDevinModelsFromPayload({
239 families: [
240 {
241 family_label: "GLM-5.2",
242 family_uid: "glm-5.2",
243 variants: [
244 {
245 model_uid: "glm-5-2",
246 label: "GLM-5.2 High",
247 context_window: 200_000,
248 pricing: { inputPerMillion: 0, outputPerMillion: 0 },
249 },
250 {
251 model_uid: "glm-5-2-1m",
252 label: "GLM-5.2 High 1M",
253 context_window: 1_000_000,
254 pricing: { inputPerMillion: 0.7, outputPerMillion: 2.2 },
255 },
256 {
257 model_uid: "glm-5-2-none",
258 label: "GLM-5.2 No Thinking",
259 context_window: 200_000,
260 pricing: { inputPerMillion: 0.7, outputPerMillion: 2.2 },
261 },
262 ],
263 },
264 ],
265 });
266​
267 const glm = models[0]!;
268 const context = glm.capabilities?.optionDescriptors?.find(
269 (descriptor) => descriptor.id === "contextWindow",
270 );
271 expect(context?.type === "select" ? context.options.map((option) => option.id) : []).toEqual([
272 "200k",
273 "1m",
274 ]);
275 expect(glm.contextWindowTokens).toBe(1_000_000);
276 expect(glm.pricingByVariant?.["glm-5-2-1m"]?.outputPerMillion).toBe(2.2);
277 });
278});
279​
280describe("Devin model catalog fallbacks", () => {
281 it("parses the human-readable CLI catalog with context and prices", () => {
282 const payload = parseDevinHumanModelList(
283 `Available models (1 families)\n\nGLM-5.2 (glm-5.2)\n aliases: glm\n glm-5-2 GLM-5.2 High [200K context, Free]\n glm-5-2-max GLM-5.2 Max [200K context, $0.7 / 1M Input · $0.13 / 1M Cached input · $2.2 / 1M Output]\n glm-5-2-none-1m GLM-5.2 No Thinking 1M [1M context, $0.7 / 1M Input · $0.13 / 1M Cached input · $2.2 / 1M Output]`,
284 );
285​
286 expect(payload?.families).toHaveLength(1);
287 expect(payload?.families[0]?.variants).toHaveLength(3);
288 expect(payload?.families[0]?.variants[1]?.contextWindow).toBe(200_000);
289 const variantPricing = payload?.families[0]?.variants[1]?.pricing as
290 | { outputPerMillion?: number }
291 | undefined;
292 expect(variantPricing?.outputPerMillion).toBe(2.2);
293​
294 const glm = buildDevinModelsFromPayload(payload!)[0]!;
295 expect(glm.slug).toBe("glm-5-2");
296 expect(glm.pricingByVariant?.["glm-5-2-max"]?.cachedInputPerMillion).toBe(0.13);
297 expect(glm.contextWindowTokens).toBe(1_000_000);
298 });
299​
300 it("infers known Devin context limits from family and variant UIDs", () => {
301 expect(inferDevinContextWindowTokens("glm-5-2-max")).toBe(200_000);
302 expect(inferDevinContextWindowTokens("glm-5-2-max-1m")).toBe(1_000_000);
303 expect(inferDevinContextWindowTokens("MODEL_GPT_5_2_HIGH")).toBe(384_000);
304 expect(inferDevinContextWindowTokens("unknown-model")).toBeUndefined();
305 });
306});
307​
308describe("parseDevinModelUid", () => {
309 it("extracts reasoning and speed from lowercase hyphenated UIDs", () => {
310 expect(parseDevinModelUid("claude-opus-5-medium")).toEqual({
311 base: "claude-opus-5",
312 reasoning: "medium",
313 speed: undefined,
314 contextWindow: undefined,
315 });
316 expect(parseDevinModelUid("claude-opus-5-medium-fast")).toEqual({
317 base: "claude-opus-5",
318 reasoning: "medium",
319 speed: "fast",
320 contextWindow: undefined,
321 });
322 });
323​
324 it("extracts reasoning from uppercase underscore UIDs", () => {
325 expect(parseDevinModelUid("MODEL_GPT_5_2_LOW")).toEqual({
326 base: "MODEL_GPT_5_2",
327 reasoning: "low",
328 speed: undefined,
329 contextWindow: undefined,
330 });
331 });
332​
333 it("extracts context window suffixes", () => {
334 expect(parseDevinModelUid("glm-5-2-max-1m")).toEqual({
335 base: "glm-5-2",
336 reasoning: "max",
337 speed: undefined,
338 contextWindow: "1m",
339 });
340 });
341​
342 it("returns no reasoning for UIDs without a known suffix", () => {
343 expect(parseDevinModelUid("kimi-k2-6")).toEqual({
344 base: "kimi-k2-6",
345 reasoning: undefined,
346 speed: undefined,
347 contextWindow: undefined,
348 });
349 expect(parseDevinModelUid("claude-opus-4-6-thinking")).toEqual({
350 base: "claude-opus-4-6",
351 reasoning: "thinking",
352 speed: undefined,
353 contextWindow: undefined,
354 });
355 });
356​
357 it("does not treat a bare speed suffix as a speed tier without reasoning", () => {
358 expect(parseDevinModelUid("claude-opus-5-fast")).toEqual({
359 base: "claude-opus-5-fast",
360 reasoning: undefined,
361 speed: undefined,
362 });
363 });
364});