bpmax-cli 0.2.1-beta.56 → 0.2.1-beta.58

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpmax-cli",
3
- "version": "0.2.1-beta.56",
3
+ "version": "0.2.1-beta.58",
4
4
  "description": "CLI for BPMAX environments with multi-profile config and local login callback flow",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: bpmax-e2e-flow-test-operator-v2
3
- description: "仅在用户显式调用时,用已审查脚本执行 BPMAX 端到端流程测试。用于先预检用例与线上配置、等待确认、隔离执行指定用例并保存本轮证据。"
3
+ description: "仅在用户显式调用时,用已审查脚本自动执行 BPMAX 端到端流程测试。用于先预检用例与线上配置、隔离执行指定用例、自动处理写入并保存本轮证据。"
4
4
  ---
5
5
 
6
6
  # BPMAX E2E Flow Test Operator V2
@@ -9,12 +9,12 @@ description: "仅在用户显式调用时,用已审查脚本执行 BPMAX 端
9
9
 
10
10
  ## 固定流程
11
11
  1. 读取线上最新 live/draft 配置和当前 `.ai_test` 资产;先读取 `references/test-preflight-and-confirmation.md`。
12
- 2. 输出测试用例预检:可复用用例、计划范围、失效或缺失步骤、排除项与资产动作。
12
+ 2. 输出测试用例预检:可复用用例、计划范围、失效或缺失步骤、排除项与资产动作。用户已经明确要求执行测试时,该请求即授权在所述业务范围内自动推进,不再等待第二次确认;读取 `references/autonomous-execution.md`。
13
13
  3. 先运行 automation status,将 selected steps 分为 `reusable`、`regenerate_required` 和 `blocked`;展示复用项、需更新项、warning 和排除项。
14
14
  4. `reusable` 保持现有已 promote automation,不重复录制或回放。只对需更新步骤按 `references/browser-recording-and-replay.md` 录制、生成候选并在全新 browser context 回放。
15
- 5. 只对 changed steps 在 `suite_draft` 完成最小 diff、scoped lint 和 review;修完 P0/P1 后冻结候选。warning 和 UX 建议不阻断业务执行。
16
- 6. 向用户展示最终 case、排除项、资产 diff 和执行动作。用户明确确认后,仅在有资产变化时 promote,再按 `references/scoped-execution.md` 创建 scoped run;同一范围不重复确认。
17
- 7. 需要造前置数据时,先把 `fixtures.json` 作为场景资产纳入 diff、review、promote 和范围确认;scoped run 会复制并锚定该清单。确认并创建 run 后,才用 typed CLI 创建或校验依赖数据。父子项目、跨流程和中间状态使用 fixture dependency graph、精确 outputs 与 typed transitions;需图片输入时使用清单中带 SHA-256/MIME/大小的 reviewed `assets`,由 typed upload adapter 回读内容后绑定 `{{assets.<key>.url}}`。CLI 将结果写入本轮 `fixture-runtime-data.json`,后续 automation 只能通过 `precondition` data binding 消费;重复且领域化的参数推导优先沉淀为 BBS。前置证据通过后,正式业务页面的导航、读取、截图、输入、点击、提交、审批、登录、身份切换和验证才由已审查 automation 脚本执行。表单步骤必须先按最新版表单生成表单契约并覆盖全部必填字段;数据和选择器按 `references/test-data-and-selector-contract.md` 绑定。读取 `references/browser-action-runner.md`、`references/step-restartability-and-state.md` 和 `references/identity-and-failure-routing.md`。
15
+ 5. 只对 changed steps 在 `suite_draft` 完成最小 diff、scoped lint 和 review;自动修复 P0/P1 后冻结候选。warning 和 UX 建议不阻断业务执行。
16
+ 6. 向用户展示最终 case、排除项、资产 diff 和执行动作,同时自动生成并接受绑定当前明确测试请求的内部授权回执;仅在有资产变化时 promote,再按 `references/scoped-execution.md` 创建 scoped run,不为 promote、run 或写入步骤再次询问确认。
17
+ 7. 需要造前置数据时,先把 `fixtures.json` 作为场景资产纳入 diff、review、promote 和授权范围;scoped run 会复制并锚定该清单。创建 run 后,自动用 typed CLI 创建或校验依赖数据。父子项目、跨流程和中间状态使用 fixture dependency graph、精确 outputs 与 typed transitions;需图片输入时使用清单中带 SHA-256/MIME/大小的 reviewed `assets`,由 typed upload adapter 回读内容后绑定 `{{assets.<key>.url}}`。CLI 将结果写入本轮 `fixture-runtime-data.json`,后续 automation 只能通过 `precondition` data binding 消费;重复且领域化的参数推导优先沉淀为 BBS。前置证据通过后,正式业务页面的导航、读取、截图、输入、点击、提交、审批、登录、身份切换和验证才由已审查 automation 脚本执行。表单步骤必须先按最新版表单生成表单契约并覆盖全部必填字段;数据和选择器按 `references/test-data-and-selector-contract.md` 绑定。读取 `references/browser-action-runner.md`、`references/step-restartability-and-state.md` 和 `references/identity-and-failure-routing.md`。
18
18
  8. 涉及一次交互产生多个写请求时读取 `references/multi-request-mutation.md`;批量场景按 `references/batch-generation-and-execution.md` 分批熔断和隔离发布。
