bpmax-cli 0.1.44-beta.1 → 0.1.44-beta.3

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.
Files changed (28) hide show
  1. package/dist/bin.js +114 -2
  2. package/dist/bin.js.map +1 -1
  3. package/package.json +1 -1
  4. package/scripts/install-skills.mjs +98 -0
  5. package/skills/bpmax-api-platform-editor/SKILL.md +1 -1
  6. package/skills/bpmax-console-template-editor/SKILL.md +1 -1
  7. package/skills/bpmax-dataset-field-template-editor/SKILL.md +1 -1
  8. package/skills/bpmax-dataset-template-editor/SKILL.md +1 -1
  9. package/skills/bpmax-e2e-flow-config-orchestrator/SKILL.md +1 -1
  10. package/skills/bpmax-e2e-flow-test-operator/SKILL.md +25 -3
  11. package/skills/bpmax-e2e-flow-test-operator/references/browser-only-checkpoints.md +8 -0
  12. package/skills/bpmax-e2e-flow-test-operator/references/minimal-test-loop.md +9 -4
  13. package/skills/bpmax-e2e-flow-test-operator/references/state-schema.md +25 -0
  14. package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_doc.py +26 -0
  15. package/skills/bpmax-filter-template-editor/SKILL.md +1 -1
  16. package/skills/bpmax-flow-template-editor/SKILL.md +1 -1
  17. package/skills/bpmax-form-template-editor/SKILL.md +1 -1
  18. package/skills/bpmax-list-template-editor/SKILL.md +1 -1
  19. package/skills/bpmax-memory-protocol/SKILL.md +72 -0
  20. package/skills/bpmax-nav-config-editor/SKILL.md +1 -1
  21. package/skills/bpmax-project-detail-template-editor/SKILL.md +1 -1
  22. package/skills/bpmax-role-editor/SKILL.md +1 -1
  23. package/skills/bpmax-user-mock-operator/SKILL.md +106 -0
  24. package/skills/bpmax-user-mock-operator/agents/openai.yaml +4 -0
  25. package/skills/bpmax-user-mock-operator/scripts/switch_user_identity.py +37 -0
  26. package/skills/bpmax-user-mock-operator/scripts/user_mock_operator_common.py +136 -0
  27. package/skills/bpmax-user-mock-operator/tests/test_user_mock_operator.py +138 -0
  28. package/skills/form-control-library/SKILL.md +1 -1
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ import json
6
+
7
+ from user_mock_operator_common import build_client, default_href_path
8
+
9
+
10
+ def build_parser() -> argparse.ArgumentParser:
11
+ parser = argparse.ArgumentParser(
12
+ description="Switch a BPMAX browser E2E session into or out of simulated identity mode via /api/user/:id."
13
+ )
14
+ parser.add_argument("--action", choices=("mock", "unmock"), required=True)
15
+ parser.add_argument("--user-id", type=int, required=True)
16
+ parser.add_argument("--workspace")
17
+ parser.add_argument("--base-url")
18
+ parser.add_argument("--language", default="zhCN")
19
+ parser.add_argument("--cookie-header")
20
+ parser.add_argument("--href-path")
21
+ parser.add_argument("--timeout", type=float, default=30)
22
+ parser.add_argument("--insecure", action="store_true")
23
+ return parser
24
+
25
+
26
+ def main() -> int:
27
+ args = build_parser().parse_args()
28
+ client = build_client(args)
29
+ workspace = args.workspace or client.workspace
30
+ href_path = args.href_path or default_href_path(workspace)
31
+ payload = client.switch_user_identity(args.user_id, args.action, href_path)
32
+ print(json.dumps(payload, ensure_ascii=False))
33
+ return 0
34
+
35
+
36
+ if __name__ == "__main__":
37
+ raise SystemExit(main())
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ import os
6
+ import ssl
7
+ import sys
8
+ import urllib.error
9
+ import urllib.parse
10
+ import urllib.request
11
+ from dataclasses import dataclass
12
+ from pathlib import Path
13
+ from typing import Any, Optional
14
+
15
+
16
+ SHARED_SKILL_ROOT = Path(__file__).resolve().parents[2] / "bpmax-builder-shared"
17
+ if str(SHARED_SKILL_ROOT) not in sys.path:
18
+ sys.path.insert(0, str(SHARED_SKILL_ROOT))
19
+
20
+ from base_url import DEFAULT_BASE_URL, resolve_base_url
21
+
22
+
23
+ DEFAULT_LANGUAGE = "zhCN"
24
+
25
+
26
+ def resolve_cookie_header(value: Optional[str]) -> str:
27
+ cookie = value or os.environ.get("BPMAX_COOKIE_HEADER", "")
28
+ if not cookie:
29
+ raise SystemExit("missing cookie header: pass --cookie-header or set BPMAX_COOKIE_HEADER")
30
+ return cookie
31
+
32
+
33
+ def resolve_workspace(value: Optional[str]) -> str:
34
+ workspace = value or os.environ.get("BPMAX_WORKSPACE", "")
35
+ if not workspace:
36
+ raise SystemExit("missing workspace: pass --workspace or set BPMAX_WORKSPACE")
37
+ return workspace
38
+
39
+
40
+ def default_href_path(workspace: str) -> str:
41
+ return f"/w:{workspace}/userManagement"
42
+
43
+
44
+ def encode_x_href(href_path: str) -> str:
45
+ return urllib.parse.quote(href_path, safe="")
46
+
47
+
48
+ def normalize_href_path(href_path: Optional[str], workspace: str) -> str:
49
+ candidate = (href_path or "").strip() or default_href_path(workspace)
50
+ if candidate.startswith("http://") or candidate.startswith("https://"):
51
+ parsed = urllib.parse.urlparse(candidate)
52
+ candidate = parsed.path or default_href_path(workspace)
53
+ if parsed.query:
54
+ candidate = f"{candidate}?{parsed.query}"
55
+ if not candidate.startswith("/"):
56
+ raise SystemExit("href path must start with '/' or be an absolute BPMAX page URL")
57
+ return candidate
58
+
59
+
60
+ def build_action_body(action: str) -> dict:
61
+ if action == "mock":
62
+ return {"mock": 1}
63
+ if action == "unmock":
64
+ return {"unmock": 1}
65
+ raise SystemExit(f"unsupported action: {action}")
66
+
67
+
68
+ @dataclass
69
+ class ApiClient:
70
+ base_url: str
71
+ workspace: str
72
+ language: str
73
+ cookie_header: str
74
+ timeout: float
75
+ insecure: bool = False
76
+
77
+ def _build_url(self, path: str) -> str:
78
+ joiner = "&" if "?" in path else "?"
79
+ suffix = f"$workspace={urllib.parse.quote(self.workspace)}&$language={urllib.parse.quote(self.language)}"
80
+ return self.base_url.rstrip("/") + path + joiner + suffix
81
+
82
+ def _build_headers(self, href_path: str) -> dict[str, str]:
83
+ normalized_href = normalize_href_path(href_path, self.workspace)
84
+ return {
85
+ "accept": "application/json, text/plain, */*",
86
+ "accept-language": "zh-CN,zh;q=0.9",
87
+ "content-type": "application/json",
88
+ "cookie": self.cookie_header,
89
+ "origin": self.base_url.rstrip("/"),
90
+ "referer": f"{self.base_url.rstrip('/')}{normalized_href}",
91
+ "x-href": encode_x_href(normalized_href),
92
+ }
93
+
94
+ def request(self, method: str, path: str, body: Optional[dict] = None, *, href_path: Optional[str] = None) -> dict:
95
+ href = normalize_href_path(href_path, self.workspace)
96
+ headers = self._build_headers(href)
97
+ data = None if body is None else json.dumps(body, ensure_ascii=False).encode("utf-8")
98
+ request = urllib.request.Request(self._build_url(path), data=data, headers=headers, method=method.upper())
99
+ context = ssl._create_unverified_context() if self.insecure else None
100
+ try:
101
+ with urllib.request.urlopen(request, timeout=self.timeout, context=context) as response:
102
+ raw = response.read().decode("utf-8", "replace")
103
+ except urllib.error.HTTPError as err:
104
+ raw = err.read().decode("utf-8", "replace")
105
+ raise SystemExit(f"HTTP {err.code} {path}: {raw}") from err
106
+ except urllib.error.URLError as err:
107
+ raise SystemExit(f"Request failed {path}: {err}") from err
108
+
109
+ try:
110
+ payload = json.loads(raw)
111
+ except json.JSONDecodeError as err:
112
+ raise SystemExit(f"Non-JSON response from {path}: {raw}") from err
113
+ if isinstance(payload, dict) and payload.get("code") not in (None, 0):
114
+ raise SystemExit(f"API error {path}: {payload}")
115
+ return payload
116
+
117
+ def switch_user_identity(self, user_id: int, action: str, href_path: Optional[str] = None) -> dict:
118
+ if user_id <= 0:
119
+ raise SystemExit("user id must be positive")
120
+ return self.request(
121
+ "PUT",
122
+ f"/api/user/{user_id}",
123
+ build_action_body(action),
124
+ href_path=href_path,
125
+ )
126
+
127
+
128
+ def build_client(args: Any) -> ApiClient:
129
+ return ApiClient(
130
+ base_url=resolve_base_url(getattr(args, "base_url", None)),
131
+ workspace=resolve_workspace(getattr(args, "workspace", None)),
132
+ language=getattr(args, "language", DEFAULT_LANGUAGE),
133
+ cookie_header=resolve_cookie_header(getattr(args, "cookie_header", None)),
134
+ timeout=float(getattr(args, "timeout", 30)),
135
+ insecure=bool(getattr(args, "insecure", False)),
136
+ )
@@ -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()
@@ -29,7 +29,7 @@ description: "用于查询和分析当前已激活 BPMAX 配置仓库里的表
29
29
  - 模板出现次数:同一 `field_type` 在不同字段上的落地次数。
30
30
 
31
31
  ## Mem0 协议
32
- - 开始前先调用 [$mem0-memory-protocol](../mem0-memory-protocol/SKILL.md),检索词至少包含:
32
+ - 开始前先调用 [$bpmax-memory-protocol](../bpmax-memory-protocol/SKILL.md),检索词至少包含:
33
33
  - `field_type`
34
34
  - 控件中文名 / 业务关键词
35
35
  - 模板名 / `flow_type`