@@ -1109,3 +1109,124 @@ impl<N: TreeNode> Default for CommonAncestorFinder<N> {
1109
1109
}
1110
1110
}
1111
1111
}
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
+ }
0 commit comments