|
| 1 | +import { describe, it, expect, vi, beforeEach } from "vitest" |
| 2 | +import OpenAI from "openai" |
| 3 | +import { miniMaxDefaultModelId, miniMaxModels } from "@roo-code/types" |
| 4 | + |
| 5 | +import type { ApiHandlerOptions } from "../../../shared/api" |
| 6 | + |
| 7 | +import { MiniMaxHandler } from "../minimax" |
| 8 | + |
| 9 | +vi.mock("openai") |
| 10 | + |
| 11 | +describe("MiniMaxHandler", () => { |
| 12 | + let handler: MiniMaxHandler |
| 13 | + let mockOptions: ApiHandlerOptions |
| 14 | + |
| 15 | + beforeEach(() => { |
| 16 | + mockOptions = { |
| 17 | + apiModelId: "abab5.5s-chat", |
| 18 | + miniMaxApiKey: "test-api-key", |
| 19 | + } |
| 20 | + handler = new MiniMaxHandler(mockOptions) |
| 21 | + vi.clearAllMocks() |
| 22 | + }) |
| 23 | + |
| 24 | + describe("constructor", () => { |
| 25 | + it("should initialize with provided options", () => { |
| 26 | + expect(handler).toBeInstanceOf(MiniMaxHandler) |
| 27 | + expect(handler.getModel().id).toBe(mockOptions.apiModelId) |
| 28 | + }) |
| 29 | + |
| 30 | + it("should handle missing API key", () => { |
| 31 | + expect(() => { |
| 32 | + new MiniMaxHandler({ |
| 33 | + ...mockOptions, |
| 34 | + miniMaxApiKey: undefined, |
| 35 | + }) |
| 36 | + }).not.toThrow() |
| 37 | + }) |
| 38 | + |
| 39 | + it("should use default model ID if not provided", () => { |
| 40 | + const handlerWithoutModel = new MiniMaxHandler({ |
| 41 | + ...mockOptions, |
| 42 | + apiModelId: undefined, |
| 43 | + }) |
| 44 | + expect(handlerWithoutModel.getModel().id).toBe(miniMaxDefaultModelId) |
| 45 | + }) |
| 46 | + |
| 47 | + it("should use default base URL if not provided", () => { |
| 48 | + const handlerWithoutBaseUrl = new MiniMaxHandler({ |
| 49 | + ...mockOptions, |
| 50 | + miniMaxBaseUrl: undefined, |
| 51 | + }) |
| 52 | + expect(handlerWithoutBaseUrl).toBeInstanceOf(MiniMaxHandler) |
| 53 | + // The base URL is passed to OpenAI client internally |
| 54 | + }) |
| 55 | + |
| 56 | + it("should use custom base URL if provided", () => { |
| 57 | + const customBaseUrl = "https://custom.minimax.com/v1" |
| 58 | + const handlerWithCustomUrl = new MiniMaxHandler({ |
| 59 | + ...mockOptions, |
| 60 | + miniMaxBaseUrl: customBaseUrl, |
| 61 | + }) |
| 62 | + expect(handlerWithCustomUrl).toBeInstanceOf(MiniMaxHandler) |
| 63 | + // The custom base URL is passed to OpenAI client |
| 64 | + }) |
| 65 | + |
| 66 | + it("should set includeMaxTokens to true", () => { |
| 67 | + // Create a new handler and verify OpenAI client was called with includeMaxTokens |
| 68 | + const _handler = new MiniMaxHandler(mockOptions) |
| 69 | + expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ apiKey: mockOptions.miniMaxApiKey })) |
| 70 | + // includeMaxTokens is an internal property passed to super constructor |
| 71 | + }) |
| 72 | + }) |
| 73 | + |
| 74 | + describe("getModel", () => { |
| 75 | + it("should return correct model info for abab5.5s-chat", () => { |
| 76 | + const model = handler.getModel() |
| 77 | + expect(model.id).toBe("abab5.5s-chat") |
| 78 | + expect(model.info).toEqual(miniMaxModels["abab5.5s-chat"]) |
| 79 | + }) |
| 80 | + |
| 81 | + it("should return correct model info for abab6.5s-chat", () => { |
| 82 | + const handlerWithPro = new MiniMaxHandler({ |
| 83 | + ...mockOptions, |
| 84 | + apiModelId: "abab6.5s-chat", |
| 85 | + }) |
| 86 | + const model = handlerWithPro.getModel() |
| 87 | + expect(model.id).toBe("abab6.5s-chat") |
| 88 | + expect(model.info).toEqual(miniMaxModels["abab6.5s-chat"]) |
| 89 | + }) |
| 90 | + |
| 91 | + it("should return correct model info for abab6.5g-chat", () => { |
| 92 | + const handlerWithVision = new MiniMaxHandler({ |
| 93 | + ...mockOptions, |
| 94 | + apiModelId: "abab6.5g-chat", |
| 95 | + }) |
| 96 | + const model = handlerWithVision.getModel() |
| 97 | + expect(model.id).toBe("abab6.5g-chat") |
| 98 | + expect(model.info).toEqual(miniMaxModels["abab6.5g-chat"]) |
| 99 | + expect(model.info.supportsImages).toBe(true) |
| 100 | + }) |
| 101 | + |
| 102 | + it("should return provided model ID with default model info if model does not exist", () => { |
| 103 | + const handlerWithInvalidModel = new MiniMaxHandler({ |
| 104 | + ...mockOptions, |
| 105 | + apiModelId: "invalid-model", |
| 106 | + }) |
| 107 | + const model = handlerWithInvalidModel.getModel() |
| 108 | + expect(model.id).toBe("invalid-model") |
| 109 | + // Should fallback to default model info |
| 110 | + expect(model.info).toEqual(miniMaxModels[miniMaxDefaultModelId]) |
| 111 | + }) |
| 112 | + |
| 113 | + it("should return default model if no model ID is provided", () => { |
| 114 | + const handlerWithoutModel = new MiniMaxHandler({ |
| 115 | + ...mockOptions, |
| 116 | + apiModelId: undefined, |
| 117 | + }) |
| 118 | + const model = handlerWithoutModel.getModel() |
| 119 | + expect(model.id).toBe(miniMaxDefaultModelId) |
| 120 | + expect(model.info).toEqual(miniMaxModels[miniMaxDefaultModelId]) |
| 121 | + }) |
| 122 | + }) |
| 123 | + |
| 124 | + describe("model capabilities", () => { |
| 125 | + it("should correctly report image support for models", () => { |
| 126 | + const textOnlyModel = new MiniMaxHandler({ |
| 127 | + ...mockOptions, |
| 128 | + apiModelId: "abab5.5s-chat", |
| 129 | + }) |
| 130 | + expect(textOnlyModel.getModel().info.supportsImages).toBe(false) |
| 131 | + |
| 132 | + const visionModel = new MiniMaxHandler({ |
| 133 | + ...mockOptions, |
| 134 | + apiModelId: "abab6.5g-chat", |
| 135 | + }) |
| 136 | + expect(visionModel.getModel().info.supportsImages).toBe(true) |
| 137 | + }) |
| 138 | + |
| 139 | + it("should report no prompt cache support for all models", () => { |
| 140 | + const models = ["abab5.5s-chat", "abab6.5s-chat", "abab6.5g-chat"] |
| 141 | + |
| 142 | + models.forEach((modelId) => { |
| 143 | + const handler = new MiniMaxHandler({ |
| 144 | + ...mockOptions, |
| 145 | + apiModelId: modelId, |
| 146 | + }) |
| 147 | + expect(handler.getModel().info.supportsPromptCache).toBe(false) |
| 148 | + }) |
| 149 | + }) |
| 150 | + |
| 151 | + it("should have correct context windows for each model", () => { |
| 152 | + const contextWindows = { |
| 153 | + "abab5.5s-chat": 128_000, |
| 154 | + "abab6.5s-chat": 245_000, |
| 155 | + "abab6.5g-chat": 245_000, |
| 156 | + } |
| 157 | + |
| 158 | + Object.entries(contextWindows).forEach(([modelId, expectedWindow]) => { |
| 159 | + const handler = new MiniMaxHandler({ |
| 160 | + ...mockOptions, |
| 161 | + apiModelId: modelId, |
| 162 | + }) |
| 163 | + expect(handler.getModel().info.contextWindow).toBe(expectedWindow) |
| 164 | + }) |
| 165 | + }) |
| 166 | + |
| 167 | + it("should have correct max tokens for all models", () => { |
| 168 | + const models = ["abab5.5s-chat", "abab6.5s-chat", "abab6.5g-chat"] |
| 169 | + |
| 170 | + models.forEach((modelId) => { |
| 171 | + const handler = new MiniMaxHandler({ |
| 172 | + ...mockOptions, |
| 173 | + apiModelId: modelId, |
| 174 | + }) |
| 175 | + expect(handler.getModel().info.maxTokens).toBe(8192) |
| 176 | + }) |
| 177 | + }) |
| 178 | + }) |
| 179 | +}) |
0 commit comments