@@ -95,3 +95,113 @@ fn list_conda_envs_discovers_base_from_another_child_env() {
9595 ]
9696 ) ;
9797}
98+
99+ /// Test that get_known_conda_install_locations discovers conda installations from PATH
100+ /// when no explicit conda_executable is provided. This is important for discovering
101+ /// conda installations on mapped drives and other non-standard locations.
102+ /// Fixes https://github.com/microsoft/python-environment-tools/issues/194
103+ #[ cfg( unix) ]
104+ #[ test]
105+ fn discovers_conda_install_from_path ( ) {
106+ use common:: { create_test_environment, resolve_test_path} ;
107+ use pet_conda:: env_variables:: EnvVariables ;
108+ use pet_conda:: environment_locations:: get_known_conda_install_locations;
109+ use std:: collections:: HashMap ;
110+
111+ // Set up PATH to include the conda bin directory (simulating conda on a mapped drive)
112+ let anaconda_bin = resolve_test_path ( & [ "unix" , "anaconda3-2023.03" , "bin" ] ) ;
113+ let path_value = anaconda_bin. to_string_lossy ( ) . to_string ( ) ;
114+
115+ let mut vars = HashMap :: new ( ) ;
116+ vars. insert ( "PATH" . to_string ( ) , path_value) ;
117+
118+ let env = create_test_environment ( vars, None , vec ! [ ] , None ) ;
119+ let env_vars = EnvVariables :: from ( & env) ;
120+
121+ // Call get_known_conda_install_locations without an explicit conda_executable
122+ let locations = get_known_conda_install_locations ( & env_vars, & None ) ;
123+
124+ // The anaconda3-2023.03 install should be discovered from PATH
125+ let expected_conda_install = resolve_test_path ( & [ "unix" , "anaconda3-2023.03" ] ) ;
126+ assert ! (
127+ locations. contains( & expected_conda_install) ,
128+ "Expected {:?} to be in {:?}" ,
129+ expected_conda_install,
130+ locations
131+ ) ;
132+ }
133+
134+ /// Test that get_known_conda_install_locations discovers conda installations from condabin in PATH.
135+ /// This simulates the typical Windows Miniforge/Anaconda setup where condabin is added to PATH.
136+ /// Fixes https://github.com/microsoft/python-environment-tools/issues/194
137+ #[ cfg( unix) ]
138+ #[ test]
139+ fn discovers_conda_install_from_condabin_in_path ( ) {
140+ use common:: { create_test_environment, resolve_test_path} ;
141+ use pet_conda:: env_variables:: EnvVariables ;
142+ use pet_conda:: environment_locations:: get_known_conda_install_locations;
143+ use std:: collections:: HashMap ;
144+
145+ // Set up PATH to include the condabin directory (typical Miniforge/Anaconda setup on Windows)
146+ let anaconda_condabin = resolve_test_path ( & [ "unix" , "anaconda3-2023.03" , "condabin" ] ) ;
147+ let path_value = anaconda_condabin. to_string_lossy ( ) . to_string ( ) ;
148+
149+ let mut vars = HashMap :: new ( ) ;
150+ vars. insert ( "PATH" . to_string ( ) , path_value) ;
151+
152+ let env = create_test_environment ( vars, None , vec ! [ ] , None ) ;
153+ let env_vars = EnvVariables :: from ( & env) ;
154+
155+ // Call get_known_conda_install_locations without an explicit conda_executable
156+ let locations = get_known_conda_install_locations ( & env_vars, & None ) ;
157+
158+ // The anaconda3-2023.03 install should be discovered from PATH via condabin
159+ let expected_conda_install = resolve_test_path ( & [ "unix" , "anaconda3-2023.03" ] ) ;
160+ assert ! (
161+ locations. contains( & expected_conda_install) ,
162+ "Expected {:?} to be in {:?}" ,
163+ expected_conda_install,
164+ locations
165+ ) ;
166+ }
167+
168+ /// Test that when an explicit conda_executable is provided, PATH lookup is skipped.
169+ /// This ensures we don't do unnecessary work when the user has configured a conda path.
170+ #[ cfg( unix) ]
171+ #[ test]
172+ fn skips_path_lookup_when_conda_executable_provided ( ) {
173+ use common:: { create_test_environment, resolve_test_path} ;
174+ use pet_conda:: env_variables:: EnvVariables ;
175+ use pet_conda:: environment_locations:: get_known_conda_install_locations;
176+ use std:: collections:: HashMap ;
177+
178+ // Set up PATH to include a conda directory
179+ let anaconda_bin = resolve_test_path ( & [ "unix" , "anaconda3-2023.03" , "bin" ] ) ;
180+ let path_value = anaconda_bin. to_string_lossy ( ) . to_string ( ) ;
181+
182+ let mut vars = HashMap :: new ( ) ;
183+ vars. insert ( "PATH" . to_string ( ) , path_value) ;
184+
185+ let env = create_test_environment ( vars, None , vec ! [ ] , None ) ;
186+ let env_vars = EnvVariables :: from ( & env) ;
187+
188+ // Provide an explicit conda_executable
189+ let conda_executable = Some ( resolve_test_path ( & [
190+ "unix" ,
191+ "anaconda3-2023.03" ,
192+ "bin" ,
193+ "conda" ,
194+ ] ) ) ;
195+
196+ // Call get_known_conda_install_locations with an explicit conda_executable
197+ let locations = get_known_conda_install_locations ( & env_vars, & conda_executable) ;
198+
199+ // The conda install should still be discovered (from the explicit path, not PATH)
200+ let expected_conda_install = resolve_test_path ( & [ "unix" , "anaconda3-2023.03" ] ) ;
201+ assert ! (
202+ locations. contains( & expected_conda_install) ,
203+ "Expected {:?} to be in {:?}" ,
204+ expected_conda_install,
205+ locations
206+ ) ;
207+ }
0 commit comments