mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-17 08:02:12 -06:00
e4ff7c1620
* fix: Discord read/search timeout, session-key fallback, and gateway execution mode - Add 15s timeout to readMessagesDiscord and searchMessagesDiscord so they fail fast instead of hanging indefinitely (#73431) - Fall back to CommandTargetSessionKey in dispatchReplyFromConfig when SessionKey is empty, so Discord inbound message:received hooks fire reliably (#73431, refs #33038) - Add resolveExecutionMode to Discord channel actions routing read/search through gateway timeout path, matching Telegram's pattern (#73431) * fix: move timeout to fetch layer, drop send.messages wrapper Inject AbortSignal.timeout into the Discord proxy-request-client fetch wrapper so every Discord REST call gets a 15s timeout at the HTTP level. This replaces the Promise.race wrapper in send.messages.ts — cleaner, covers all calls, and actually aborts the TCP connection. * fix: remove unused callerController variable in proxy-request-client test * fix: remove unnecessary mergeAbortSignal helper
67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { createDiscordRequestClient, DISCORD_REST_TIMEOUT_MS } from "./proxy-request-client.js";
|
|
|
|
describe("createDiscordRequestClient", () => {
|
|
it("injects an abort timeout signal into fetch calls", async () => {
|
|
const fetchSpy = vi.fn(async (_input: string | URL | Request, init?: RequestInit) => {
|
|
expect(init?.signal).toBeDefined();
|
|
expect(init!.signal!.aborted).toBe(false);
|
|
return new Response(JSON.stringify([]), { status: 200 });
|
|
});
|
|
|
|
const client = createDiscordRequestClient("Bot test-token", {
|
|
fetch: fetchSpy as never,
|
|
queueRequests: false,
|
|
});
|
|
|
|
await client.get("/channels/123/messages");
|
|
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it(
|
|
"aborts hanging requests after the timeout",
|
|
async () => {
|
|
const fetchSpy = vi.fn(
|
|
(_input: string | URL | Request, init?: RequestInit) =>
|
|
new Promise<Response>((_resolve, reject) => {
|
|
init?.signal?.addEventListener("abort", () => {
|
|
reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
});
|
|
}),
|
|
);
|
|
|
|
const client = createDiscordRequestClient("Bot test-token", {
|
|
fetch: fetchSpy as never,
|
|
queueRequests: false,
|
|
});
|
|
|
|
await expect(client.get("/channels/123/messages")).rejects.toThrow();
|
|
},
|
|
DISCORD_REST_TIMEOUT_MS + 5_000,
|
|
);
|
|
|
|
it("always injects a timeout signal even without a caller signal", async () => {
|
|
let receivedSignal: AbortSignal | undefined;
|
|
|
|
const fetchSpy = vi.fn(async (_input: string | URL | Request, init?: RequestInit) => {
|
|
receivedSignal = init?.signal ?? undefined;
|
|
return new Response(JSON.stringify({}), { status: 200 });
|
|
});
|
|
|
|
const client = createDiscordRequestClient("Bot test-token", {
|
|
fetch: fetchSpy as never,
|
|
queueRequests: false,
|
|
});
|
|
|
|
await client.get("/channels/123/messages");
|
|
|
|
expect(receivedSignal).toBeDefined();
|
|
expect(receivedSignal!.aborted).toBe(false);
|
|
});
|
|
|
|
it("exports a reasonable timeout constant", () => {
|
|
expect(DISCORD_REST_TIMEOUT_MS).toBeGreaterThanOrEqual(5_000);
|
|
expect(DISCORD_REST_TIMEOUT_MS).toBeLessThanOrEqual(30_000);
|
|
});
|
|
});
|