bpmax-cli 0.1.44-beta.2 → 0.1.44-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +1 -1
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-e2e-flow-test-operator/SKILL.md +23 -0
- package/skills/bpmax-e2e-flow-test-operator/references/browser-only-checkpoints.md +8 -0
- package/skills/bpmax-e2e-flow-test-operator/references/minimal-test-loop.md +9 -4
- package/skills/bpmax-e2e-flow-test-operator/references/state-schema.md +25 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_doc.py +26 -0
- package/skills/bpmax-form-template-editor/SKILL.md +2 -0
- package/skills/bpmax-form-template-editor/scripts/export_form_template.py +2 -0
- package/skills/bpmax-form-template-editor/scripts/form_template_editor_common.py +17 -0
- package/skills/bpmax-form-template-editor/tests/test_form_template_editor.py +6 -17
- package/skills/bpmax-user-mock-operator/SKILL.md +106 -0
- package/skills/bpmax-user-mock-operator/agents/openai.yaml +4 -0
- package/skills/bpmax-user-mock-operator/scripts/switch_user_identity.py +37 -0
- package/skills/bpmax-user-mock-operator/scripts/user_mock_operator_common.py +136 -0
- package/skills/bpmax-user-mock-operator/tests/test_user_mock_operator.py +138 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import unittest
|
|
6
|
+
from contextlib import redirect_stdout
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from unittest import mock
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
SCRIPT_DIR = Path(__file__).resolve().parents[1] / "scripts"
|
|
12
|
+
if str(SCRIPT_DIR) not in sys.path:
|
|
13
|
+
sys.path.insert(0, str(SCRIPT_DIR))
|
|
14
|
+
|
|
15
|
+
import switch_user_identity as cli # noqa: E402
|
|
16
|
+
from user_mock_operator_common import ( # noqa: E402
|
|
17
|
+
DEFAULT_BASE_URL,
|
|
18
|
+
ApiClient,
|
|
19
|
+
build_action_body,
|
|
20
|
+
build_client,
|
|
21
|
+
default_href_path,
|
|
22
|
+
encode_x_href,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class FakeResponse:
|
|
27
|
+
def __init__(self, body: bytes, status: int = 200) -> None:
|
|
28
|
+
self._body = body
|
|
29
|
+
self.status = status
|
|
30
|
+
|
|
31
|
+
def __enter__(self) -> "FakeResponse":
|
|
32
|
+
return self
|
|
33
|
+
|
|
34
|
+
def __exit__(self, exc_type, exc, tb) -> None:
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
def read(self) -> bytes:
|
|
38
|
+
return self._body
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class UserMockOperatorTests(unittest.TestCase):
|
|
42
|
+
def test_default_base_url_is_empty_until_runtime_configured(self) -> None:
|
|
43
|
+
self.assertEqual(DEFAULT_BASE_URL, "")
|
|
44
|
+
|
|
45
|
+
def test_build_action_body_maps_mock_and_unmock(self) -> None:
|
|
46
|
+
self.assertEqual(build_action_body("mock"), {"mock": 1})
|
|
47
|
+
self.assertEqual(build_action_body("unmock"), {"unmock": 1})
|
|
48
|
+
|
|
49
|
+
def test_default_href_path_and_encoding_follow_user_management_route(self) -> None:
|
|
50
|
+
href = default_href_path("store_mgr")
|
|
51
|
+
self.assertEqual(href, "/w:store_mgr/userManagement")
|
|
52
|
+
self.assertEqual(encode_x_href(href), "%2Fw%3Astore_mgr%2FuserManagement")
|
|
53
|
+
|
|
54
|
+
def test_build_client_uses_environment_origin_without_api_suffix(self) -> None:
|
|
55
|
+
args = type(
|
|
56
|
+
"Args",
|
|
57
|
+
(),
|
|
58
|
+
{
|
|
59
|
+
"base_url": None,
|
|
60
|
+
"workspace": "store_mgr",
|
|
61
|
+
"language": "zhCN",
|
|
62
|
+
"cookie_header": "token=demo",
|
|
63
|
+
"timeout": 30,
|
|
64
|
+
"insecure": False,
|
|
65
|
+
},
|
|
66
|
+
)()
|
|
67
|
+
with mock.patch.dict(os.environ, {"BPMAX_BASE_URL": "https://bpmax.example.com/api/"}, clear=False):
|
|
68
|
+
client = build_client(args)
|
|
69
|
+
self.assertEqual(
|
|
70
|
+
client._build_url("/api/user/995920025"),
|
|
71
|
+
"https://bpmax.example.com/api/user/995920025?$workspace=store_mgr&$language=zhCN",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def test_client_builds_expected_headers_for_user_management_page(self) -> None:
|
|
75
|
+
client = ApiClient(
|
|
76
|
+
base_url="https://bpmax.example.com",
|
|
77
|
+
workspace="store_mgr",
|
|
78
|
+
language="zhCN",
|
|
79
|
+
cookie_header="token=demo",
|
|
80
|
+
timeout=30,
|
|
81
|
+
)
|
|
82
|
+
headers = client._build_headers(default_href_path("store_mgr"))
|
|
83
|
+
self.assertEqual(headers["origin"], "https://bpmax.example.com")
|
|
84
|
+
self.assertEqual(headers["referer"], "https://bpmax.example.com/w:store_mgr/userManagement")
|
|
85
|
+
self.assertEqual(headers["x-href"], "%2Fw%3Astore_mgr%2FuserManagement")
|
|
86
|
+
self.assertEqual(headers["cookie"], "token=demo")
|
|
87
|
+
|
|
88
|
+
def test_switch_user_identity_sends_put_with_expected_body(self) -> None:
|
|
89
|
+
client = ApiClient(
|
|
90
|
+
base_url="https://bpmax.example.com",
|
|
91
|
+
workspace="store_mgr",
|
|
92
|
+
language="zhCN",
|
|
93
|
+
cookie_header="token=demo",
|
|
94
|
+
timeout=30,
|
|
95
|
+
)
|
|
96
|
+
captured = {}
|
|
97
|
+
|
|
98
|
+
def fake_urlopen(req, timeout, context=None):
|
|
99
|
+
captured["url"] = req.full_url
|
|
100
|
+
captured["method"] = req.get_method()
|
|
101
|
+
captured["data"] = req.data.decode("utf-8")
|
|
102
|
+
captured["headers"] = {k.lower(): v for k, v in req.header_items()}
|
|
103
|
+
return FakeResponse(b'{"code":0,"data":{"ok":true}}')
|
|
104
|
+
|
|
105
|
+
with mock.patch.object(
|
|
106
|
+
__import__("user_mock_operator_common").urllib.request,
|
|
107
|
+
"urlopen",
|
|
108
|
+
side_effect=fake_urlopen,
|
|
109
|
+
):
|
|
110
|
+
payload = client.switch_user_identity(995920025, "mock", default_href_path("store_mgr"))
|
|
111
|
+
|
|
112
|
+
self.assertTrue(payload["data"]["ok"])
|
|
113
|
+
self.assertEqual(captured["method"], "PUT")
|
|
114
|
+
self.assertEqual(json.loads(captured["data"]), {"mock": 1})
|
|
115
|
+
self.assertEqual(
|
|
116
|
+
captured["url"],
|
|
117
|
+
"https://bpmax.example.com/api/user/995920025?$workspace=store_mgr&$language=zhCN",
|
|
118
|
+
)
|
|
119
|
+
self.assertEqual(captured["headers"]["x-href"], "%2Fw%3Astore_mgr%2FuserManagement")
|
|
120
|
+
|
|
121
|
+
def test_cli_dispatches_selected_action_and_prints_json(self) -> None:
|
|
122
|
+
client = mock.Mock()
|
|
123
|
+
client.switch_user_identity.return_value = {"code": 0, "data": {"userId": 995920025, "mocked": False}}
|
|
124
|
+
output = io.StringIO()
|
|
125
|
+
with mock.patch.object(cli, "build_client", return_value=client), mock.patch.object(
|
|
126
|
+
sys,
|
|
127
|
+
"argv",
|
|
128
|
+
["switch_user_identity.py", "--action", "unmock", "--user-id", "995920025", "--workspace", "store_mgr"],
|
|
129
|
+
), redirect_stdout(output):
|
|
130
|
+
result = cli.main()
|
|
131
|
+
|
|
132
|
+
self.assertEqual(result, 0)
|
|
133
|
+
client.switch_user_identity.assert_called_once_with(995920025, "unmock", "/w:store_mgr/userManagement")
|
|
134
|
+
self.assertEqual(json.loads(output.getvalue()), {"code": 0, "data": {"userId": 995920025, "mocked": False}})
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
if __name__ == "__main__":
|
|
138
|
+
unittest.main()
|