|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +import json |
| 6 | +from typing import Any |
| 7 | + |
5 | 8 | import pytest |
6 | 9 |
|
7 | 10 | from automation_file import __main__ as cli_main |
@@ -55,3 +58,40 @@ def _fake_cli(argv: list[str] | None = None) -> int: |
55 | 58 | assert rc == 0 |
56 | 59 | assert "--allowed-actions" not in captured["argv"] |
57 | 60 | 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