Skip to content

Commit 275c795

Browse files
committed
test(wdl-engine): add unit test for workflow graph input dependencies
- Add sample test from stjude-rust-labs#356 - fix typo - remove debugging logs - update changelog - format files - remove unncecessary to_string() calls
1 parent a58d85e commit 275c795

File tree

3 files changed

+124
-1
lines changed

3 files changed

+124
-1
lines changed

wdl-analysis/src/document/v1.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,8 @@ fn populate_workflow(
850850
)];
851851
let mut output_scope = None;
852852

853-
// For static analysis, we don't need to provide inputs to the workflow graph builder
853+
// For static analysis, we don't need to provide inputs to the workflow graph
854+
// builder
854855
let graph =
855856
WorkflowGraphBuilder::default().build(workflow, &mut document.diagnostics, |_| false);
856857

wdl-analysis/src/eval/v1.rs

+121
Original file line numberDiff line numberDiff line change
@@ -1109,3 +1109,124 @@ impl<N: TreeNode> Default for CommonAncestorFinder<N> {
11091109
}
11101110
}
11111111
}
1112+
1113+
#[cfg(test)]
1114+
mod test {
1115+
use wdl_ast::Document;
1116+
1117+
use super::*;
1118+
1119+
#[test]
1120+
fn test_input_dependency_handling() {
1121+
let source = r#"
1122+
version 1.1
1123+
1124+
task my_task {
1125+
input {
1126+
Int i
1127+
}
1128+
1129+
command <<<>>>
1130+
1131+
output {
1132+
Int out = i
1133+
}
1134+
}
1135+
1136+
workflow foo {
1137+
input {
1138+
Int x = 10
1139+
Int y = t1.out
1140+
}
1141+
1142+
call my_task as t1 { input: i = x }
1143+
call my_task as t2 { input: i = y }
1144+
}
1145+
"#;
1146+
1147+
let (document, diagnostics) = Document::parse(source);
1148+
assert!(
1149+
diagnostics.is_empty(),
1150+
"parsing should succeed without diagnostics"
1151+
);
1152+
1153+
let workflow = document
1154+
.ast()
1155+
.into_v1()
1156+
.expect("document should be v1")
1157+
.workflows()
1158+
.next()
1159+
.expect("document should have a workflow");
1160+
1161+
let mut diagnostics = Vec::new();
1162+
1163+
// Testing without providing inputs i.e. static analysis
1164+
let graph = WorkflowGraphBuilder::default().build(&workflow, &mut diagnostics, |_| false);
1165+
1166+
let t1_out = graph
1167+
.node_indices()
1168+
.find(|i| {
1169+
if let WorkflowGraphNode::Call(call) = &graph[*i] {
1170+
call.alias().map(|a| a.name().text().to_string()) == Some("t1".to_string())
1171+
} else {
1172+
false
1173+
}
1174+
})
1175+
.expect("t1 node not found");
1176+
1177+
let y = graph
1178+
.node_indices()
1179+
.find(|i| {
1180+
if let WorkflowGraphNode::Input(input) = &graph[*i] {
1181+
input.name().text() == "y"
1182+
} else {
1183+
false
1184+
}
1185+
})
1186+
.expect("y node not found");
1187+
1188+
assert!(
1189+
graph.contains_edge(t1_out, y),
1190+
"y should depend on t1.out when input 'y' is not provided"
1191+
);
1192+
1193+
let y_input = graph
1194+
.node_indices()
1195+
.find(|i| {
1196+
if let WorkflowGraphNode::Input(input) = &graph[*i] {
1197+
input.name().text() == "y"
1198+
} else {
1199+
false
1200+
}
1201+
})
1202+
.expect("y node not found");
1203+
1204+
let t2 = graph
1205+
.node_indices()
1206+
.find(|i| {
1207+
if let WorkflowGraphNode::Call(call) = &graph[*i] {
1208+
call.alias().map(|a| a.name().text().to_string()) == Some("t2".to_string())
1209+
} else {
1210+
false
1211+
}
1212+
})
1213+
.expect("t2 node not found");
1214+
1215+
assert!(graph.contains_edge(y_input, t2), "t2 should depend on y");
1216+
1217+
// Testing with providing input y i.e. runtime analysis - case for wdl_engine
1218+
let mut diagnostics = Vec::new();
1219+
let graph =
1220+
WorkflowGraphBuilder::default().build(&workflow, &mut diagnostics, |name| name == "y");
1221+
1222+
assert!(
1223+
!graph.contains_edge(t1_out, y),
1224+
"y should not depend on t1.out when input 'y' is provided"
1225+
);
1226+
1227+
assert!(
1228+
graph.contains_edge(y_input, t2),
1229+
"t2 should depend on y even when input y is provided"
1230+
);
1231+
}
1232+
}

wdl-engine/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
* Fixed path translation to mount inputs individually (#[327](https://github.com/stjude-rust-labs/wdl/pull/327)).
2626
* Fixed not including task temp directories in mounts (#[327](https://github.com/stjude-rust-labs/wdl/pull/327)).
2727
* Fixed an incorrect type being used for scatter statement outputs ([#316](https://github.com/stjude-rust-labs/wdl/pull/316)).
28+
* Fixed handling of input dependencies in workflow graph evaluation ([#360](https://github.com/stjude-rust-labs/wdl/pull/360)).
2829

2930
### Changed
3031

0 commit comments

Comments
 (0)