2026-02-18 13:17:44 +00:00
|
|
|
import { vi } from "vitest";
|
|
|
|
|
|
2026-02-18 13:27:31 +00:00
|
|
|
type ModelAuthMockModule = {
|
|
|
|
|
resolveApiKeyForProvider: (...args: unknown[]) => unknown;
|
|
|
|
|
requireApiKey: (auth: { apiKey?: string; mode?: string }, provider: string) => string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function createModelAuthMockModule(): ModelAuthMockModule {
|
2026-02-18 13:17:44 +00:00
|
|
|
return {
|
2026-02-18 13:27:31 +00:00
|
|
|
resolveApiKeyForProvider: vi.fn() as (...args: unknown[]) => unknown,
|
2026-02-18 13:17:44 +00:00
|
|
|
requireApiKey: (auth: { apiKey?: string; mode?: string }, provider: string) => {
|
|
|
|
|
if (auth?.apiKey) {
|
|
|
|
|
return auth.apiKey;
|
|
|
|
|
}
|
|
|
|
|
throw new Error(`No API key resolved for provider "${provider}" (auth mode: ${auth?.mode}).`);
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|