|
| 1 | +import type { ModelInfo } from "../model.js" |
| 2 | +import type { BedrockDiscoveredTarget } from "../providers/bedrock.js" |
| 3 | +import { |
| 4 | + BEDROCK_1M_CONTEXT_DEFAULT_MODEL_IDS, |
| 5 | + BEDROCK_1M_CONTEXT_MODEL_IDS, |
| 6 | + BEDROCK_1M_CONTEXT_OPT_IN_MODEL_IDS, |
| 7 | + BEDROCK_GLOBAL_INFERENCE_MODEL_IDS, |
| 8 | + BEDROCK_NATIVE_1M_CONTEXT_MODEL_IDS, |
| 9 | + bedrockModels, |
| 10 | + expandBedrockTargetsWith1MVariants, |
| 11 | + hasBedrock1MContextIndicator, |
| 12 | + resolveBedrockModelInfo, |
| 13 | + stripBedrock1MContextSuffix, |
| 14 | +} from "../providers/bedrock.js" |
| 15 | + |
| 16 | +describe("Bedrock model catalog", () => { |
| 17 | + it("includes Claude Opus 4.7 with flat $5/$25 pricing across its 200K base and 1M tier", () => { |
| 18 | + // `bedrockModels` is typed as a giant discriminated union across every model entry, |
| 19 | + // so narrowing to `ModelInfo` lets us read the common fields without per-model checks. |
| 20 | + const opus47 = bedrockModels["anthropic.claude-opus-4-7" as keyof typeof bedrockModels] as ModelInfo |
| 21 | + expect(opus47).toBeDefined() |
| 22 | + expect(opus47.contextWindow).toBe(200_000) |
| 23 | + expect(opus47.supportsReasoningBudget).toBe(true) |
| 24 | + expect(opus47.inputPrice).toBe(5.0) |
| 25 | + expect(opus47.outputPrice).toBe(25.0) |
| 26 | + |
| 27 | + // Tier exists only so the dropdown split can offer a 1M variant; pricing is flat. |
| 28 | + const tier = opus47.tiers?.[0] |
| 29 | + expect(tier).toBeDefined() |
| 30 | + expect(tier?.contextWindow).toBe(1_000_000) |
| 31 | + expect(tier?.inputPrice).toBe(5.0) |
| 32 | + expect(tier?.outputPrice).toBe(25.0) |
| 33 | + }) |
| 34 | + |
| 35 | + it("flags Opus 4.7 as a native-1M model (so beta flags are NOT sent at runtime)", () => { |
| 36 | + expect(BEDROCK_NATIVE_1M_CONTEXT_MODEL_IDS).toContain("anthropic.claude-opus-4-7") |
| 37 | + }) |
| 38 | + |
| 39 | + it("includes Opus 4.7 in the 1M-capable and global-inference lists", () => { |
| 40 | + expect(BEDROCK_1M_CONTEXT_MODEL_IDS).toContain("anthropic.claude-opus-4-7") |
| 41 | + expect(BEDROCK_GLOBAL_INFERENCE_MODEL_IDS).toContain("anthropic.claude-opus-4-7") |
| 42 | + }) |
| 43 | + |
| 44 | + it("makes every 1M-capable model opt-in (empty default list)", () => { |
| 45 | + // Previously Sonnet 4.6 and Opus 4.6 auto-advertised 1M; the new dual-variant dropdown |
| 46 | + // presents both context tiers explicitly, so no model is auto-flipped anymore. |
| 47 | + expect(BEDROCK_1M_CONTEXT_DEFAULT_MODEL_IDS.length).toBe(0) |
| 48 | + expect(BEDROCK_1M_CONTEXT_OPT_IN_MODEL_IDS.length).toBe(BEDROCK_1M_CONTEXT_MODEL_IDS.length) |
| 49 | + }) |
| 50 | + |
| 51 | + it("matches per-model maxTokens to the documented Bedrock caps for current Anthropic models", () => { |
| 52 | + // These caps mirror the Anthropic-direct entries in `anthropic.ts`. Bumping them lets the |
| 53 | + // reasoning-budget slider extend past the legacy 8K cap (the original bug surfaced by Opus 4.7). |
| 54 | + expect((bedrockModels["anthropic.claude-opus-4-7"] as ModelInfo).maxTokens).toBe(128_000) |
| 55 | + expect((bedrockModels["anthropic.claude-opus-4-6-v1"] as ModelInfo).maxTokens).toBe(128_000) |
| 56 | + expect((bedrockModels["anthropic.claude-opus-4-5-20251101-v1:0"] as ModelInfo).maxTokens).toBe(32_000) |
| 57 | + expect((bedrockModels["anthropic.claude-opus-4-1-20250805-v1:0"] as ModelInfo).maxTokens).toBe(32_000) |
| 58 | + expect((bedrockModels["anthropic.claude-sonnet-4-6"] as ModelInfo).maxTokens).toBe(64_000) |
| 59 | + expect((bedrockModels["anthropic.claude-sonnet-4-5-20250929-v1:0"] as ModelInfo).maxTokens).toBe(64_000) |
| 60 | + expect((bedrockModels["anthropic.claude-haiku-4-5-20251001-v1:0"] as ModelInfo).maxTokens).toBe(64_000) |
| 61 | + }) |
| 62 | + |
| 63 | + it("marks AWS-documented Claude 4.5 models for 1-hour Bedrock prompt cache TTL", () => { |
| 64 | + expect((bedrockModels["anthropic.claude-sonnet-4-5-20250929-v1:0"] as ModelInfo).promptCacheTtl).toBe("1h") |
| 65 | + expect((bedrockModels["anthropic.claude-haiku-4-5-20251001-v1:0"] as ModelInfo).promptCacheTtl).toBe("1h") |
| 66 | + expect((bedrockModels["anthropic.claude-opus-4-5-20251101-v1:0"] as ModelInfo).promptCacheTtl).toBe("1h") |
| 67 | + }) |
| 68 | +}) |
| 69 | + |
| 70 | +describe("resolveBedrockModelInfo", () => { |
| 71 | + it("prefers the static maxTokens when no override is set", () => { |
| 72 | + const { info } = resolveBedrockModelInfo({ |
| 73 | + baseModelId: "anthropic.claude-opus-4-7", |
| 74 | + targetId: "anthropic.claude-opus-4-7", |
| 75 | + }) |
| 76 | + expect(info.maxTokens).toBe(128_000) |
| 77 | + }) |
| 78 | + |
| 79 | + it("applies maxOutputTokensOverride above the static cap", () => { |
| 80 | + const { info } = resolveBedrockModelInfo({ |
| 81 | + baseModelId: "anthropic.claude-opus-4-7", |
| 82 | + targetId: "anthropic.claude-opus-4-7", |
| 83 | + maxOutputTokensOverride: 256_000, |
| 84 | + }) |
| 85 | + expect(info.maxTokens).toBe(256_000) |
| 86 | + }) |
| 87 | + |
| 88 | + it("lets request-time modelMaxTokens still override (lowering for cost control)", () => { |
| 89 | + const { info } = resolveBedrockModelInfo({ |
| 90 | + baseModelId: "anthropic.claude-opus-4-7", |
| 91 | + targetId: "anthropic.claude-opus-4-7", |
| 92 | + maxOutputTokensOverride: 256_000, |
| 93 | + modelMaxTokens: 32_000, |
| 94 | + }) |
| 95 | + expect(info.maxTokens).toBe(32_000) |
| 96 | + }) |
| 97 | +}) |
| 98 | + |
| 99 | +describe("expandBedrockTargetsWith1MVariants", () => { |
| 100 | + const makeTarget = (overrides: Partial<BedrockDiscoveredTarget> = {}): BedrockDiscoveredTarget => ({ |
| 101 | + id: "anthropic.claude-opus-4-6-v1", |
| 102 | + label: "Claude Opus 4.6", |
| 103 | + baseModelId: "anthropic.claude-opus-4-6-v1", |
| 104 | + targetKind: "foundation-model", |
| 105 | + contextWindow: 200_000, |
| 106 | + contextSource: "base", |
| 107 | + ...overrides, |
| 108 | + }) |
| 109 | + |
| 110 | + it("emits two entries for a 1M-capable base target: default + :1m variant", () => { |
| 111 | + const expanded = expandBedrockTargetsWith1MVariants([makeTarget()]) |
| 112 | + |
| 113 | + expect(expanded).toHaveLength(2) |
| 114 | + const [base, oneM] = expanded as [BedrockDiscoveredTarget, BedrockDiscoveredTarget] |
| 115 | + expect(base.id).toBe("anthropic.claude-opus-4-6-v1") |
| 116 | + expect(base.contextWindow).toBe(200_000) |
| 117 | + expect(oneM.id).toBe("anthropic.claude-opus-4-6-v1:1m") |
| 118 | + expect(oneM.contextWindow).toBe(1_000_000) |
| 119 | + expect(oneM.label).toMatch(/1M context/i) |
| 120 | + expect(oneM.contextSource).toBe("profile-id") |
| 121 | + }) |
| 122 | + |
| 123 | + it("also emits two entries when AWS discovery returns a system profile id", () => { |
| 124 | + const expanded = expandBedrockTargetsWith1MVariants([ |
| 125 | + makeTarget({ |
| 126 | + id: "us.anthropic.claude-opus-4-7", |
| 127 | + baseModelId: "anthropic.claude-opus-4-7", |
| 128 | + targetKind: "system-profile", |
| 129 | + label: "Claude Opus 4.7 (us.anthropic.claude-opus-4-7)", |
| 130 | + }), |
| 131 | + ]) |
| 132 | + |
| 133 | + expect(expanded).toHaveLength(2) |
| 134 | + const oneM = expanded[1] as BedrockDiscoveredTarget |
| 135 | + expect(oneM.id).toBe("us.anthropic.claude-opus-4-7:1m") |
| 136 | + expect(hasBedrock1MContextIndicator(oneM.id)).toBe(true) |
| 137 | + expect(stripBedrock1MContextSuffix(oneM.id)).toBe("us.anthropic.claude-opus-4-7") |
| 138 | + }) |
| 139 | + |
| 140 | + it("leaves non-1M-capable targets untouched", () => { |
| 141 | + const expanded = expandBedrockTargetsWith1MVariants([ |
| 142 | + makeTarget({ |
| 143 | + id: "anthropic.claude-3-5-sonnet-20241022-v2:0", |
| 144 | + baseModelId: "anthropic.claude-3-5-sonnet-20241022-v2:0", |
| 145 | + }), |
| 146 | + ]) |
| 147 | + |
| 148 | + expect(expanded).toHaveLength(1) |
| 149 | + expect((expanded[0] as BedrockDiscoveredTarget).id).toBe("anthropic.claude-3-5-sonnet-20241022-v2:0") |
| 150 | + }) |
| 151 | + |
| 152 | + it("does not double-expand a target that already represents the 1M variant", () => { |
| 153 | + const expanded = expandBedrockTargetsWith1MVariants([ |
| 154 | + makeTarget({ id: "anthropic.claude-opus-4-6-v1:1m", contextWindow: 1_000_000 }), |
| 155 | + ]) |
| 156 | + |
| 157 | + expect(expanded).toHaveLength(1) |
| 158 | + expect((expanded[0] as BedrockDiscoveredTarget).id).toBe("anthropic.claude-opus-4-6-v1:1m") |
| 159 | + }) |
| 160 | +}) |
0 commit comments