mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 04:27:27 +00:00
refactor(agents): dedupe minimax api-key normalization tests
This commit is contained in:
@@ -3,30 +3,31 @@ import { withFetchPreconnect } from "../test-utils/fetch-mock.js";
|
|||||||
|
|
||||||
describe("minimaxUnderstandImage apiKey normalization", () => {
|
describe("minimaxUnderstandImage apiKey normalization", () => {
|
||||||
const priorFetch = global.fetch;
|
const priorFetch = global.fetch;
|
||||||
|
const apiResponse = JSON.stringify({
|
||||||
|
base_resp: { status_code: 0, status_msg: "ok" },
|
||||||
|
content: "ok",
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
global.fetch = priorFetch;
|
global.fetch = priorFetch;
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("strips embedded CR/LF before sending Authorization header", async () => {
|
async function runNormalizationCase(apiKey: string) {
|
||||||
const fetchSpy = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
|
const fetchSpy = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
|
||||||
const auth = (init?.headers as Record<string, string> | undefined)?.Authorization;
|
const auth = (init?.headers as Record<string, string> | undefined)?.Authorization;
|
||||||
expect(auth).toBe("Bearer minimax-test-key");
|
expect(auth).toBe("Bearer minimax-test-key");
|
||||||
|
|
||||||
return new Response(
|
return new Response(apiResponse, {
|
||||||
JSON.stringify({
|
status: 200,
|
||||||
base_resp: { status_code: 0, status_msg: "ok" },
|
headers: { "Content-Type": "application/json" },
|
||||||
content: "ok",
|
});
|
||||||
}),
|
|
||||||
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
global.fetch = withFetchPreconnect(fetchSpy);
|
global.fetch = withFetchPreconnect(fetchSpy);
|
||||||
|
|
||||||
const { minimaxUnderstandImage } = await import("./minimax-vlm.js");
|
const { minimaxUnderstandImage } = await import("./minimax-vlm.js");
|
||||||
const text = await minimaxUnderstandImage({
|
const text = await minimaxUnderstandImage({
|
||||||
apiKey: "minimax-test-\r\nkey",
|
apiKey,
|
||||||
prompt: "hi",
|
prompt: "hi",
|
||||||
imageDataUrl: "data:image/png;base64,AAAA",
|
imageDataUrl: "data:image/png;base64,AAAA",
|
||||||
apiHost: "https://api.minimax.io",
|
apiHost: "https://api.minimax.io",
|
||||||
@@ -34,32 +35,13 @@ describe("minimaxUnderstandImage apiKey normalization", () => {
|
|||||||
|
|
||||||
expect(text).toBe("ok");
|
expect(text).toBe("ok");
|
||||||
expect(fetchSpy).toHaveBeenCalled();
|
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 () => {
|
it("drops non-Latin1 characters from apiKey before sending Authorization header", async () => {
|
||||||
const fetchSpy = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
|
await runNormalizationCase("minimax-\u0417\u2502test-key");
|
||||||
const auth = (init?.headers as Record<string, string> | undefined)?.Authorization;
|
|
||||||
expect(auth).toBe("Bearer minimax-test-key");
|
|
||||||
|
|
||||||
return new Response(
|
|
||||||
JSON.stringify({
|
|
||||||
base_resp: { status_code: 0, status_msg: "ok" },
|
|
||||||
content: "ok",
|
|
||||||
}),
|
|
||||||
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
||||||
);
|
|
||||||
});
|
|
||||||
global.fetch = withFetchPreconnect(fetchSpy);
|
|
||||||
|
|
||||||
const { minimaxUnderstandImage } = await import("./minimax-vlm.js");
|
|
||||||
const text = await minimaxUnderstandImage({
|
|
||||||
apiKey: "minimax-\u0417\u2502test-key",
|
|
||||||
prompt: "hi",
|
|
||||||
imageDataUrl: "data:image/png;base64,AAAA",
|
|
||||||
apiHost: "https://api.minimax.io",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(text).toBe("ok");
|
|
||||||
expect(fetchSpy).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user