diff --git a/src/task/task_environment.rs b/src/task/task_environment.rs index c71c6b498..27661f2ac 100644 --- a/src/task/task_environment.rs +++ b/src/task/task_environment.rs @@ -118,7 +118,7 @@ impl<'p, D: TaskDisambiguation<'p>> SearchEnvironments<'p, D> { source: FindTaskSource<'p>, ) -> Result, FindTaskError> { // If no explicit environment was specified - if matches!(source, FindTaskSource::CmdArgs) && self.explicit_environment.is_none() { + if self.explicit_environment.is_none() { let default_env = self.project.default_environment(); // If the default environment has the task if let Ok(default_env_task) = default_env.task(&name, self.platform) { diff --git a/src/task/task_graph.rs b/src/task/task_graph.rs index aa195138b..282a563af 100644 --- a/src/task/task_graph.rs +++ b/src/task/task_graph.rs @@ -499,4 +499,61 @@ mod test { vec![r#"python train.py --cuda"#, r#"python test.py --cuda"#] ); } + + #[test] + fn test_multi_env_defaults() { + // It should select foobar and foo in the default environment + assert_eq!( + commands_in_order( + r#" + [project] + name = "pixi" + channels = ["conda-forge"] + platforms = ["linux-64", "osx-64", "win-64", "osx-arm64"] + + [tasks] + foo = "echo foo" + foobar = { cmd = "echo bar", depends_on = ["foo"] } + + [feature.build.tasks] + build = "echo build" + + [environments] + build = ["build"] + "#, + &["foobar"], + None, + None + ), + vec![r#"echo foo"#, r#"echo bar"#] + ); + } + + #[test] + #[should_panic] + fn test_multi_env_defaults_ambigu() { + // As foo is really ambiguous it should panic + commands_in_order( + r#" + [project] + name = "pixi" + channels = ["conda-forge"] + platforms = ["linux-64", "osx-64", "win-64", "osx-arm64"] + + [tasks] + foo = "echo foo" + foobar = { cmd = "echo bar", depends_on = ["foo"] } + + [feature.build.tasks] + build = "echo build" + foo = "echo foo abmiguity" + + [environments] + build = ["build"] + "#, + &["foobar"], + None, + None, + ); + } }