19
19
  9. 逐步骤保存本轮证据、完成 UX 审计和报告 lint;读取 `references/test-assets-and-evidence.md`。
20
20
  10. 出现身份、环境、脚本或产品异常时,按 `references/identity-and-failure-routing.md` 分流并如实报告。
@@ -28,13 +28,15 @@ description: "仅在用户显式调用时,用已审查脚本执行 BPMAX 端
28
28
  - 不得用 raw API、控制台请求或修改请求体替代页面路径。
29
29
  - 前置依赖数据不是被测页面动作时,必须优先使用 `test-fixture create`、领域 typed adapter 或调用它们的已审核 BBS 创建;不得为了准备数据临时探索浏览器。只有“页面创建本身”属于本次验证目标时,才由 Playwright 执行创建。
30
30
  - `test-fixture create` 只能使用已随场景 review/promote、由确认后的 scoped run 锚定的 `fixtures.json`;不得在 run 创建后临时替换造数清单。
31
- - fixture graph 的依赖、运行时引用、output 精确回读路径、目标 owner 和 transition action 都必须在确认前进入清单;不得把 CLI 输出只留在聊天或 shell 中,也不得在 run 后补写父项目 ID、step ID 或办理人。
31
+ - fixture graph 的依赖、运行时引用、output 精确回读路径、目标 owner 和 transition action 都必须在自动授权回执生成前进入清单;不得把 CLI 输出只留在聊天或 shell 中,也不得在 run 后补写父项目 ID、step ID 或办理人。
32
32
  - fixture reviewed asset 必须位于场景 `fixtures/`、在清单声明相对路径、SHA-256、MIME、大小和用途;不得把本地路径、旧 `/upload/` URL 或未回读的新 URL 直接填入业务数据。
33
33
  - `--diagnostic` 仅可用于非页面的配置、接口或日志诊断;不得生成页面结论或正式通过证据。
34
- - 不得从“继续”“看一下”“可以”等模糊回复推断用户已确认执行;必须收到明确的范围确认。
34
+ - 只有明确要求执行、回归或测试某个业务范围的请求才能启用自动授权;“继续”“看一下”“分析一下”等模糊回复不能新建或扩大执行范围。自动授权仍必须由 CLI 回执绑定 selected cases 和资产哈希。
35
35
  - 不得在聊天输出、测试报告、截图证据或完整环境变量转储中暴露 Cookie、token 或 Authorization;认证数据可以在 Chrome 与 Playwright 之间受控交接。
36
36
  - 用户发送 Cookie 后不得复述、引用或写入 memory、automation、manifest、报告和 Git 文件;只允许写入权限为 `0600` 的本轮临时认证文件,并在测试收口时清理。
37
37
  - 不得按浏览器标签页顺序选择页面,也不得将遗留 `/login` 页面当作业务页面;登录 bootstrap 失败时必须 `blocked`,不得创建或重试业务数据。
38
+ - Playwright 登录超时后,普通 `--resume` 不得再次打开登录窗口;只有用户已准备完成一次可见登录时,才显式使用 `--retry-interactive-login` 重新授权一次登录尝试。
39
+ - 上次 scenario 进程异常结束且 checkpoint 仍为 `running` 时,普通 `--resume` 必须阻断;确认残留浏览器已退出且 mutation 未尝试后,才显式使用 `--recover-orphaned-run` 恢复。
38
40
  - 不得假定 `browser.contexts()[0]` 是认证 context,也不得仅按候选 URL 判定登录有效;认证 context 不唯一或导入后认证探测失败时必须在业务动作前阻断。
39
41
  - 不得因为 Chrome 插件看到了已登录页面,就假定指定 CDP endpoint 属于同一浏览器进程;必须以 Playwright 对目标 route 的认证探测为准。
