diff --git a/src/onepin/_cli/commands/composites.py b/src/onepin/_cli/commands/composites.py index 5ba1ae6..63fe444 100644 --- a/src/onepin/_cli/commands/composites.py +++ b/src/onepin/_cli/commands/composites.py @@ -27,6 +27,12 @@ def workflow_run( workflow_id: str = typer.Argument(..., help="Workflow UUID."), + script: Optional[str] = typer.Option( + None, "--script", help="Run-scoped script text; overrides the saved script for this run only." + ), + source_language: Optional[str] = typer.Option( + None, "--source-language", help="BCP-47 language of --script (e.g. en-us); defaults to the saved language." + ), watch: bool = typer.Option(False, "--watch", help="Poll run status until a terminal state."), timeout: float = typer.Option(300.0, "--timeout", help="Max seconds to watch before giving up."), json_output_local: bool = typer.Option(False, "--json", help="Emit JSON instead of text."), @@ -41,6 +47,16 @@ def workflow_run( with api_errors(json_on): client = get_client() kwargs = _maybe_workspace(client.workflows.runs.start) + # Run-scoped inputs ride as additional body parameters until the generated + # start() gains script_text/source_language on the next spec regen — the wire + # format is identical either way, so this keeps working after the regen too. + overrides = { + key: value + for key, value in (("script_text", script), ("source_language", source_language)) + if value is not None + } + if overrides: + kwargs["request_options"] = {"additional_body_parameters": overrides} started = client.workflows.runs.start(workflow_id, **kwargs) run = to_jsonable(getattr(started, "data", started)) run_id = run.get("id") if isinstance(run, dict) else None diff --git a/tests/cli/_manifest_snapshot.json b/tests/cli/_manifest_snapshot.json index 0d19237..8bf8af6 100644 --- a/tests/cli/_manifest_snapshot.json +++ b/tests/cli/_manifest_snapshot.json @@ -1120,6 +1120,20 @@ "group": "workflows", "name": "run", "options": [ + { + "default": null, + "flag": "--script", + "help": "Run-scoped script text; overrides the saved script for this run only.", + "required": false, + "type": "text" + }, + { + "default": null, + "flag": "--source-language", + "help": "BCP-47 language of --script (e.g. en-us); defaults to the saved language.", + "required": false, + "type": "text" + }, { "default": false, "flag": "--watch", diff --git a/tests/cli/test_cli_composites.py b/tests/cli/test_cli_composites.py index 893d24d..e048cdf 100644 --- a/tests/cli/test_cli_composites.py +++ b/tests/cli/test_cli_composites.py @@ -55,8 +55,10 @@ class _Runs: def __init__(self, statuses: list[str]) -> None: self._statuses = statuses self._i = 0 + self.start_kwargs: dict | None = None def start(self, workflow_id, **kw): + self.start_kwargs = kw return _run_out(self._statuses[0]) def status(self, workflow_id, run_id, **kw): @@ -108,6 +110,44 @@ def test_watch_timeout_exits_1(self, patch_client, monkeypatch, tmp_home) -> Non assert result.exit_code == 1 assert "Timed out" in result.output + def test_script_flags_ride_as_body_params(self, patch_client, tmp_home) -> None: + client = _WfClient(["running"]) + patch_client(client) + result = runner.invoke( + app, + [ + "--api-key", + "op_live_x", + "workflows", + "run", + "wf-1", + "--script", + "Hello world!", + "--source-language", + "en-us", + ], + ) + assert result.exit_code == 0, result.output + assert client.workflows.runs.start_kwargs["request_options"] == { + "additional_body_parameters": {"script_text": "Hello world!", "source_language": "en-us"} + } + + def test_script_flag_alone_sends_only_script_text(self, patch_client, tmp_home) -> None: + client = _WfClient(["running"]) + patch_client(client) + result = runner.invoke(app, ["--api-key", "op_live_x", "workflows", "run", "wf-1", "--script", "Hi"]) + assert result.exit_code == 0, result.output + assert client.workflows.runs.start_kwargs["request_options"] == { + "additional_body_parameters": {"script_text": "Hi"} + } + + def test_no_script_flags_sends_no_request_options(self, patch_client, tmp_home) -> None: + client = _WfClient(["running"]) + patch_client(client) + result = runner.invoke(app, ["--api-key", "op_live_x", "workflows", "run", "wf-1"]) + assert result.exit_code == 0, result.output + assert "request_options" not in client.workflows.runs.start_kwargs + # === uploads create ======================================================================