Files
openclaw/src/agents/minimax-vlm.normalizes-api-key.test.ts
Tars dab0e97c22 fix(models): support minimax-portal coding plan vlm routing for image tool (openclaw#33953)
Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: tars90percent <252094836+tars90percent@users.noreply.github.com>
2026-03-07 14:30:53 -06:00

59 lines
2.0 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import { withFetchPreconnect } from "../test-utils/fetch-mock.js";
describe("minimaxUnderstandImage apiKey normalization", () => {
const priorFetch = global.fetch;
const apiResponse = JSON.stringify({
base_resp: { status_code: 0, status_msg: "ok" },
content: "ok",
});
afterEach(() => {
global.fetch = priorFetch;
vi.restoreAllMocks();
});
async function runNormalizationCase(apiKey: string) {
const fetchSpy = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
const auth = (init?.headers as Record<string, string> | undefined)?.Authorization;
expect(auth).toBe("Bearer minimax-test-key");
return new Response(apiResponse, {
status: 200,
headers: { "Content-Type": "application/json" },
});
});
global.fetch = withFetchPreconnect(fetchSpy);
const { minimaxUnderstandImage } = await import("./minimax-vlm.js");
const text = await minimaxUnderstandImage({
apiKey,
prompt: "hi",
imageDataUrl: "data:image/png;base64,AAAA",
apiHost: "https://api.minimax.io",
});
expect(text).toBe("ok");
expect(fetchSpy).toHaveBeenCalled();
}
it("strips embedded CR/LF before sending Authorization header", async () => {
await runNormalizationCase("minimax-test-\r\nkey");
});
it("drops non-Latin1 characters from apiKey before sending Authorization header", async () => {
await runNormalizationCase("minimax-\u0417\u2502test-key");
});
});
describe("isMinimaxVlmModel", () => {
it("only matches the canonical MiniMax VLM model id", async () => {
const { isMinimaxVlmModel } = await import("./minimax-vlm.js");
expect(isMinimaxVlmModel("minimax", "MiniMax-VL-01")).toBe(true);
expect(isMinimaxVlmModel("minimax-portal", "MiniMax-VL-01")).toBe(true);
expect(isMinimaxVlmModel("minimax-portal", "custom-vision")).toBe(false);
expect(isMinimaxVlmModel("openai", "MiniMax-VL-01")).toBe(false);
});
});