|
1 | 1 | // Media-understanding defaults tests keep bundled provider metadata priorities, |
2 | 2 | // default models, and native document support aligned with manifests. |
3 | 3 | import { describe, expect, it, vi } from "vitest"; |
| 4 | +import type { MediaUnderstandingCapability, MediaUnderstandingProvider } from "./types.js"; |
4 | 5 |
|
5 | 6 | const mediaMetadataPlugins = vi.hoisted(() => [ |
6 | 7 | { |
@@ -112,6 +113,43 @@ import { |
112 | 113 | } from "./defaults.js"; |
113 | 114 |
|
114 | 115 | describe("resolveDefaultMediaModel", () => { |
| 116 | + it.each<MediaUnderstandingCapability>(["image", "audio", "video"])( |
| 117 | + "uses supplied %s registry defaults before configured models", |
| 118 | + (capability) => { |
| 119 | + const providerRegistry = new Map<string, MediaUnderstandingProvider>([ |
| 120 | + ["google", { id: "google", defaultModels: { [capability]: " registry-model " } }], |
| 121 | + ["blank", { id: "blank", defaultModels: { [capability]: " \t " } }], |
| 122 | + ]); |
| 123 | + const models = [" GEMINI ", "blank", "missing"].map((providerId) => |
| 124 | + resolveDefaultMediaModel({ |
| 125 | + capability, |
| 126 | + providerId, |
| 127 | + providerRegistry, |
| 128 | + cfg: { |
| 129 | + models: { |
| 130 | + providers: { |
| 131 | + google: { |
| 132 | + baseUrl: "https://example.invalid", |
| 133 | + models: [ |
| 134 | + { |
| 135 | + id: "configured-image", |
| 136 | + name: "configured", |
| 137 | + input: ["image"], |
| 138 | + reasoning: false, |
| 139 | + cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, |
| 140 | + maxTokens: 1024, |
| 141 | + }, |
| 142 | + ], |
| 143 | + }, |
| 144 | + }, |
| 145 | + }, |
| 146 | + }, |
| 147 | + }), |
| 148 | + ); |
| 149 | + expect(models).toEqual(["registry-model", undefined, undefined]); |
| 150 | + }, |
| 151 | + ); |
| 152 | + |
115 | 153 | it("resolves bundled audio defaults from provider metadata", () => { |
116 | 154 | expect(resolveDefaultMediaModel({ providerId: "mistral", capability: "audio" })).toBe( |
117 | 155 | "voxtral-mini-latest", |
@@ -169,6 +207,42 @@ describe("resolveDefaultMediaModel", () => { |
169 | 207 | }); |
170 | 208 |
|
171 | 209 | describe("resolveAutoMediaKeyProviders", () => { |
| 210 | + it.each<MediaUnderstandingCapability>(["image", "audio", "video"])( |
| 211 | + "orders %s priorities without conflating declared capabilities and runtime hooks", |
| 212 | + (capability) => { |
| 213 | + const hooks = { |
| 214 | + describeImage: async () => ({ text: "image" }), |
| 215 | + transcribeAudio: async () => ({ text: "audio" }), |
| 216 | + describeVideo: async () => ({ text: "video" }), |
| 217 | + }; |
| 218 | + const providers: MediaUnderstandingProvider[] = [ |
| 219 | + { id: "z-tie", capabilities: [capability], autoPriority: { [capability]: 2 } }, |
| 220 | + { id: "a-tie", capabilities: [capability], autoPriority: { [capability]: 2 } }, |
| 221 | + { id: "zero", capabilities: [capability], autoPriority: { [capability]: 0 } }, |
| 222 | + { id: "negative", capabilities: [capability], autoPriority: { [capability]: -2 } }, |
| 223 | + { id: "nan", capabilities: [capability], autoPriority: { [capability]: Number.NaN } }, |
| 224 | + { id: "infinity", capabilities: [capability], autoPriority: { [capability]: Infinity } }, |
| 225 | + { id: "declared-empty", capabilities: [], autoPriority: { [capability]: -10 }, ...hooks }, |
| 226 | + { id: "hook-only", autoPriority: { [capability]: 1 }, ...hooks }, |
| 227 | + { id: "no-hook", autoPriority: { [capability]: -20 } }, |
| 228 | + { id: "gemini", capabilities: [capability], autoPriority: { [capability]: 3 } }, |
| 229 | + { id: "google", capabilities: [capability], autoPriority: { [capability]: 4 } }, |
| 230 | + ]; |
| 231 | + const providerRegistry = new Map(providers.map((provider) => [provider.id, provider])); |
| 232 | + |
| 233 | + expect(resolveAutoMediaKeyProviders({ capability, providerRegistry })).toEqual([ |
| 234 | + "negative", |
| 235 | + "zero", |
| 236 | + "hook-only", |
| 237 | + "a-tie", |
| 238 | + "z-tie", |
| 239 | + "google", |
| 240 | + "google", |
| 241 | + ]); |
| 242 | + expect([...providerRegistry.values()]).toEqual(providers); |
| 243 | + }, |
| 244 | + ); |
| 245 | + |
172 | 246 | it("keeps the bundled audio fallback order", () => { |
173 | 247 | expect(resolveAutoMediaKeyProviders({ capability: "audio" })).toEqual([ |
174 | 248 | "openai", |
|
0 commit comments