Skip to content

Commit ea8ceda

Browse files
authored
Merge pull request #69 from Integration-Automation/dev
Restore Windows double-decode for --execute_str
2 parents 1733993 + 10b19d8 commit ea8ceda

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

automation_file/__main__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ def _execute_dir(path: str) -> Any:
3838

3939

4040
def _execute_str(raw: str) -> Any:
41-
return execute_action(json.loads(raw))
41+
parsed = json.loads(raw)
42+
# PyBreeze (and other launchers) double-encode the action list on Windows
43+
# to survive command-line escaping — peel the second JSON layer if we got
44+
# a string back. Guarded by isinstance, so callers that pass a single-encoded
45+
# payload still work on every platform.
46+
if isinstance(parsed, str):
47+
parsed = json.loads(parsed)
48+
return execute_action(parsed)
4249

4350

4451
_LEGACY_DISPATCH: dict[str, Callable[[str], Any]] = {

tests/test_cli_main.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
from __future__ import annotations
44

5+
import json
6+
from typing import Any
7+
58
import pytest
69

710
from automation_file import __main__ as cli_main
@@ -55,3 +58,40 @@ def _fake_cli(argv: list[str] | None = None) -> int:
5558
assert rc == 0
5659
assert "--allowed-actions" not in captured["argv"]
5760
assert captured["argv"] == ["--name", "automation_file", "--version", "1.0.0"]
61+
62+
63+
def _capture_execute_action(monkeypatch: pytest.MonkeyPatch) -> list[Any]:
64+
received: list[Any] = []
65+
66+
def _fake_execute(action_list: Any) -> dict:
67+
received.append(action_list)
68+
return {}
69+
70+
monkeypatch.setattr(cli_main, "execute_action", _fake_execute)
71+
return received
72+
73+
74+
def test_execute_str_accepts_single_encoded_payload(
75+
monkeypatch: pytest.MonkeyPatch,
76+
) -> None:
77+
received = _capture_execute_action(monkeypatch)
78+
actions = [["FA_create_file", {"file_path": "x.txt", "content": "hi"}]]
79+
80+
rc = cli_main.main(["--execute_str", json.dumps(actions)])
81+
82+
assert rc == 0
83+
assert received == [actions]
84+
85+
86+
def test_execute_str_accepts_double_encoded_payload(
87+
monkeypatch: pytest.MonkeyPatch,
88+
) -> None:
89+
received = _capture_execute_action(monkeypatch)
90+
actions = [["FA_create_file", {"file_path": "x.txt", "content": "hi"}]]
91+
92+
# PyBreeze on Windows wraps the JSON list once more before handing the
93+
# argument to subprocess; the CLI must peel both layers off.
94+
rc = cli_main.main(["--execute_str", json.dumps(json.dumps(actions))])
95+
96+
assert rc == 0
97+
assert received == [actions]

0 commit comments

Comments
 (0)