@@ -163,7 +163,12 @@ async function runHttpDiscovery(modulePath: string): Promise<DiscoveryResult> {
163
163
return true ;
164
164
} catch ( e : unknown ) {
165
165
const error = e as { code ?: string } ;
166
- return error . code !== "ECONNREFUSED" ;
166
+ if ( error . code === "ECONNREFUSED" ) {
167
+ // This is an expected error during server startup, so we should retry.
168
+ return false ;
169
+ }
170
+ // Any other error is unexpected and should fail the test immediately.
171
+ throw e ;
167
172
}
168
173
} , TIMEOUT_L ) ;
169
174
@@ -199,9 +204,15 @@ async function runStdioDiscovery(modulePath: string): Promise<DiscoveryResult> {
199
204
stderr += chunk . toString ( "utf8" ) ;
200
205
} ) ;
201
206
207
+ const timeoutId = setTimeout ( ( ) => {
208
+ proc . kill ( 9 ) ;
209
+ reject ( new Error ( "Stdio discovery timed out after " + TIMEOUT_M + "ms" ) ) ;
210
+ } , TIMEOUT_M ) ;
211
+
202
212
proc . on ( "close" , ( ) => {
213
+ clearTimeout ( timeoutId ) ;
203
214
// Try to parse manifest
204
- const manifestMatch = stderr . match ( / _ _ F I R E B A S E _ F U N C T I O N S _ M A N I F E S T _ _ : ( . + ) / ) ;
215
+ const manifestMatch = stderr . match ( / _ _ F I R E B A S E _ F U N C T I O N S _ M A N I F E S T _ _ : ( [ \s \S ] + ) / ) ;
205
216
if ( manifestMatch ) {
206
217
const base64 = manifestMatch [ 1 ] ;
207
218
const manifestJson = Buffer . from ( base64 , "base64" ) . toString ( "utf8" ) ;
@@ -211,7 +222,7 @@ async function runStdioDiscovery(modulePath: string): Promise<DiscoveryResult> {
211
222
}
212
223
213
224
// Try to parse error
214
- const errorMatch = stderr . match ( / _ _ F I R E B A S E _ F U N C T I O N S _ M A N I F E S T _ E R R O R _ _ : ( . + ) / ) ;
225
+ const errorMatch = stderr . match ( / _ _ F I R E B A S E _ F U N C T I O N S _ M A N I F E S T _ E R R O R _ _ : ( [ \s \S ] + ) / ) ;
215
226
if ( errorMatch ) {
216
227
resolve ( { success : false , error : errorMatch [ 1 ] } ) ;
217
228
return ;
@@ -221,6 +232,7 @@ async function runStdioDiscovery(modulePath: string): Promise<DiscoveryResult> {
221
232
} ) ;
222
233
223
234
proc . on ( "error" , ( err ) => {
235
+ clearTimeout ( timeoutId ) ;
224
236
reject ( err ) ;
225
237
} ) ;
226
238
} ) ;
0 commit comments