Files
openclaw/test/scripts/tool-search-gateway-e2e.test.ts
2026-05-28 22:14:46 +02:00

62 lines
2.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { fetchJson } from "../../scripts/tool-search-gateway-e2e.ts";
describe("tool search gateway e2e fetch helper", () => {
it("aborts requests that never resolve", async () => {
let signal: AbortSignal | undefined;
await expect(
fetchJson("https://qa.example.invalid/debug/requests", undefined, {
timeoutMs: 25,
fetchImpl: async (_url, init) => {
signal = init.signal as AbortSignal | undefined;
return new Promise<Response>(() => {});
},
}),
).rejects.toMatchObject({
code: "ETIMEDOUT",
message: "HTTP request to https://qa.example.invalid/debug/requests timed out after 25ms",
});
expect(signal?.aborted).toBe(true);
});
it("times out while reading stalled response bodies", async () => {
await expect(
fetchJson("https://qa.example.invalid/v1/responses", undefined, {
timeoutMs: 25,
fetchImpl: async () =>
new Response(new ReadableStream<Uint8Array>({ start() {} }), {
status: 200,
}),
}),
).rejects.toMatchObject({
code: "ETIMEDOUT",
message: "HTTP request to https://qa.example.invalid/v1/responses timed out after 25ms",
});
});
it("parses successful JSON responses", async () => {
await expect(
fetchJson("https://qa.example.invalid/debug/requests", undefined, {
timeoutMs: 25,
fetchImpl: async () => new Response('{"ok":true}', { status: 200 }),
}),
).resolves.toEqual({ ok: true });
});
it("bounds oversized response bodies", async () => {
await expect(
fetchJson("https://qa.example.invalid/debug/requests", undefined, {
maxBodyBytes: 16,
timeoutMs: 1000,
fetchImpl: async () =>
new Response(JSON.stringify({ ok: true, padding: "x".repeat(128) }), {
status: 200,
}),
}),
).rejects.toMatchObject({
code: "ETOOBIG",
message: "HTTP response from https://qa.example.invalid/debug/requests exceeded 16 bytes",
});
});
});