From 86844c33a3753a68511a8d8fce057e1c52c96ca0 Mon Sep 17 00:00:00 2001 From: arimu1 <19286898+arimu1@users.noreply.github.com> Date: Thu, 18 Jun 2026 20:31:26 +0700 Subject: [PATCH] Add regression test for boolean input with a default (#779) Issue #779 reported that a boolean input with `default: false` was treated as a required CLI argument (`error: the following arguments are required: --a_false`), while `default: true` worked fine. This was fixed in 48e8afd1 (2019) when `required` became `default is None and input_required`, but the behavior was never locked down by a test and the issue stayed open. Add a parametrized regression test in test_toolargparse.py covering both `default: false` and `default: true`, asserting the generated parser treats the input as optional and falls back to the declared default. Verified the test fails against the pre-fix logic with the exact error from the issue. Co-Authored-By: Claude Opus 4.8 --- tests/test_toolargparse.py | 24 ++++++++++++++++++++++++ tests/wf/779-boolean-default-false.cwl | 13 +++++++++++++ tests/wf/779-boolean-default-true.cwl | 13 +++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 tests/wf/779-boolean-default-false.cwl create mode 100644 tests/wf/779-boolean-default-true.cwl diff --git a/tests/test_toolargparse.py b/tests/test_toolargparse.py index 2bf7a809a..4c46fe4ac 100644 --- a/tests/test_toolargparse.py +++ b/tests/test_toolargparse.py @@ -308,3 +308,27 @@ def test_argparse_append_with_default(job_order: list[str], expected_values: lis cmd_line = vars(toolparser.parse_args(job_order)) file_paths = list(cmd_line["file_paths"]) assert expected_values == file_paths + + +@pytest.mark.parametrize( + "cwl_file,expected_default", + [ + ("tests/wf/779-boolean-default-false.cwl", False), + ("tests/wf/779-boolean-default-true.cwl", True), + ], +) +def test_boolean_with_default_not_required(cwl_file: str, expected_default: bool) -> None: + """A boolean input with a default value must not be a required CLI argument. + + Regression test for https://github.com/common-workflow-language/cwltool/issues/779 + where ``default: false`` was incorrectly treated as a required ``--a_bool`` flag. + """ + loadingContext = LoadingContext() + tool = load_tool(get_data(cwl_file), loadingContext) + # input_required=True mirrors the default CLI behavior; the input must still be + # optional purely because it declares a default value. + toolparser = generate_parser(argparse.ArgumentParser(prog="test"), tool, {}, [], True) + # Parsing with no arguments must succeed (the flag is optional) and fall back + # to the declared default rather than erroring with "arguments are required". + cmd_line = vars(toolparser.parse_args([])) + assert cmd_line["a_bool"] == expected_default diff --git a/tests/wf/779-boolean-default-false.cwl b/tests/wf/779-boolean-default-false.cwl new file mode 100644 index 000000000..57ea0129f --- /dev/null +++ b/tests/wf/779-boolean-default-false.cwl @@ -0,0 +1,13 @@ +#!/usr/bin/env cwl-runner +# Regression fixture for https://github.com/common-workflow-language/cwltool/issues/779 +# A boolean input with `default: false` must NOT become a required CLI argument. +cwlVersion: v1.2 +class: CommandLineTool +inputs: + a_bool: + type: boolean + default: false + inputBinding: + prefix: --a_bool +outputs: [] +baseCommand: echo diff --git a/tests/wf/779-boolean-default-true.cwl b/tests/wf/779-boolean-default-true.cwl new file mode 100644 index 000000000..89a4f9bb2 --- /dev/null +++ b/tests/wf/779-boolean-default-true.cwl @@ -0,0 +1,13 @@ +#!/usr/bin/env cwl-runner +# Companion fixture for https://github.com/common-workflow-language/cwltool/issues/779 +# A boolean input with `default: true` must also NOT be a required CLI argument. +cwlVersion: v1.2 +class: CommandLineTool +inputs: + a_bool: + type: boolean + default: true + inputBinding: + prefix: --a_bool +outputs: [] +baseCommand: echo