fix(qa-matrix): cap substrate request timeouts · openclaw/openclaw@0983e76
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
File tree
extensions/qa-matrix/src/substrate
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import { requestMatrixJson, type MatrixQaFetchLike } from "./request.js"; |
| 3 | + |
| 4 | +const MAX_TIMER_TIMEOUT_MS = 2_147_000_000; |
| 5 | + |
| 6 | +describe("requestMatrixJson", () => { |
| 7 | +afterEach(() => { |
| 8 | +vi.restoreAllMocks(); |
| 9 | +}); |
| 10 | + |
| 11 | +it("caps oversized request timeouts before creating the abort signal", async () => { |
| 12 | +const signal = AbortSignal.abort(); |
| 13 | +const timeoutSpy = vi.spyOn(AbortSignal, "timeout").mockReturnValue(signal); |
| 14 | +const fetchImpl = vi.fn<MatrixQaFetchLike>(async () => Response.json({ ok: true })); |
| 15 | + |
| 16 | +await requestMatrixJson({ |
| 17 | +baseUrl: "https://matrix.example.test", |
| 18 | +endpoint: "/_matrix/client/v3/account/whoami", |
| 19 | + fetchImpl, |
| 20 | +method: "GET", |
| 21 | +timeoutMs: MAX_TIMER_TIMEOUT_MS + 1_000_000, |
| 22 | +}); |
| 23 | + |
| 24 | +expect(timeoutSpy).toHaveBeenCalledWith(MAX_TIMER_TIMEOUT_MS); |
| 25 | +expect(fetchImpl).toHaveBeenCalledWith(expect.any(URL), expect.objectContaining({ signal })); |
| 26 | +}); |
| 27 | +}); |
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime"; |
| 2 | + |
1 | 3 | export type MatrixQaFetchLike = typeof fetch; |
2 | 4 | |
3 | 5 | type MatrixQaRequestResult<T> = { |
@@ -30,7 +32,7 @@ export async function requestMatrixJson<T>(params: {
|
30 | 32 | ...(params.accessToken ? { authorization: `Bearer ${params.accessToken}` } : {}), |
31 | 33 | }, |
32 | 34 | ...(params.body !== undefined ? { body: JSON.stringify(params.body) } : {}), |
33 | | -signal: AbortSignal.timeout(params.timeoutMs ?? 20_000), |
| 35 | +signal: AbortSignal.timeout(resolveTimerTimeoutMs(params.timeoutMs, 20_000)), |
34 | 36 | }); |
35 | 37 | let body: unknown = {}; |
36 | 38 | try { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。