@@ -138,6 +138,18 @@ impl CodeVersionManager {
138
138
pub async fn get_entrypoint_for_install_dir ( path : & Path ) -> Option < PathBuf > {
139
139
use tokio:: sync:: mpsc;
140
140
141
+ // Check whether the user is supplying a path to the CLI directly (e.g. #164622)
142
+ if let Ok ( true ) = path. metadata ( ) . map ( |m| m. is_file ( ) ) {
143
+ let result = std:: process:: Command :: new ( path)
144
+ . args ( [ "--version" ] )
145
+ . output ( )
146
+ . map ( |o| o. status . success ( ) ) ;
147
+
148
+ if let Ok ( true ) = result {
149
+ return Some ( path. to_owned ( ) ) ;
150
+ }
151
+ }
152
+
141
153
let ( tx, mut rx) = mpsc:: channel ( 1 ) ;
142
154
143
155
// Look for all the possible paths in parallel
@@ -576,4 +588,37 @@ mod tests {
576
588
. is_none( )
577
589
) ;
578
590
}
591
+
592
+ #[ tokio:: test]
593
+ async fn test_gets_entrypoint_as_binary ( ) {
594
+ let dir = tempfile:: tempdir ( ) . expect ( "expected to make temp dir" ) ;
595
+
596
+ #[ cfg( windows) ]
597
+ let binary_file_path = {
598
+ let path = dir. path ( ) . join ( "code.cmd" ) ;
599
+ File :: create ( & path) . expect ( "expected to create file" ) ;
600
+ path
601
+ } ;
602
+
603
+ #[ cfg( unix) ]
604
+ let binary_file_path = {
605
+ use std:: fs;
606
+ use std:: os:: unix:: fs:: PermissionsExt ;
607
+
608
+ let path = dir. path ( ) . join ( "code" ) ;
609
+ {
610
+ let mut f = File :: create ( & path) . expect ( "expected to create file" ) ;
611
+ f. write_all ( b"#!/bin/sh" )
612
+ . expect ( "expected to write to file" ) ;
613
+ }
614
+ fs:: set_permissions ( & path, fs:: Permissions :: from_mode ( 0o777 ) )
615
+ . expect ( "expected to set permissions" ) ;
616
+ path
617
+ } ;
618
+
619
+ assert_eq ! (
620
+ CodeVersionManager :: get_entrypoint_for_install_dir( & binary_file_path) . await ,
621
+ Some ( binary_file_path)
622
+ ) ;
623
+ }
579
624
}
0 commit comments