@@ -75,6 +75,8 @@ type SourceControlCliRemoteRefinementSpec = SourceControlCliDiscoverySpec & {
7575} ;
7676
7777const DEFAULT_PROBE_TIMEOUT_MS = 5_000 ;
78+ /** An API host that stalls must not hold the whole discovery answer behind it. */
79+ const API_PROBE_TIMEOUT = "3 seconds" ;
7880
7981function probeTimeoutMs ( spec : SourceControlCliDiscoverySpec ) : number {
8082 return spec . probeTimeoutMs ?? DEFAULT_PROBE_TIMEOUT_MS ;
@@ -236,6 +238,12 @@ export function probeSourceControlProvider(input: {
236238 if ( input . spec . type === "managed-cli" ) return input . spec . probe ( input . cwd ) ;
237239 if ( input . spec . type === "api" ) {
238240 return input . spec . probeAuth . pipe (
241+ Effect . timeoutOption ( API_PROBE_TIMEOUT ) ,
242+ Effect . map (
243+ Option . getOrElse ( ( ) =>
244+ unknownAuth ( "The hosting service did not answer in time. Refresh to try again." ) ,
245+ ) ,
246+ ) ,
239247 Effect . map (
240248 ( auth ) =>
241249 ( {
@@ -253,20 +261,15 @@ export function probeSourceControlProvider(input: {
253261
254262 const spec = input . spec ;
255263
256- return probeCli ( {
257- spec,
258- process : input . process ,
259- cwd : input . cwd ,
260- } ) . pipe (
261- Effect . flatMap ( ( item ) => {
262- if ( item . status !== "available" ) {
263- return Effect . succeed ( {
264- ...item ,
265- auth : unknownAuth ( "Hosting integration command was not found on the server PATH." ) ,
266- } satisfies SourceControlProviderDiscoveryItem ) ;
267- }
268-
269- return input . process
264+ // The auth check does not depend on the version output, so both spawn at once.
265+ return Effect . all (
266+ [
267+ probeCli ( {
268+ spec,
269+ process : input . process ,
270+ cwd : input . cwd ,
271+ } ) ,
272+ input . process
270273 . run ( {
271274 operation : "source-control.discovery.auth" ,
272275 command : spec . executable ,
@@ -278,21 +281,24 @@ export function probeSourceControlProvider(input: {
278281 appendTruncationMarker : true ,
279282 } )
280283 . pipe (
281- Effect . map (
282- ( result ) =>
283- ( {
284- ...item ,
285- auth : spec . parseAuth ( result ) ,
286- } ) satisfies SourceControlProviderDiscoveryItem ,
287- ) ,
284+ Effect . map ( spec . parseAuth ) ,
288285 Effect . catch ( ( cause ) =>
289- Effect . succeed ( {
290- ...item ,
291- auth : unknownAuth ( Option . getOrUndefined ( detailFromCause ( cause ) ) ) ,
292- } satisfies SourceControlProviderDiscoveryItem ) ,
286+ Effect . succeed ( unknownAuth ( Option . getOrUndefined ( detailFromCause ( cause ) ) ) ) ,
293287 ) ,
294- ) ;
295- } ) ,
288+ ) ,
289+ ] ,
290+ { concurrency : "unbounded" } ,
291+ ) . pipe (
292+ Effect . map (
293+ ( [ item , auth ] ) =>
294+ ( {
295+ ...item ,
296+ auth :
297+ item . status === "available"
298+ ? auth
299+ : unknownAuth ( "Hosting integration command was not found on the server PATH." ) ,
300+ } ) satisfies SourceControlProviderDiscoveryItem ,
301+ ) ,
296302 ) ;
297303}
298304
0 commit comments