continue-custom/extensions/cli/src/config.test.ts
2025-08-20 17:57:35 -07:00

58 lines
1.5 KiB
TypeScript

import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml";
import { describe, expect, test, vi, beforeEach } from "vitest";
// Mock dependencies
vi.mock("./auth/workos.js");
import type { AuthConfig } from "./auth/workos.js";
import { getLlmApi } from "./config.js";
describe("config", () => {
let mockAuthConfig: AuthConfig;
beforeEach(() => {
vi.clearAllMocks();
mockAuthConfig = {
accessToken: "test-token",
refreshToken: "test-refresh",
userEmail: "test@example.com",
userId: "test-user",
organizationId: "test-org",
expiresAt: Date.now() + 3600000,
};
});
describe("getLlmApi()", () => {
test("should throw error when models array is empty", () => {
const assistant: AssistantUnrolled = {
name: "test-assistant",
version: "1.0.0",
models: [],
};
expect(() => getLlmApi(assistant, mockAuthConfig)).toThrow(
"No models found in the configured assistant",
);
});
test("should throw error when no chat models available", () => {
const assistant: AssistantUnrolled = {
name: "test-assistant",
version: "1.0.0",
models: [
{
provider: "openai",
model: "text-embedding-ada-002",
name: "Ada Embeddings",
roles: ["embed"],
} as ModelConfig,
],
};
expect(() => getLlmApi(assistant, mockAuthConfig)).toThrow(
"No models with the chat role found in the configured assistant",
);
});
});
});