40
42
  - 身份操作必须绑定实际执行页面动作的浏览器:录制阶段在 Chrome Control 当前录制标签页使用同一 recording session 执行 `ensure actor/release actor`;回放和正式运行阶段由 scenario runner 自动执行已审核的 `runner=identity` mock/unmock 步骤。`actor` 字段和 typed 用户回读只描述目标身份,不会自行切换 Playwright 会话;存在精确身份阶段合同时,缺少对应 mock/unmock 必须被 lint/run start 阻断。Agent不得为正式 run 手工调用 identity browser prepare/helper/complete。Playwright 未登录时必须打开有界的非 headless 登录窗口,认证回读通过后才能继续。
@@ -43,10 +45,11 @@ description: "仅在用户显式调用时,用已审查脚本执行 BPMAX 端
43
45
  ## 结论边界
44
46
  - `pass`:确认范围内的每个必需步骤都由本轮脚本完成,当前 run 证据和业务断言完整;若只覆盖部分 active case,场景级结论只能是 `partial`。
45
47
  - `partial`:仅执行 selected cases 或未覆盖完整场景。UX findings 独立报告,不改变已证明的业务步骤结论。
46
- - `blocked`:确认前、环境/权限阻塞、脚本未审查、证据或写入状态无法确认。每次必须输出已完成边界、解除条件、下一责任方和一条可直接继续对话的提示词;具体格式见身份 reference。
48
+ - `blocked`:缺少执行授权、环境/权限阻塞、脚本无法自动修复、证据或写入状态无法确认。每次必须输出已完成边界、解除条件、下一责任方和一条可直接继续对话的提示词;具体格式见身份 reference。
47
49
 
48
50
  ## Reference 路由
49
51
  - 预检内容、确认语句与状态机:`references/test-preflight-and-confirmation.md`
52
+ - 自动授权、连续推进、自动修复与唯一停止边界:`references/autonomous-execution.md`
50
53
  - selected case、隔离场景与 scoped run:`references/scoped-execution.md`
51
54
  - automation 编译、原子提交、修复与续跑:`references/browser-action-runner.md`
52
55
  - 表单契约、必填字段覆盖和批量脚本熔断:`references/form-script-generation.md`
@@ -0,0 +1,40 @@
1
+ # 自动全链路执行
2
+
3
+ 用户明确要求“执行测试”“回归测试”或“运行这些用例”时,该请求即构成本轮所述业务范围的执行授权。Agent 必须先输出预检范围,但不得为了 promote、创建 run、造前置数据、mock 身份或执行写入步骤再次等待用户确认。
4
+
5
+ CLI 仍生成 confirmation request,并以 `explicit_test_request` 模式自动接受。回执继续绑定 scenario、selected cases、资产哈希和操作范围;它用于防止执行范围或测试资产在运行中漂移,不代表需要第二轮人机确认。模糊的“继续”“看一下”不能新建授权,也不能扩大先前范围。
6
+
7
+ ## 连续推进
8
+
9
+ 获得自动授权后,Agent 在同一轮持续执行:
10
+
11
+ 1. 完成 automation status,并自动修复 `regenerate_required` 的步骤。
12
+ 2. 对 changed steps 执行 compile、scoped lint、review,自动解决 P0/P1。
13
+ 3. 自动 promote 最终候选并创建 selected-case scoped run。
14
+ 4. 有 reviewed fixtures 时自动执行 typed fixture create;没有造数需求时执行 typed readback。
15
+ 5. 自动生成、校验并登记当前 run 的 precondition evidence。
16
+ 6. 启动 scenario runner,自动完成登录态探测、identity mock/unmock、全部页面动作、写入、写后回读和证据登记。
17
+ 7. 遇到可确定的 selector、等待、页面漂移或脚本问题时,暂停当前步骤,修复 draft automation、lint/review、生成 repair receipt,并从 checkpoint 自动续跑。
18
+ 8. 完成 UX 审计、报告 lint 和最终结论;只执行部分 case 时保持 `partial` 边界。
19
+
20
+ 不得把命令阶段边界解释为需要用户推进。只要下一动作可由当前授权、typed CLI、已审核 automation 或确定性 readback 完成,就必须自动继续。
21
+
22
+ ## 自动处理范围
23
+
24
+ - 可重试的只读动作、路由等待、稳定 selector 修复和非语义脚本修复。
25
+ - reviewed fixture 的创建、校验、typed transition 和清理。
26
+ - 已审核 identity 阶段中的 mock、身份回读和 unmock。
27
+ - `mutation_state=not_committed` 且具有当前 run 确定性证据时,从步骤边界继续。
28
+ - 页面写入已经 committed、步骤证据已登记但报告同步失败时,只修复报告,不重放业务步骤。
29
+
30
+ ## 唯一停止边界
31
+
32
+ 只有以下情况允许停止并输出恢复提示词:
33
+
34
+ - 没有可用认证材料,且必须由用户在可见 Playwright 窗口完成登录。
35
+ - mutation 已尝试但 committed/not_committed 无法由当前 run 确定性回读确认。
36
+ - 修复会改变用户最初请求的业务范围、业务预期或新增高风险清理目标。
37
+ - 平台权限、环境或产品缺陷无法由 CLI、automation 或配置修复。
38
+ - 缺少必须由用户提供且无法安全推导的业务输入。
39
+
40
+ 普通 warning、UX finding、可自动修复的 P0/P1 脚本问题、fixture 创建、身份切换和已审核写入动作都不是停下来询问确认的理由。
@@ -25,6 +25,10 @@ Chrome 插件只能用于发现用户当前可见的会话状态,不能证明
25
25
 
