|
| 1 | +// npx vitest run src/api/providers/__tests__/aetherapi.spec.ts |
| 2 | + |
| 3 | +import OpenAI from "openai" |
| 4 | + |
| 5 | +import { type AetherapiModelId, type ProviderSettings, aetherapiDefaultModelId, aetherapiModels } from "@roo-code/types" |
| 6 | + |
| 7 | +import { buildApiHandler } from "../../index" |
| 8 | +import { AetherapiHandler } from "../aetherapi" |
| 9 | + |
| 10 | +const mockCreate = vi.fn() |
| 11 | + |
| 12 | +vi.mock("openai", () => ({ |
| 13 | + default: vi.fn(() => ({ |
| 14 | + chat: { |
| 15 | + completions: { |
| 16 | + create: mockCreate, |
| 17 | + }, |
| 18 | + }, |
| 19 | + })), |
| 20 | +})) |
| 21 | + |
| 22 | +describe("AetherapiHandler", () => { |
| 23 | + beforeEach(() => { |
| 24 | + vi.clearAllMocks() |
| 25 | + }) |
| 26 | + |
| 27 | + it("uses the default AetherAPI base URL", () => { |
| 28 | + new AetherapiHandler({ aetherapiApiKey: "test-aetherapi-api-key" }) |
| 29 | + |
| 30 | + expect(OpenAI).toHaveBeenCalledWith( |
| 31 | + expect.objectContaining({ |
| 32 | + baseURL: "https://api.aetherapi.dev/v1", |
| 33 | + }), |
| 34 | + ) |
| 35 | + }) |
| 36 | + |
| 37 | + it("uses a configured AetherAPI base URL", () => { |
| 38 | + new AetherapiHandler({ |
| 39 | + aetherapiApiKey: "test-aetherapi-api-key", |
| 40 | + aetherapiBaseUrl: "https://gateway.example.test/v1", |
| 41 | + }) |
| 42 | + |
| 43 | + expect(OpenAI).toHaveBeenCalledWith( |
| 44 | + expect.objectContaining({ |
| 45 | + baseURL: "https://gateway.example.test/v1", |
| 46 | + }), |
| 47 | + ) |
| 48 | + }) |
| 49 | + |
| 50 | + it("uses the AetherAPI API key", () => { |
| 51 | + new AetherapiHandler({ aetherapiApiKey: "test-aetherapi-api-key" }) |
| 52 | + |
| 53 | + expect(OpenAI).toHaveBeenCalledWith( |
| 54 | + expect.objectContaining({ |
| 55 | + apiKey: "test-aetherapi-api-key", |
| 56 | + }), |
| 57 | + ) |
| 58 | + }) |
| 59 | + |
| 60 | + it("throws when the AetherAPI API key is missing", () => { |
| 61 | + expect(() => new AetherapiHandler({})).toThrow("API key is required") |
| 62 | + }) |
| 63 | + |
| 64 | + it("returns the default AetherAPI model when no model is specified", () => { |
| 65 | + const handler = new AetherapiHandler({ aetherapiApiKey: "test-aetherapi-api-key" }) |
| 66 | + |
| 67 | + expect(handler.getModel()).toEqual({ |
| 68 | + id: aetherapiDefaultModelId, |
| 69 | + info: aetherapiModels[aetherapiDefaultModelId], |
| 70 | + }) |
| 71 | + }) |
| 72 | + |
| 73 | + it("returns a configured AetherAPI model", () => { |
| 74 | + const modelId: AetherapiModelId = "gpt-5.4" |
| 75 | + const handler = new AetherapiHandler({ |
| 76 | + apiModelId: modelId, |
| 77 | + aetherapiApiKey: "test-aetherapi-api-key", |
| 78 | + }) |
| 79 | + |
| 80 | + expect(handler.getModel()).toEqual({ |
| 81 | + id: modelId, |
| 82 | + info: aetherapiModels[modelId], |
| 83 | + }) |
| 84 | + }) |
| 85 | +}) |
| 86 | + |
| 87 | +describe("buildApiHandler AetherAPI routing", () => { |
| 88 | + it("builds an AetherAPI handler for the aetherapi provider", () => { |
| 89 | + const handler = buildApiHandler({ |
| 90 | + apiProvider: "aetherapi", |
| 91 | + aetherapiApiKey: "test-aetherapi-api-key", |
| 92 | + apiModelId: "gpt-5.4", |
| 93 | + } as ProviderSettings) |
| 94 | + |
| 95 | + expect(handler).toBeInstanceOf(AetherapiHandler) |
| 96 | + expect(handler.getModel()).toEqual({ |
| 97 | + id: "gpt-5.4", |
| 98 | + info: aetherapiModels["gpt-5.4"], |
| 99 | + }) |
| 100 | + }) |
| 101 | +}) |
0 commit comments