fix(discord): cap request timeout signals · openclaw/openclaw@4b9a80d
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime"; |
1 | 2 | import { withFetchPreconnect } from "openclaw/plugin-sdk/test-env"; |
2 | 3 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 4 | import { DiscordApiError, fetchDiscord, requestDiscord } from "./api.js"; |
@@ -204,4 +205,23 @@ describe("fetchDiscord", () => {
|
204 | 205 | expect(request.body).toBe(JSON.stringify({ content: "hello" })); |
205 | 206 | expect(new Headers(request.headers).get("content-type")).toBe("application/json"); |
206 | 207 | }); |
| 208 | + |
| 209 | +it("caps oversized request timeouts before creating abort signals", async () => { |
| 210 | +const timeoutController = new AbortController(); |
| 211 | +const timeoutSpy = vi.spyOn(AbortSignal, "timeout").mockReturnValue(timeoutController.signal); |
| 212 | +let request: RequestInit | undefined; |
| 213 | +const fetcher = withFetchPreconnect(async (_url, init) => { |
| 214 | +request = init; |
| 215 | +return jsonResponse({ id: "42" }, 200); |
| 216 | +}); |
| 217 | + |
| 218 | +await requestDiscord<{ id: string }>("/channels/c/messages", "test", { |
| 219 | + fetcher, |
| 220 | +retry: { attempts: 1 }, |
| 221 | +timeoutMs: Number.MAX_SAFE_INTEGER, |
| 222 | +}); |
| 223 | + |
| 224 | +expect(timeoutSpy).toHaveBeenCalledWith(MAX_TIMER_TIMEOUT_MS); |
| 225 | +expect(request?.signal).toBe(timeoutController.signal); |
| 226 | +}); |
207 | 227 | }); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。