test(agents): cover anthropic 4.6 forward-compat mapping

This commit is contained in:
Peter Steinberger
2026-02-19 00:06:30 +00:00
parent cb9e098554
commit 8e1f25631b

View File

@@ -0,0 +1,59 @@
import type { Api, Model } from "@mariozechner/pi-ai";
import { describe, expect, it } from "vitest";
import { resolveForwardCompatModel } from "./model-forward-compat.js";
import type { ModelRegistry } from "./pi-model-discovery.js";
function createTemplateModel(provider: string, id: string): Model<Api> {
return {
id,
name: id,
provider,
api: "anthropic-messages",
input: ["text"],
reasoning: true,
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 200_000,
maxTokens: 8_192,
} as Model<Api>;
}
function createRegistry(models: Record<string, Model<Api>>): ModelRegistry {
return {
find(provider: string, modelId: string) {
return models[`${provider}/${modelId}`] ?? null;
},
} as ModelRegistry;
}
describe("agents/model-forward-compat", () => {
it("resolves anthropic opus 4.6 via 4.5 template", () => {
const registry = createRegistry({
"anthropic/claude-opus-4-5": createTemplateModel("anthropic", "claude-opus-4-5"),
});
const model = resolveForwardCompatModel("anthropic", "claude-opus-4-6", registry);
expect(model?.id).toBe("claude-opus-4-6");
expect(model?.name).toBe("claude-opus-4-6");
expect(model?.provider).toBe("anthropic");
});
it("resolves anthropic sonnet 4.6 dot variant with suffix", () => {
const registry = createRegistry({
"anthropic/claude-sonnet-4.5-20260219": createTemplateModel(
"anthropic",
"claude-sonnet-4.5-20260219",
),
});
const model = resolveForwardCompatModel("anthropic", "claude-sonnet-4.6-20260219", registry);
expect(model?.id).toBe("claude-sonnet-4.6-20260219");
expect(model?.name).toBe("claude-sonnet-4.6-20260219");
expect(model?.provider).toBe("anthropic");
});
it("does not resolve anthropic 4.6 fallback for other providers", () => {
const registry = createRegistry({
"anthropic/claude-opus-4-5": createTemplateModel("anthropic", "claude-opus-4-5"),
});
const model = resolveForwardCompatModel("openai", "claude-opus-4-6", registry);
expect(model).toBeUndefined();
});
});