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