|
1 | 1 | import { describe, expect, it, vi } from "vitest"; |
| 2 | +import { MAX_TIMER_TIMEOUT_MS } from "../shared/number-coercion.js"; |
2 | 3 | import { createTypingCallbacks } from "./typing.js"; |
3 | 4 | |
4 | 5 | type TypingCallbackOverrides = Partial<Parameters<typeof createTypingCallbacks>[0]>; |
@@ -186,6 +187,21 @@ describe("createTypingCallbacks", () => {
|
186 | 187 | }); |
187 | 188 | }); |
188 | 189 | |
| 190 | +it("clamps oversized keepalive intervals before arming timers", async () => { |
| 191 | +await withFakeTimers(async () => { |
| 192 | +const setIntervalSpy = vi.spyOn(globalThis, "setInterval"); |
| 193 | +const { callbacks } = createTypingHarness({ |
| 194 | +keepaliveIntervalMs: Number.MAX_SAFE_INTEGER, |
| 195 | +}); |
| 196 | + |
| 197 | +await callbacks.onReplyStart(); |
| 198 | +await flushMicrotasks(); |
| 199 | + |
| 200 | +expect(setIntervalSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS); |
| 201 | +callbacks.onCleanup?.(); |
| 202 | +}); |
| 203 | +}); |
| 204 | + |
189 | 205 | it("does not restart keepalive when breaker trips on initial start", async () => { |
190 | 206 | await withFakeTimers(async () => { |
191 | 207 | const { start, onStartError, callbacks } = createTypingHarness({ |
@@ -347,6 +363,21 @@ describe("createTypingCallbacks", () => {
|
347 | 363 | }); |
348 | 364 | }); |
349 | 365 | |
| 366 | +it("clamps oversized TTLs before arming timers", async () => { |
| 367 | +await withFakeTimers(async () => { |
| 368 | +const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout"); |
| 369 | +const { callbacks } = createTypingHarness({ |
| 370 | +maxDurationMs: Number.MAX_SAFE_INTEGER, |
| 371 | +}); |
| 372 | + |
| 373 | +await callbacks.onReplyStart(); |
| 374 | +await flushMicrotasks(); |
| 375 | + |
| 376 | +expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS); |
| 377 | +callbacks.onCleanup?.(); |
| 378 | +}); |
| 379 | +}); |
| 380 | + |
350 | 381 | it("resets TTL timer on restart after idle", async () => { |
351 | 382 | await withFakeTimers(async () => { |
352 | 383 | const { stop, callbacks } = createTypingHarness({ maxDurationMs: 10_000 }); |
|