💫 Toolkit to help you get started with SDD or any other process!
fix(workflows): shell step validate() rejects non-string run (#3348)
Ali jawwadfb796c2a39d2
diff --git a/src/specify_cli/workflows/steps/shell/__init__.py b/src/specify_cli/workflows/steps/shell/__init__.pyindex 2a65fca44..3ef94892e 100644--- a/src/specify_cli/workflows/steps/shell/__init__.py+++ b/src/specify_cli/workflows/steps/shell/__init__.py@@ -90,6 +90,16 @@ class ShellStep(StepBase):errors.append(f"Shell step {config.get('id', '?')!r} is missing 'run' field.")+ elif not isinstance(config["run"], str):+ # execute() str()-coerces run and invokes it under shell=True, so a+ # null or list 'run' would run the Python repr ('None', "['echo']")+ # as a command. Reject non-strings at validation, mirroring the+ # command-step input/options and gate options type checks. An+ # expression like "{{ ... }}" is still a str, so it stays valid.+ errors.append(+ f"Shell step {config.get('id', '?')!r}: 'run' must be a string, "+ f"got {type(config['run']).__name__}."+ )output_format = config.get("output_format")if output_format is not None and output_format != "json":errors.append(diff --git a/tests/test_workflows.py b/tests/test_workflows.pyindex 11338b300..77868cb34 100644--- a/tests/test_workflows.py+++ b/tests/test_workflows.py@@ -1266,6 +1266,26 @@ class TestShellStep:errors = step.validate({"id": "test"})assert any("missing 'run'" in e for e in errors)+ @pytest.mark.parametrize("bad_run", [None, ["echo", "hi"], 42])+ def test_validate_rejects_non_string_run(self, bad_run):+ """A non-string 'run' must be rejected at validation.++ execute() str()-coerces run and invokes it under shell=True, so a+ null or list run would otherwise run the Python repr as a command.+ """+ from specify_cli.workflows.steps.shell import ShellStep++ step = ShellStep()+ errors = step.validate({"id": "s", "run": bad_run})+ assert any("'run' must be a string" in e for e in errors)++ def test_validate_accepts_string_and_expression_run(self):+ from specify_cli.workflows.steps.shell import ShellStep++ step = ShellStep()+ assert step.validate({"id": "s", "run": "echo hi"}) == []+ assert step.validate({"id": "s", "run": "{{ steps.x.output }}"}) == []+def test_output_format_json_exposes_data(self, tmp_path):from specify_cli.workflows.steps.shell import ShellStep