@@ -39,3 +39,59 @@ fn list_conda_envs_in_install_location() {
3939 ]
4040 ) ;
4141}
42+
43+ /// Test that when get_environments is called with a child environment under the `envs` folder,
44+ /// it also discovers the parent conda install (base environment) and all sibling environments.
45+ /// This is the fix for https://github.com/microsoft/python-environment-tools/issues/236
46+ /// where the base conda environment wasn't discovered when only child envs were listed
47+ /// in environments.txt (e.g., from Homebrew Cask installs like /opt/homebrew/Caskroom/miniforge/base).
48+ #[ cfg( unix) ]
49+ #[ test]
50+ fn list_conda_envs_discovers_base_from_child_env ( ) {
51+ use common:: resolve_test_path;
52+ use pet_conda:: environment_locations:: get_environments;
53+
54+ // Call get_environments with a child environment path (not the install directory)
55+ let child_env_path = resolve_test_path ( & [ "unix" , "anaconda3-2023.03" , "envs" , "myenv" ] ) ;
56+
57+ let mut locations = get_environments ( & child_env_path) ;
58+ locations. sort ( ) ;
59+
60+ // Should discover not only the child env, but also the base env (conda install dir)
61+ // and all sibling environments
62+ assert_eq ! (
63+ locations,
64+ vec![
65+ resolve_test_path( & [ "unix" , "anaconda3-2023.03" ] ) ,
66+ resolve_test_path( & [ "unix" , "anaconda3-2023.03" , "envs" , "env_python_3" ] ) ,
67+ resolve_test_path( & [ "unix" , "anaconda3-2023.03" , "envs" , "myenv" ] ) ,
68+ resolve_test_path( & [ "unix" , "anaconda3-2023.03" , "envs" , "without_python" ] ) ,
69+ ]
70+ ) ;
71+ }
72+
73+ /// Test that get_environments works correctly with an env_python_3 child environment
74+ /// (another sibling to verify the fix works for any child env under envs folder).
75+ #[ cfg( unix) ]
76+ #[ test]
77+ fn list_conda_envs_discovers_base_from_another_child_env ( ) {
78+ use common:: resolve_test_path;
79+ use pet_conda:: environment_locations:: get_environments;
80+
81+ // Call get_environments with a different child environment path
82+ let child_env_path = resolve_test_path ( & [ "unix" , "anaconda3-2023.03" , "envs" , "env_python_3" ] ) ;
83+
84+ let mut locations = get_environments ( & child_env_path) ;
85+ locations. sort ( ) ;
86+
87+ // Should discover the base env and all sibling environments
88+ assert_eq ! (
89+ locations,
90+ vec![
91+ resolve_test_path( & [ "unix" , "anaconda3-2023.03" ] ) ,
92+ resolve_test_path( & [ "unix" , "anaconda3-2023.03" , "envs" , "env_python_3" ] ) ,
93+ resolve_test_path( & [ "unix" , "anaconda3-2023.03" , "envs" , "myenv" ] ) ,
94+ resolve_test_path( & [ "unix" , "anaconda3-2023.03" , "envs" , "without_python" ] ) ,
95+ ]
96+ ) ;
97+ }
0 commit comments