fix(feishu): cap async helper timeouts

This commit is contained in:
Peter Steinberger
2026-05-29 17:01:11 -04:00
parent e6b011823e
commit 95f9231136
2 changed files with 22 additions and 2 deletions

View File

@@ -1,8 +1,25 @@
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
import { afterEach, describe, expect, it, vi } from "vitest";
import { waitForAbortableDelay } from "./async.js";
import { raceWithTimeoutAndAbort, waitForAbortableDelay } from "./async.js";
afterEach(() => {
vi.useRealTimers();
vi.restoreAllMocks();
});
describe("raceWithTimeoutAndAbort", () => {
it("normalizes oversized timeouts before arming the watchdog", async () => {
const timeoutSpy = vi
.spyOn(globalThis, "setTimeout")
.mockReturnValue(1 as unknown as ReturnType<typeof setTimeout>);
vi.spyOn(globalThis, "clearTimeout").mockImplementation(() => undefined);
await raceWithTimeoutAndAbort(Promise.resolve("ok"), {
timeoutMs: Number.MAX_SAFE_INTEGER,
});
expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
});
});
describe("waitForAbortableDelay", () => {

View File

@@ -1,3 +1,5 @@
import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
const RACE_TIMEOUT = Symbol("race-timeout");
const RACE_ABORT = Symbol("race-abort");
@@ -26,9 +28,10 @@ export async function raceWithTimeoutAndAbort<T>(
const contenders: Array<Promise<T | typeof RACE_TIMEOUT | typeof RACE_ABORT>> = [promise];
if (options.timeoutMs !== undefined) {
const timeoutMs = resolveTimerTimeoutMs(options.timeoutMs, 1);
contenders.push(
new Promise((resolve) => {
timeoutHandle = setTimeout(() => resolve(RACE_TIMEOUT), options.timeoutMs);
timeoutHandle = setTimeout(() => resolve(RACE_TIMEOUT), timeoutMs);
}),
);
}