Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/onepin/_cli/commands/composites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/cli/_manifest_snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions tests/cli/test_cli_composites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 ======================================================================

Expand Down
Loading