Repository: chanzuckerberg/miniwdl

Issue:
available_inputs returns output Decls 
miniwdl version:  V0.1.7

For older workflows (ie draft 2/3) or really any workflow which does not define an `input { ... }` section, the `available_outputs` will return the `output` declarations as well as any input declarations.

For example, calling `available_outputs` on:
```wdl
workflow a {
   File in
   output {
      File out = in
   }
}
```
would yield both `in` and `out` as `inputs` to the workflow. Simply specifcying and input section for the workflow fixes this behaviour, however since alot of existing workflows do not have this section, we can expect a large number of workflows to exhibit this behaviour




Discussion:
coveralls: ## Pull Request Test Coverage Report for [Build 613](https://coveralls.io/builds/23582325)

* **7** of **7**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.005%**) to **96.496%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/23582325/badge)](https://coveralls.io/builds/23582325) |
| :-- | --: |
| Change from base [Build 595](https://coveralls.io/builds/23330796): |  0.005% |
| Covered Lines: | 2919 |
| Relevant Lines: | 3025 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/WDL/Tree.py b/WDL/Tree.py
index a27ba2e..ad9f379 100644
--- a/WDL/Tree.py
+++ b/WDL/Tree.py
@@ -736,7 +736,7 @@ class Workflow(SourceNode):
             for decl in self.inputs:
                 ans = Env.bind(ans, [], decl.name, decl)
 
-        for elt in _decls_and_calls(self):
+        for elt in _decls_and_calls(self, exclude_outputs=True):
             if isinstance(elt, Decl):
                 if self.inputs is None:
                     ans = Env.bind(ans, [], elt.name, elt)
@@ -760,7 +760,7 @@ class Workflow(SourceNode):
                 if decl.expr is None and decl.type.optional is False:
                     ans = Env.bind(ans, [], decl.name, decl)
 
-        for elt in _decls_and_calls(self):
+        for elt in _decls_and_calls(self, exclude_outputs=True):
             if isinstance(elt, Decl):
                 if self.inputs is None and elt.expr is None and elt.type.optional is False:
                     ans = Env.bind(ans, [], elt.name, elt)
@@ -1060,11 +1060,15 @@ def load(
 
 
 def _decls_and_calls(
-    element: Union[Workflow, Scatter, Conditional]
+    element: Union[Workflow, Scatter, Conditional], exclude_outputs: bool = True
 ) -> Generator[Union[Decl, Call], None, None]:
     # Yield each Decl and Call in the workflow, including those nested within
     # scatter/conditional sections
-    for ch in element.children:
+    children = element.children
+    if isinstance(element, Workflow) and exclude_outputs:
+        children = element.inputs if element.inputs else []
+        children = children + element.elements
+    for ch in children:
         if isinstance(ch, (Decl, Call)):
             yield ch
         elif isinstance(ch, (Scatter, Conditional)):


Test patch:
diff --git a/tests/test_1doc.py b/tests/test_1doc.py
index 9087237..08310df 100644
--- a/tests/test_1doc.py
+++ b/tests/test_1doc.py
@@ -1279,6 +1279,22 @@ class TestDoc(unittest.TestCase):
         except WDL.Error.MultipleValidationErrors as multi:
             self.assertEqual(len(multi.exceptions), 2)
 
+    def test_issue135_workflow_available_inputs(self):
+        # Workflow.available_inputs should not include declarations in the
+        # output section
+        doc = r"""
+        workflow a {
+            File in
+            output {
+                File out = in
+            }
+        }
+        """
+        doc = WDL.parse_document(doc)
+        doc.typecheck()
+        self.assertEqual(len(doc.workflow.available_inputs), 1)
+        self.assertEqual(doc.workflow.available_inputs[0].name, "in")
+
 class TestCycleDetection(unittest.TestCase):
     def test_task(self):
         doc = r"""