bpmax-cli 0.2.1-beta.63 → 0.2.1-beta.66
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 +222 -25
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -501,7 +501,7 @@ function pluginAgentCapabilityForRequest(method, normalizedPath) {
|
|
|
501
501
|
// package.json
|
|
502
502
|
var package_default = {
|
|
503
503
|
name: "bpmax-cli",
|
|
504
|
-
version: "0.2.1-beta.
|
|
504
|
+
version: "0.2.1-beta.66",
|
|
505
505
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
506
506
|
type: "module",
|
|
507
507
|
bin: {
|
|
@@ -8665,6 +8665,9 @@ function lintConsoleTemplateModule(module, index, errors, warnings) {
|
|
|
8665
8665
|
if (name === "\u56FE\u8868" && configScript.includes("ctx.config") && !consoleTemplateHasCtxConfigFallback(configScript)) {
|
|
8666
8666
|
errors.push(`${moduleLabel} config \u811A\u672C\u5F15\u7528 ctx.config \u65F6\u5FC5\u987B\u63D0\u4F9B\u7A7A\u5BF9\u8C61 fallback\u3002`);
|
|
8667
8667
|
}
|
|
8668
|
+
if (name === "\u56FE\u8868" && /^(?:const|let|var)\b/.test(configScript.trim()) && !/\n/.test(configScript)) {
|
|
8669
|
+
errors.push(`${moduleLabel} config \u811A\u672C\u4E0D\u80FD\u4F7F\u7528\u5355\u884C const/let/var \u8BED\u53E5\uFF1B\u8BF7\u6539\u4E3A\u591A\u884C\u51FD\u6570\u4F53\u6216 return \u8868\u8FBE\u5F0F\u4EE5\u517C\u5BB9\u8FD0\u884C\u65F6\u89E3\u6790\u5668\u3002`);
|
|
8670
|
+
}
|
|
8668
8671
|
if (name === "\u4E00\u822C\u8868\u683C") {
|
|
8669
8672
|
if (/\$\{\s*(page_size|offset)\s*\}/.test(configScript)) {
|
|
8670
8673
|
errors.push(`${moduleLabel} config \u811A\u672C\u4E0D\u80FD\u5305\u542B\u524D\u7AEF\u5206\u9875\u5360\u4F4D\u7B26 \${page_size}/\${offset}\uFF1B\u8BF7\u4F7F\u7528 typed \u53C2\u6570\u6216 ctx.pageInfo\u3002`);
|
|
@@ -21129,6 +21132,17 @@ function validateBrowserAutomationDocument(value, options = {}) {
|
|
|
21129
21132
|
}
|
|
21130
21133
|
actions.forEach((action, index) => issues.push(...actionIssues(action, stepKey, index, false)));
|
|
21131
21134
|
checks.forEach((action, index) => issues.push(...actionIssues(action, stepKey, index, true)));
|
|
21135
|
+
const localContextNames = new Set(actions.flatMap((action) => isRecord8(action) && action.type === "context.extract" && stringValue2(action.name) ? [stringValue2(action.name)] : []));
|
|
21136
|
+
const contextReferences = JSON.stringify({ actions, checks }).matchAll(/\{\{context\.([A-Za-z0-9_-]+)\}\}/g);
|
|
21137
|
+
for (const match of contextReferences) {
|
|
21138
|
+
if (!localContextNames.has(match[1])) {
|
|
21139
|
+
issues.push({
|
|
21140
|
+
rule_id: "test_suite.automation.context_cross_step",
|
|
21141
|
+
step_key: stepKey,
|
|
21142
|
+
message: `${stepKey} references context.${match[1]} without extracting it in the same reconstructable step`
|
|
21143
|
+
});
|
|
21144
|
+
}
|
|
21145
|
+
}
|
|
21132
21146
|
const formContractValidation = formContractIssues(
|
|
21133
21147
|
rawStep,
|
|
21134
21148
|
stepKey,
|
|
@@ -21206,6 +21220,14 @@ function validateBrowserAutomationDocument(value, options = {}) {
|
|
|
21206
21220
|
message: `${stepKey} resolution_checks.${outcome} requires wait.route, page.assert_step, or list.assert_record; visibility-only checks cannot resolve an uncertain write`
|
|
21207
21221
|
});
|
|
21208
21222
|
}
|
|
21223
|
+
const committedTypes = outcomeChecks.map((check) => isRecord8(check) ? stringValue2(check.type) : "");
|
|
21224
|
+
if (outcome === "committed" && committedTypes.length > 1 && committedTypes.includes("navigation.open") && committedTypes.includes("wait.route") && committedTypes.every((type) => ["navigation.open", "wait.route"].includes(type))) {
|
|
21225
|
+
issues.push({
|
|
21226
|
+
rule_id: "test_suite.automation.mutation_resolution_committed_weak",
|
|
21227
|
+
step_key: stepKey,
|
|
21228
|
+
message: `${stepKey} resolution_checks.committed must include a business-state readback (page.assert_step, list.assert_record, or equivalent); navigation.open/wait.route alone cannot prove the mutation committed`
|
|
21229
|
+
});
|
|
21230
|
+
}
|
|
21209
21231
|
}
|
|
21210
21232
|
if (normalizedResolutionBranches.committed && normalizedResolutionBranches.committed === normalizedResolutionBranches.not_committed) {
|
|
21211
21233
|
issues.push({
|
|
@@ -21233,6 +21255,30 @@ function validateBrowserAutomationDocument(value, options = {}) {
|
|
|
21233
21255
|
}
|
|
21234
21256
|
}
|
|
21235
21257
|
}
|
|
21258
|
+
const extractedByName = /* @__PURE__ */ new Map();
|
|
21259
|
+
for (const [stepKey, rawStep] of Object.entries(value.steps)) {
|
|
21260
|
+
if (!isRecord8(rawStep)) continue;
|
|
21261
|
+
for (const action of Array.isArray(rawStep.actions) ? rawStep.actions : []) {
|
|
21262
|
+
if (!isRecord8(action) || action.type !== "context.extract") continue;
|
|
21263
|
+
const name = stringValue2(action.name);
|
|
21264
|
+
if (!name) continue;
|
|
21265
|
+
const owners = extractedByName.get(name) ?? /* @__PURE__ */ new Set();
|
|
21266
|
+
owners.add(stepKey);
|
|
21267
|
+
extractedByName.set(name, owners);
|
|
21268
|
+
}
|
|
21269
|
+
}
|
|
21270
|
+
for (const [stepKey, rawStep] of Object.entries(value.steps)) {
|
|
21271
|
+
for (const match of JSON.stringify(rawStep).matchAll(/\{\{data\.([A-Za-z0-9_-]+)\}\}/g)) {
|
|
21272
|
+
const owners = extractedByName.get(match[1]);
|
|
21273
|
+
if (owners && !owners.has(stepKey)) {
|
|
21274
|
+
issues.push({
|
|
21275
|
+
rule_id: "test_suite.automation.context_cross_step",
|
|
21276
|
+
step_key: stepKey,
|
|
21277
|
+
message: `${stepKey} references data.${match[1]}, but that name is produced only by context.extract in another step; step context is not persistent`
|
|
21278
|
+
});
|
|
21279
|
+
}
|
|
21280
|
+
}
|
|
21281
|
+
}
|
|
21236
21282
|
return { document: value, issues, warnings };
|
|
21237
21283
|
}
|
|
21238
21284
|
function validateBrowserAutomationCompileMetadataDetailed(document2) {
|
|
@@ -24479,7 +24525,7 @@ async function applyReviewedAutomationRepairUnlocked(options) {
|
|
|
24479
24525
|
const [caseId, caseStepId] = currentKey.split("/");
|
|
24480
24526
|
const attemptedStepSha256 = browserAutomationStepSha256(currentStep);
|
|
24481
24527
|
const mutationGuardCheckpoint = mutationGuard ? await realpath6(mutationGuard.checkpoint).catch(() => path17.resolve(mutationGuard.checkpoint)) : "";
|
|
24482
|
-
if (!mutationGuard || mutationGuard.state !== "attempted_unconfirmed" || mutationGuardCheckpoint !== checkpointPath || mutationGuard.case_id !== caseId || mutationGuard.case_step_id !== caseStepId || mutationGuard.automation_step_sha256 !== attemptedStepSha256 || mutationGuard.automation_step_sha256 !== String(pause2.failed_step_hash || "") || mutationGuard.checkpoint_revision !== Number(
|
|
24528
|
+
if (!mutationGuard || mutationGuard.state !== "attempted_unconfirmed" || mutationGuardCheckpoint !== checkpointPath || mutationGuard.case_id !== caseId || mutationGuard.case_step_id !== caseStepId || mutationGuard.automation_step_sha256 !== attemptedStepSha256 || mutationGuard.automation_step_sha256 !== String(pause2.failed_step_hash || "") || mutationGuard.checkpoint_revision !== Number(pause2.checkpoint_revision) || mutationGuard.mutation_attempt_id !== String(pause2.mutation_attempt_id || "")) {
|
|
24483
24529
|
fail("paused_write_state_unknown resolution repair is not bound to the active mutation attempt", {
|
|
24484
24530
|
rule_id: "test_suite.automation.resolution_repair_guard_mismatch",
|
|
24485
24531
|
path: checkpointPath
|
|
@@ -26524,7 +26570,7 @@ async function acquireActiveRunLease(options) {
|
|
|
26524
26570
|
}
|
|
26525
26571
|
if (existing.manifest && await exists3(existing.manifest)) {
|
|
26526
26572
|
const manifest = await readExecutionManifest(existing.manifest);
|
|
26527
|
-
if (manifest.mutation_attempt_guard) {
|
|
26573
|
+
if (manifest.mutation_attempt_guard && !manifest.abandoned_mutation) {
|
|
26528
26574
|
fail(`previous run ${manifest.run_id} still has an unresolved mutation attempt; starting another run could replay the same business write`, {
|
|
26529
26575
|
rule_id: "test_suite.run.mutation_resolution_required",
|
|
26530
26576
|
path: existing.manifest,
|
|
@@ -26588,7 +26634,7 @@ async function assertNoUnresolvedMutationInReportRoot(reportRoot, scenarioId, ca
|
|
|
26588
26634
|
}
|
|
26589
26635
|
if (candidate.scenario_id !== scenarioId || candidate.profile !== profile || !manifestSelectedCaseIds(candidate).some((caseId) => caseIds.includes(caseId))) continue;
|
|
26590
26636
|
const manifest = await readExecutionManifest(manifestPath);
|
|
26591
|
-
if (manifest.scenario_id !== scenarioId || manifest.profile !== profile || !manifest.mutation_attempt_guard || !caseIds.includes(manifest.mutation_attempt_guard.case_id)) continue;
|
|
26637
|
+
if (manifest.scenario_id !== scenarioId || manifest.profile !== profile || !manifest.mutation_attempt_guard || Boolean(manifest.abandoned_mutation) || !caseIds.includes(manifest.mutation_attempt_guard.case_id)) continue;
|
|
26592
26638
|
fail(`previous run ${manifest.run_id} still has an unresolved mutation attempt; starting another run could replay the same business write`, {
|
|
26593
26639
|
rule_id: "test_suite.run.mutation_resolution_required",
|
|
26594
26640
|
path: manifestPath,
|
|
@@ -27339,6 +27385,84 @@ async function testSuiteRunStatus(manifestPath, profile) {
|
|
|
27339
27385
|
const warnings = await executionManifestSkillWarnings(manifest);
|
|
27340
27386
|
return { ok: true, execution: manifest, ...warnings.length > 0 ? { warnings } : {} };
|
|
27341
27387
|
}
|
|
27388
|
+
async function abandonTestSuiteRun(options) {
|
|
27389
|
+
return withExecutionManifestLock(options.manifest, async () => {
|
|
27390
|
+
const manifestPath = path17.resolve(options.manifest);
|
|
27391
|
+
const manifest = await readExecutionManifest(manifestPath, true);
|
|
27392
|
+
const reason = String(options.reason || "").trim();
|
|
27393
|
+
if (!reason) fail("abandon requires a non-empty reason", { rule_id: "test_suite.run.abandon_reason_required", path: manifestPath });
|
|
27394
|
+
if (manifest.result !== "running") {
|
|
27395
|
+
fail("only a running manifest can be abandoned", {
|
|
27396
|
+
rule_id: "test_suite.run.abandon_not_allowed",
|
|
27397
|
+
path: manifestPath
|
|
27398
|
+
});
|
|
27399
|
+
}
|
|
27400
|
+
const expectedConfirm = `abandon e2e run ${manifest.run_id}`;
|
|
27401
|
+
if (options.confirm !== expectedConfirm) {
|
|
27402
|
+
fail(`abandon requires exact --confirm "${expectedConfirm}"`, {
|
|
27403
|
+
rule_id: "test_suite.run.abandon_confirmation_required",
|
|
27404
|
+
path: manifestPath,
|
|
27405
|
+
suggestion: `Re-run with --confirm "${expectedConfirm}" after reviewing the run and reason.`
|
|
27406
|
+
});
|
|
27407
|
+
}
|
|
27408
|
+
const operator = String(options.operator || process.env.USER || "unknown").trim() || "unknown";
|
|
27409
|
+
const abandonedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
27410
|
+
const receipt = path17.join(path17.dirname(manifestPath), "abandonment-receipt.json");
|
|
27411
|
+
const guard = manifest.mutation_attempt_guard;
|
|
27412
|
+
const receiptValue = {
|
|
27413
|
+
schema_version: 1,
|
|
27414
|
+
kind: "bpmax_e2e_run_abandonment_receipt",
|
|
27415
|
+
run_id: manifest.run_id,
|
|
27416
|
+
scenario_id: manifest.scenario_id,
|
|
27417
|
+
case_id: guard?.case_id ?? manifest.current_case_id ?? null,
|
|
27418
|
+
case_step_id: guard?.case_step_id ?? manifest.current_step_id ?? null,
|
|
27419
|
+
mutation_attempt_id: guard?.mutation_attempt_id ?? null,
|
|
27420
|
+
mutation_state: guard ? "abandoned_unknown" : "not_attempted",
|
|
27421
|
+
reason,
|
|
27422
|
+
operator,
|
|
27423
|
+
original_mutation_guard: guard,
|
|
27424
|
+
abandoned_at: abandonedAt
|
|
27425
|
+
};
|
|
27426
|
+
const receiptText = `${JSON.stringify(receiptValue, null, 2)}
|
|
27427
|
+
`;
|
|
27428
|
+
await writeAtomicText(receipt, receiptText);
|
|
27429
|
+
const receiptSha256 = createHash11("sha256").update(receiptText).digest("hex");
|
|
27430
|
+
manifest.abandoned_mutation = {
|
|
27431
|
+
state: guard ? "abandoned_unknown" : "not_attempted",
|
|
27432
|
+
reason,
|
|
27433
|
+
operator,
|
|
27434
|
+
receipt,
|
|
27435
|
+
receipt_sha256: receiptSha256,
|
|
27436
|
+
...guard?.mutation_attempt_id ? { mutation_attempt_id: guard.mutation_attempt_id } : {},
|
|
27437
|
+
abandoned_at: abandonedAt
|
|
27438
|
+
};
|
|
27439
|
+
manifest.mutation_attempt_guard = void 0;
|
|
27440
|
+
manifest.result = "blocked";
|
|
27441
|
+
manifest.current_case_id = void 0;
|
|
27442
|
+
manifest.current_step_id = null;
|
|
27443
|
+
manifest.finished_at = abandonedAt;
|
|
27444
|
+
await writeExecutionManifest(manifestPath, manifest, true);
|
|
27445
|
+
const released = manifest.active_run_lease ? await releaseActiveRunLease(manifest.active_run_lease) : false;
|
|
27446
|
+
let reportSync;
|
|
27447
|
+
try {
|
|
27448
|
+
reportSync = await syncTestSuiteRunReportUnlocked(manifestPath);
|
|
27449
|
+
} catch (error) {
|
|
27450
|
+
reportSync = { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
27451
|
+
}
|
|
27452
|
+
return {
|
|
27453
|
+
ok: true,
|
|
27454
|
+
status: "abandoned",
|
|
27455
|
+
mutation_state: guard ? "abandoned_unknown" : "not_attempted",
|
|
27456
|
+
manifest: manifestPath,
|
|
27457
|
+
receipt,
|
|
27458
|
+
receipt_sha256: receiptSha256,
|
|
27459
|
+
active_run_lease_released: released,
|
|
27460
|
+
report_sync: reportSync,
|
|
27461
|
+
execution: manifest,
|
|
27462
|
+
next_action: "Start a fresh full_rerun run. The abandoned run remains blocked and its mutation outcome must not be interpreted as not committed."
|
|
27463
|
+
};
|
|
27464
|
+
});
|
|
27465
|
+
}
|
|
27342
27466
|
async function indexSuite(root = DEFAULT_SUITE_ROOT, includeInactive = false, options = {}) {
|
|
27343
27467
|
const items = await lintSuite(root, options);
|
|
27344
27468
|
return includeInactive ? items : items.filter((item) => item.status === "active");
|
|
@@ -28572,7 +28696,11 @@ async function lintReport(root = DEFAULT_REPORT_ROOT, options = {}) {
|
|
|
28572
28696
|
const missingExecuted = plannedCases.filter((caseId) => !executedCases.includes(caseId));
|
|
28573
28697
|
const unexpectedExecuted = executedCases.filter((caseId) => !plannedCases.includes(caseId));
|
|
28574
28698
|
if (plannedCases.length > 0 && missingExecuted.length > 0) {
|
|
28575
|
-
|
|
28699
|
+
const notRunEvidence = reportKeyValue(text5, "not_run_cases:");
|
|
28700
|
+
const hasStructuredNotRun = missingExecuted.every((caseId) => new RegExp(`(?:^|,)\\s*${caseId.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\\\$&")}\\s*[:=]`).test(notRunEvidence));
|
|
28701
|
+
if (!hasStructuredNotRun) {
|
|
28702
|
+
errors.push(`[test_suite.report.case_reconciliation] ${reportPath}: planned_cases \u4E2D\u5B58\u5728\u672A\u6267\u884C\u7528\u4F8B: ${missingExecuted.join(", ")}\uFF1B\u62A5\u544A\u5FC5\u987B\u5199\u660E blocked/not run \u539F\u56E0\u5E76\u964D\u7EA7\u7ED3\u8BBA`);
|
|
28703
|
+
}
|
|
28576
28704
|
}
|
|
28577
28705
|
if (unexpectedExecuted.length > 0) {
|
|
28578
28706
|
errors.push(`[test_suite.report.case_reconciliation] ${reportPath}: executed_cases \u5305\u542B\u4E0D\u5728 planned_cases \u4E2D\u7684\u7528\u4F8B: ${unexpectedExecuted.join(", ")}`);
|
|
@@ -29260,10 +29388,6 @@ function browserStepHasMutation(step) {
|
|
|
29260
29388
|
function matchingMutationRequest(request, patterns) {
|
|
29261
29389
|
return ["POST", "PUT", "PATCH", "DELETE"].includes(request.method().toUpperCase()) && [...patterns].some((pattern) => request.url().includes(pattern));
|
|
29262
29390
|
}
|
|
29263
|
-
function matchingMutationRecord(value, urlPattern) {
|
|
29264
|
-
if (!isRecord11(value)) return false;
|
|
29265
|
-
return ["POST", "PUT", "PATCH", "DELETE"].includes(String(value.method || "").toUpperCase()) && String(value.url || "").includes(urlPattern);
|
|
29266
|
-
}
|
|
29267
29391
|
async function waitForMutationNetworkClosure(options) {
|
|
29268
29392
|
const timeoutMs = options.timeoutMs ?? 1e4;
|
|
29269
29393
|
const quietWindowMs = 1e3;
|
|
@@ -29831,6 +29955,7 @@ async function selectBrowserUser(page, target, userName, expectedUserId, timeout
|
|
|
29831
29955
|
}
|
|
29832
29956
|
if (expectedUserId) {
|
|
29833
29957
|
const candidateRows = picker.locator(".checkbox-item-list").filter({ hasText: userName });
|
|
29958
|
+
await firstVisibleLocator(candidateRows, timeout);
|
|
29834
29959
|
const exactCandidates = [];
|
|
29835
29960
|
const candidateCount = await candidateRows.count();
|
|
29836
29961
|
for (let index = 0; index < candidateCount; index += 1) {
|
|
@@ -29963,6 +30088,11 @@ async function tableLocator(page, table) {
|
|
|
29963
30088
|
const direct = page.locator(`[data-table-key="${escaped}"], [table-key="${escaped}"], [data-key="${escaped}"]`);
|
|
29964
30089
|
if (await direct.count()) return direct.first();
|
|
29965
30090
|
const heading = page.getByText(table, { exact: false }).first();
|
|
30091
|
+
const formItem = heading.locator('xpath=ancestor::*[contains(concat(" ", normalize-space(@class), " "), " el-form-item ")][1]');
|
|
30092
|
+
if (await formItem.count()) {
|
|
30093
|
+
const elTable = formItem.locator(".el-table").first();
|
|
30094
|
+
if (await elTable.count()) return elTable;
|
|
30095
|
+
}
|
|
29966
30096
|
return heading.locator('xpath=ancestor::*[contains(@class,"table") or contains(@class,"sub-form")][1]');
|
|
29967
30097
|
}
|
|
29968
30098
|
async function assertFingerprint(page, fingerprint, variables) {
|
|
@@ -30309,7 +30439,7 @@ async function executeAction(page, action, variables, runtime) {
|
|
|
30309
30439
|
}
|
|
30310
30440
|
case "detail.assert_rows": {
|
|
30311
30441
|
const table = await tableLocator(page, String(next.table));
|
|
30312
|
-
const count = await table.locator(".el-table__body tr, tbody tr").count();
|
|
30442
|
+
const count = await table.locator(".el-table__body-wrapper tbody tr, .el-table__body tr, tbody tr").count();
|
|
30313
30443
|
const passed = count === Number(next.count);
|
|
30314
30444
|
if (!passed) throw new Error(`detail row count mismatch: expected ${next.count}, got ${count}`);
|
|
30315
30445
|
return { assertion: { type: next.type, passed, table: next.table, count } };
|
|
@@ -30706,15 +30836,27 @@ async function contextHasAuthenticatedIdentity(context2, profileOrigin) {
|
|
|
30706
30836
|
failOnStatusCode: false,
|
|
30707
30837
|
timeout: 15e3
|
|
30708
30838
|
});
|
|
30709
|
-
if (
|
|
30710
|
-
|
|
30711
|
-
|
|
30712
|
-
|
|
30713
|
-
|
|
30714
|
-
|
|
30839
|
+
if (response.ok()) {
|
|
30840
|
+
const payload = await response.json();
|
|
30841
|
+
if (isRecord11(payload)) {
|
|
30842
|
+
const data = isRecord11(payload.data) ? payload.data : payload;
|
|
30843
|
+
const id = Number(data.id);
|
|
30844
|
+
if (Number.isSafeInteger(id) && id > 0 && data.role !== void 0 && data.role !== null) return true;
|
|
30845
|
+
}
|
|
30846
|
+
}
|
|
30715
30847
|
} catch {
|
|
30716
|
-
return false;
|
|
30717
30848
|
}
|
|
30849
|
+
for (const page of context2.pages()) {
|
|
30850
|
+
try {
|
|
30851
|
+
const url = new URL(page.url());
|
|
30852
|
+
if (url.origin !== new URL(profileOrigin).origin || /(?:^|\/)login(?:\/|$)/i.test(url.pathname)) continue;
|
|
30853
|
+
const authenticatedMarker = page.locator('[data-user-id], [data-testid*="logout" i], [aria-label*="\u9000\u51FA" i]').first();
|
|
30854
|
+
if (await authenticatedMarker.isVisible({ timeout: 500 }).catch(() => false)) return true;
|
|
30855
|
+
if (await page.getByText(/退出登录|登出|Logout/i).first().isVisible({ timeout: 500 }).catch(() => false)) return true;
|
|
30856
|
+
} catch {
|
|
30857
|
+
}
|
|
30858
|
+
}
|
|
30859
|
+
return false;
|
|
30718
30860
|
}
|
|
30719
30861
|
async function probeAuthenticatedContext(options) {
|
|
30720
30862
|
let profileOrigin;
|
|
@@ -31245,6 +31387,15 @@ async function runPlaywrightIdentityOperation(options) {
|
|
|
31245
31387
|
await page.screenshot({ path: screenshotPath, fullPage: false });
|
|
31246
31388
|
const assertions = options.operation === "mock" ? [{ name: "Playwright context switched to exact target user", passed: after.mock === true && Number(after.id) === Number(options.userId) }] : options.operation === "unmock" ? [{ name: "Playwright context restored original user", passed: after.mock === false }] : [{ name: "Playwright context current identity read back", passed: Number(after.id) > 0 }];
|
|
31247
31389
|
const evidence = path18.join(evidenceDir, `identity-playwright-${options.operation}.json`);
|
|
31390
|
+
const redactIdentity = (value) => ({
|
|
31391
|
+
id: Number.isSafeInteger(Number(value.id)) ? Number(value.id) : void 0,
|
|
31392
|
+
name: typeof value.name === "string" ? value.name : void 0,
|
|
31393
|
+
organization_id: Number.isSafeInteger(Number(value.organization_id)) ? Number(value.organization_id) : void 0,
|
|
31394
|
+
mock: value.mock === true,
|
|
31395
|
+
mock_by_user: Number.isSafeInteger(Number(value.mock_by_user)) ? Number(value.mock_by_user) : void 0,
|
|
31396
|
+
can_mock: value.can_mock === true,
|
|
31397
|
+
source: typeof value.source === "string" ? value.source : void 0
|
|
31398
|
+
});
|
|
31248
31399
|
await writeFile12(evidence, `${JSON.stringify({
|
|
31249
31400
|
schema_version: 2,
|
|
31250
31401
|
run_id: options.runId,
|
|
@@ -31262,10 +31413,10 @@ async function runPlaywrightIdentityOperation(options) {
|
|
|
31262
31413
|
remote_submitted: options.operation !== "status",
|
|
31263
31414
|
resolved_from_readback: resolvedFromReadback,
|
|
31264
31415
|
readback_confirmed: true,
|
|
31265
|
-
current_user: after,
|
|
31266
|
-
before,
|
|
31267
|
-
after,
|
|
31268
|
-
...target ? { target_user: target } : {},
|
|
31416
|
+
current_user: redactIdentity(after),
|
|
31417
|
+
before: redactIdentity(before),
|
|
31418
|
+
after: redactIdentity(after),
|
|
31419
|
+
...target ? { target_user: redactIdentity(target) } : {},
|
|
31269
31420
|
runtime_scope: "page",
|
|
31270
31421
|
runtime_environment: "profile",
|
|
31271
31422
|
runtime_url: page.url(),
|
|
@@ -32079,7 +32230,20 @@ function mutationResolutionNoRequestEvidenceMatches(options) {
|
|
|
32079
32230
|
if (!patterns.includes(options.urlPattern)) return false;
|
|
32080
32231
|
const requests = Array.isArray(evidence.mutation_requests) ? evidence.mutation_requests : [];
|
|
32081
32232
|
const responses = Array.isArray(evidence.network_responses) ? evidence.network_responses : [];
|
|
32082
|
-
|
|
32233
|
+
const matchesEndpoint = (value) => {
|
|
32234
|
+
if (!isRecord11(value) || !["POST", "PUT", "PATCH", "DELETE"].includes(String(value.method || "").toUpperCase())) return false;
|
|
32235
|
+
const raw = String(value.url || "");
|
|
32236
|
+
try {
|
|
32237
|
+
const actual = new URL(raw).pathname.replace(/\/+$/, "");
|
|
32238
|
+
const expected = new URL(options.urlPattern, raw).pathname.replace(/\/+$/, "");
|
|
32239
|
+
return actual === expected || actual.startsWith(`${expected}/`);
|
|
32240
|
+
} catch {
|
|
32241
|
+
const actual = raw.split(/[?#]/, 1)[0].replace(/\/+$/, "");
|
|
32242
|
+
const expected = options.urlPattern.split(/[?#]/, 1)[0].replace(/\/+$/, "");
|
|
32243
|
+
return actual === expected || actual.startsWith(`${expected}/`);
|
|
32244
|
+
}
|
|
32245
|
+
};
|
|
32246
|
+
return !requests.some(matchesEndpoint) && !responses.some(matchesEndpoint);
|
|
32083
32247
|
}
|
|
32084
32248
|
function mutationResolutionNoRequestFingerprintIsStrong(step) {
|
|
32085
32249
|
return Boolean(String(step.page_fingerprint.route || "").trim()) && Array.isArray(step.page_fingerprint.buttons) && step.page_fingerprint.buttons.some((value) => String(value || "").trim());
|
|
@@ -32645,7 +32809,8 @@ function externalActionForStep(manifest, step) {
|
|
|
32645
32809
|
const evidenceDir = path19.join(runDir, "evidence", `${caseId}-${stepId}`);
|
|
32646
32810
|
if (step.runner === "identity") {
|
|
32647
32811
|
const source = `${String(step.action || "")} ${String(step.input_data || "")}`;
|
|
32648
|
-
const
|
|
32812
|
+
const structuredOperation = isRecord12(step.input_data) ? String(step.input_data.operation || "").trim().toLowerCase() : "";
|
|
32813
|
+
const operation = ["mock", "unmock", "status"].includes(structuredOperation) ? structuredOperation : /unmock|恢复.*身份|还原.*身份/i.test(source) ? "unmock" : /status|当前.*身份|确认.*身份/i.test(source) ? "status" : "mock";
|
|
32649
32814
|
const userId = source.match(/(?:user_id|用户ID|用户 id)\s*[=::]\s*(\d+)/i)?.[1];
|
|
32650
32815
|
if (operation === "mock" && !userId) {
|
|
32651
32816
|
return {
|
|
@@ -32806,14 +32971,22 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
32806
32971
|
automation: automationFile,
|
|
32807
32972
|
allowAutomationChange: hasCheckpoint && options.resume
|
|
32808
32973
|
});
|
|
32809
|
-
const
|
|
32974
|
+
const runDir = path19.dirname(manifest);
|
|
32975
|
+
const snapshotCandidate = path19.join(runDir, "plan.snapshot.json");
|
|
32976
|
+
let planSnapshotFile = hasCheckpoint ? void 0 : snapshotCandidate;
|
|
32977
|
+
if (!hasCheckpoint) {
|
|
32978
|
+
await writeAtomicJson3(snapshotCandidate, JSON.parse(await readFile17(planFile, "utf8")));
|
|
32979
|
+
planSnapshotFile = snapshotCandidate;
|
|
32980
|
+
}
|
|
32981
|
+
const planSource = hasCheckpoint ? (await loadOperationState(checkpoint)).plan_snapshot_file || planFile : planSnapshotFile || planFile;
|
|
32982
|
+
const plan = await readJsonFile2(planSource);
|
|
32810
32983
|
const automation = await loadBrowserAutomation(automationFile);
|
|
32811
32984
|
const scenario = String(plan.scenario || automation.scenario || "");
|
|
32812
32985
|
if (!scenario) throw new Error("e2e.scenario.scenario_missing: scenario plan or automation.json must declare scenario");
|
|
32813
32986
|
if (automation.scenario && automation.scenario !== scenario) {
|
|
32814
32987
|
throw new Error(`e2e.scenario.automation_mismatch: automation scenario ${automation.scenario} does not match plan ${scenario}`);
|
|
32815
32988
|
}
|
|
32816
|
-
const planHash = await fileSha256(
|
|
32989
|
+
const planHash = await fileSha256(planSource);
|
|
32817
32990
|
const automationHash = await fileSha256(automationFile);
|
|
32818
32991
|
let runState = await dependencies.nextTestSuiteRunStep(manifest, options.profile);
|
|
32819
32992
|
let execution = executionRecord(runState);
|
|
@@ -32836,6 +33009,7 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
32836
33009
|
run_id: String(execution.run_id || path19.basename(path19.dirname(manifest))),
|
|
32837
33010
|
scenario,
|
|
32838
33011
|
plan_file: planFile,
|
|
33012
|
+
plan_snapshot_file: planSource,
|
|
32839
33013
|
plan_sha256: planHash,
|
|
32840
33014
|
automation_file: automationFile,
|
|
32841
33015
|
automation_sha256: automationHash,
|
|
@@ -33222,6 +33396,26 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
33222
33396
|
await saveOperationState(checkpoint, operation);
|
|
33223
33397
|
return pausedResult(operation, checkpoint);
|
|
33224
33398
|
}
|
|
33399
|
+
const actor = String(step.actor || "").trim();
|
|
33400
|
+
if (actor) {
|
|
33401
|
+
const actorIdentity = executionSteps(execution).find((item) => item.runner === "identity" && String(item.actor || "").trim() === actor && item.status === "pass");
|
|
33402
|
+
if (!actorIdentity) {
|
|
33403
|
+
operation.status = "paused_external_action";
|
|
33404
|
+
operation.pause = {
|
|
33405
|
+
kind: "identity_binding_required",
|
|
33406
|
+
message: `browser_action ${stepKey} declares actor=${actor} but no completed identity lease is bound to that actor.`,
|
|
33407
|
+
repair_scope: stepKey,
|
|
33408
|
+
script_change_required: false,
|
|
33409
|
+
external_action: {
|
|
33410
|
+
kind: "identity_binding_required",
|
|
33411
|
+
actor,
|
|
33412
|
+
instruction: "Complete the reviewed runner=identity mock step for this actor in the same Playwright run, then resume. Actor labels never impersonate a user."
|
|
33413
|
+
}
|
|
33414
|
+
};
|
|
33415
|
+
await saveOperationState(checkpoint, operation);
|
|
33416
|
+
return pausedResult(operation, checkpoint);
|
|
33417
|
+
}
|
|
33418
|
+
}
|
|
33225
33419
|
let result;
|
|
33226
33420
|
try {
|
|
33227
33421
|
result = await dependencies.runBrowserAutomation({
|
|
@@ -42204,6 +42398,9 @@ function registerTestSuiteCommands(program2) {
|
|
|
42204
42398
|
run.command("status").description("Show execution manifest status").requiredOption("--manifest <file>", "Execution manifest file").option("--profile <profile>", "Profile name; must match the execution manifest").option("--format <format>", "Output format", "json").action(async (options, command) => {
|
|
42205
42399
|
printResult(options.format, await testSuiteRunStatus(options.manifest, effectiveProfileOption(options, command)));
|
|
42206
42400
|
});
|
|
42401
|
+
run.command("abandon").description("Abandon a running E2E manifest with an unresolved mutation and release its active-run lease").requiredOption("--manifest <file>", "Execution manifest file").requiredOption("--reason <reason>", "Audited reason for abandoning the unresolved run").requiredOption("--confirm <confirmation>", "Exact confirmation: abandon e2e run <run_id>").option("--operator <name>", "Operator identity recorded in the abandonment receipt").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
42402
|
+
printResult(options.format, await abandonTestSuiteRun(options));
|
|
42403
|
+
});
|
|
42207
42404
|
review.command("repair").description("Repair missing schema fields in an existing draft review.json").requiredOption("--scenario <id>", "Scenario id").option("--draft-root <path>", "Draft suite root directory", DEFAULT_DRAFT_ROOT).requiredOption("--latest-proof <path>", "latest-* proof JSON written after syncing the sysconfig repo").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
42208
42405
|
printResult(options.format, await initOrRepairReview({ ...options, repair: true }));
|
|
42209
42406
|
});
|