|
1 | 1 | // Covers MiniMax VLM auth/header normalization and provider-specific routing. |
| 2 | +import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion"; |
2 | 3 | import { afterEach, describe, expect, it, vi } from "vitest"; |
3 | 4 | import { withFetchPreconnect } from "../test-utils/fetch-mock.js"; |
4 | 5 | import { isMinimaxVlmModel, minimaxUnderstandImage } from "./minimax-vlm.js"; |
@@ -157,6 +158,54 @@ describe("minimaxUnderstandImage apiKey normalization", () => {
|
157 | 158 | expect(timeoutSpy).toHaveBeenCalledWith(180_000); |
158 | 159 | }); |
159 | 160 | |
| 161 | +it("uses the default request timeout for non-positive caller timeouts", async () => { |
| 162 | +const timeoutSpy = vi.spyOn(AbortSignal, "timeout"); |
| 163 | +const fetchSpy = vi.fn(async () => { |
| 164 | +return new Response(apiResponse, { |
| 165 | +status: 200, |
| 166 | +headers: { "Content-Type": "application/json" }, |
| 167 | +}); |
| 168 | +}); |
| 169 | +global.fetch = withFetchPreconnect(fetchSpy); |
| 170 | + |
| 171 | +await expect( |
| 172 | +minimaxUnderstandImage({ |
| 173 | +apiKey: "minimax-test-key", |
| 174 | +prompt: "hi", |
| 175 | +imageDataUrl: "data:image/png;base64,AAAA", |
| 176 | +apiHost: "https://api.minimax.io", |
| 177 | +timeoutMs: 0, |
| 178 | +}), |
| 179 | +).resolves.toBe("ok"); |
| 180 | + |
| 181 | +expect(timeoutSpy).toHaveBeenCalledOnce(); |
| 182 | +expect(timeoutSpy).toHaveBeenCalledWith(60_000); |
| 183 | +}); |
| 184 | + |
| 185 | +it("clamps oversized caller request timeouts before creating the abort signal", async () => { |
| 186 | +const timeoutSpy = vi.spyOn(AbortSignal, "timeout"); |
| 187 | +const fetchSpy = vi.fn(async () => { |
| 188 | +return new Response(apiResponse, { |
| 189 | +status: 200, |
| 190 | +headers: { "Content-Type": "application/json" }, |
| 191 | +}); |
| 192 | +}); |
| 193 | +global.fetch = withFetchPreconnect(fetchSpy); |
| 194 | + |
| 195 | +await expect( |
| 196 | +minimaxUnderstandImage({ |
| 197 | +apiKey: "minimax-test-key", |
| 198 | +prompt: "hi", |
| 199 | +imageDataUrl: "data:image/png;base64,AAAA", |
| 200 | +apiHost: "https://api.minimax.io", |
| 201 | +timeoutMs: Number.MAX_SAFE_INTEGER, |
| 202 | +}), |
| 203 | +).resolves.toBe("ok"); |
| 204 | + |
| 205 | +expect(timeoutSpy).toHaveBeenCalledOnce(); |
| 206 | +expect(timeoutSpy).toHaveBeenCalledWith(MAX_TIMER_TIMEOUT_MS); |
| 207 | +}); |
| 208 | + |
160 | 209 | it("bounds large provider error response bodies", async () => { |
161 | 210 | // Provider error bodies can be large. Read enough for diagnostics, then |
162 | 211 | // cancel the stream so failures stay bounded. |
|