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/dist/bin.js CHANGED
@@ -499,7 +499,7 @@ function pluginAgentCapabilityForRequest(method, normalizedPath) {
499
499
  // package.json
500
500
  var package_default = {
501
501
  name: "bpmax-cli",
502
- version: "0.2.1-beta.56",
502
+ version: "0.2.1-beta.58",
503
503
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
504
504
  type: "module",
505
505
  bin: {
@@ -6144,7 +6144,8 @@ function validateFlowTemplateStartConditionalJump(value, errors) {
6144
6144
  let lastJumpResult = "";
6145
6145
  if (Array.isArray(jumps)) {
6146
6146
  jumps.forEach((jump, index) => {
6147
- const pathName = `data.meta.condational_jump[${index}]`;
6147
+ const evidenceId = isRecord4(jump) && typeof jump.__bpmax_lint_evidence_id === "string" ? jump.__bpmax_lint_evidence_id : null;
6148
+ const pathName = evidenceId ? `data.meta.condational_jump[evidence=${evidenceId}]` : `data.meta.condational_jump[${index}]`;
6148
6149
  if (!isRecord4(jump)) {
6149
6150
  nextErrors.push(`${pathName} must be an object with name, result, condition_mode, and a boolean condition script.`);
6150
6151
  return;
@@ -9200,8 +9201,108 @@ function flowLiveExportPath(id) {
9200
9201
  function hasUsableFlowTemplateData(value) {
9201
9202
  return isRecord4(value) && isRecord4(value.data) && Object.keys(value.data).length > 0;
9202
9203
  }
9203
- function normalizeFlowTemplatePayload(work) {
9204
- validateFlowTemplateStandardFlowType(work);
9204
+ function validateFlowTemplateHardGates(work) {
9205
+ validateFlowTemplateRemoteTemplateRefs(work);
9206
+ validateFlowTemplateExpectedChildFlows(work);
9207
+ validateFlowTemplateStandardPageCreateFormTemplate(work);
9208
+ validateFlowTemplatePluginRejectionControl(work);
9209
+ validateFlowTemplateCodeModeMessages(work);
9210
+ validateFlowTemplateRuntimeScripts(work);
9211
+ validateFlowTemplateFeishuChatPlugin(work);
9212
+ }
9213
+ function collectFlowTemplateLintErrors(work) {
9214
+ const errors = [];
9215
+ validateFlowTemplateStandardFlowType(work, errors);
9216
+ validateFlowTemplateProjectNameTemplate(work, errors);
9217
+ validateFlowTemplateRemoteTemplateRefs(work, errors);
9218
+ validateFlowTemplateExpectedChildFlows(work, errors);
9219
+ validateFlowTemplateProjectAfterCreatePath(work, errors);
9220
+ validateFlowTemplateStandardPageCreateFormTemplate(work, errors);
9221
+ validateFlowTemplateStartConditionalJump(work, errors);
9222
+ validateFlowTemplatePostCreateInitiatorStep(work, errors);
9223
+ validateFlowTemplateApproveActionShape(work, errors);
9224
+ validateFlowTemplatePluginRejectionControl(work, errors);
9225
+ validateFlowTemplateStandardConditionEditorRules(work, errors);
9226
+ validateFlowTemplateCodeModeMessages(work, errors);
9227
+ validateFlowTemplateRuntimeScripts(work, errors);
9228
+ validateFlowTemplateFeishuChatPlugin(work, errors);
9229
+ return errors;
9230
+ }
9231
+ function flowTemplateLintEvidenceWork(work) {
9232
+ const data = isRecord4(work.data) ? work.data : {};
9233
+ const meta = isRecord4(data.meta) ? data.meta : {};
9234
+ const nodes = Array.isArray(data.nodes) ? data.nodes : [];
9235
+ const jumps = meta.condational_jump;
9236
+ return {
9237
+ ...work,
9238
+ data: {
9239
+ ...data,
9240
+ meta: {
9241
+ ...meta,
9242
+ ...Array.isArray(jumps) ? {
9243
+ condational_jump: jumps.map((jump) => isRecord4(jump) ? { ...jump, __bpmax_lint_evidence_id: hashJson(jump).slice(0, 16) } : jump)
9244
+ } : {}
9245
+ },
9246
+ nodes: nodes.map((node, index) => {
9247
+ if (!isRecord4(node)) return node;
9248
+ const id = String(node.id ?? "").trim();
9249
+ const name = typeof node.name === "string" && node.name.trim() ? node.name.trim() : `nodes[${index}]`;
9250
+ return { ...node, name: `${name} [bpmax-node:${id || `index-${index}`}]` };
9251
+ })
9252
+ }
9253
+ };
9254
+ }
9255
+ function collectFlowTemplateLintEvidence(work) {
9256
+ const errors = collectFlowTemplateLintErrors(work);
9257
+ const keys = collectFlowTemplateLintErrors(flowTemplateLintEvidenceWork(work));
9258
+ if (errors.length !== keys.length) {
9259
+ throw new Error("flow-template lint evidence generation was inconsistent; rebuild without a preexisting lint exemption.");
9260
+ }
9261
+ return { errors, keys };
9262
+ }
9263
+ function subtractUnchangedLintErrors(current, baseline) {
9264
+ const remaining = /* @__PURE__ */ new Map();
9265
+ for (const key of baseline.keys) remaining.set(key, (remaining.get(key) ?? 0) + 1);
9266
+ const fresh = [];
9267
+ const ignored = [];
9268
+ current.errors.forEach((error, index) => {
9269
+ const key = current.keys[index];
9270
+ const count = remaining.get(key) ?? 0;
9271
+ if (count > 0) {
9272
+ remaining.set(key, count - 1);
9273
+ ignored.push(error);
9274
+ } else {
9275
+ fresh.push(error);
9276
+ }
9277
+ });
9278
+ return { errors: fresh, ignored };
9279
+ }
9280
+ function evaluateFlowTemplateBaselineLint(work, raw) {
9281
+ validateFlowTemplateHardGates(work);
9282
+ return subtractUnchangedLintErrors(collectFlowTemplateLintEvidence(work), collectFlowTemplateLintEvidence(raw));
9283
+ }
9284
+ async function validateFlowTemplateSubmitLintExemption(submit) {
9285
+ const meta = isRecord4(submit.meta) ? submit.meta : {};
9286
+ const exemption = isRecord4(meta.preexisting_lint_exemption) ? meta.preexisting_lint_exemption : null;
9287
+ if (!exemption) return false;
9288
+ if (exemption.schema_version !== 1 || typeof submit.base_hash !== "string" || exemption.base_hash !== submit.base_hash || !Array.isArray(exemption.ignored_errors) || !exemption.ignored_errors.every((error) => typeof error === "string")) {
9289
+ throw new Error("flow-template preexisting lint exemption evidence is invalid; rebuild from a fresh export baseline.");
9290
+ }
9291
+ const raw = await readFlowTemplateBaselineFromMeta(meta);
9292
+ if (!raw || hashJson(raw) !== submit.base_hash) {
9293
+ throw new Error("flow-template preexisting lint exemption baseline is missing or stale; re-export and rebuild.");
9294
+ }
9295
+ const evaluated = evaluateFlowTemplateBaselineLint(submit.payload, raw);
9296
+ if (evaluated.errors.length) {
9297
+ throw new Error(`flow-template lint failed: ${evaluated.errors.join("; ")}`);
9298
+ }
9299
+ if (!isDeepStrictEqual(evaluated.ignored, exemption.ignored_errors)) {
9300
+ throw new Error("flow-template preexisting lint exemption evidence does not match the submit payload; rebuild before submitting.");
9301
+ }
9302
+ return true;
9303
+ }
9304
+ function normalizeFlowTemplatePayload(work, options = {}) {
9305
+ if (!options.prevalidatedFlowTemplateLint) validateFlowTemplateStandardFlowType(work);
9205
9306
  if (!isRecord4(work.data)) {
9206
9307
  throw new Error("flow-template work requires data object.");
9207
9308
  }
@@ -9214,19 +9315,16 @@ function normalizeFlowTemplatePayload(work) {
9214
9315
  meta.form_template = work.meta_form_id;
9215
9316
  }
9216
9317
  data.meta = meta;
9217
- validateFlowTemplateProjectNameTemplate({ ...work, data });
9218
- validateFlowTemplateRemoteTemplateRefs({ ...work, data });
9219
- validateFlowTemplateExpectedChildFlows({ ...work, data });
9220
- validateFlowTemplateProjectAfterCreatePath({ ...work, data });
9221
- validateFlowTemplateStandardPageCreateFormTemplate({ ...work, data });
9222
- validateFlowTemplateStartConditionalJump({ ...work, data });
9223
- validateFlowTemplatePostCreateInitiatorStep({ ...work, data });
9224
- validateFlowTemplateApproveActionShape({ ...work, data });
9225
- validateFlowTemplatePluginRejectionControl({ ...work, data });
9226
- validateFlowTemplateStandardConditionEditorRules({ ...work, data });
9227
- validateFlowTemplateCodeModeMessages({ ...work, data });
9228
- validateFlowTemplateRuntimeScripts({ ...work, data });
9229
- validateFlowTemplateFeishuChatPlugin({ ...work, data });
9318
+ if (!options.prevalidatedFlowTemplateLint) {
9319
+ const normalizedWork = { ...work, data };
9320
+ validateFlowTemplateProjectNameTemplate(normalizedWork);
9321
+ validateFlowTemplateHardGates(normalizedWork);
9322
+ validateFlowTemplateProjectAfterCreatePath(normalizedWork);
9323
+ validateFlowTemplateStartConditionalJump(normalizedWork);
9324
+ validateFlowTemplatePostCreateInitiatorStep(normalizedWork);
9325
+ validateFlowTemplateApproveActionShape(normalizedWork);
9326
+ validateFlowTemplateStandardConditionEditorRules(normalizedWork);
9327
+ }
9230
9328
  const payload = pickDefined(work, [
9231
9329
  "name",
9232
9330
  "flow_type",
@@ -12016,7 +12114,7 @@ function buildDomainSubmitPayload(domain, work, options = {}, raw) {
12016
12114
  return payload;
12017
12115
  }
12018
12116
  if (domain === "flow-template") {
12019
- const payload = normalizeFlowTemplatePayload(work);
12117
+ const payload = normalizeFlowTemplatePayload(work, options);
12020
12118
  if (work.mode === "create") {
12021
12119
  validateNonEmptyFlowCreatePayload(payload);
12022
12120
  }
@@ -14140,6 +14238,21 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
14140
14238
  throw new Error("Config build requires a meta file produced by `bpmax-cli config <domain> export`.");
14141
14239
  }
14142
14240
  const raw = typeof meta.raw_file === "string" ? await readJsonFile(meta.raw_file) : void 0;
14241
+ let ignoredPreexistingLintErrors = [];
14242
+ if (domain === "flow-template" && options.allowPreexistingLintErrors) {
14243
+ if (createMode) {
14244
+ throw new Error("--allow-preexisting-lint-errors requires an exported edit baseline and cannot be used for create mode.");
14245
+ }
14246
+ if (!isRecord4(raw) || hashJson(raw) !== meta.base_hash) {
14247
+ throw new Error("--allow-preexisting-lint-errors requires the exact raw export baseline matching meta.base_hash. Re-export before building.");
14248
+ }
14249
+ if (!isRecord4(work)) throw new Error("Config work file must be a JSON object.");
14250
+ const evaluated = evaluateFlowTemplateBaselineLint(work, raw);
14251
+ if (evaluated.errors.length) {
14252
+ throw new Error(`flow-template lint failed: ${evaluated.errors.join("; ")}`);
14253
+ }
14254
+ ignoredPreexistingLintErrors = evaluated.ignored;
14255
+ }
14143
14256
  let formTemplateWarnings = [];
14144
14257
  let flowDetailTemplateWarnings = [];
14145
14258
  let stepDetailReferenceAudit;
@@ -14228,7 +14341,10 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
14228
14341
  datasetValidation = datasetValidationArtifact(work, datasetMapping);
14229
14342
  }
14230
14343
  const payloadWork = (domain === "dataset" || domain === "dataset-field") && createMode && isRecord4(work) ? { ...work, mode: "create" } : work;
14231
- const payload = buildDomainSubmitPayload(domain, payloadWork, options, raw);
14344
+ const payload = buildDomainSubmitPayload(domain, payloadWork, {
14345
+ ...options,
14346
+ prevalidatedFlowTemplateLint: domain === "flow-template" && options.allowPreexistingLintErrors === true
14347
+ }, raw);
14232
14348
  if (domain === "flow-template" && options.publishLive) {
14233
14349
  payload.publish_live = true;
14234
14350
  }
@@ -14250,6 +14366,13 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
14250
14366
  if (createMode) {
14251
14367
  submitMeta.mode = "create";
14252
14368
  }
14369
+ if (domain === "flow-template" && options.allowPreexistingLintErrors) {
14370
+ submitMeta.preexisting_lint_exemption = {
14371
+ schema_version: 1,
14372
+ base_hash: meta.base_hash,
14373
+ ignored_errors: ignoredPreexistingLintErrors
14374
+ };
14375
+ }
14253
14376
  const result = {
14254
14377
  domain,
14255
14378
  built_at: (/* @__PURE__ */ new Date()).toISOString(),
@@ -14286,7 +14409,8 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
14286
14409
  flow_report_references: flowReportReferenceAudit.references,
14287
14410
  flow_report_warnings: flowReportReferenceAudit.warnings,
14288
14411
  runtime_proof_required: flowReportReferenceAudit.references.length > 0 || flowStepDetailRuntimeProofRequired(stepDetailReferenceAudit)
14289
- } : {}
14412
+ } : {},
14413
+ ...ignoredPreexistingLintErrors.length ? { ignored_preexisting_lint_errors: ignoredPreexistingLintErrors } : {}
14290
14414
  };
14291
14415
  await writeJsonFile(outFile, result);
14292
14416
  return {
@@ -14326,7 +14450,8 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
14326
14450
  flow_report_references: flowReportReferenceAudit.references,
14327
14451
  flow_report_warnings: flowReportReferenceAudit.warnings,
14328
14452
  runtime_proof_required: flowReportReferenceAudit.references.length > 0 || flowStepDetailRuntimeProofRequired(stepDetailReferenceAudit)
14329
- } : {}
14453
+ } : {},
14454
+ ...ignoredPreexistingLintErrors.length ? { ignored_preexisting_lint_errors: ignoredPreexistingLintErrors } : {}
14330
14455
  };
14331
14456
  }
14332
14457
  async function runFlowTemplatePluginLint(flowWork, options = {}) {
@@ -15066,19 +15191,22 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
15066
15191
  let flowReportReferenceAudit;
15067
15192
  let flowCategoryReferenceAudit;
15068
15193
  if (domain === "flow-template") {
15069
- validateFlowTemplateRemoteTemplateRefs(submit.payload);
15070
- validateFlowTemplateExpectedChildFlows(submit.payload);
15071
- validateFlowTemplateProjectAfterCreatePath(submit.payload);
15072
- validateFlowTemplateStandardPageCreateFormTemplate(submit.payload);
15073
- validateFlowTemplateStartConditionalJump(submit.payload);
15074
- validateFlowTemplateApproveActionShape(submit.payload);
15075
- validateFlowTemplatePluginRejectionControl(submit.payload);
15076
- validateFlowTemplateStandardConditionEditorRules(submit.payload);
15077
- validateFlowTemplateCodeModeMessages(submit.payload);
15078
- validateFlowTemplateRuntimeScripts(submit.payload);
15079
- validateFlowTemplateFeishuChatPlugin(submit.payload);
15080
- validateFlowTemplateProjectNameTemplate(submit.payload);
15081
- validateFlowTemplateStandardFlowType(submit.payload);
15194
+ const lintExemptionVerified = await validateFlowTemplateSubmitLintExemption(submit);
15195
+ if (!lintExemptionVerified) {
15196
+ validateFlowTemplateRemoteTemplateRefs(submit.payload);
15197
+ validateFlowTemplateExpectedChildFlows(submit.payload);
15198
+ validateFlowTemplateProjectAfterCreatePath(submit.payload);
15199
+ validateFlowTemplateStandardPageCreateFormTemplate(submit.payload);
15200
+ validateFlowTemplateStartConditionalJump(submit.payload);
15201
+ validateFlowTemplateApproveActionShape(submit.payload);
15202
+ validateFlowTemplatePluginRejectionControl(submit.payload);
15203
+ validateFlowTemplateStandardConditionEditorRules(submit.payload);
15204
+ validateFlowTemplateCodeModeMessages(submit.payload);
15205
+ validateFlowTemplateRuntimeScripts(submit.payload);
15206
+ validateFlowTemplateFeishuChatPlugin(submit.payload);
15207
+ validateFlowTemplateProjectNameTemplate(submit.payload);
15208
+ validateFlowTemplateStandardFlowType(submit.payload);
15209
+ }
15082
15210
  validateFlowTemplateIdentityStandard(id, submit.payload);
15083
15211
  const pluginLint = await runFlowTemplatePluginLint(submit.payload, {
15084
15212
  profile,
@@ -18446,7 +18574,11 @@ function registerConfigCommands(program2) {
18446
18574
  }
18447
18575
  printResult(options.format, result);
18448
18576
  });
18449
- domainCommand.command("build").description(`Build a submit payload for ${domain} when a verified domain adapter is available`).requiredOption("--work <file>", "Work JSON file").requiredOption("--out <file>", "Submit payload output file").option("--meta <file>", "Export meta JSON file").option("--all-records", "For aggregate domains, submit every record instead of only changed records").option("--publish-live", "For flow-template, build a live publish payload instead of draft save").option("--usage <usage>", "Filter-template usage: ordinary | console | dashboard").option("--profile <profile>", "Profile name for plugin lint discovery").option("--agent <agent>", "Agent adapter for installed plugin lint discovery", "codex").option("--format <format>", "Output format", "pretty").action(async (options) => {
18577
+ const buildCommand = domainCommand.command("build").description(`Build a submit payload for ${domain} when a verified domain adapter is available`).requiredOption("--work <file>", "Work JSON file").requiredOption("--out <file>", "Submit payload output file").option("--meta <file>", "Export meta JSON file").option("--all-records", "For aggregate domains, submit every record instead of only changed records").option("--publish-live", "For flow-template, build a live publish payload instead of draft save").option("--usage <usage>", "Filter-template usage: ordinary | console | dashboard").option("--profile <profile>", "Profile name for plugin lint discovery").option("--agent <agent>", "Agent adapter for installed plugin lint discovery", "codex").option("--format <format>", "Output format", "pretty");
18578
+ if (domain === "flow-template") {
18579
+ buildCommand.option("--allow-preexisting-lint-errors", "Allow unchanged non-hard lint errors already present in the verified raw export baseline");
18580
+ }
18581
+ buildCommand.action(async (options) => {
18450
18582
  if (options.usage && !["ordinary", "console", "dashboard"].includes(options.usage)) {
18451
18583
  throw new Error("--usage \u53EA\u5141\u8BB8 ordinary\u3001console \u6216 dashboard\u3002");
18452
18584
  }
@@ -18461,6 +18593,7 @@ function registerConfigCommands(program2) {
18461
18593
  const result = await buildConfigSubmitPayload(domain, options.work, options.out, options.meta, {
18462
18594
  allRecords: Boolean(options.allRecords),
18463
18595
  publishLive: Boolean(options.publishLive),
18596
+ allowPreexistingLintErrors: Boolean(options.allowPreexistingLintErrors),
18464
18597
  pluginLint,
18465
18598
  usage: options.usage
18466
18599
  });
@@ -22810,6 +22943,8 @@ async function prepareV2TestSuiteConfirmation(options) {
22810
22943
  digest: request.digest,
22811
22944
  confirmation_required: true,
22812
22945
  exact_confirmation_text_required: false,
22946
+ autonomous_accept_supported: true,
22947
+ acceptance_modes: ["explicit_user_confirmation", "explicit_test_request"],
22813
22948
  confirmation_summary: {
22814
22949
  scope: request.scope,
22815
22950
  scenario_ids: request.scenario_ids,
@@ -22831,25 +22966,46 @@ async function acceptV2TestSuiteConfirmation(options) {
22831
22966
  const base = { ...request };
22832
22967
  delete base.digest;
22833
22968
  if (request.version !== 1 || request.kind !== "bpmax_e2e_v2_confirmation_request" || request.state !== "pending" || request.digest !== v2ConfirmationDigest(base)) fail(`invalid V2 confirmation request: ${requestPath}`, { rule_id: "test_suite.v2_confirmation.request_invalid", path: requestPath });
22834
- if (options.confirmed !== true) {
22969
+ if (options.confirmed === true && options.autonomous === true) {
22970
+ fail("V2 confirmation acceptance must use either explicit confirmation or autonomous test-request authorization, not both", {
22971
+ rule_id: "test_suite.v2_confirmation.mode_conflict",
22972
+ path: requestPath
22973
+ });
22974
+ }
22975
+ if (options.autonomous === true && request.scope === "shared_scenario_replace") {
22976
+ fail("Replacing a shared V2 scenario cannot use autonomous test-request authorization", {
22977
+ rule_id: "test_suite.v2_confirmation.autonomous_shared_replace_forbidden",
22978
+ path: requestPath,
22979
+ suggestion: "Keep the isolated draft, or obtain explicit confirmation before replacing the shared scenario."
22980
+ });
22981
+ }
22982
+ if (options.confirmed !== true && options.autonomous !== true) {
22835
22983
  fail("V2 confirmation request has not been explicitly confirmed by the user", {
22836
22984
  rule_id: "test_suite.v2_confirmation.explicit_confirmation_required",
22837
22985
  path: requestPath,
22838
- suggestion: "After the user clearly confirms the displayed scenario, case scope, and operation, retry with --confirmed."
22986
+ suggestion: "Use --confirmed after a separate confirmation, or --autonomous when the current explicit test request already authorizes automatic execution of the displayed scope."
22839
22987
  });
22840
22988
  }
22989
+ const confirmationMode = options.autonomous === true ? "explicit_test_request" : "explicit_user_confirmation";
22841
22990
  const receipt = {
22842
22991
  ...request,
22843
22992
  kind: "bpmax_e2e_v2_confirmation_receipt",
22844
22993
  state: "accepted",
22845
- confirmation_mode: "explicit_user_confirmation",
22994
+ confirmation_mode: confirmationMode,
22846
22995
  request: requestPath,
22847
22996
  request_sha256: await sha256(requestPath),
22848
22997
  accepted_at: (/* @__PURE__ */ new Date()).toISOString()
22849
22998
  };
22850
22999
  const receiptPath = path15.resolve(options.receipt ?? path15.join(path15.dirname(requestPath), V2_CONFIRMATION_RECEIPT));
22851
23000
  await writeAtomicJson(receiptPath, receipt);
22852
- return { ok: true, receipt: receiptPath, digest: receipt.digest, scope: receipt.scope };
23001
+ return {
23002
+ ok: true,
23003
+ receipt: receiptPath,
23004
+ digest: receipt.digest,
23005
+ scope: receipt.scope,
23006
+ confirmation_mode: receipt.confirmation_mode,
23007
+ continue_without_second_confirmation: receipt.confirmation_mode === "explicit_test_request"
23008
+ };
22853
23009
  }
22854
23010
  async function validateV2Confirmation(options) {
22855
23011
  if (!options.required) return void 0;
@@ -22885,7 +23041,7 @@ async function validateV2Confirmation(options) {
22885
23041
  const expectedScopes = Array.isArray(options.scope) ? options.scope : [options.scope];
22886
23042
  const receiptScenarios = [...receipt.scenario_ids ?? []].sort();
22887
23043
  const receiptCases = normalizedCaseIds(receipt.selected_case_ids ?? []);
22888
- if (receipt.version !== 1 || receipt.kind !== "bpmax_e2e_v2_confirmation_receipt" || receipt.state !== "accepted" || !expectedScopes.includes(receipt.scope) || JSON.stringify(receiptScenarios) !== JSON.stringify(scenarioIds) || (options.validateCaseIds ?? true) && JSON.stringify(receiptCases) !== JSON.stringify(expectedCaseIds) || receipt.confirmation_mode !== "explicit_user_confirmation" || !receipt.accepted_at || Number.isNaN(Date.parse(receipt.accepted_at))) fail("V2 confirmation receipt does not match this scenario, selected cases, or operation scope", {
23044
+ if (receipt.version !== 1 || receipt.kind !== "bpmax_e2e_v2_confirmation_receipt" || receipt.state !== "accepted" || !expectedScopes.includes(receipt.scope) || JSON.stringify(receiptScenarios) !== JSON.stringify(scenarioIds) || (options.validateCaseIds ?? true) && JSON.stringify(receiptCases) !== JSON.stringify(expectedCaseIds) || !["explicit_user_confirmation", "explicit_test_request"].includes(receipt.confirmation_mode) || !receipt.accepted_at || Number.isNaN(Date.parse(receipt.accepted_at))) fail("V2 confirmation receipt does not match this scenario, selected cases, or operation scope", {
22889
23045
  rule_id: "test_suite.v2_confirmation.scope_mismatch",
22890
23046
  path: receiptPath
22891
23047
  });
@@ -29935,6 +30091,28 @@ function repairRequiresAutomationChange(result) {
29935
30091
  "assertion_failed"
29936
30092
  ].includes(String(result.failure_kind || ""));
29937
30093
  }
30094
+ function isBrowserAuthenticationErrorMessage(message) {
30095
+ return /e2e\.browser\.(?:interactive_login_timeout|login_bootstrap_required|auth_(?:cookie|import)_probe_failed|auth_context_missing)/i.test(message);
30096
+ }
30097
+ function isBrowserAuthenticationFailure(result) {
30098
+ return isBrowserAuthenticationErrorMessage(String(result.error || ""));
30099
+ }
30100
+ function interactiveLoginRecoveryAction() {
30101
+ return {
30102
+ kind: "playwright_authentication_recovery",
30103
+ user_action_required: true,
30104
+ instruction: "Complete or repair authentication for the run-scoped Playwright profile. A normal --resume will stay blocked and will not reopen Chrome.",
30105
+ next_command: `Re-run the same e2e scenario execute command with --resume --retry-interactive-login only when the user is ready to complete one visible login attempt.`
30106
+ };
30107
+ }
30108
+ function orphanedRunRecoveryAction() {
30109
+ return {
30110
+ kind: "playwright_orphaned_run_recovery",
30111
+ user_action_required: true,
30112
+ instruction: "The previous scenario process ended while its checkpoint was running. Confirm that no browser process remains and that no mutation was attempted.",
30113
+ next_command: "Re-run the same e2e scenario execute command with --resume --recover-orphaned-run only after the stale browser process is gone."
30114
+ };
30115
+ }
29938
30116
  function completedBrowserStepHashes(execution, automation) {
29939
30117
  const hashes = {};
29940
30118
  for (const step of executionSteps(execution)) {
@@ -30087,6 +30265,7 @@ async function saveOperationState(file, state) {
30087
30265
  await writeAtomicJson3(file, state);
30088
30266
  }
30089
30267
  function pausedResult(state, checkpoint) {
30268
+ const userActionRequired = state.status === "paused_external_action" && ["playwright_authentication_required", "orphaned_execution_recovery_required"].includes(state.pause?.kind || "");
30090
30269
  return {
30091
30270
  ok: false,
30092
30271
  status: state.status,
@@ -30096,7 +30275,8 @@ function pausedResult(state, checkpoint) {
30096
30275
  current_step: state.current_step,
30097
30276
  current_action_index: state.current_action_index,
30098
30277
  mutation_state: state.mutation_state,
30099
- resume_allowed: state.status !== "paused_write_state_unknown",
30278
+ resume_allowed: state.status !== "paused_write_state_unknown" && !userActionRequired,
30279
+ ...userActionRequired ? { user_action_required: true } : {},
30100
30280
  llm_intervention_required: state.status === "paused_repairable",
30101
30281
  ...state.pause ? { pause: state.pause } : {}
30102
30282
  };
@@ -30189,6 +30369,21 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
30189
30369
  if (operation.manifest !== manifest || operation.scenario !== scenario || operation.plan_file !== planFile || operation.automation_file !== automationFile) {
30190
30370
  throw new Error("e2e.scenario.checkpoint_binding_mismatch: checkpoint is bound to a different manifest, scenario, plan, or automation file");
30191
30371
  }
30372
+ if (hasCheckpoint && options.resume && operation.status === "running" && options.recoverOrphanedRun !== true) {
30373
+ if (operation.mutation_state !== "not_attempted") {
30374
+ throw new Error("e2e.scenario.orphaned_mutation_state_unknown: a crashed running checkpoint may have attempted a mutation; resolve current-run write state before recovery");
30375
+ }
30376
+ operation.status = "paused_external_action";
30377
+ operation.pause = {
30378
+ kind: "orphaned_execution_recovery_required",
30379
+ message: "The previous scenario process ended while the checkpoint was running. Automatic resume is blocked to prevent repeated browser launches.",
30380
+ ...operation.current_step ? { repair_scope: operation.current_step } : {},
30381
+ script_change_required: false,
30382
+ external_action: orphanedRunRecoveryAction()
30383
+ };
30384
+ await saveOperationState(checkpoint, operation);
30385
+ return pausedResult(operation, checkpoint);
30386
+ }
30192
30387
  const mutationGuard = initialMutationGuard;
30193
30388
  let recoveredMutationGuard = false;
30194
30389
  if (mutationGuard) {
@@ -30278,6 +30473,18 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
30278
30473
  throw new Error(`e2e.scenario.mutation_guard_mismatch: guarded step is already ${String(guardedStep.status)}`);
30279
30474
  }
30280
30475
  }
30476
+ if (operation.status === "paused_repairable" && isBrowserAuthenticationErrorMessage(operation.pause?.message || "")) {
30477
+ operation.status = "paused_external_action";
30478
+ operation.pause = {
30479
+ ...operation.pause,
30480
+ kind: "playwright_authentication_required",
30481
+ message: operation.pause?.message || "Playwright authentication must be restored before this run can continue.",
30482
+ repair_request: void 0,
30483
+ script_change_required: false,
30484
+ external_action: interactiveLoginRecoveryAction()
30485
+ };
30486
+ await saveOperationState(checkpoint, operation);
30487
+ }
30281
30488
  if (recoveredMutationGuard && operation.status === "complete") {
30282
30489
  return {
30283
30490
  ok: true,
@@ -30334,6 +30541,12 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
30334
30541
  if (operation.status === "complete") {
30335
30542
  throw new Error("test_suite.run.completed_manifest: completed cases are never resumed or reused; start a new full_rerun manifest");
30336
30543
  }
30544
+ if (options.resume && operation.status === "paused_external_action" && operation.pause?.kind === "playwright_authentication_required" && options.retryInteractiveLogin !== true) {
30545
+ return pausedResult(operation, checkpoint);
30546
+ }
30547
+ if (options.resume && operation.status === "paused_external_action" && operation.pause?.kind === "orphaned_execution_recovery_required" && options.recoverOrphanedRun !== true) {
30548
+ return pausedResult(operation, checkpoint);
30549
+ }
30337
30550
  if (options.resume && operation.status === "paused_external_action" && operation.pause?.kind === "report_sync_failed") {
30338
30551
  try {
30339
30552
  const reportSync = await dependencies.syncTestSuiteRunReport(manifest);
@@ -30723,6 +30936,21 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
30723
30936
  await saveOperationState(checkpoint, operation);
30724
30937
  return pausedResult(operation, checkpoint);
30725
30938
  }
30939
+ if (isBrowserAuthenticationFailure(result)) {
30940
+ operation.status = "paused_external_action";
30941
+ operation.mutation_state = "not_attempted";
30942
+ operation.pause = {
30943
+ kind: "playwright_authentication_required",
30944
+ message: result.error || result.status,
30945
+ repair_scope: failedStepKey,
30946
+ failed_action_index: result.failure_action_index,
30947
+ script_change_required: false,
30948
+ evidence: result.evidence,
30949
+ external_action: interactiveLoginRecoveryAction()
30950
+ };
30951
+ await saveOperationState(checkpoint, operation);
30952
+ return pausedResult(operation, checkpoint);
30953
+ }
30726
30954
  if (result.repairable || ["cache_stale", "execution_failed"].includes(result.status)) {
30727
30955
  const failedStepHash = browserAutomationStepSha256(requiredAutomationStep(automation, failedStepKey));
30728
30956
  const scriptChangeRequired = repairRequiresAutomationChange(result);
@@ -34188,7 +34416,7 @@ function registerE2eCommands(program2) {
34188
34416
  });
34189
34417
  });
34190
34418
  const scenario = e2e.command("scenario").description("Run resumable BPMAX E2E scenario plans");
34191
- scenario.command("execute").description("Execute the formal deterministic operation flow until complete or a controlled pause").requiredOption("--plan <file>", "Scenario plan JSON file").requiredOption("--automation <file>", "Scenario automation.json").requiredOption("--execution-manifest <file>", "Current formal test-suite execution manifest").option("--data-profile <json>", "Current-run JSON variables or @file").option("--base-url <url>", "Browser base URL; defaults to the manifest profile origin").option("--profile <profile>", "Profile name; must match the execution manifest").option("--cdp-endpoint <url>", "Connect to an existing authenticated Chrome CDP endpoint").option("--cookie-env <name>", "Environment variable containing a current browser Cookie header", "BPMAX_COOKIE_HEADER").option("--storage-state <file>", "Playwright storage state JSON").option("--user-data-dir <dir>", "Persistent Chrome user data directory").option("--executable-path <file>", "Chrome/Chromium executable path").option("--headed", "Run a visible browser window").option("--no-interactive-login", "Fail instead of opening a visible Playwright login window when authentication is missing").option("--login-timeout <seconds>", "Maximum time to wait for interactive Playwright login", "300").option("--checkpoint <file>", "Operation-flow checkpoint; defaults to the current report run directory").option("--resume", "Resume the same unfinished operation flow after a controlled repair or external action").option("--format <format>", "Output format", "json").action(async (options) => {
34419
+ scenario.command("execute").description("Execute the formal deterministic operation flow until complete or a controlled pause").requiredOption("--plan <file>", "Scenario plan JSON file").requiredOption("--automation <file>", "Scenario automation.json").requiredOption("--execution-manifest <file>", "Current formal test-suite execution manifest").option("--data-profile <json>", "Current-run JSON variables or @file").option("--base-url <url>", "Browser base URL; defaults to the manifest profile origin").option("--profile <profile>", "Profile name; must match the execution manifest").option("--cdp-endpoint <url>", "Connect to an existing authenticated Chrome CDP endpoint").option("--cookie-env <name>", "Environment variable containing a current browser Cookie header", "BPMAX_COOKIE_HEADER").option("--storage-state <file>", "Playwright storage state JSON").option("--user-data-dir <dir>", "Persistent Chrome user data directory").option("--executable-path <file>", "Chrome/Chromium executable path").option("--headed", "Run a visible browser window").option("--no-interactive-login", "Fail instead of opening a visible Playwright login window when authentication is missing").option("--retry-interactive-login", "Explicitly allow one new visible login attempt after an authentication pause").option("--recover-orphaned-run", "Explicitly recover a stale running checkpoint after confirming no browser process or mutation remains").option("--login-timeout <seconds>", "Maximum time to wait for interactive Playwright login", "300").option("--checkpoint <file>", "Operation-flow checkpoint; defaults to the current report run directory").option("--resume", "Resume the same unfinished operation flow after a controlled repair or external action").option("--format <format>", "Output format", "json").action(async (options) => {
34192
34420
  const loginTimeoutMs = Number(options.loginTimeout) * 1e3;
34193
34421
  if (!Number.isFinite(loginTimeoutMs) || loginTimeoutMs <= 0) {
34194
34422
  throw new Error("e2e.browser.login_timeout_invalid: --login-timeout must be a positive number of seconds");
@@ -39679,7 +39907,7 @@ function registerTestSuiteCommands(program2) {
39679
39907
  output: options.output
39680
39908
  }));
39681
39909
  });
39682
- confirmation.command("accept").description("Accept a prepared V2 E2E confirmation request after explicit user confirmation").requiredOption("--request <file>", "Prepared V2 confirmation request").option("--confirmed", "The user explicitly confirmed the displayed scenario, case scope, and operation").option("--receipt <file>", "Accepted confirmation receipt output path").option("--format <format>", "Output format", "json").action(async (options) => {
39910
+ confirmation.command("accept").description("Accept a prepared V2 E2E scope after explicit confirmation or an explicit autonomous test request").requiredOption("--request <file>", "Prepared V2 confirmation request").option("--confirmed", "The user explicitly confirmed the displayed scenario, case scope, and operation").option("--autonomous", "The current explicit test request authorizes automatic execution of the bound scope without a second confirmation").option("--receipt <file>", "Accepted confirmation receipt output path").option("--format <format>", "Output format", "json").action(async (options) => {
39683
39911
  printResult(options.format, await acceptV2TestSuiteConfirmation(options));
39684
39912
  });
39685
39913
  suite.command("draft-update").description("Copy one formal suite scenario to the draft suite for editing").requiredOption("--scenario <id>", "Scenario id").option("--suite-root <path>", "Formal suite root directory", DEFAULT_SUITE_ROOT).option("--draft-root <path>", "Draft suite root directory", DEFAULT_DRAFT_ROOT).option("--replace", "Allow replacing an existing draft scenario").option("--diff-reviewed", "Confirm the copy diff preview was reviewed").requiredOption("--latest-proof <path>", "latest-* proof JSON written after syncing the sysconfig repo").option("--format <format>", "Output format", "json").action(async (options) => {