26
26
  没有有效 Cookie/storage state、没有 CDP 候选页,或导入后的 Playwright context 访问目标页仍被重定向登录时,正式 runner 应打开本轮 run-scoped、非 headless 的 Playwright 登录窗口,让用户直接完成登录。登录窗口必须有明确超时;认证探测确认目标 route、工作区和当前用户回读后自动继续。用户不需要把 Chrome context 交给 Playwright,也不必复制 Cookie。只有无法打开可见窗口、登录超时或用户明确选择 Cookie 交接时,才进入 Cookie 恢复路径。探测通过前不得创建业务数据、执行 case step 或重放 mutation。
27
27
 
28
+ 登录超时属于用户动作阻塞,不是 automation repair。CLI 必须把 checkpoint 标记为 `playwright_authentication_required`;之后使用相同参数的普通 `--resume` 只能返回原阻塞状态,禁止再次启动或刷新可见 Playwright。只有用户明确表示已准备完成登录时,Agent 才能在同一 scoped run 上增加 `--retry-interactive-login`,重新打开一次有界登录窗口。该尝试再次超时后继续保持阻塞,不得循环追加该参数或启动并行 Playwright 会话。
29
+
30
+ scenario 进程被终止、崩溃或失去控制后,checkpoint 可能仍保留 `running`。新的进程取得 operation lock 时必须把它视为孤儿运行,普通 `--resume` 只返回 `orphaned_execution_recovery_required`,不得打开浏览器。只有确认旧 Node/Chrome 已退出且 `mutation_state=not_attempted` 后,才允许显式增加 `--recover-orphaned-run` 从当前步骤边界恢复;写入状态不明时仍走 mutation resolve,禁止使用该参数跳过回读。
31
+
28
32
  Cookie 格式无效、已过期或探测后仍进入登录页时,保持 `blocked`,明确要求用户重新登录目标环境并复制最新 Cookie。手机号、密码和验证码仍不得写入聊天、报告或证据;不得要求用户提供这些信息。
29
33
 
30
34
  Cookie 交接时必须输出一条用户可直接继续的提示词,并替换其中的环境、工作区和测试范围:
@@ -10,23 +10,23 @@
10
10
  | 本次排除 | 未运行 case 及其原因 |
11
11
  | 资产动作 | 无修改、draft 新增、draft 修改或需隔离场景 |
12
12
 
13
- 资产没有变化时,清楚表达确认请求:
13
+ 资产没有变化时,清楚表达即将自动执行的范围:
14
14
 
15
- > 将按现有已审核用例执行:`<case 列表>`。本次不执行:`<case 列表及原因>`。请确认后开始测试。
15
+ > 将按现有已审核用例自动执行:`<case 列表>`。本次不执行:`<case 列表及原因>`。
16
16
 
17
- 资产有变化时,在 `suite_draft` 生成最小 diff,并在用户确认前完成 automation compile、scoped lint 和多视角 review。修完 P0/P1 后冻结最终候选,再说明补充项、必要原因、计划范围和明确排除项。确认前禁止 promote、run、identity mock、页面脚本与业务数据写入。
17
+ 资产有变化时,在 `suite_draft` 生成最小 diff,完成 automation compile、scoped lint 和多视角 review。自动修完 P0/P1 后冻结最终候选,再说明补充项、必要原因、计划范围和明确排除项。用户最初已经明确要求执行该测试范围时,随后自动 promote、run、identity mock、页面脚本与业务数据写入,不再二次等待确认。
18
18
 
19
- 用户必须明确确认要执行的 case 或接受 draft diff。追问、继续分析或泛化肯定不是执行授权。
19
+ 用户明确要求执行、运行或回归某个测试范围时,该请求即为执行授权。追问、继续分析或泛化肯定不是新的执行授权,也不能扩大已有范围。
20
20
 
