diff --git a/src/media-understanding/media-understanding-url-fallback.test.ts b/src/media-understanding/media-understanding-url-fallback.test.ts index 62cbc662bf8..4f8e93b89b8 100644 --- a/src/media-understanding/media-understanding-url-fallback.test.ts +++ b/src/media-understanding/media-understanding-url-fallback.test.ts @@ -15,6 +15,23 @@ vi.mock("../media/fetch.js", async () => { }; }); +function requireFetchRemoteMediaInput(): { + url?: unknown; + fetchImpl?: unknown; + maxBytes?: unknown; + ssrfPolicy?: unknown; +} { + const [call] = fetchRemoteMediaMock.mock.calls; + if (!call) { + throw new Error("expected fetchRemoteMedia call"); + } + const [input] = call; + if (typeof input !== "object" || input === null || Array.isArray(input)) { + throw new Error("expected fetchRemoteMedia input to be an object"); + } + return input; +} + async function withBlockedLocalAttachmentFallback( prefix: string, run: (params: { cache: MediaAttachmentCache; fallbackUrl: string }) => Promise, @@ -65,10 +82,8 @@ describe("media understanding attachment URL fallback", () => { expect(path.basename(result.path).startsWith("openclaw-media-")).toBe(true); expect(path.extname(result.path)).toBe(".jpg"); expect(fetchRemoteMediaMock).toHaveBeenCalledTimes(1); - const fetchInput = fetchRemoteMediaMock.mock.calls[0]?.[0] as - | { url?: unknown; fetchImpl?: unknown; maxBytes?: unknown; ssrfPolicy?: unknown } - | undefined; - const fetchImpl = fetchInput?.fetchImpl; + const fetchInput = requireFetchRemoteMediaInput(); + const fetchImpl = fetchInput.fetchImpl; expect(fetchInput).toStrictEqual({ url: fallbackUrl, fetchImpl, @@ -95,10 +110,8 @@ describe("media understanding attachment URL fallback", () => { }); expect(result.buffer.toString()).toBe("fallback-buffer"); expect(fetchRemoteMediaMock).toHaveBeenCalledTimes(1); - const fetchInput = fetchRemoteMediaMock.mock.calls[0]?.[0] as - | { url?: unknown; fetchImpl?: unknown; maxBytes?: unknown; ssrfPolicy?: unknown } - | undefined; - const fetchImpl = fetchInput?.fetchImpl; + const fetchInput = requireFetchRemoteMediaInput(); + const fetchImpl = fetchInput.fetchImpl; expect(fetchInput).toStrictEqual({ url: fallbackUrl, fetchImpl, diff --git a/src/media-understanding/openai-compatible-audio.pin-dns.test.ts b/src/media-understanding/openai-compatible-audio.pin-dns.test.ts index 6e726a567a6..e5507382677 100644 --- a/src/media-understanding/openai-compatible-audio.pin-dns.test.ts +++ b/src/media-understanding/openai-compatible-audio.pin-dns.test.ts @@ -12,6 +12,18 @@ vi.mock("./shared.js", async () => { }; }); +function requirePostTranscriptionRequest(): { pinDns?: unknown; body?: unknown } { + const [call] = postTranscriptionRequestMock.mock.calls; + if (!call) { + throw new Error("expected postTranscriptionRequest call"); + } + const [request] = call; + if (typeof request !== "object" || request === null || Array.isArray(request)) { + throw new Error("expected postTranscriptionRequest params to be an object"); + } + return request; +} + import { transcribeOpenAiCompatibleAudio } from "./openai-compatible-audio.js"; afterEach(() => { @@ -37,10 +49,8 @@ describe("transcribeOpenAiCompatibleAudio pinDns", () => { }); expect(result.text).toBe("ok"); - const request = postTranscriptionRequestMock.mock.calls[0]?.[0] as - | { pinDns?: boolean; body?: unknown } - | undefined; - expect(request?.pinDns).toBe(false); - expect(request?.body).toBeInstanceOf(FormData); + const request = requirePostTranscriptionRequest(); + expect(request.pinDns).toBe(false); + expect(request.body).toBeInstanceOf(FormData); }); }); diff --git a/src/media-understanding/runtime.test.ts b/src/media-understanding/runtime.test.ts index 521fd93263d..c7312b805fc 100644 --- a/src/media-understanding/runtime.test.ts +++ b/src/media-understanding/runtime.test.ts @@ -46,6 +46,14 @@ vi.mock("./image-runtime.js", () => ({ describeImageWithModel: mocks.describeImageWithModel, })); +function requireRunCapabilityRequest(): unknown { + const [call] = mocks.runCapability.mock.calls; + if (!call) { + throw new Error("expected runCapability call"); + } + return call[0]; +} + describe("media-understanding runtime", () => { afterEach(() => { mocks.buildProviderRegistry.mockReset(); @@ -200,7 +208,7 @@ describe("media-understanding runtime", () => { }); expect(mocks.runCapability).toHaveBeenCalledOnce(); - expect(mocks.runCapability.mock.calls[0]?.[0]).toEqual({ + expect(requireRunCapabilityRequest()).toEqual({ capability: "image", cfg: { tools: {