|
| 1 | +// Anthropic tests cover the live-discovery contract gate. |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | +import { acceptsAnthropicLiveModelContract } from "./live-model-contract-gate.js"; |
| 4 | + |
| 5 | +/** Capability tree shaped like Anthropic's `/v1/models` response. */ |
| 6 | +function capabilities(params: { |
| 7 | + adaptive: boolean; |
| 8 | + xhigh: boolean; |
| 9 | + max: boolean; |
| 10 | +}): Record<string, unknown> { |
| 11 | + return { |
| 12 | + capabilities: { |
| 13 | + image_input: { supported: true }, |
| 14 | + thinking: { |
| 15 | + supported: true, |
| 16 | + types: { |
| 17 | + enabled: { supported: !params.adaptive }, |
| 18 | + adaptive: { supported: params.adaptive }, |
| 19 | + }, |
| 20 | + }, |
| 21 | + effort: { |
| 22 | + low: { supported: params.max }, |
| 23 | + high: { supported: params.max }, |
| 24 | + xhigh: { supported: params.xhigh }, |
| 25 | + max: { supported: params.max }, |
| 26 | + }, |
| 27 | + }, |
| 28 | + }; |
| 29 | +} |
| 30 | + |
| 31 | +const MODERN = { adaptive: true, xhigh: true, max: true }; |
| 32 | +const LEGACY = { adaptive: false, xhigh: false, max: false }; |
| 33 | + |
| 34 | +describe("acceptsAnthropicLiveModelContract", () => { |
| 35 | + it("accepts current models whose advertised capabilities match our contracts", () => { |
| 36 | + // Adaptive + full effort range: what the contracts already shape correctly. |
| 37 | + for (const id of ["claude-opus-5", "claude-sonnet-5", "claude-fable-5", "claude-opus-4-8"]) { |
| 38 | + expect(acceptsAnthropicLiveModelContract({ id, record: capabilities(MODERN) }), id).toBe( |
| 39 | + true, |
| 40 | + ); |
| 41 | + } |
| 42 | + }); |
| 43 | + |
| 44 | + it("accepts legacy models that correctly advertise no adaptive thinking", () => { |
| 45 | + // The gate must not confuse "old model we shape with budget_tokens" for |
| 46 | + // "model we do not understand" — both miss the modern predicates. |
| 47 | + for (const id of ["claude-haiku-4-5", "claude-sonnet-4-5", "claude-3-opus-20240229"]) { |
| 48 | + expect(acceptsAnthropicLiveModelContract({ id, record: capabilities(LEGACY) }), id).toBe( |
| 49 | + true, |
| 50 | + ); |
| 51 | + } |
| 52 | + }); |
| 53 | + |
| 54 | + it("rejects an unreleased model generation our contracts do not recognize", () => { |
| 55 | + // The regression this gate exists to prevent: a future Claude family that |
| 56 | + // needs adaptive shaping but matches no version predicate, so it would be |
| 57 | + // sent manual budget_tokens plus sampling params and 400 on every request. |
| 58 | + for (const id of ["claude-opus-6", "claude-sonnet-6", "claude-zephyr-1"]) { |
| 59 | + expect(acceptsAnthropicLiveModelContract({ id, record: capabilities(MODERN) }), id).toBe( |
| 60 | + false, |
| 61 | + ); |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + it("rejects a known model whose advertised capabilities drift from our contracts", () => { |
| 66 | + // If Anthropic changes a shipped model's capabilities, our shaping is stale |
| 67 | + // for it; hide it rather than keep sending the old request shape. |
| 68 | + expect( |
| 69 | + acceptsAnthropicLiveModelContract({ |
| 70 | + id: "claude-opus-5", |
| 71 | + record: capabilities({ adaptive: false, xhigh: true, max: true }), |
| 72 | + }), |
| 73 | + ).toBe(false); |
| 74 | + expect( |
| 75 | + acceptsAnthropicLiveModelContract({ |
| 76 | + id: "claude-haiku-4-5", |
| 77 | + record: capabilities(MODERN), |
| 78 | + }), |
| 79 | + ).toBe(false); |
| 80 | + }); |
| 81 | + |
| 82 | + it("fails closed when the capability tree is missing or unreadable", () => { |
| 83 | + for (const record of [ |
| 84 | + {}, |
| 85 | + { capabilities: null }, |
| 86 | + { capabilities: "yes" }, |
| 87 | + { capabilities: {} }, |
| 88 | + { capabilities: { thinking: { types: { adaptive: {} } } } }, |
| 89 | + ] as Record<string, unknown>[]) { |
| 90 | + expect(acceptsAnthropicLiveModelContract({ id: "claude-opus-5", record })).toBe(false); |
| 91 | + } |
| 92 | + }); |
| 93 | +}); |
0 commit comments