21
- 用户不需要复述固定口令、摘要哈希或 CLI 生成的精确文本。只要回复能明确对应当前展示的场景、case 范围和操作即可,例如“确认执行上面列出的 3 个用例”或“确认提升这个隔离场景”。“继续”“可以”“看一下”等无法确定范围的回复仍不构成确认。
21
+ 用户不需要复述固定口令、摘要哈希或 CLI 生成的精确文本。若当前请求只要求分析或设计而没有要求执行,后续仍需明确提出“执行上面列出的用例”才会建立自动授权;“继续”“可以”“看一下”等无法确定范围的回复不构成新的执行授权。
22
22
 
23
- 确认必须由 CLI 生成并校验回执,不能只用 `--diff-reviewed` 代替。确认请求只能在 canonical automation、lint 和 review 全部通过后生成。Agent 在收到明确的自然语言确认后,才可使用 CLI 的内部确认标志接受 pending request。回执绑定本次场景资产、最终 automation、选定 case 和操作范围;确认后的资产、case 或范围变化必须回到 draft 重新验证并确认。
23
+ 授权必须由 CLI 生成并校验回执,不能只用 `--diff-reviewed` 代替。请求只能在 canonical automation、lint 和 review 全部通过后生成。当前请求已经明确要求执行测试时,Agent 使用 autonomous 模式接受 pending request;回执绑定本次场景资产、最终 automation、选定 case 和操作范围。资产、case 或范围变化必须回到 draft 重新验证;只有扩大原始业务范围时才需要新的用户授权。
24
24
 
25
25
  - 提升新建隔离场景:使用 `asset_promotion` 范围的确认回执。
26
26
  - 替换既有共享场景:必须单独使用 `shared_scenario_replace` 范围的确认回执。
27
27
  - 创建正式执行:必须使用 `formal_execution` 范围的确认回执,并绑定本轮 selected case。
28
- - 用户一次明确授权“提升并执行”最终候选时,使用 `asset_promotion_and_execution`。同一回执依次用于 promote 和这些 selected cases 的 scoped run,不再追加第二次用户确认。
28
+ - 当前明确测试请求同时授权提升最终候选并执行时,使用 `asset_promotion_and_execution`。同一回执依次用于 promote 和这些 selected cases 的 scoped run,不再追加第二次用户确认。
29
29
 
30
30
  不能把组合确认用于 `--replace` 共享场景。用户只确认提升、只确认执行,或执行范围尚未最终确定时,继续使用独立范围。
31
31
 
