@@ -89,4 +89,51 @@ describe("web-guarded-fetch", () => {
8989 expect ( call ?. policy ) . toBeUndefined ( ) ;
9090 expect ( call ?. mode ) . toBe ( GUARDED_FETCH_MODE . STRICT ) ;
9191 } ) ;
92+
93+ it ( "normalizes string timeouts before guarded fetch dispatch" , async ( ) => {
94+ vi . mocked ( fetchWithSsrFGuard ) . mockResolvedValue ( {
95+ response : new Response ( "ok" , { status : 200 } ) ,
96+ finalUrl : "https://example.com" ,
97+ release : async ( ) => { } ,
98+ } ) ;
99+
100+ await withStrictWebToolsEndpoint (
101+ { url : "https://example.com" , timeoutSeconds : "7" as never } ,
102+ async ( ) => undefined ,
103+ ) ;
104+ expect ( firstFetchCall ( ) . timeoutMs ) . toBe ( 7000 ) ;
105+
106+ vi . clearAllMocks ( ) ;
107+ vi . mocked ( fetchWithSsrFGuard ) . mockResolvedValue ( {
108+ response : new Response ( "ok" , { status : 200 } ) ,
109+ finalUrl : "https://example.com" ,
110+ release : async ( ) => { } ,
111+ } ) ;
112+
113+ await withStrictWebToolsEndpoint (
114+ {
115+ url : "https://example.com" ,
116+ timeoutMs : "2500" as never ,
117+ timeoutSeconds : "7" as never ,
118+ } ,
119+ async ( ) => undefined ,
120+ ) ;
121+ expect ( firstFetchCall ( ) . timeoutMs ) . toBe ( 2500 ) ;
122+ } ) ;
123+
124+ it ( "rejects malformed timeouts before guarded fetch dispatch" , async ( ) => {
125+ await expect (
126+ withStrictWebToolsEndpoint (
127+ { url : "https://example.com" , timeoutMs : "2.5" as never } ,
128+ async ( ) => undefined ,
129+ ) ,
130+ ) . rejects . toThrow ( "timeoutMs must be a positive integer" ) ;
131+ await expect (
132+ withStrictWebToolsEndpoint (
133+ { url : "https://example.com" , timeoutSeconds : - 1 } ,
134+ async ( ) => undefined ,
135+ ) ,
136+ ) . rejects . toThrow ( "timeoutSeconds must be a positive integer" ) ;
137+ expect ( fetchWithSsrFGuard ) . not . toHaveBeenCalled ( ) ;
138+ } ) ;
92139} ) ;
0 commit comments