From 785b088c942a334bd757b67f4096311a89a0cd48 Mon Sep 17 00:00:00 2001 From: Vasu Jaganath Date: Tue, 17 Nov 2026 12:08:00 -0500 Subject: [PATCH] Keep the empty listing of a CWL Directory literal CWLJob.run dropped every empty listing so that cwltool would list each directory again, but a literal ("_:" location) is nowhere to be listed: the worker then failed reading its listing (KeyError). --- src/toil/cwl/cwltoil.py | 9 ++++++++ src/toil/test/cwl/cwlTest.py | 23 +++++++++++++++++++ src/toil/test/cwl/empty_directory_literal.cwl | 17 ++++++++++++++ .../test/cwl/empty_directory_literal.json | 7 ++++++ 4 files changed, 56 insertions(+) create mode 100644 src/toil/test/cwl/empty_directory_literal.cwl create mode 100644 src/toil/test/cwl/empty_directory_literal.json diff --git a/src/toil/cwl/cwltoil.py b/src/toil/cwl/cwltoil.py index 94e0952ba1..1fb12e802c 100644 --- a/src/toil/cwl/cwltoil.py +++ b/src/toil/cwl/cwltoil.py @@ -2648,12 +2648,21 @@ def writeGlobalFileWrapper( def remove_empty_listings(rec: CWLDirectoryType) -> None: + """ + Drop each empty listing that cwltool can list again from where it is. + + A Directory literal (one cwltool gave a "_:" location) is not anywhere to + be listed: its listing is all there is of it, even when empty, so it keeps + it. + """ if rec.get("class") != "Directory": finddirs: list[CWLDirectoryType] = [] visit_class(rec, ("Directory",), finddirs.append) for f in finddirs: remove_empty_listings(f) return + if rec.get("location", "_:").startswith("_:"): + return if "listing" in rec and rec["listing"] == []: del rec["listing"] return diff --git a/src/toil/test/cwl/cwlTest.py b/src/toil/test/cwl/cwlTest.py index e805289429..60cbd4a825 100644 --- a/src/toil/test/cwl/cwlTest.py +++ b/src/toil/test/cwl/cwlTest.py @@ -2275,6 +2275,29 @@ def test_captured_stderr_for_failed_job_is_reported(tmp_path: Path) -> None: assert "Message: This is a test" in p.stderr +@needs_cwl +@pytest.mark.cwl +@pytest.mark.cwl_small +def test_empty_directory_literal_input(tmp_path: Path) -> None: + """ + Make sure a tool can write into an empty Directory literal it is given: + the literal has nothing on disk to list, so its empty listing is all + there is of it and must reach the worker. + """ + with get_data("test/cwl/empty_directory_literal.cwl") as cwl_file: + with get_data("test/cwl/empty_directory_literal.json") as job_file: + cmd = [ + "toil-cwl-runner", + f"--jobStore=file:{tmp_path / 'jobStore'}", + f"--outdir={tmp_path / 'outdir'}", + str(cwl_file), + str(job_file), + ] + p = subprocess.run(cmd, capture_output=True, text=True) + assert p.returncode == 0, p.stderr + assert (tmp_path / "outdir" / "out" / "written").is_file() + + @needs_cwl @pytest.mark.cwl @pytest.mark.cwl_small diff --git a/src/toil/test/cwl/empty_directory_literal.cwl b/src/toil/test/cwl/empty_directory_literal.cwl new file mode 100644 index 0000000000..fd70ffcc88 --- /dev/null +++ b/src/toil/test/cwl/empty_directory_literal.cwl @@ -0,0 +1,17 @@ +cwlVersion: v1.2 +class: CommandLineTool +doc: Write a file into an empty Directory literal given as an input, and return it. +requirements: + InitialWorkDirRequirement: + listing: + - entry: $(inputs.target) + writable: true +inputs: + target: Directory +baseCommand: [touch] +arguments: [$(inputs.target.basename)/written] +outputs: + filled: + type: Directory + outputBinding: + glob: $(inputs.target.basename) diff --git a/src/toil/test/cwl/empty_directory_literal.json b/src/toil/test/cwl/empty_directory_literal.json new file mode 100644 index 0000000000..d6a4d5cd76 --- /dev/null +++ b/src/toil/test/cwl/empty_directory_literal.json @@ -0,0 +1,7 @@ +{ + "target": { + "class": "Directory", + "basename": "out", + "listing": [] + } +}