core: prevent TimeoutOverflowWarning by capping setTimeout delay to max 32-bit signed integer

This commit is contained in:
Aiden Cline
2025-12-31 16:15:49 -06:00
parent c93e7621be
commit 9a1dc1ffe4
2 changed files with 22 additions and 1 deletions

View File

@@ -58,6 +58,26 @@ describe("session.retry.delay", () => {
const longError = apiError({ "retry-after-ms": "700000" })
expect(SessionRetry.delay(1, longError)).toBe(700000)
})
test("sleep caps delay to max 32-bit signed integer to avoid TimeoutOverflowWarning", async () => {
const controller = new AbortController()
const warnings: string[] = []
const originalWarn = process.emitWarning
process.emitWarning = (warning: string | Error) => {
warnings.push(typeof warning === "string" ? warning : warning.message)
}
const promise = SessionRetry.sleep(2_560_914_000, controller.signal)
controller.abort()
try {
await promise
} catch {}
process.emitWarning = originalWarn
expect(warnings.some((w) => w.includes("TimeoutOverflowWarning"))).toBe(false)
})
})
describe("session.message-v2.fromError", () => {