scientific_workflow/
composition.rs1use crate::runtime::{RunSummary, RuntimeError};
4use crate::study::Study;
5use crate::ui::UiSession;
6
7pub fn execute(study: Study) -> Result<RunSummary, RuntimeError> {
10 execute_options(study, false)
11}
12
13pub(crate) fn execute_options(study: Study, clean: bool) -> Result<RunSummary, RuntimeError> {
14 UiSession::require_terminal()
15 .map_err(|error| RuntimeError::presentation_boxed(Box::new(error)))?;
16 crate::runtime::execute_with_observer_options(
17 study,
18 || UiSession::automatic().map_err(|source| Box::new(source) as _),
19 clean,
20 )
21}
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26 use std::io::IsTerminal;
27
28 #[test]
29 fn noninteractive_launch_rejects_before_clean_or_output_creation() {
30 if std::io::stdin().is_terminal() && std::io::stderr().is_terminal() {
31 return; }
33 let root = std::env::temp_dir().join(format!(
34 "workflow-dashboard-preflight-{}",
35 std::process::id()
36 ));
37 std::fs::create_dir_all(root.join("wf_configs")).unwrap();
38 std::fs::write(root.join("wf_configs/study.json"), r#"{"workflow_schema":1,"threads":1,"compute":{"mode":"auto"},"phases":{"run":{"tasks":[{"program":"/bin/true"}]}}}"#).unwrap();
39 std::fs::write(root.join("wf_configs/parameters.json"), "{}").unwrap();
40 let error = execute(Study::load(&root).unwrap()).unwrap_err();
41 assert!(error.to_string().contains("screen or tmux"));
42 assert!(!root.join("output").exists());
43 std::fs::create_dir(root.join("output")).unwrap();
44 std::fs::write(root.join("output/keep"), "complete result").unwrap();
45 let error = execute_options(Study::load(&root).unwrap(), true).unwrap_err();
46 assert!(matches!(error, RuntimeError::Presentation { .. }));
47 assert_eq!(
48 std::fs::read_to_string(root.join("output/keep")).unwrap(),
49 "complete result"
50 );
51 std::fs::remove_dir_all(root).unwrap();
52 }
53}