Open History to see the last commit
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 resolveClaudeCatalogEffort,
11 resolveClaudeModelCatalog,
12 resolveClaudeModelsForVersion,
13 resolveClaudeModelSlug,
14 scopeClaudeModelCatalog,
15} from "./ClaudeModelCatalog.ts";
16
17/**
18 * Test policy: adding or changing a real Claude model in model-manifest.json
19 * must not add or update tests here. These synthetic fixtures cover resolver
20 * behavior once. Add a test only when Claude adapter semantics change, such
21 * as introducing a new compatibility rule or dispatch mapping type.
22 */
23
24const manifest = (): ModelManifestData => ({
25 version: 1,
26 currentModels: {},
27 providers: {
28 claudeAgent: {
29 profiles: {
30 synthetic: {
31 capabilities: {
32 optionDescriptors: [
33 {
34 id: "effort",
35 label: "Reasoning",
36 type: "select",
37 options: [{ id: "extreme", label: "Extreme", isDefault: true }],
38 },
39 {
40 id: "contextWindow",
41 label: "Context Window",
42 type: "select",
43 options: [{ id: "large", label: "Large", isDefault: true }],
44 },
45 ],
46 },
47 adapter: {
48 claudeCode: {
49 effortMap: { extreme: "high" },
50 modelSuffixes: { contextWindow: { large: "[large]" } },
51 },
52 },
53 },
54 },
55 models: [
56 {
57 slug: "claude-synthetic-next",
58 name: "Claude Synthetic Next",
59 aliases: ["synthetic"],
60 status: "current",
61 profile: "synthetic",
62 adapter: { claudeCode: { minVersion: "3.2.0" } },
63 },
64 ],
65 },
66 },
67});
68
69describe("Claude model catalog", () => {
70 it("filters models at runtime-version boundaries and derives the upgrade message", () => {
71 const catalog = resolveClaudeModelCatalog(manifest());
72 assert.deepStrictEqual(resolveClaudeModelsForVersion(catalog, "3.1.9"), []);
73 assert.deepStrictEqual(
74 resolveClaudeModelsForVersion(catalog, "3.2.0").map((model) => model.slug),
75 ["claude-synthetic-next"],
76 );
77 assert.strictEqual(
78 formatClaudeVersionUpgradeMessage(catalog, "3.1.9"),
79 "Claude Code v3.1.9 is too old for Claude Synthetic Next. Upgrade to v3.2.0 or newer to access it.",
80 );
81 });
82
83 it("resolves aliases and declarative adapter mappings", () => {
84 const base = manifest();
85 const input: ModelManifestData = {
86 ...base,
87 providers: {
88 ...base.providers,
89 claudeAgent: {
90 ...base.providers!.claudeAgent!,
91 models: [
92 {
93 slug: "claude-synthetic-collision",
94 name: "Claude Synthetic Collision",
95 aliases: ["claude-synthetic-next"],
96 status: "current",
97 },
98 ...base.providers!.claudeAgent!.models,
99 ],
100 },
101 },
102 };
103 const catalog = resolveClaudeModelCatalog(input);
104 assert.strictEqual(resolveClaudeModelSlug(catalog, "synthetic"), "claude-synthetic-next");
105 assert.strictEqual(
106 resolveClaudeModelSlug(catalog, "claude-synthetic-next"),
107 "claude-synthetic-next",
108 );
109 assert.strictEqual(normalizeClaudeCatalogEffort(catalog, "extreme", "synthetic"), "high");
110 assert.strictEqual(
111 resolveClaudeCatalogApiModelId(catalog, {
112 instanceId: ProviderInstanceId.make("claudeAgent"),
113 model: "synthetic",
114 }),
115 "claude-synthetic-next[large]",
116 );
117 });
118
119 it("rejects malformed adapter mappings", () => {
120 const base = manifest();
121 const malformed: ModelManifestData = {
122 ...base,
123 providers: {
124 ...base.providers,
125 claudeAgent: {
126 ...base.providers!.claudeAgent!,
127 profiles: {
128 ...base.providers!.claudeAgent!.profiles,
129 synthetic: {
130 ...base.providers!.claudeAgent!.profiles.synthetic!,
131 adapter: { claudeCode: { effortMap: { extreme: 123 } } },
132 },
133 },
134 },
135 },
136 };
137 assert.isFalse(hasValidClaudeManifestAdapters(malformed));
138 });
139
140 it("appends custom models with their own descriptors and keeps bare slugs opaque", () => {
141 const catalog = scopeClaudeModelCatalog(resolveClaudeModelCatalog(manifest()), [
142 "synthetic",
143 {
144 slug: "claude-custom-tuned",
145 name: "Tuned",
146 capabilities: {
147 optionDescriptors: [
148 {
149 id: "effort",
150 label: "Reasoning",
151 type: "select",
152 options: [
153 { id: "gentle", label: "Gentle", isDefault: true },
154 { id: "brutal", label: "Brutal" },
155 ],
156 },
157 ],
158 },
159 },
160 ]);
161
162 // The bare custom slug shadows the built-in alias, so it no longer resolves to it.
163 assert.strictEqual(resolveClaudeModelSlug(catalog, "synthetic"), "synthetic");
164 assert.strictEqual(resolveClaudeCatalogEffort(catalog, "synthetic", "extreme"), undefined);
165
166 // The entry with descriptors resolves user-defined effort ids and passes
167 // them through untouched (no effortMap, no model suffix).
168 assert.strictEqual(
169 resolveClaudeCatalogEffort(catalog, "claude-custom-tuned", "brutal"),
170 "brutal",
171 );
172 assert.strictEqual(
173 resolveClaudeCatalogEffort(catalog, "claude-custom-tuned", "bogus"),
174 "gentle",
175 );
176 assert.strictEqual(
177 normalizeClaudeCatalogEffort(catalog, "brutal", "claude-custom-tuned"),
178 "brutal",
179 );
180 assert.strictEqual(
181 resolveClaudeCatalogApiModelId(catalog, {
182 instanceId: ProviderInstanceId.make("claudeAgent"),
183 model: "claude-custom-tuned",
184 options: [{ id: "effort", value: "brutal" }],
185 }),
186 "claude-custom-tuned",
187 );
188 assert.deepStrictEqual(
189 resolveClaudeModelsForVersion(catalog, "3.2.0").map((model) => model.slug),
190 ["claude-synthetic-next", "claude-custom-tuned"],
191 );
192 });
193});