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
package/package.json
CHANGED
|
@@ -22,7 +22,9 @@ description: "用于在 BPMAX 中做全链路流程测试、场景回归、前
|
|
|
22
22
|
- 开始前先查 [$bpmax-memory-protocol](../bpmax-memory-protocol/SKILL.md),不要直接重复试错。
|
|
23
23
|
- 浏览器实时页面、实时接口返回、最新 live/draft 配置优先于本地镜像。
|
|
24
24
|
- 若用户要求“线上跑完整链路”“真实验证用户路径”或等价目标,必须在真实运行页面完成发起、填单、选择、提交、审批、驳回、回退等关键动作;不得用脚本、控制台、手改 request body 或接口直调绕过界面。
|
|
25
|
+
- 浏览器 E2E 中如果发起页、审批页或详情页的表单打不开、白屏、字段不渲染、按钮不可用,第一步必须检查浏览器 Console 和 Network 里的真实报错;优先解决 `form_template` 加载、表单控件渲染、`lambda`、`customeValidate`、`sub_form` 绑定等表单模板相关错误,再排查流程、权限、数据或缓存问题。
|
|
25
26
|
- 只有在用户明确确认接受“非页面路径”后,才可以用脚本代替真实页面操作;确认前,脚本最多只用于摸底、状态记录、接口回读、证据补充和首次抓请求骨架,不得直接当成线上链路测试结论。
|
|
27
|
+
- 浏览器 E2E 涉及多角色时,使用 [$bpmax-user-mock-operator](../bpmax-user-mock-operator/SKILL.md) 切换当前浏览器身份;该能力只用于浏览器页面测试,不用于 API Key 冒充或 CLI 业务命令身份切换。
|
|
26
28
|
- 测试 H5 界面时,必须打开 `/m/#/...` H5 路由,并把页面可视区域(viewport)设置为 `412x844`;只允许调整页面 viewport,不要修改 Chrome/浏览器整个窗口的外层尺寸。
|
|
27
29
|
- 默认按“线上完整链路页面优先 / 非完整链路接口优先”分层推进:
|
|
28
30
|
- 线上完整链路:页面优先,必须走真实运行页真实操作;接口与脚本只做辅助,不替代用户路径
|
|
@@ -46,6 +48,7 @@ description: "用于在 BPMAX 中做全链路流程测试、场景回归、前
|
|
|
46
48
|
- [$bpmax-filter-template-editor](../bpmax-filter-template-editor/SKILL.md)
|
|
47
49
|
- [$bpmax-nav-config-editor](../bpmax-nav-config-editor/SKILL.md)
|
|
48
50
|
- [$form-control-library](../form-control-library/SKILL.md)
|
|
51
|
+
- [$bpmax-user-mock-operator](../bpmax-user-mock-operator/SKILL.md)
|
|
49
52
|
- [$feishu-doc-ops](/Users/yanghanwen/.codex/skills/feishu-doc-ops/SKILL.md)
|
|
50
53
|
- 优先把测试过程写入本地状态文件,而不是在对话里反复长篇复述。
|
|
51
54
|
- 每发现一个“可复现、可复用”的坑,优先更新对应来源 skill 的 `references/`,不要只记在当前会话里。
|
|
@@ -98,6 +101,26 @@ description: "用于在 BPMAX 中做全链路流程测试、场景回归、前
|
|
|
98
101
|
- 预期自动联动的项目类型
|
|
99
102
|
- 若发现依赖数据不足,优先补数据或重造样本,再开始场景;不要把“缺前置数据”误判成流程故障。
|
|
100
103
|
|
|
104
|
+
### 1.6 多角色浏览器身份切换
|
|
105
|
+
- 这一节只适用于浏览器 E2E 页面测试。不要把模拟用户身份用于 API Key、CLI 远端命令或非页面路径结论。
|
|
106
|
+
- 多角色场景必须先列出角色矩阵:
|
|
107
|
+
- 原始管理账号
|
|
108
|
+
- 目标角色
|
|
109
|
+
- 目标用户 id / 用户名
|
|
110
|
+
- 该角色要完成的浏览器动作
|
|
111
|
+
- 预期可见入口、按钮、表单或审批权限
|
|
112
|
+
- 切换角色时调用 [$bpmax-user-mock-operator](../bpmax-user-mock-operator/SKILL.md),然后必须验证当前身份:
|
|
113
|
+
- 优先调用 `/api/user/current` 或刷新页面确认当前用户名/头像/权限入口
|
|
114
|
+
- 验证失败时不得继续执行该角色的浏览器步骤
|
|
115
|
+
- 完成该角色动作后,记录:
|
|
116
|
+
- role
|
|
117
|
+
- target_user_id / target_user_name
|
|
118
|
+
- mocked 状态
|
|
119
|
+
- workspace
|
|
120
|
+
- 页面截图或关键 UI 证据
|
|
121
|
+
- project_id / step_id 等运行时样本
|
|
122
|
+
- 测试结束必须执行 unmock,并刷新页面验证恢复原始管理账号身份;没有完成恢复验证,不得结束多角色 E2E。
|
|
123
|
+
|
|
101
124
|
### 2. 初始化本地测试状态
|
|
102
125
|
- 用脚本初始化或续写测试状态:
|
|
103
126
|
|
|
@@ -31,3 +31,11 @@
|
|
|
31
31
|
|
|
32
32
|
原因:
|
|
33
33
|
- skill 已明确:凡是报告写“页面真实结果”,都必须有截图证据
|
|
34
|
+
|
|
35
|
+
## 5. 多角色身份切换与恢复
|
|
36
|
+
- 需要以发起人、审批人、查看人等不同用户身份验证页面行为时,必须在浏览器会话里完成 mock/unmock。
|
|
37
|
+
- mock 后必须刷新或调用 `/api/user/current` 验证当前身份。
|
|
38
|
+
- unmock 后必须验证已经恢复原始管理账号身份。
|
|
39
|
+
|
|
40
|
+
原因:
|
|
41
|
+
- 多角色结论证明的是“真实用户在页面里能否看见并完成动作”,不能只用接口调用成功替代。
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
1. 查记忆
|
|
6
6
|
2. 读当前 live/draft 与浏览器页
|
|
7
7
|
3. 确认前置数据
|
|
8
|
-
4.
|
|
9
|
-
5.
|
|
10
|
-
6.
|
|
11
|
-
7.
|
|
8
|
+
4. 若场景涉及多角色,先完成浏览器身份切换并验证当前身份
|
|
9
|
+
5. 执行场景
|
|
10
|
+
6. 记录样本 ID、关键接口、当前环节、业务字段、当前角色
|
|
11
|
+
7. 判定 `pass / fail / blocked`
|
|
12
|
+
8. 多角色场景结束后执行 unmock 并验证恢复原始身份
|
|
13
|
+
9. 如果失败,修最小问题后立刻复测当前场景
|
|
12
14
|
|
|
13
15
|
判定优先级:
|
|
14
16
|
- 运行时真实行为
|
|
@@ -17,3 +19,6 @@
|
|
|
17
19
|
- 编辑器草稿
|
|
18
20
|
- 本地镜像
|
|
19
21
|
|
|
22
|
+
多角色场景额外要求:
|
|
23
|
+
- 未验证当前浏览器身份,不得判定该角色场景通过
|
|
24
|
+
- 未恢复原始身份,不得结束本轮浏览器 E2E
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
- `endpoint_calls`
|
|
16
16
|
- `browser_only_steps`
|
|
17
17
|
- `runtime_bindings`
|
|
18
|
+
- `identity_steps`
|
|
19
|
+
- `role_contexts`
|
|
20
|
+
- `identity_cleanup`
|
|
18
21
|
- `next_step`
|
|
19
22
|
- `updated_at`
|
|
20
23
|
|
|
@@ -52,6 +55,28 @@
|
|
|
52
55
|
- `title`
|
|
53
56
|
- `reason`
|
|
54
57
|
|
|
58
|
+
`identity_steps` 每项建议包含:
|
|
59
|
+
- `role`
|
|
60
|
+
- `action`: `mock | verify | unmock`
|
|
61
|
+
- `target_user_id`
|
|
62
|
+
- `target_user_name`
|
|
63
|
+
- `workspace`
|
|
64
|
+
- `status`
|
|
65
|
+
- `evidence`
|
|
66
|
+
|
|
67
|
+
`role_contexts` 每项建议包含:
|
|
68
|
+
- `role`
|
|
69
|
+
- `user_id`
|
|
70
|
+
- `user_name`
|
|
71
|
+
- `expected_actions`
|
|
72
|
+
- `expected_visibility`
|
|
73
|
+
|
|
74
|
+
`identity_cleanup` 建议保存:
|
|
75
|
+
- `unmock_done`
|
|
76
|
+
- `restored_user`
|
|
77
|
+
- `verified_at`
|
|
78
|
+
- `evidence`
|
|
79
|
+
|
|
55
80
|
`runtime_bindings` 建议保存:
|
|
56
81
|
- 最近创建的项目 ID
|
|
57
82
|
- 最近回读的项目 ID
|
|
@@ -65,6 +65,32 @@ def main():
|
|
|
65
65
|
lines.append(f"- {item.get('title', '')}")
|
|
66
66
|
if item.get("reason"):
|
|
67
67
|
lines.append(f" - {item['reason']}")
|
|
68
|
+
if state.get("identity_steps") or state.get("role_contexts"):
|
|
69
|
+
lines.append("")
|
|
70
|
+
lines.append("### 2.5 多角色浏览器身份")
|
|
71
|
+
if state.get("role_contexts"):
|
|
72
|
+
lines.append("- 角色矩阵:")
|
|
73
|
+
for item in state.get("role_contexts", []):
|
|
74
|
+
lines.append(
|
|
75
|
+
f" - `{item.get('role', '')}`: `{item.get('user_name', '')}` / `{item.get('user_id', '')}`"
|
|
76
|
+
)
|
|
77
|
+
if item.get("expected_actions"):
|
|
78
|
+
lines.append(f" - 动作:{item['expected_actions']}")
|
|
79
|
+
if state.get("identity_steps"):
|
|
80
|
+
lines.append("- 身份切换记录:")
|
|
81
|
+
for item in state.get("identity_steps", []):
|
|
82
|
+
lines.append(
|
|
83
|
+
f" - `{item.get('action', '')}` `{item.get('role', '')}` "
|
|
84
|
+
f"`{item.get('target_user_id', '')}`: `{item.get('status', '')}`"
|
|
85
|
+
)
|
|
86
|
+
if item.get("evidence"):
|
|
87
|
+
lines.append(f" - 证据:{item['evidence']}")
|
|
88
|
+
if state.get("identity_cleanup"):
|
|
89
|
+
cleanup = state["identity_cleanup"]
|
|
90
|
+
lines.append(
|
|
91
|
+
f"- 恢复原始身份:`{cleanup.get('unmock_done', False)}`,"
|
|
92
|
+
f"当前账号:`{cleanup.get('restored_user', '')}`"
|
|
93
|
+
)
|
|
68
94
|
lines.append("")
|
|
69
95
|
lines.append("## 3. 给测试人员的操作手册")
|
|
70
96
|
lines.append("### 3.1 前置数据")
|
|
@@ -8,6 +8,7 @@ description: "用于在 BPMAX 的表单模板页面中创建或编辑表单。
|
|
|
8
8
|
## 写入路径硬约束
|
|
9
9
|
- 执行前必须先运行 `bpmax-cli config adapters --format json` 核对 `form-template`;只有 `build_status` 和 `submit_status` 都是 `supported` 时才允许进入 build/submit。当前若显示 `blocked`,只能导出、编辑 work、lint 和形成变更建议,不得提交。
|
|
10
10
|
- 在 bpmax-cli npm 分发包中,真实远端写操作只能走 `bpmax-cli config form-template submit`。
|
|
11
|
+
- `bpmax-cli config form-template export/submit/verify` 和 `export_form_template.py --template-id` 必须硬阻断发布态模板 ID;若 `origin_template_id != 0`,只能改用该草稿 ID 后重试。
|
|
11
12
|
- 旧来源脚本 `scripts/submit*.py` 只保留为结构参考,默认会硬失败;不得用它们直调 BPMAX API。
|
|
12
13
|
- 不得用 `bpmax-cli api POST/PUT/DELETE /form_template*` 或其它 raw API 绕过 typed config submit。
|
|
13
14
|
|
|
@@ -862,6 +863,7 @@ bpmax-cli config form-template submit \
|
|
|
862
863
|
- 这类场景里 `actualRuntimeFormTemplateId = <publishedId>` 就是主证据
|
|
863
864
|
- 不要求再额外补一个 `flow_live_form_template_id` 才算通过
|
|
864
865
|
- 典型场景:纯文案、小字段显示、提示语、非流程绑定结构的小改动
|
|
866
|
+
- 如果运行态发起页、审批页或详情页表单打不开、白屏、字段不渲染或提交控件不可用,不得先跳到接口结论;必须先检查浏览器 Console 和 Network 报错,并优先处理 `form_template` 加载、控件渲染、`lambda`、`customeValidate`、`sub_form` 绑定等表单模板相关错误。
|
|
865
867
|
- 推荐命令:
|
|
866
868
|
|
|
867
869
|
```bash
|
|
@@ -7,6 +7,7 @@ from form_template_editor_common import (
|
|
|
7
7
|
build_client,
|
|
8
8
|
build_create_raw_payload,
|
|
9
9
|
create_stem,
|
|
10
|
+
assert_form_template_draft_id,
|
|
10
11
|
detail_to_work_payload,
|
|
11
12
|
dump_json,
|
|
12
13
|
paths_for,
|
|
@@ -36,6 +37,7 @@ def main() -> int:
|
|
|
36
37
|
if args.template_id:
|
|
37
38
|
response = client.get_form_template(args.template_id)
|
|
38
39
|
detail = response.get("data") or {}
|
|
40
|
+
assert_form_template_draft_id(args.template_id, detail, "export")
|
|
39
41
|
stem = str(args.template_id)
|
|
40
42
|
mode = "edit"
|
|
41
43
|
raw = detail
|
|
@@ -133,6 +133,23 @@ def extract_api_data(payload: Dict[str, Any]) -> Any:
|
|
|
133
133
|
return payload
|
|
134
134
|
|
|
135
135
|
|
|
136
|
+
def normalize_numeric_id(value: Any) -> int | None:
|
|
137
|
+
if isinstance(value, int):
|
|
138
|
+
return value
|
|
139
|
+
if isinstance(value, str) and value.isdigit():
|
|
140
|
+
return int(value)
|
|
141
|
+
return None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def assert_form_template_draft_id(template_id: Any, detail: Dict[str, Any], action: str) -> None:
|
|
145
|
+
origin_template_id = normalize_numeric_id(detail.get("origin_template_id"))
|
|
146
|
+
if origin_template_id and origin_template_id > 0:
|
|
147
|
+
raise SystemExit(
|
|
148
|
+
f"refusing to {action} published form-template id {template_id}; "
|
|
149
|
+
f"use draft id {origin_template_id}. Published ids are readback-only."
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
|
|
136
153
|
def _extract_field_pairs(rule_rows: Any, value_items: Any) -> tuple[Dict[str, Dict[str, Any]], list[str]]:
|
|
137
154
|
value_by_field: Dict[str, Dict[str, Any]] = {}
|
|
138
155
|
if isinstance(value_items, list):
|
|
@@ -12,8 +12,8 @@ if str(SCRIPT_DIR) not in sys.path:
|
|
|
12
12
|
sys.path.insert(0, str(SCRIPT_DIR))
|
|
13
13
|
|
|
14
14
|
import form_template_editor_common as common
|
|
15
|
-
import submit_form_template as submit_script
|
|
16
15
|
from form_template_editor_common import (
|
|
16
|
+
assert_form_template_draft_id,
|
|
17
17
|
build_drift_report,
|
|
18
18
|
build_publish_safety_report,
|
|
19
19
|
build_runtime_acceptance_payload,
|
|
@@ -1223,23 +1223,12 @@ class FormTemplateEditorCommonTests(unittest.TestCase):
|
|
|
1223
1223
|
self.assertEqual(payload["flowDraftFormTemplateId"], 990702161)
|
|
1224
1224
|
self.assertEqual(payload["runtimeReferenceSource"], "flow_live_api")
|
|
1225
1225
|
|
|
1226
|
-
def
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
return {"data": {"id": template_id, "origin_template_id": 990702142}}
|
|
1226
|
+
def test_form_template_draft_id_gate_blocks_published_template_id(self) -> None:
|
|
1227
|
+
with self.assertRaisesRegex(SystemExit, "published form-template id 990702161.*draft id 990702142"):
|
|
1228
|
+
assert_form_template_draft_id(990702161, {"id": 990702161, "origin_template_id": 990702142}, "export")
|
|
1230
1229
|
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
self.assertEqual(detail["id"], 990702161)
|
|
1234
|
-
|
|
1235
|
-
def test_submit_script_uses_requested_id_as_edit_target_when_origin_missing(self) -> None:
|
|
1236
|
-
class FakeClient:
|
|
1237
|
-
def get_form_template(self, template_id):
|
|
1238
|
-
return {"data": {"id": template_id, "origin_template_id": 0}}
|
|
1239
|
-
|
|
1240
|
-
draft_id, detail = submit_script.resolve_edit_target_ids(FakeClient(), 990702161)
|
|
1241
|
-
self.assertEqual(draft_id, 990702161)
|
|
1242
|
-
self.assertEqual(detail["id"], 990702161)
|
|
1230
|
+
def test_form_template_draft_id_gate_allows_draft_template_id(self) -> None:
|
|
1231
|
+
assert_form_template_draft_id(990702142, {"id": 990702142, "origin_template_id": 0}, "export")
|
|
1243
1232
|
|
|
1244
1233
|
def test_runtime_acceptance_payload_accepts_browser_runtime_without_flow_live_reference(self) -> None:
|
|
1245
1234
|
payload = build_runtime_acceptance_payload(
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "bpmax-user-mock-operator"
|
|
3
|
+
description: "用于 BPMAX 浏览器 E2E 测试中的用户身份切换。只要用户提到“浏览器 E2E 切换用户”“模拟审批人测试”“多角色页面回归”“mock 用户做页面测试”“退出模拟用户”或等价表达,就应使用这个 skill。它只复用当前浏览器登录态调用既有 `PUT /api/user/:id` mock/unmock 接口,不提供 API Key 冒充、不修改平台权限、不修改本地配置镜像。"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# BPMAX User Mock Operator
|
|
7
|
+
|
|
8
|
+
## 使用范围
|
|
9
|
+
- 本 skill 只用于“浏览器 E2E 测试中的用户身份切换”。
|
|
10
|
+
- 目标是让同一浏览器会话在完整页面链路中切到发起人、审批人、查看人等角色,验证真实 UI 可见性、按钮、表单和流转。
|
|
11
|
+
- 不用于普通 CLI API 调用身份切换,不用于 API Key impersonation,不新增 `bpmax-cli user mock` typed command。
|
|
12
|
+
- 不修改 BPMAX 平台权限、角色配置、本地 `think_*` 镜像或配置提交体。
|
|
13
|
+
|
|
14
|
+
## 何时使用
|
|
15
|
+
- E2E 场景需要用不同用户在浏览器里发起、审批、驳回、查看或验证权限。
|
|
16
|
+
- 当前浏览器已登录一个具备模拟用户权限的管理账号,需要临时 mock 到目标用户。
|
|
17
|
+
- 测试结束后需要 unmock,恢复原管理账号身份。
|
|
18
|
+
- 用户只给了姓名但没有给 `user_id` 时,先通过用户管理页或已有查询链路确认目标用户 id。
|
|
19
|
+
|
|
20
|
+
## 前置条件
|
|
21
|
+
- 浏览器里已有可用 BPMAX 登录态。
|
|
22
|
+
- 当前账号具备平台已有的用户模拟权限。
|
|
23
|
+
- 已确认 workspace、目标用户 `user_id`、目标测试角色。
|
|
24
|
+
- 默认页面为 `.../w:<workspace>/userManagement`;如果测试页不是这个路由,可以传 `--href-path` 覆盖。
|
|
25
|
+
|
|
26
|
+
## Memory 协议
|
|
27
|
+
- 开始前先调用 [$bpmax-memory-protocol](../bpmax-memory-protocol/SKILL.md),检索词至少包含:
|
|
28
|
+
- `浏览器 E2E`
|
|
29
|
+
- `模拟用户`
|
|
30
|
+
- `mock unmock`
|
|
31
|
+
- `workspace`
|
|
32
|
+
- 只有遇到稳定经验时才写回 memory,例如:
|
|
33
|
+
- 某工作区用户管理路由不是默认 `/w:<workspace>/userManagement`
|
|
34
|
+
- 某环境对 `x-href` 或 `referer` 有额外要求
|
|
35
|
+
- 某类角色切换后的页面权限验证方式
|
|
36
|
+
- 不要写入 Cookie、Authorization、API Key、手机号、验证码、密码或完整接口响应。
|
|
37
|
+
|
|
38
|
+
## 核心接口
|
|
39
|
+
- 进入模拟:`PUT /api/user/<user_id>`,body `{"mock": 1}`
|
|
40
|
+
- 退出模拟:`PUT /api/user/<user_id>`,body `{"unmock": 1}`
|
|
41
|
+
- query 需要带 `$workspace=<workspace>&$language=<language>`
|
|
42
|
+
- 请求头复用当前浏览器登录态:
|
|
43
|
+
- `Cookie`
|
|
44
|
+
- `Origin`
|
|
45
|
+
- `Referer`
|
|
46
|
+
- `x-href`
|
|
47
|
+
- `Content-Type: application/json`
|
|
48
|
+
|
|
49
|
+
## 操作命令
|
|
50
|
+
|
|
51
|
+
### 进入目标用户身份
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
PYTHON_BIN=./venv/bin/python
|
|
55
|
+
[[ -x "$PYTHON_BIN" ]] || PYTHON_BIN=./.venv/bin/python
|
|
56
|
+
[[ -x "$PYTHON_BIN" ]] || PYTHON_BIN=python3
|
|
57
|
+
|
|
58
|
+
"$PYTHON_BIN" .codex/skills/bpmax-user-mock-operator/scripts/switch_user_identity.py \
|
|
59
|
+
--action mock \
|
|
60
|
+
--user-id <target_user_id> \
|
|
61
|
+
--workspace <workspace> \
|
|
62
|
+
--base-url <bpmax_origin> \
|
|
63
|
+
--cookie-header "$BPMAX_COOKIE_HEADER"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 退出模拟身份
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
"$PYTHON_BIN" .codex/skills/bpmax-user-mock-operator/scripts/switch_user_identity.py \
|
|
70
|
+
--action unmock \
|
|
71
|
+
--user-id <target_user_id> \
|
|
72
|
+
--workspace <workspace> \
|
|
73
|
+
--base-url <bpmax_origin> \
|
|
74
|
+
--cookie-header "$BPMAX_COOKIE_HEADER"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 参数说明
|
|
78
|
+
- `--action`:只能是 `mock` 或 `unmock`。
|
|
79
|
+
- `--user-id`:目标用户 id,必须是正整数。
|
|
80
|
+
- `--workspace`:工作区 key;也可用 `BPMAX_WORKSPACE` 环境变量。
|
|
81
|
+
- `--base-url`:BPMAX 页面 origin;也可用 `BPMAX_BASE_URL` 环境变量。
|
|
82
|
+
- `--cookie-header`:当前浏览器页面有效 Cookie 串;也可用 `BPMAX_COOKIE_HEADER` 环境变量。
|
|
83
|
+
- `--href-path`:覆盖默认 `/w:<workspace>/userManagement` 的 `x-href` / `Referer` 口径。
|
|
84
|
+
- `--language`:默认 `zhCN`。
|
|
85
|
+
- `--insecure`:仅用于证书异常的临时排障。
|
|
86
|
+
|
|
87
|
+
## 浏览器 E2E 工作流
|
|
88
|
+
1. 记录原始管理账号、workspace、当前页面和目标测试角色。
|
|
89
|
+
2. 从当前浏览器页面提取 Cookie,设置 `BPMAX_COOKIE_HEADER`。
|
|
90
|
+
3. 用本 skill 执行 `mock`。
|
|
91
|
+
4. 刷新或打开待测页面,通过 `/api/user/current` 或页面头像/用户名/权限入口确认当前身份已经切到目标用户。
|
|
92
|
+
5. 在浏览器中执行该角色的真实动作:发起、填写、提交、审批、驳回、查看或权限验证。
|
|
93
|
+
6. 记录截图、项目 ID、step ID、当前角色、目标用户 id 和结论。
|
|
94
|
+
7. 执行 `unmock`,刷新页面并确认已恢复原管理账号身份。
|
|
95
|
+
|
|
96
|
+
## 硬门禁
|
|
97
|
+
- 没有确认当前浏览器身份前,不得声称该角色浏览器 E2E 已通过。
|
|
98
|
+
- 没有执行 unmock 和恢复验证前,不得结束多角色测试。
|
|
99
|
+
- 不得把 mock 后的 Cookie/API 响应用作普通 API Key 或 CLI 业务命令身份。
|
|
100
|
+
- 不得把浏览器抓包中的 Cookie 或 Authorization 写入报告、memory、AGENTS.md 或 git。
|
|
101
|
+
|
|
102
|
+
## 常见问题
|
|
103
|
+
- 401/403:先确认 Cookie 是否过期,再确认原始管理账号是否具备模拟用户权限。
|
|
104
|
+
- HTTP 200 但业务 `code` 非 0:以后端返回的 JSON 错误为准,不要继续执行页面测试。
|
|
105
|
+
- 页面身份未变化:刷新页面,或调用 `/api/user/current` 验证;仍未变化则先 unmock 再重试。
|
|
106
|
+
- 目标用户 id 不确定:先在用户管理页定位用户,不要凭姓名猜 id。
|
|
@@ -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
|
+
)
|