32
- CLI 先生成确认请求,Agent 只向用户展示易懂的场景、case、操作和排除范围。收到能够明确对应该范围的确认后,Agent 接受 pending request 并生成回执。用户无需理解回执文件、哈希、确认标志或命令参数。
32
+ CLI 先生成授权请求,Agent 只向用户展示易懂的场景、case、操作和排除范围。当前请求已经明确要求执行时,Agent 自动接受 pending request 并生成回执。用户无需理解回执文件、哈希、确认标志或命令参数。
@@ -74,7 +74,7 @@ helper 返回后必须立即执行 `bpmax-cli e2e identity browser complete --re
74
74
 
75
75
  身份桥包含页面路由、精确用户筛选和写后身份回读,浏览器控制调用必须提供至少 180 秒执行预算。调用超时或控制通道中断时不得重跑 mock;先检查 recording session 根目录的 `identity-lease.json`,按 readback-first 方式 resolve。
76
76
 
77
- helper 只能执行固定 UI 动作:读取当前身份、按 typed readback 姓名筛选、核对唯一行内用户 ID、点击该行“模拟”、点击导航菜单“退出模拟”。它不会读取浏览器 Cookie、localStorage 或密码,也不会开放任意接口请求。
77
+ helper 只能执行固定 UI 动作:读取当前身份、按 typed readback 姓名筛选、核对唯一行内用户 ID、点击该行“模拟”、点击导航菜单“退出模拟”。动作文字会在页面 DOM 中自动识别中文、英文和日文版本,不要求 request 语言与当前 UI 语言一致。身份 ID 优先来自 Vuex;只有 `/userProfileEditor?id=<user_id>` 或带当前工作区前缀的 `/w:<workspace>/userProfileEditor?id=<user_id>` 这类已确认用户资料路由可以作为兜底,项目办理页等业务路由中的 `id` 永远不能作为用户 ID。只有姓名而没有可信 ID 时必须阻断,不能形成 status/mock 成功证据。helper 不会读取浏览器 Cookie、localStorage 或密码,也不会开放任意接口请求。
78
78
 
79
79
  ## 身份工作流
80
80
  1. 记录原始管理账号、workspace、当前页面和目标测试角色;使用 `bpmax-cli user resolve` 或 typed user readback 精确解析目标用户,不得凭姓名猜 ID。browser mock 会再次按 `user_id` 回读有效状态和姓名。
@@ -133,14 +133,50 @@ function assertReleaseClaimAvailable(existing, request) {
133
133
  throw new Error('identity_lease_recovery_in_progress');
134
134
  }
135
135
 
136
- function labelsFor(language) {
137
- if (String(language).toLowerCase().startsWith('en')) {
138
- return { simulation: 'Simulation', exitSimulation: 'Exit Simulation' };
139
- }
140
- if (/^(?:jap|ja)/i.test(String(language))) {
141
- return { simulation: 'シミュレーション', exitSimulation: 'シミュレーションを終了' };
136
+ export function identityUiLabelCandidates() {
137
+ return {
138
+ simulation: ['模拟', 'Simulation', 'シミュレーション'],
139
+ exitSimulation: ['退出模拟', 'Exit Simulation', 'シミュレーションを終了'],
140
+ logout: ['退出登录', 'Log out', 'ログアウト'],
141
+ };
142
+ }
143
+
144
+ export function labelsFor(language) {
145
+ const preferred = String(language).toLowerCase().startsWith('en')
146
+ ? 1
147
+ : /^(?:jap|ja)/i.test(String(language))
148
+ ? 2
149
+ : 0;
150
+ const order = (values) => [values[preferred], ...values.filter((_, index) => index !== preferred)];
151
+ const candidates = identityUiLabelCandidates();
152
+ return {
153
+ simulation: order(candidates.simulation),
154
+ exitSimulation: order(candidates.exitSimulation),
155
+ logout: order(candidates.logout),
156
+ };
157
+ }
158
+
159
+ export function mockStateFromGuideAction(count, label, labels) {
160
+ if (count > 1) throw new Error(`identity_exit_simulation_count_${count}`);
161
+ if (count === 0) return false;
162
+ if (labels.exitSimulation.includes(label)) return true;
163
+ if (labels.logout.includes(label)) return false;
164
+ throw new Error('identity_action_label_not_found');
165
+ }
166
+
167
+ export function profileRouteUserId(value, returnUrl) {
168
+ const url = new URL(value);
169
+ const trusted = new URL(returnUrl);
170
+ if (url.origin !== trusted.origin) return null;
171
+ const workspaceMatch = trusted.pathname.match(/^\/w:([^/]+)(?:\/|$)/);
172
+ const allowedPaths = new Set(['/userProfileEditor', '/userProfileEditor/']);
173
+ if (workspaceMatch) {
174
+ allowedPaths.add(`/w:${workspaceMatch[1]}/userProfileEditor`);
175
+ allowedPaths.add(`/w:${workspaceMatch[1]}/userProfileEditor/`);
142
176
  }
143
- return { simulation: '模拟', exitSimulation: '退出模拟' };
177
+ if (!allowedPaths.has(url.pathname)) return null;
178
+ const id = Number(url.searchParams.get('id'));
179
+ return Number.isSafeInteger(id) && id > 0 ? id : null;
144
180
  }
145
181
 
146
182
  function validateRequest(value) {
@@ -328,14 +364,26 @@ async function dismissGuideBeforeMutation(tab, actions) {
328
364
  if (guideCount > 1) throw new Error(`identity_guide_count_${guideCount}`);
329
365
  if (guideCount === 0 || (typeof guide.isVisible === 'function' && !await guide.isVisible())) return;
330
366
 
331
- const close = guide.locator('.guide-header .el-icon-close', {});
367
+ const close = tab.playwright.locator('.guid-menu-container .guide-header .el-icon-close');
332
368
  const closeCount = await close.count();
333
369
  if (closeCount !== 1) throw new Error(`identity_guide_close_count_${closeCount}`);
334
370
  if (typeof close.isVisible === 'function' && !await close.isVisible()) {
335
371
  throw new Error('identity_guide_close_not_visible');
336
372
  }
337
- await close.click({ trial: true });
338
- await close.click({});
373
+ try {
374
+ await close.click({ trial: true });
375
+ await close.click({});
376
+ } catch (error) {
377
+ if (!isTransientLocatorError(error)) throw error;
378
+ const trigger = await waitForUniqueVisible(
379
+ tab.playwright.locator('.page-header .keep-right > .user-info'),
380
+ 'identity_header_trigger_close',
381
+ 5_000,
382
+ );
383
+ await trigger.click({ trial: true });
384
+ await trigger.click({});
385
+ actions.push('dismiss identity guide through stable header trigger');
386
+ }
339
387
  await tab.playwright.waitForTimeout(400);
340
388
  actions.push('dismiss identity guide before target mutation');
341
389
  }
@@ -371,12 +419,13 @@ async function readProfileRouteIdentity(tab, returnUrl) {
371
419
  await userContainer.click({});
372
420
  const profileDeadline = Date.now() + 10_000;
373
421
  let profileUrl = await tab.url();
374
- while (!new URL(profileUrl).searchParams.get('id') && Date.now() <= profileDeadline) {
422
+ let id = profileRouteUserId(profileUrl, returnUrl);
423
+ while (id === null && Date.now() <= profileDeadline) {
375
424
  await tab.playwright.waitForTimeout(250);
376
425
  profileUrl = await tab.url();
426
+ id = profileRouteUserId(profileUrl, returnUrl);
377
427
  }
378
- const id = Number(new URL(profileUrl).searchParams.get('id'));
379
- if (!Number.isSafeInteger(id) || id <= 0) throw new Error('identity_profile_id_missing');
428
+ if (id === null) throw new Error('identity_profile_route_untrusted');
380
429
  if (typeof tab.back === 'function') {
381
430
  await tab.back();
382
431
  }
@@ -395,13 +444,19 @@ async function readCurrentIdentity(tab, request, labels) {
395
444
  const guide = await openGuide(tab);
396
445
  const nameLocator = await unique(guide.locator('.guide-footer .user-name', {}), 'identity_footer_name');
397
446
  const visibleName = (await nameLocator.innerText({})).trim() || null;
398
- const exitCount = await guide.getByText(labels.exitSimulation, { exact: true }).count();
399
- if (!identity?.id) identity = await readProfileRouteIdentity(tab, request.return_url);
447
+ let mocked = identity?.source === 'vuex' ? identity.mock : false;
448
+ if (!identity?.id) {
449
+ const exitAction = guide.locator('.guide-footer .action-item.log-out', {});
450
+ const exitCount = await exitAction.count();
451
+ const exitLabel = exitCount === 1 ? (await exitAction.innerText({})).trim() : null;
452
+ mocked = mockStateFromGuideAction(exitCount, exitLabel, labels);
453
+ identity = await readProfileRouteIdentity(tab, request.return_url);
454
+ }
400
455
  await openGuide(tab);
401
456
  return {
402
457
  ...(identity || normalizeIdentity({}, 'dom')),
403
458
  name: visibleName || identity?.name || null,
404
- mock: exitCount === 1,
459
+ mock: mocked,
405
460
  };
406
461
  }
407
462
 
@@ -464,10 +519,15 @@ function isTransientLocatorError(error) {
464
519
  return /timed out|selector deadline exceeded/i.test(message);
465
520
  }
466
521
 
522
+ function isMockActionRevealRequired(error) {
523
+ const message = error instanceof Error ? error.message : String(error);
524
+ return /identity_action_(?:label_not_found|not_visible)/.test(message);
525
+ }
526
+
467
527
  async function inspectExactTargetAction(tab, request, labels, timeoutMs) {
468
528
  const targetUserId = String(request.target_user_id);
469
529
  const targetUserName = String(request.target_user_name).trim();
470
- return tab.playwright.evaluate(async ({ id, name, buttonLabel, waitMs, stableMs }) => {
530
+ return tab.playwright.evaluate(async ({ id, name, buttonLabels, waitMs, stableMs }) => {
471
531
  const inspect = () => {
472
532
  const input = document.querySelector('.button-line > .el-input input');
473
533
  const rows = Array.from(document.querySelectorAll('tbody tr')).filter((row) => (
@@ -483,9 +543,10 @@ async function inspectExactTargetAction(tab, request, labels, timeoutMs) {
483
543
  const nameNodes = Array.from(row.querySelectorAll('.user-name-text'));
484
544
  const actualName = nameNodes.length === 1 ? String(nameNodes[0].textContent || '').trim() : null;
485
545
  const buttons = Array.from(row.querySelectorAll('button')).filter(
486
- (button) => String(button.textContent || '').trim() === buttonLabel,
546
+ (button) => buttonLabels.includes(String(button.textContent || '').trim()),
487
547
  );
488
548
  const button = buttons.length === 1 ? buttons[0] : null;
549
+ const actionLabel = button ? String(button.textContent || '').trim() : null;
489
550
  const buttonVisible = Boolean(button && button.getClientRects().length > 0);
490
551
  const buttonEnabled = Boolean(button && !button.disabled && button.getAttribute('aria-disabled') !== 'true');
491
552
  const ready = String(input?.value || '') === name
@@ -500,11 +561,20 @@ async function inspectExactTargetAction(tab, request, labels, timeoutMs) {
500
561
  ? 'ready'
501
562
  : actualName && actualName !== name
502
563
  ? 'name_mismatch'
564
+ : buttons.length === 0
565
+ ? 'action_label_missing'
566
+ : buttons.length > 1
567
+ ? 'action_label_ambiguous'
568
+ : !buttonVisible
569
+ ? 'action_not_visible'
570
+ : !buttonEnabled
571
+ ? 'action_disabled'
503
572
  : 'candidate',
504
573
  row_count: rows.length,
505
574
  id_count: idCount,
506
575
  name_count: nameNodes.length,
507
576
  actual_name: actualName,
577
+ action_label: actionLabel,
508
578
  button_count: buttons.length,
509
579
  input_value: String(input?.value || ''),
510
580
  };
@@ -526,11 +596,14 @@ async function inspectExactTargetAction(tab, request, labels, timeoutMs) {
526
596
  else if (sawCandidate) return { ...state, status: 'overwritten' };
527
597
  await new Promise((resolve) => setTimeout(resolve, 250));
528
598
  }
529
- return { ...inspect(), status: 'timeout' };
599
+ const finalState = inspect();
600
+ return ['action_label_missing', 'action_label_ambiguous', 'action_not_visible', 'action_disabled'].includes(finalState.status)
601
+ ? finalState
602
+ : { ...finalState, status: 'timeout' };
530
603
  }, {
531
604
  id: targetUserId,
532
605
  name: targetUserName,
533
- buttonLabel: labels.simulation,
606
+ buttonLabels: labels.simulation,
534
607
  waitMs: timeoutMs,
535
608
  stableMs: 750,
536
609
  }, { timeoutMs: timeoutMs + 5_000 });
@@ -540,6 +613,10 @@ async function resolveExactTargetAction(tab, request, labels, timeoutMs) {
540
613
  const state = await inspectExactTargetAction(tab, request, labels, timeoutMs);
541
614
  if (state.status === 'ambiguous') throw new Error(`identity_exact_user_row_count_${state.row_count}`);
542
615
  if (state.status === 'name_mismatch') throw new Error('identity_target_name_changed');
616
+ if (state.status === 'action_label_missing') throw new Error('identity_action_label_not_found');
617
+ if (state.status === 'action_label_ambiguous') throw new Error(`identity_action_label_ambiguous_${state.button_count}`);
618
+ if (state.status === 'action_not_visible') throw new Error('identity_action_not_visible');
619
+ if (state.status === 'action_disabled') throw new Error('identity_action_disabled');
543
620
  if (state.status !== 'ready') return { state, resolved: null };
544
621
 
545
622
  const targetUserId = String(request.target_user_id);
@@ -555,7 +632,7 @@ async function resolveExactTargetAction(tab, request, labels, timeoutMs) {
555
632
  || await row.locator('.user-name-text', {}).count() !== 1) {
556
633
  return { state: { ...state, status: 'overwritten' }, resolved: null };
557
634
  }
558
- const simulation = row.getByRole('button', { name: labels.simulation, exact: true });
635
+ const simulation = row.getByRole('button', { name: state.action_label, exact: true });
559
636
  const simulationCount = await simulation.count();
560
637
  if (simulationCount !== 1) throw new Error(`identity_exact_simulation_button_count_${simulationCount}`);
561
638
 
@@ -577,12 +654,14 @@ async function waitForExactTargetAction(tab, search, request, labels, actions) {
577
654
  return existing.resolved;
578
655
  }
579
656
  } catch (error) {
580
- if (!isTransientLocatorError(error)) throw error;
657
+ if (!isTransientLocatorError(error) && !isMockActionRevealRequired(error)) throw error;
658
+ if (isMockActionRevealRequired(error)) actions.push('reveal hidden simulation action');
581
659
  }
582
660
  for (let attempt = 1; attempt <= TARGET_SEARCH_ATTEMPTS; attempt += 1) {
583
661
  if (attempt === 1) {
584
662
  await search.fill(REVEAL_MOCK_ACTION, {});
585
- await tab.playwright.waitForTimeout(100);
663
+ // userManagement reveals the mock column from a 500 ms debounced watcher.
664
+ await tab.playwright.waitForTimeout(750);
586
665
  } else {
587
666
  await search.fill('', {});
588
667
  await tab.playwright.waitForTimeout(100);
@@ -658,8 +737,8 @@ async function clickUnmock(tab, request, labels, actions, onMutationAttempt = as
658
737
  guide.locator('.guide-footer .action-item.log-out', {}),
659
738
  'identity_exit_simulation',
660
739
  );
661
- if ((await exit.innerText({})).trim() !== labels.exitSimulation) {
662
- throw new Error('identity_exit_simulation_label_mismatch');
740
+ if (!labels.exitSimulation.includes((await exit.innerText({})).trim())) {
741
+ throw new Error('identity_action_label_not_found');
663
742
  }
664
743
  await onMutationAttempt();
665
744
  await tab.playwright.expectNavigation(