mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-19 01:24:46 +00:00
test: guard media understanding calls
This commit is contained in:
@@ -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<void>,
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user