refactor: send cmd verbatim, drop /bin/sh -c wrap
All checks were successful
ci/woodpecker/push/unit Pipeline was successful

commands.run / stream now forward the user-supplied command string as
`cmd` instead of repackaging it as `cmd=/bin/sh args=["-c", cmd]`.
Callers that want shell semantics or argv splitting handle it
themselves; stream still accepts an optional `args` list for explicit
argv. Updated docstrings and payload tests accordingly.
This commit is contained in:
2026-06-26 17:33:32 +06:00
parent d8ff68f014
commit ad454cd909
3 changed files with 53 additions and 54 deletions

View File

@ -145,8 +145,8 @@ class TestRunPayload:
route = respx.post(EXEC_URL).respond(200, json={"stdout": "hi", "exit_code": 0})
result = _make_commands().run("echo hi")
body = json.loads(route.calls[0].request.content)
assert body["cmd"] == "/bin/sh"
assert body["args"] == ["-c", "echo hi"]
assert body["cmd"] == "echo hi"
assert "args" not in body
assert body["background"] is False
assert body["timeout_sec"] == 30
assert result.stdout == "hi"
@ -361,12 +361,12 @@ def _patch_async_ws(monkeypatch, ws: _AsyncFakeWS) -> None:
class TestStream:
def test_stream_sends_shell_wrapped_start(self, monkeypatch):
def test_stream_sends_cmd_verbatim(self, monkeypatch):
ws = _FakeWS([{"type": "exit", "exit_code": 0}])
_patch_sync_ws(monkeypatch, ws)
list(_make_commands().stream("echo hi"))
start = json.loads(ws.sent[0])
assert start == {"type": "start", "cmd": "/bin/sh", "args": ["-c", "echo hi"]}
assert start == {"type": "start", "cmd": "echo hi"}
def test_stream_with_explicit_args(self, monkeypatch):
ws = _FakeWS([{"type": "exit", "exit_code": 0}])
@ -480,7 +480,8 @@ class TestAsyncCommands:
events = [e async for e in _make_async_commands().stream("echo out")]
assert [e.type for e in events] == ["start", "stdout", "exit"]
start = json.loads(ws.sent[0])
assert start["cmd"] == "/bin/sh"
assert start["cmd"] == "echo out"
assert "args" not in start
@pytest.mark.asyncio
async def test_async_connect(self, monkeypatch):