mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 18:57:27 +00:00
refactor(gateway): dedupe invalid image request assertions
This commit is contained in:
@@ -137,6 +137,19 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
|
||||
}
|
||||
| undefined;
|
||||
const getFirstAgentMessage = () => getFirstAgentCall()?.message ?? "";
|
||||
const expectInvalidRequestNoDispatch = async (messages: unknown[]) => {
|
||||
agentCommand.mockClear();
|
||||
const res = await postChatCompletions(port, {
|
||||
model: "openclaw",
|
||||
messages,
|
||||
});
|
||||
expect(res.status).toBe(400);
|
||||
const json = (await res.json()) as Record<string, unknown>;
|
||||
expect((json.error as Record<string, unknown> | undefined)?.type).toBe(
|
||||
"invalid_request_error",
|
||||
);
|
||||
expect(agentCommand).toHaveBeenCalledTimes(0);
|
||||
};
|
||||
const postSyncUserMessage = async (message: string) => {
|
||||
const res = await postChatCompletions(port, {
|
||||
stream: false,
|
||||
@@ -308,27 +321,17 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
|
||||
}
|
||||
|
||||
{
|
||||
agentCommand.mockClear();
|
||||
const res = await postChatCompletions(port, {
|
||||
model: "openclaw",
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "image_url",
|
||||
image_url: { url: "https://example.com/image.png" },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(res.status).toBe(400);
|
||||
const json = (await res.json()) as Record<string, unknown>;
|
||||
expect((json.error as Record<string, unknown> | undefined)?.type).toBe(
|
||||
"invalid_request_error",
|
||||
);
|
||||
expect(agentCommand).toHaveBeenCalledTimes(0);
|
||||
await expectInvalidRequestNoDispatch([
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "image_url",
|
||||
image_url: { url: "https://example.com/image.png" },
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -423,50 +426,30 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
|
||||
}
|
||||
|
||||
{
|
||||
agentCommand.mockClear();
|
||||
const res = await postChatCompletions(port, {
|
||||
model: "openclaw",
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "image_url",
|
||||
image_url: { url: "data:application/pdf;base64,QUJDRA==" },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(res.status).toBe(400);
|
||||
const json = (await res.json()) as Record<string, unknown>;
|
||||
expect((json.error as Record<string, unknown> | undefined)?.type).toBe(
|
||||
"invalid_request_error",
|
||||
);
|
||||
expect(agentCommand).toHaveBeenCalledTimes(0);
|
||||
await expectInvalidRequestNoDispatch([
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "image_url",
|
||||
image_url: { url: "data:application/pdf;base64,QUJDRA==" },
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
agentCommand.mockClear();
|
||||
const manyImageParts = Array.from({ length: 9 }).map(() => ({
|
||||
type: "image_url",
|
||||
image_url: { url: "data:image/png;base64,QUJDRA==" },
|
||||
}));
|
||||
const res = await postChatCompletions(port, {
|
||||
model: "openclaw",
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: manyImageParts,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(res.status).toBe(400);
|
||||
const json = (await res.json()) as Record<string, unknown>;
|
||||
expect((json.error as Record<string, unknown> | undefined)?.type).toBe(
|
||||
"invalid_request_error",
|
||||
);
|
||||
expect(agentCommand).toHaveBeenCalledTimes(0);
|
||||
await expectInvalidRequestNoDispatch([
|
||||
{
|
||||
role: "user",
|
||||
content: manyImageParts,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user