Compare commits

...

2 Commits

Author SHA1 Message Date
Dallin Romney
4a7aa9a733 test: preserve caught rejection cause 2026-05-27 22:17:40 -07:00
Dallin Romney
5009f31f0c test: narrow rejected provider errors 2026-05-27 22:09:42 -07:00
2 changed files with 36 additions and 12 deletions

View File

@@ -2,6 +2,18 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { withFetchPreconnect } from "../test-utils/fetch-mock.js";
import { isMinimaxVlmModel, minimaxUnderstandImage } from "./minimax-vlm.js";
async function mustRejectWithError(promise: Promise<unknown>): Promise<Error> {
try {
await promise;
} catch (caught) {
if (caught instanceof Error) {
return caught;
}
throw new Error("expected promise to reject with an Error", { cause: caught });
}
throw new Error("expected promise to reject");
}
describe("minimaxUnderstandImage apiKey normalization", () => {
const priorFetch = global.fetch;
const priorMinimaxApiHost = process.env.MINIMAX_API_HOST;
@@ -173,12 +185,14 @@ describe("minimaxUnderstandImage apiKey normalization", () => {
});
global.fetch = withFetchPreconnect(fetchSpy);
const error = await minimaxUnderstandImage({
apiKey: "minimax-test-key",
prompt: "hi",
imageDataUrl: "data:image/png;base64,AAAA",
apiHost: "https://api.minimax.io",
}).catch((caught: unknown) => caught as Error);
const error = await mustRejectWithError(
minimaxUnderstandImage({
apiKey: "minimax-test-key",
prompt: "hi",
imageDataUrl: "data:image/png;base64,AAAA",
apiHost: "https://api.minimax.io",
}),
);
expect(error).toBeInstanceOf(Error);
expect(error.message).toContain("MiniMax VLM request failed");

View File

@@ -8,6 +8,18 @@ vi.mock("../../plugins/provider-runtime.js", () => ({
const TEST_PDF_INPUT = { base64: "dGVzdA==", filename: "doc.pdf" } as const;
async function mustRejectWithError(promise: Promise<unknown>): Promise<Error> {
try {
await promise;
} catch (caught) {
if (caught instanceof Error) {
return caught;
}
throw new Error("expected promise to reject with an Error", { cause: caught });
}
throw new Error("expected promise to reject");
}
function makeAnthropicAnalyzeParams(
overrides: Partial<{
apiKey: string;
@@ -129,9 +141,9 @@ describe("native PDF provider API calls", () => {
}),
);
const error = await pdfNativeProviders
.anthropicAnalyzePdf(makeAnthropicAnalyzeParams())
.catch((caught: unknown) => caught as Error);
const error = await mustRejectWithError(
pdfNativeProviders.anthropicAnalyzePdf(makeAnthropicAnalyzeParams()),
);
expect(error).toBeInstanceOf(Error);
expect(error.message).toContain("Anthropic PDF request failed");
@@ -158,9 +170,7 @@ describe("native PDF provider API calls", () => {
);
const error = await Promise.race([
pdfNativeProviders
.anthropicAnalyzePdf(makeAnthropicAnalyzeParams())
.catch((caught: unknown) => caught as Error),
mustRejectWithError(pdfNativeProviders.anthropicAnalyzePdf(makeAnthropicAnalyzeParams())),
new Promise<Error>((_resolve, reject) => {
setTimeout(() => reject(new Error("timed out waiting for bounded error body")), 500);
}),