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

ClaudeModelCatalog.test.ts

245 lines7.9 KB

1import { assert, describe, it } from "@effect/vitest";
2import { ProviderInstanceId } from "@t3tools/contracts";
3​
4import { hasValidClaudeManifestAdapters } from "./ClaudeModelManifest.ts";
5import type { ModelManifestData } from "./ModelManifest.ts";
6import {
7 formatClaudeVersionUpgradeMessage,
8 normalizeClaudeCatalogEffort,
9 resolveClaudeCatalogApiModelId,
10 resolveClaudeCatalogContextWindowTokens,
11 resolveClaudeCatalogEffort,
12 resolveClaudeModelCatalog,
13 resolveClaudeModelsForVersion,
14 resolveClaudeModelSlug,
15 scopeClaudeModelCatalog,
16} from "./ClaudeModelCatalog.ts";
17​
18/**
19 * Test policy: adding or changing a real Claude model in model-manifest.json
20 * must not add or update tests here. These synthetic fixtures cover resolver
21 * behavior once. Add a test only when Claude adapter semantics change, such
22 * as introducing a new compatibility rule or dispatch mapping type.
23 */
24​
25const manifest = (): ModelManifestData => ({
26 version: 1,
27 currentModels: {},
28 providers: {
29 claudeAgent: {
30 profiles: {
31 synthetic: {
32 capabilities: {
33 optionDescriptors: [
34 {
35 id: "effort",
36 label: "Reasoning",
37 type: "select",
38 options: [{ id: "extreme", label: "Extreme", isDefault: true }],
39 },
40 {
41 id: "contextWindow",
42 label: "Context Window",
43 type: "select",
44 options: [
45 { id: "large", label: "Large", isDefault: true },
46 { id: "small", label: "Small" },
47 ],
48 },
49 ],
50 },
51 adapter: {
52 claudeCode: {
53 effortMap: { extreme: "high" },
54 modelSuffixes: { contextWindow: { large: "[large]" } },
55 },
56 },
57 },
58 },
59 models: [
60 {
61 slug: "claude-synthetic-next",
62 name: "Claude Synthetic Next",
63 aliases: ["synthetic"],
64 status: "current",
65 profile: "synthetic",
66 adapter: { claudeCode: { minVersion: "3.2.0" } },
67 },
68 ],
69 },
70 },
71});
72​
73describe("Claude model catalog", () => {
74 it("resolves capacity from selected options and fixed catalog windows without guessing custom models", () => {
75 const source = manifest();
76 const profile = source.providers!.claudeAgent!.profiles.synthetic!;
77 const catalog = resolveClaudeModelCatalog({
78 ...source,
79 providers: {
80 claudeAgent: {
81 ...source.providers!.claudeAgent!,
82 profiles: {
83 fixed: {
84 capabilities: { optionDescriptors: [] },
85 adapter: { claudeCode: { fixedContextWindowTokens: 64_000 } },
86 },
87 synthetic: {
88 ...profile,
89 adapter: { claudeCode: { contextWindowTokens: { large: 1_000_000, small: 32_000 } } },
90 },
91 },
92 models: [
93 ...source.providers!.claudeAgent!.models,
94 {
95 slug: "fixed",
96 name: "Fixed",
97 status: "current",
98 profile: "fixed",
99 },
100 ],
101 },
102 },
103 });
104 const selection = { instanceId: ProviderInstanceId.make("claudeAgent"), model: "synthetic" };
105 assert.equal(resolveClaudeCatalogContextWindowTokens(catalog, selection), 1_000_000);
106 assert.equal(
107 resolveClaudeCatalogContextWindowTokens(catalog, {
108 ...selection,
109 options: [{ id: "contextWindow", value: "small" }],
110 }),
111 32_000,
112 );
113 assert.equal(
114 resolveClaudeCatalogContextWindowTokens(catalog, { ...selection, model: "fixed" }),
115 64_000,
116 );
117 assert.isUndefined(
118 resolveClaudeCatalogContextWindowTokens(catalog, { ...selection, model: "custom" }),
119 );
120 });
121​
122 it("filters models at runtime-version boundaries and derives the upgrade message", () => {
123 const catalog = resolveClaudeModelCatalog(manifest());
124 assert.deepStrictEqual(resolveClaudeModelsForVersion(catalog, "3.1.9"), []);
125 assert.deepStrictEqual(
126 resolveClaudeModelsForVersion(catalog, "3.2.0").map((model) => model.slug),
127 ["claude-synthetic-next"],
128 );
129 assert.strictEqual(
130 formatClaudeVersionUpgradeMessage(catalog, "3.1.9"),
131 "Claude Code v3.1.9 is too old for Claude Synthetic Next. Upgrade to v3.2.0 or newer to access it.",
132 );
133 });
134​
135 it("resolves aliases and declarative adapter mappings", () => {
136 const base = manifest();
137 const input: ModelManifestData = {
138 ...base,
139 providers: {
140 ...base.providers,
141 claudeAgent: {
142 ...base.providers!.claudeAgent!,
143 models: [
144 {
145 slug: "claude-synthetic-collision",
146 name: "Claude Synthetic Collision",
147 aliases: ["claude-synthetic-next"],
148 status: "current",
149 },
150 ...base.providers!.claudeAgent!.models,
151 ],
152 },
153 },
154 };
155 const catalog = resolveClaudeModelCatalog(input);
156 assert.strictEqual(resolveClaudeModelSlug(catalog, "synthetic"), "claude-synthetic-next");
157 assert.strictEqual(
158 resolveClaudeModelSlug(catalog, "claude-synthetic-next"),
159 "claude-synthetic-next",
160 );
161 assert.strictEqual(normalizeClaudeCatalogEffort(catalog, "extreme", "synthetic"), "high");
162 assert.strictEqual(
163 resolveClaudeCatalogApiModelId(catalog, {
164 instanceId: ProviderInstanceId.make("claudeAgent"),
165 model: "synthetic",
166 }),
167 "claude-synthetic-next[large]",
168 );
169 });
170​
171 it("rejects malformed adapter mappings", () => {
172 const base = manifest();
173 const malformed: ModelManifestData = {
174 ...base,
175 providers: {
176 ...base.providers,
177 claudeAgent: {
178 ...base.providers!.claudeAgent!,
179 profiles: {
180 ...base.providers!.claudeAgent!.profiles,
181 synthetic: {
182 ...base.providers!.claudeAgent!.profiles.synthetic!,
183 adapter: { claudeCode: { effortMap: { extreme: 123 } } },
184 },
185 },
186 },
187 },
188 };
189 assert.isFalse(hasValidClaudeManifestAdapters(malformed));
190 });
191​
192 it("appends custom models with their own descriptors and keeps bare slugs opaque", () => {
193 const catalog = scopeClaudeModelCatalog(resolveClaudeModelCatalog(manifest()), [
194 "synthetic",
195 {
196 slug: "claude-custom-tuned",
197 name: "Tuned",
198 capabilities: {
199 optionDescriptors: [
200 {
201 id: "effort",
202 label: "Reasoning",
203 type: "select",
204 options: [
205 { id: "gentle", label: "Gentle", isDefault: true },
206 { id: "brutal", label: "Brutal" },
207 ],
208 },
209 ],
210 },
211 },
212 ]);
213​
214 // The bare custom slug shadows the built-in alias, so it no longer resolves to it.
215 assert.strictEqual(resolveClaudeModelSlug(catalog, "synthetic"), "synthetic");
216 assert.strictEqual(resolveClaudeCatalogEffort(catalog, "synthetic", "extreme"), undefined);
217​
218 // The entry with descriptors resolves user-defined effort ids and passes
219 // them through untouched (no effortMap, no model suffix).
220 assert.strictEqual(
221 resolveClaudeCatalogEffort(catalog, "claude-custom-tuned", "brutal"),
222 "brutal",
223 );
224 assert.strictEqual(
225 resolveClaudeCatalogEffort(catalog, "claude-custom-tuned", "bogus"),
226 "gentle",
227 );
228 assert.strictEqual(
229 normalizeClaudeCatalogEffort(catalog, "brutal", "claude-custom-tuned"),
230 "brutal",
231 );
232 assert.strictEqual(
233 resolveClaudeCatalogApiModelId(catalog, {
234 instanceId: ProviderInstanceId.make("claudeAgent"),
235 model: "claude-custom-tuned",
236 options: [{ id: "effort", value: "brutal" }],
237 }),
238 "claude-custom-tuned",
239 );
240 assert.deepStrictEqual(
241 resolveClaudeModelsForVersion(catalog, "3.2.0").map((model) => model.slug),
242 ["claude-synthetic-next", "claude-custom-tuned"],
243 );
244 });
245});