| 1 | import { assert, it } from "@effect/vitest"; |
| 2 | |
| 3 | import { applyPreferredCodexDefaultModel, mapCodexModelCapabilities } from "./CodexProvider.ts"; |
| 4 | |
| 5 | it("maps current Codex model capability fields", () => { |
| 6 | const capabilities = mapCodexModelCapabilities({ |
| 7 | additionalSpeedTiers: [], |
| 8 | defaultReasoningEffort: "super-high", |
| 9 | description: "Test model", |
| 10 | displayName: "GPT Test", |
| 11 | hidden: false, |
| 12 | id: "gpt-test", |
| 13 | isDefault: true, |
| 14 | model: "gpt-test", |
| 15 | defaultServiceTier: "flex", |
| 16 | serviceTiers: [ |
| 17 | { |
| 18 | id: "priority", |
| 19 | name: "Fast", |
| 20 | description: "Lower latency responses.", |
| 21 | }, |
| 22 | { |
| 23 | id: "flex", |
| 24 | name: "Flex", |
| 25 | description: "Lower-cost asynchronous routing.", |
| 26 | }, |
| 27 | ], |
| 28 | supportedReasoningEfforts: [ |
| 29 | { |
| 30 | description: "Maximum reasoning", |
| 31 | reasoningEffort: "super-high", |
| 32 | }, |
| 33 | ], |
| 34 | }); |
| 35 | |
| 36 | assert.deepStrictEqual(capabilities.optionDescriptors, [ |
| 37 | { |
| 38 | id: "reasoningEffort", |
| 39 | label: "Reasoning", |
| 40 | type: "select", |
| 41 | options: [{ id: "super-high", label: "super-high", isDefault: true }], |
| 42 | currentValue: "super-high", |
| 43 | }, |
| 44 | { |
| 45 | id: "serviceTier", |
| 46 | label: "Service Tier", |
| 47 | type: "select", |
| 48 | options: [ |
| 49 | { id: "default", label: "Standard" }, |
| 50 | { |
| 51 | id: "priority", |
| 52 | label: "Fast", |
| 53 | description: "Lower latency responses.", |
| 54 | }, |
| 55 | { |
| 56 | id: "flex", |
| 57 | label: "Flex", |
| 58 | description: "Lower-cost asynchronous routing.", |
| 59 | isDefault: true, |
| 60 | }, |
| 61 | ], |
| 62 | currentValue: "flex", |
| 63 | }, |
| 64 | ]); |
| 65 | }); |
| 66 | |
| 67 | it("uses standard routing when the catalog has no default service tier", () => { |
| 68 | const capabilities = mapCodexModelCapabilities({ |
| 69 | additionalSpeedTiers: ["fast"], |
| 70 | defaultReasoningEffort: "medium", |
| 71 | defaultServiceTier: null, |
| 72 | description: "Test model", |
| 73 | displayName: "GPT Test", |
| 74 | hidden: false, |
| 75 | id: "gpt-test", |
| 76 | isDefault: true, |
| 77 | model: "gpt-test", |
| 78 | serviceTiers: [ |
| 79 | { |
| 80 | id: "priority", |
| 81 | name: "Fast", |
| 82 | description: "1.5x speed, increased usage", |
| 83 | }, |
| 84 | { |
| 85 | id: "ultrafast", |
| 86 | name: "Ultrafast", |
| 87 | description: "The fastest available responses for latency-sensitive work.", |
| 88 | }, |
| 89 | ], |
| 90 | supportedReasoningEfforts: [], |
| 91 | }); |
| 92 | |
| 93 | assert.deepStrictEqual(capabilities.optionDescriptors, [ |
| 94 | { |
| 95 | id: "serviceTier", |
| 96 | label: "Service Tier", |
| 97 | type: "select", |
| 98 | options: [ |
| 99 | { id: "default", label: "Standard", isDefault: true }, |
| 100 | { |
| 101 | id: "priority", |
| 102 | label: "Fast", |
| 103 | description: "1.5x speed, increased usage", |
| 104 | }, |
| 105 | { |
| 106 | id: "ultrafast", |
| 107 | label: "Ultrafast", |
| 108 | description: "Even faster, more expensive", |
| 109 | }, |
| 110 | ], |
| 111 | currentValue: "default", |
| 112 | }, |
| 113 | ]); |
| 114 | }); |
| 115 | |
| 116 | it("marks the most preferred available model as default", () => { |
| 117 | const models = applyPreferredCodexDefaultModel([ |
| 118 | { slug: "gpt-5.6-terra", name: "GPT-5.6-Terra", isCustom: false, capabilities: null }, |
| 119 | { slug: "gpt-5.4", name: "GPT-5.4", isCustom: false, isDefault: true, capabilities: null }, |
| 120 | ]); |
| 121 | |
| 122 | assert.deepStrictEqual( |
| 123 | models.map((model) => ({ slug: model.slug, isDefault: model.isDefault })), |
| 124 | [ |
| 125 | { slug: "gpt-5.6-terra", isDefault: true }, |
| 126 | { slug: "gpt-5.4", isDefault: undefined }, |
| 127 | ], |
| 128 | ); |
| 129 | }); |
| 130 | |
| 131 | it("prefers sol over terra when both are available", () => { |
| 132 | const models = applyPreferredCodexDefaultModel([ |
| 133 | { slug: "gpt-5.6-terra", name: "GPT-5.6-Terra", isCustom: false, capabilities: null }, |
| 134 | { slug: "gpt-5.6-sol", name: "GPT-5.6-Sol", isCustom: false, capabilities: null }, |
| 135 | ]); |
| 136 | |
| 137 | assert.deepStrictEqual(models.find((model) => model.isDefault)?.slug, "gpt-5.6-sol"); |
| 138 | }); |
| 139 | |
| 140 | it("ranks qualified Codex models while preserving their wire ids", () => { |
| 141 | const models = applyPreferredCodexDefaultModel([ |
| 142 | { |
| 143 | slug: "openai.gpt-5.6-luna", |
| 144 | name: "Luna", |
| 145 | isCustom: false, |
| 146 | isDefault: true, |
| 147 | capabilities: null, |
| 148 | }, |
| 149 | { slug: "openai.gpt-5.6-sol", name: "Sol", isCustom: false, capabilities: null }, |
| 150 | ]); |
| 151 | assert.deepStrictEqual( |
| 152 | models.filter((model) => model.isDefault).map((model) => model.slug), |
| 153 | ["openai.gpt-5.6-sol"], |
| 154 | ); |
| 155 | }); |
| 156 | |
| 157 | it("keeps Codex's own default when no preferred model is available", () => { |
| 158 | const models = applyPreferredCodexDefaultModel([ |
| 159 | { slug: "gpt-5.5", name: "GPT-5.5", isCustom: false, capabilities: null }, |
| 160 | { slug: "gpt-5.4", name: "GPT-5.4", isCustom: false, isDefault: true, capabilities: null }, |
| 161 | ]); |
| 162 | |
| 163 | assert.deepStrictEqual(models.find((model) => model.isDefault)?.slug, "gpt-5.4"); |
| 164 | }); |
| 165 | |
| 166 | it("ignores custom models that shadow a preferred slug", () => { |
| 167 | const models = applyPreferredCodexDefaultModel([ |
| 168 | { slug: "gpt-5.6-sol", name: "gpt-5.6-sol", isCustom: true, capabilities: null }, |
| 169 | { slug: "gpt-5.4", name: "GPT-5.4", isCustom: false, isDefault: true, capabilities: null }, |
| 170 | ]); |
| 171 | |
| 172 | assert.deepStrictEqual(models.find((model) => model.isDefault)?.slug, "gpt-5.4"); |
| 173 | }); |