| 1 | import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; |
| 2 | import { describe, expect, test, vi, beforeEach } from "vitest"; |
| 3 | |
| 4 | // Mock dependencies |
| 5 | vi.mock("./auth/workos.js"); |
| 6 | |
| 7 | import type { AuthConfig } from "./auth/workos.js"; |
| 8 | import { getLlmApi } from "./config.js"; |
| 9 | |
| 10 | describe("config", () => { |
| 11 | let mockAuthConfig: AuthConfig; |
| 12 | |
| 13 | beforeEach(() => { |
| 14 | vi.clearAllMocks(); |
| 15 | |
| 16 | mockAuthConfig = { |
| 17 | accessToken: "test-token", |
| 18 | refreshToken: "test-refresh", |
| 19 | userEmail: "test@example.com", |
| 20 | userId: "test-user", |
| 21 | organizationId: "test-org", |
| 22 | expiresAt: Date.now() + 3600000, |
| 23 | }; |
| 24 | }); |
| 25 | |
| 26 | describe("getLlmApi()", () => { |
| 27 | test("should throw error when models array is empty", () => { |
| 28 | const assistant: AssistantUnrolled = { |
| 29 | name: "test-assistant", |
| 30 | version: "1.0.0", |
| 31 | models: [], |
| 32 | }; |
| 33 | |
| 34 | expect(() => getLlmApi(assistant, mockAuthConfig)).toThrow( |
| 35 | "No models found in the configured assistant", |
| 36 | ); |
| 37 | }); |
| 38 | |
| 39 | test("should throw error when no chat models available", () => { |
| 40 | const assistant: AssistantUnrolled = { |
| 41 | name: "test-assistant", |
| 42 | version: "1.0.0", |
| 43 | models: [ |
| 44 | { |
| 45 | provider: "openai", |
| 46 | model: "text-embedding-ada-002", |
| 47 | name: "Ada Embeddings", |
| 48 | roles: ["embed"], |
| 49 | } as ModelConfig, |
| 50 | ], |
| 51 | }; |
| 52 | |
| 53 | expect(() => getLlmApi(assistant, mockAuthConfig)).toThrow( |
| 54 | "No models with the chat role found in the configured assistant", |
| 55 | ); |
| 56 | }); |
| 57 | }); |
| 58 | }); |