bpmax-cli 0.2.1-beta.57 → 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
|
@@ -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
|
|
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
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
338
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
399
|
-
if (!identity?.id)
|
|
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:
|
|
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,
|
|
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()
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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()
|
|
662
|
-
throw new Error('
|
|
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(
|