11import { beforeEach , describe , expect , it , vi } from "vitest" ;
2+ import { MAX_TIMER_TIMEOUT_MS } from "../shared/number-coercion.js" ;
23import {
34 formatOpenAIOAuthTlsPreflightFix ,
45 runOpenAIOAuthTlsPreflight ,
@@ -18,6 +19,23 @@ describe("runOpenAIOAuthTlsPreflight", () => {
1819 expect ( result ) . toEqual ( { ok : true } ) ;
1920 } ) ;
2021
22+ it ( "caps oversized probe timeouts before creating abort signals" , async ( ) => {
23+ const timeoutController = new AbortController ( ) ;
24+ const timeoutSpy = vi . spyOn ( AbortSignal , "timeout" ) . mockReturnValue ( timeoutController . signal ) ;
25+ const fetchImpl = vi . fn ( async ( _input : RequestInfo | URL , init ?: RequestInit ) => {
26+ expect ( init ?. signal ) . toBe ( timeoutController . signal ) ;
27+ return new Response ( "" , { status : 400 } ) ;
28+ } ) as unknown as typeof fetch ;
29+
30+ const result = await runOpenAIOAuthTlsPreflight ( {
31+ fetchImpl,
32+ timeoutMs : Number . MAX_SAFE_INTEGER ,
33+ } ) ;
34+
35+ expect ( result ) . toEqual ( { ok : true } ) ;
36+ expect ( timeoutSpy ) . toHaveBeenCalledWith ( MAX_TIMER_TIMEOUT_MS ) ;
37+ } ) ;
38+
2139 it ( "classifies TLS trust failures from fetch cause code" , async ( ) => {
2240 const tlsFetchImpl = vi . fn ( async ( ) => {
2341 const cause = new Error ( "unable to get local issuer certificate" ) as Error & {
0 commit comments