bpmax-cli 0.2.1-beta.51 → 0.2.1-beta.52
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 +1483 -423
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-e2e-flow-test-operator/SKILL.md +4 -3
- package/skills/bpmax-e2e-flow-test-operator/references/ai-test-suite.md +1 -1
- package/skills/bpmax-e2e-flow-test-operator/references/browser-only-checkpoints.md +2 -2
- package/skills/bpmax-e2e-flow-test-operator/references/full-detail-guide.md +4 -5
- package/skills/bpmax-e2e-flow-test-operator/references/minimal-test-loop.md +1 -1
- package/skills/bpmax-user-mock-operator/SKILL.md +42 -19
- package/skills/bpmax-user-mock-operator/scripts/chrome_identity_bridge.mjs +940 -0
package/dist/bin.js
CHANGED
|
@@ -233,8 +233,8 @@ function throwCliGovernanceUnsupportedIfNeeded(error, fallbackPath) {
|
|
|
233
233
|
}
|
|
234
234
|
throw error;
|
|
235
235
|
}
|
|
236
|
-
function normalizePath(
|
|
237
|
-
let normalized =
|
|
236
|
+
function normalizePath(path20) {
|
|
237
|
+
let normalized = path20.split("?")[0] || "/";
|
|
238
238
|
if (!normalized.startsWith("/")) {
|
|
239
239
|
normalized = `/${normalized}`;
|
|
240
240
|
}
|
|
@@ -244,17 +244,17 @@ function normalizePath(path19) {
|
|
|
244
244
|
}
|
|
245
245
|
return normalized.replace(/\/+$/g, "") || "/api";
|
|
246
246
|
}
|
|
247
|
-
function getNumber(value,
|
|
248
|
-
const result = getValue(value,
|
|
247
|
+
function getNumber(value, path20) {
|
|
248
|
+
const result = getValue(value, path20);
|
|
249
249
|
return typeof result === "number" ? result : void 0;
|
|
250
250
|
}
|
|
251
|
-
function getString(value,
|
|
252
|
-
const result = getValue(value,
|
|
251
|
+
function getString(value, path20) {
|
|
252
|
+
const result = getValue(value, path20);
|
|
253
253
|
return typeof result === "string" ? result : void 0;
|
|
254
254
|
}
|
|
255
|
-
function getValue(value,
|
|
255
|
+
function getValue(value, path20) {
|
|
256
256
|
let current = value;
|
|
257
|
-
for (const key of
|
|
257
|
+
for (const key of path20) {
|
|
258
258
|
if (!current || typeof current !== "object" || !(key in current)) {
|
|
259
259
|
return void 0;
|
|
260
260
|
}
|
|
@@ -264,10 +264,10 @@ function getValue(value, path19) {
|
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
// src/core/capabilities.ts
|
|
267
|
-
function capabilityForRequest(method,
|
|
267
|
+
function capabilityForRequest(method, path20) {
|
|
268
268
|
const normalizedMethod = method.toUpperCase();
|
|
269
|
-
const normalizedPath = normalizePath2(
|
|
270
|
-
const pageTemplatePrefix = flowPageTemplateCapabilityPrefix(
|
|
269
|
+
const normalizedPath = normalizePath2(path20);
|
|
270
|
+
const pageTemplatePrefix = flowPageTemplateCapabilityPrefix(path20);
|
|
271
271
|
if (normalizedPath === "/cli/capabilities") {
|
|
272
272
|
return void 0;
|
|
273
273
|
}
|
|
@@ -446,8 +446,8 @@ async function updateProfileCapabilities(profileName, cache) {
|
|
|
446
446
|
};
|
|
447
447
|
await saveConfig(config);
|
|
448
448
|
}
|
|
449
|
-
function flowPageTemplateCapabilityPrefix(
|
|
450
|
-
const query =
|
|
449
|
+
function flowPageTemplateCapabilityPrefix(path20) {
|
|
450
|
+
const query = path20.includes("?") ? path20.slice(path20.indexOf("?") + 1) : "";
|
|
451
451
|
const type = new URLSearchParams(query).get("type");
|
|
452
452
|
if (type === "2") {
|
|
453
453
|
return "config.project_detail_template";
|
|
@@ -466,8 +466,8 @@ function flowPageTemplateCapabilityPrefix(path19) {
|
|
|
466
466
|
}
|
|
467
467
|
return "config.list_template";
|
|
468
468
|
}
|
|
469
|
-
function normalizePath2(
|
|
470
|
-
let normalized =
|
|
469
|
+
function normalizePath2(path20) {
|
|
470
|
+
let normalized = path20.split("?")[0] || "/";
|
|
471
471
|
if (!normalized.startsWith("/")) {
|
|
472
472
|
normalized = `/${normalized}`;
|
|
473
473
|
}
|
|
@@ -498,7 +498,7 @@ function pluginAgentCapabilityForRequest(method, normalizedPath) {
|
|
|
498
498
|
// package.json
|
|
499
499
|
var package_default = {
|
|
500
500
|
name: "bpmax-cli",
|
|
501
|
-
version: "0.2.1-beta.
|
|
501
|
+
version: "0.2.1-beta.52",
|
|
502
502
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
503
503
|
type: "module",
|
|
504
504
|
bin: {
|
|
@@ -550,8 +550,8 @@ var NPM_PACKAGE = "bpmax-cli";
|
|
|
550
550
|
// src/core/terminal.ts
|
|
551
551
|
import { randomUUID } from "crypto";
|
|
552
552
|
import os from "os";
|
|
553
|
-
function isCliControlPath(
|
|
554
|
-
const normalized = normalizeApiPath(
|
|
553
|
+
function isCliControlPath(path20) {
|
|
554
|
+
const normalized = normalizeApiPath(path20);
|
|
555
555
|
return normalized === "/api/cli/capabilities" || normalized === "/api/cli/terminals/register" || normalized === "/api/cli/audit/start" || normalized === "/api/cli/audit/finish" || normalized === "/api/cli/bbs_invocations/start" || normalized === "/api/cli/bbs_invocations/finish";
|
|
556
556
|
}
|
|
557
557
|
function commandSummary(argv = process.argv) {
|
|
@@ -715,8 +715,8 @@ async function updateProfileTerminal(profile, terminalId, status) {
|
|
|
715
715
|
profile.config.terminal_status = status;
|
|
716
716
|
profile.config.terminal_registered_at = config.profiles[profile.name].terminal_registered_at;
|
|
717
717
|
}
|
|
718
|
-
function normalizeApiPath(
|
|
719
|
-
let normalized =
|
|
718
|
+
function normalizeApiPath(path20) {
|
|
719
|
+
let normalized = path20.split("?")[0] || "/";
|
|
720
720
|
if (!normalized.startsWith("/")) {
|
|
721
721
|
normalized = `/${normalized}`;
|
|
722
722
|
}
|
|
@@ -839,14 +839,14 @@ function recordCommandAuditResult(value) {
|
|
|
839
839
|
state.result_summary = redactAuditValue(value);
|
|
840
840
|
}
|
|
841
841
|
}
|
|
842
|
-
var ensureApiPath = (
|
|
843
|
-
if (!
|
|
844
|
-
|
|
842
|
+
var ensureApiPath = (path20) => {
|
|
843
|
+
if (!path20.startsWith("/")) {
|
|
844
|
+
path20 = `/${path20}`;
|
|
845
845
|
}
|
|
846
|
-
if (
|
|
847
|
-
return
|
|
846
|
+
if (path20.startsWith("/api/")) {
|
|
847
|
+
return path20;
|
|
848
848
|
}
|
|
849
|
-
return `/api${
|
|
849
|
+
return `/api${path20}`;
|
|
850
850
|
};
|
|
851
851
|
function normalizeWorkspaceForApi(workspace) {
|
|
852
852
|
const normalized = workspace?.trim();
|
|
@@ -892,10 +892,10 @@ function createApiClient(profile) {
|
|
|
892
892
|
});
|
|
893
893
|
return instance;
|
|
894
894
|
}
|
|
895
|
-
async function apiRequest(client, method,
|
|
895
|
+
async function apiRequest(client, method, path20, options = {}) {
|
|
896
896
|
const profile = clientProfiles.get(client);
|
|
897
|
-
const apiPath2 = ensureApiPath(
|
|
898
|
-
const capability = options.capability ?? capabilityForRequest(method,
|
|
897
|
+
const apiPath2 = ensureApiPath(path20);
|
|
898
|
+
const capability = options.capability ?? capabilityForRequest(method, path20);
|
|
899
899
|
const shouldControl = Boolean(profile?.config.api_key) && !isCliControlPath(apiPath2);
|
|
900
900
|
const reqId = requestId();
|
|
901
901
|
if (profile) {
|
|
@@ -1222,8 +1222,8 @@ async function parseJsonAny(input, label = "JSON input") {
|
|
|
1222
1222
|
function isMutatingMethod(method) {
|
|
1223
1223
|
return ["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase());
|
|
1224
1224
|
}
|
|
1225
|
-
function normalizeApiPath2(
|
|
1226
|
-
let normalized =
|
|
1225
|
+
function normalizeApiPath2(path20) {
|
|
1226
|
+
let normalized = path20.trim();
|
|
1227
1227
|
const queryIndex = normalized.indexOf("?");
|
|
1228
1228
|
if (queryIndex >= 0) {
|
|
1229
1229
|
normalized = normalized.slice(0, queryIndex);
|
|
@@ -1240,9 +1240,9 @@ function normalizeApiPath2(path19) {
|
|
|
1240
1240
|
}
|
|
1241
1241
|
return normalized;
|
|
1242
1242
|
}
|
|
1243
|
-
function pluginAgentCapabilityForRawApi(method,
|
|
1243
|
+
function pluginAgentCapabilityForRawApi(method, path20) {
|
|
1244
1244
|
const normalizedMethod = method.toUpperCase();
|
|
1245
|
-
const normalizedPath = normalizeApiPath2(
|
|
1245
|
+
const normalizedPath = normalizeApiPath2(path20);
|
|
1246
1246
|
const match = normalizedPath.match(/^\/(plugin_[A-Za-z0-9_]+)\/agents(?:\/|$)/);
|
|
1247
1247
|
if (!match) {
|
|
1248
1248
|
return void 0;
|
|
@@ -1256,19 +1256,19 @@ function pluginAgentCapabilityForRawApi(method, path19) {
|
|
|
1256
1256
|
}
|
|
1257
1257
|
return void 0;
|
|
1258
1258
|
}
|
|
1259
|
-
function parseQuery(
|
|
1260
|
-
const queryIndex =
|
|
1261
|
-
return new URLSearchParams(queryIndex >= 0 ?
|
|
1259
|
+
function parseQuery(path20) {
|
|
1260
|
+
const queryIndex = path20.indexOf("?");
|
|
1261
|
+
return new URLSearchParams(queryIndex >= 0 ? path20.slice(queryIndex + 1) : "");
|
|
1262
1262
|
}
|
|
1263
|
-
function isRawConfigPath(method,
|
|
1264
|
-
const normalizedPath = normalizeApiPath2(
|
|
1263
|
+
function isRawConfigPath(method, path20) {
|
|
1264
|
+
const normalizedPath = normalizeApiPath2(path20);
|
|
1265
1265
|
if (/^\/(configuration|form_template|flow_page_template|data_set|data_set_field|api_platform|api_platform_instance|api_proxy|api_proxy_entity_binding|entity|entity_field|role|point|user_role|workspace|group|config_repository)(\/|$)/.test(normalizedPath)) {
|
|
1266
1266
|
return true;
|
|
1267
1267
|
}
|
|
1268
1268
|
if (normalizedPath === "/flow/list/lightweight" || normalizedPath.startsWith("/flow/configuration/")) {
|
|
1269
1269
|
return true;
|
|
1270
1270
|
}
|
|
1271
|
-
if (normalizedPath === "/flow" && method === "GET" && parseQuery(
|
|
1271
|
+
if (normalizedPath === "/flow" && method === "GET" && parseQuery(path20).has("draft")) {
|
|
1272
1272
|
return true;
|
|
1273
1273
|
}
|
|
1274
1274
|
if (normalizedPath.startsWith("/flow/") && !["/flow/flow_type", "/flow/options", "/flow/batch_get"].includes(normalizedPath)) {
|
|
@@ -1279,35 +1279,35 @@ function isRawConfigPath(method, path19) {
|
|
|
1279
1279
|
}
|
|
1280
1280
|
return false;
|
|
1281
1281
|
}
|
|
1282
|
-
function assertRawApiPathAllowed(method,
|
|
1283
|
-
if (isRawConfigPath(method,
|
|
1282
|
+
function assertRawApiPathAllowed(method, path20) {
|
|
1283
|
+
if (isRawConfigPath(method, path20)) {
|
|
1284
1284
|
throw new Error(
|
|
1285
|
-
`Raw API ${method} ${
|
|
1285
|
+
`Raw API ${method} ${path20} is blocked because BPMAX configuration APIs must use typed bpmax-cli config commands. Run bpmax-cli config adapters --format json to check whether the target config domain is supported.`
|
|
1286
1286
|
);
|
|
1287
1287
|
}
|
|
1288
1288
|
if (!isMutatingMethod(method)) {
|
|
1289
1289
|
return;
|
|
1290
1290
|
}
|
|
1291
|
-
const normalizedPath = normalizeApiPath2(
|
|
1291
|
+
const normalizedPath = normalizeApiPath2(path20);
|
|
1292
1292
|
const isProjectPath = normalizedPath === "/project" || normalizedPath.startsWith("/project/");
|
|
1293
1293
|
const isAllowedProjectReadPost = method === "POST" && normalizedPath === "/project/list";
|
|
1294
1294
|
if (!isProjectPath || isAllowedProjectReadPost) {
|
|
1295
1295
|
return;
|
|
1296
1296
|
}
|
|
1297
1297
|
throw new Error(
|
|
1298
|
-
`Raw API ${method} ${
|
|
1298
|
+
`Raw API ${method} ${path20} is blocked because /api/project/<id> falls back to project creation in huanpingtong-server. Do not call /project/es-search or /project/raw-es-search; huanpingtong-server does not expose those as public ES APIs. Use bpmax-cli project create --flow-id <id> --json <json> for project creation, or bpmax-cli project search / project list for project reads.`
|
|
1299
1299
|
);
|
|
1300
1300
|
}
|
|
1301
1301
|
function registerApiCommands(program2) {
|
|
1302
|
-
program2.command("api <method> <path>").description("Call an arbitrary BPMAX /api endpoint").option("--profile <profile>", "Profile name").option("--params <json>", "Query params JSON or @file").option("--data <json>", "Request body JSON or @file").option("--confirm-mutating", "Allow mutating API calls").option("--format <format>", "Output format", "json").action(async (method,
|
|
1302
|
+
program2.command("api <method> <path>").description("Call an arbitrary BPMAX /api endpoint").option("--profile <profile>", "Profile name").option("--params <json>", "Query params JSON or @file").option("--data <json>", "Request body JSON or @file").option("--confirm-mutating", "Allow mutating API calls").option("--format <format>", "Output format", "json").action(async (method, path20, options) => {
|
|
1303
1303
|
const normalizedMethod = method.toUpperCase();
|
|
1304
|
-
assertRawApiPathAllowed(normalizedMethod,
|
|
1304
|
+
assertRawApiPathAllowed(normalizedMethod, path20);
|
|
1305
1305
|
if (isMutatingMethod(normalizedMethod) && options.confirmMutating !== true) {
|
|
1306
1306
|
printResult(options.format, {
|
|
1307
1307
|
ok: false,
|
|
1308
1308
|
dry_run: true,
|
|
1309
1309
|
method: normalizedMethod,
|
|
1310
|
-
path:
|
|
1310
|
+
path: path20,
|
|
1311
1311
|
warning: "Mutating raw API calls require --confirm-mutating. Prefer typed bpmax-cli commands such as step submit."
|
|
1312
1312
|
});
|
|
1313
1313
|
return;
|
|
@@ -1315,8 +1315,8 @@ function registerApiCommands(program2) {
|
|
|
1315
1315
|
const config = await loadConfig();
|
|
1316
1316
|
const profile = resolveProfile(config, options.profile);
|
|
1317
1317
|
const client = createApiClient(profile);
|
|
1318
|
-
const capability = pluginAgentCapabilityForRawApi(normalizedMethod,
|
|
1319
|
-
const result = await apiRequest(client, normalizedMethod,
|
|
1318
|
+
const capability = pluginAgentCapabilityForRawApi(normalizedMethod, path20) || "api.raw";
|
|
1319
|
+
const result = await apiRequest(client, normalizedMethod, path20, {
|
|
1320
1320
|
params: options.params ? await parseJsonInput(options.params, "--params") : void 0,
|
|
1321
1321
|
data: await parseJsonAny(options.data, "--data"),
|
|
1322
1322
|
capability
|
|
@@ -1415,18 +1415,18 @@ function normalizeDeviceAuthorizationUrl(urlValue, workspace) {
|
|
|
1415
1415
|
}
|
|
1416
1416
|
return url.toString();
|
|
1417
1417
|
}
|
|
1418
|
-
function apiPath(
|
|
1419
|
-
if (
|
|
1420
|
-
return
|
|
1418
|
+
function apiPath(path20) {
|
|
1419
|
+
if (path20.startsWith("/api/")) {
|
|
1420
|
+
return path20;
|
|
1421
1421
|
}
|
|
1422
|
-
return `/api${
|
|
1422
|
+
return `/api${path20.startsWith("/") ? path20 : `/${path20}`}`;
|
|
1423
1423
|
}
|
|
1424
1424
|
function createDeviceRequest(origin) {
|
|
1425
1425
|
const client = axios2.create({ baseURL: origin, withCredentials: false });
|
|
1426
|
-
return async (method,
|
|
1426
|
+
return async (method, path20, options) => {
|
|
1427
1427
|
const response = await client.request({
|
|
1428
1428
|
method,
|
|
1429
|
-
url: apiPath(
|
|
1429
|
+
url: apiPath(path20),
|
|
1430
1430
|
data: options.data
|
|
1431
1431
|
});
|
|
1432
1432
|
const body = response.data;
|
|
@@ -2587,7 +2587,7 @@ function validatePluginLintManifest(item, issues, context2) {
|
|
|
2587
2587
|
}
|
|
2588
2588
|
}
|
|
2589
2589
|
function isAllowedPluginConfigScanPath(scanPath) {
|
|
2590
|
-
return scanPath === "data.meta.<plugin_key>" || scanPath === "data.nodes[].<plugin_key>" || /^data\.nodes\[\]\.<plugin_key>\.[A-Za-z0-9_]+\[\]$/.test(scanPath) || /^data\.nodes\[\]\.[A-Za-z0-9_]+$/.test(scanPath) || /^data\.nodes\[\]\.[A-Za-z0-9_]+_(?:triggers|configs|plugins)\[\]$/.test(scanPath);
|
|
2590
|
+
return scanPath === "data.meta.<plugin_key>" || scanPath === "data.nodes[].<plugin_key>" || /^data\.nodes\[\]\.<plugin_key>\.[A-Za-z0-9_]+\[\]$/.test(scanPath) || /^data\.nodes\[\]\.plugin_[A-Za-z0-9_]+$/.test(scanPath) || /^data\.nodes\[\]\.[A-Za-z0-9_]+_(?:triggers|configs|plugins)\[\]$/.test(scanPath);
|
|
2591
2591
|
}
|
|
2592
2592
|
async function validatePluginLintRuleFiles(skillDir, files, issues) {
|
|
2593
2593
|
for (const file of files) {
|
|
@@ -3338,7 +3338,7 @@ function collectFlowTemplatePluginConfigsByPath(flowWork, scanPath, pluginKey) {
|
|
|
3338
3338
|
});
|
|
3339
3339
|
return occurrences2;
|
|
3340
3340
|
}
|
|
3341
|
-
const objectMatch = scanPath.match(/^data\.nodes\[\]\.([A-Za-z0-9_]+)$/);
|
|
3341
|
+
const objectMatch = scanPath.match(/^data\.nodes\[\]\.(plugin_[A-Za-z0-9_]+)$/);
|
|
3342
3342
|
if (objectMatch) {
|
|
3343
3343
|
const field2 = objectMatch[1];
|
|
3344
3344
|
const data2 = typeof flowWork.data === "object" && flowWork.data !== null && !Array.isArray(flowWork.data) ? flowWork.data : {};
|
|
@@ -3496,7 +3496,7 @@ async function lintFlowTemplatePluginExtensions(options) {
|
|
|
3496
3496
|
...installedLintDeclarations.map((item) => item.lint.plugin_key)
|
|
3497
3497
|
]);
|
|
3498
3498
|
const declaredExplicitNodeKeys = new Set(
|
|
3499
|
-
[...platformLintDeclarations, ...installedLintDeclarations].flatMap((item) => item.lint.paths || []).map((scanPath) => scanPath.match(/^data\.nodes\[\]\.([A-Za-z0-9_]+)$/)?.[1]).filter((key) => Boolean(key))
|
|
3499
|
+
[...platformLintDeclarations, ...installedLintDeclarations].flatMap((item) => item.lint.paths || []).map((scanPath) => scanPath.match(/^data\.nodes\[\]\.(plugin_[A-Za-z0-9_]+)$/)?.[1]).filter((key) => Boolean(key))
|
|
3500
3500
|
);
|
|
3501
3501
|
for (const pluginKey of usedPluginKeys) {
|
|
3502
3502
|
if (allPluginKeys.has(pluginKey) || declaredExplicitNodeKeys.has(pluginKey)) {
|
|
@@ -3917,20 +3917,20 @@ function requireNumericId(value, name) {
|
|
|
3917
3917
|
}
|
|
3918
3918
|
return nextValue;
|
|
3919
3919
|
}
|
|
3920
|
-
function withQuery(
|
|
3920
|
+
function withQuery(path20, query) {
|
|
3921
3921
|
const params = new URLSearchParams();
|
|
3922
3922
|
for (const [key, value] of Object.entries(query)) {
|
|
3923
3923
|
if (value !== void 0) {
|
|
3924
3924
|
params.set(key, value);
|
|
3925
3925
|
}
|
|
3926
3926
|
}
|
|
3927
|
-
return `${
|
|
3927
|
+
return `${path20}?${params.toString()}`;
|
|
3928
3928
|
}
|
|
3929
3929
|
function buildBpmaxUrl(profile, kind, params = {}) {
|
|
3930
3930
|
const origin = normalizeOrigin2(profile.config.origin);
|
|
3931
3931
|
const workspace = normalizeWorkspaceForUrl(params.workspace || profile.config.workspace);
|
|
3932
3932
|
const basePath = `/${workspace}`;
|
|
3933
|
-
let
|
|
3933
|
+
let path20 = basePath;
|
|
3934
3934
|
const result = {
|
|
3935
3935
|
kind,
|
|
3936
3936
|
profile: profile.name,
|
|
@@ -3938,15 +3938,15 @@ function buildBpmaxUrl(profile, kind, params = {}) {
|
|
|
3938
3938
|
workspace
|
|
3939
3939
|
};
|
|
3940
3940
|
if (kind === "project-list") {
|
|
3941
|
-
|
|
3941
|
+
path20 = `${basePath}/project`;
|
|
3942
3942
|
} else if (kind === "project-detail") {
|
|
3943
3943
|
const projectId = requireNumericId(params.projectId, "projectId");
|
|
3944
|
-
|
|
3944
|
+
path20 = `${basePath}/project_detail/0/${projectId}`;
|
|
3945
3945
|
result.project_id = projectId;
|
|
3946
3946
|
} else if (kind === "project-step") {
|
|
3947
3947
|
const projectId = requireNumericId(params.projectId, "projectId");
|
|
3948
3948
|
const stepId = requireNumericId(params.stepId, "stepId");
|
|
3949
|
-
|
|
3949
|
+
path20 = withQuery(`${basePath}/projectContinue`, {
|
|
3950
3950
|
id: projectId,
|
|
3951
3951
|
step_id: stepId,
|
|
3952
3952
|
prefill_token: params.prefillToken
|
|
@@ -3964,15 +3964,15 @@ function buildBpmaxUrl(profile, kind, params = {}) {
|
|
|
3964
3964
|
...flowKey ? { key: flowKey } : {},
|
|
3965
3965
|
...prefillToken ? { prefill_token: prefillToken } : { init_value: initValue }
|
|
3966
3966
|
};
|
|
3967
|
-
|
|
3967
|
+
path20 = withQuery(`${basePath}/project/create`, query);
|
|
3968
3968
|
result.flow_type = flowType;
|
|
3969
3969
|
result.flow_key = flowKey;
|
|
3970
3970
|
result.mobile_path = withQuery("/pages/projectCreate/projectCreate", query);
|
|
3971
3971
|
}
|
|
3972
|
-
const url = `${origin}${
|
|
3972
|
+
const url = `${origin}${path20}`;
|
|
3973
3973
|
return {
|
|
3974
3974
|
...result,
|
|
3975
|
-
path:
|
|
3975
|
+
path: path20,
|
|
3976
3976
|
url,
|
|
3977
3977
|
...kind === "project-create" ? { pc_url: url } : {}
|
|
3978
3978
|
};
|
|
@@ -4352,17 +4352,17 @@ function containsOuterReturn(value, root = true) {
|
|
|
4352
4352
|
return containsOuterReturn(child, false);
|
|
4353
4353
|
});
|
|
4354
4354
|
}
|
|
4355
|
-
function validateExpression(expression,
|
|
4355
|
+
function validateExpression(expression, path20, errors) {
|
|
4356
4356
|
try {
|
|
4357
4357
|
const program2 = parse(`async function __bpmaxReport(ctx) {
|
|
4358
4358
|
${expression}
|
|
4359
4359
|
}`, { ecmaVersion: "latest" });
|
|
4360
4360
|
const reportFunction = program2.body[0];
|
|
4361
4361
|
if (!containsOuterReturn(reportFunction)) {
|
|
4362
|
-
errors.push(`${
|
|
4362
|
+
errors.push(`${path20} \u662F\u5E73\u53F0\u5F02\u6B65\u51FD\u6570\u4F53\uFF0C\u5FC5\u987B\u663E\u5F0F return\uFF0C\u4E14 return \u5FC5\u987B\u4F4D\u4E8E\u5916\u5C42\u51FD\u6570\u4E2D\uFF1B\u5426\u5219\u62A5\u544A\u5B57\u6BB5\u4F1A\u751F\u6210\u7A7A\u503C\u3002`);
|
|
4363
4363
|
}
|
|
4364
4364
|
} catch (error) {
|
|
4365
|
-
errors.push(`${
|
|
4365
|
+
errors.push(`${path20} \u4E0D\u662F\u5408\u6CD5\u7684 JavaScript \u5F02\u6B65\u51FD\u6570\u4F53\uFF1A${error instanceof Error ? error.message : String(error)}\u3002`);
|
|
4366
4366
|
}
|
|
4367
4367
|
}
|
|
4368
4368
|
function analyzeFlowReportTemplate(value, options = {}) {
|
|
@@ -5156,9 +5156,9 @@ function summarizeOperationPlan(payload) {
|
|
|
5156
5156
|
return "submit operation";
|
|
5157
5157
|
}
|
|
5158
5158
|
const method = typeof operation.method === "string" ? operation.method : "REQUEST";
|
|
5159
|
-
const
|
|
5159
|
+
const path20 = typeof operation.path === "string" ? operation.path : "";
|
|
5160
5160
|
const type = typeof operation.type === "string" ? ` ${operation.type}` : "";
|
|
5161
|
-
return `submit${type}: ${method}${
|
|
5161
|
+
return `submit${type}: ${method}${path20 ? ` ${path20}` : ""}`;
|
|
5162
5162
|
}),
|
|
5163
5163
|
...skipped.slice(0, Math.max(0, 20 - operations.length)).map((operation) => {
|
|
5164
5164
|
if (!isRecord4(operation)) {
|
|
@@ -6809,7 +6809,65 @@ function stepDetailPayloadWithLintArtifact(payload, submit) {
|
|
|
6809
6809
|
function numericTemplateId(value) {
|
|
6810
6810
|
return isRemoteNumericTemplateId(value) ? String(value).trim() : null;
|
|
6811
6811
|
}
|
|
6812
|
-
|
|
6812
|
+
function flowStepDetailBindingSnapshot(value) {
|
|
6813
|
+
const snapshot = /* @__PURE__ */ new Map();
|
|
6814
|
+
const data = isRecord4(value.data) ? value.data : {};
|
|
6815
|
+
const meta = isRecord4(data.meta) ? data.meta : {};
|
|
6816
|
+
const metaId = numericTemplateId(meta.step_detail_id);
|
|
6817
|
+
if (metaId) snapshot.set("data.meta.step_detail_id", metaId);
|
|
6818
|
+
const nodes = Array.isArray(data.nodes) ? data.nodes : [];
|
|
6819
|
+
nodes.forEach((node, index) => {
|
|
6820
|
+
if (!isRecord4(node)) return;
|
|
6821
|
+
const id = numericTemplateId(node.step_detail_id);
|
|
6822
|
+
if (!id) return;
|
|
6823
|
+
const stableNodeId = String(node.id ?? "").trim();
|
|
6824
|
+
snapshot.set(stableNodeId ? `node:${stableNodeId}` : `node-index:${index}`, id);
|
|
6825
|
+
});
|
|
6826
|
+
return snapshot;
|
|
6827
|
+
}
|
|
6828
|
+
function flowStepDetailBindingChanges(current, baseline) {
|
|
6829
|
+
const currentSnapshot = flowStepDetailBindingSnapshot(current);
|
|
6830
|
+
const baselineSnapshot = flowStepDetailBindingSnapshot(baseline);
|
|
6831
|
+
const keys = /* @__PURE__ */ new Set([...currentSnapshot.keys(), ...baselineSnapshot.keys()]);
|
|
6832
|
+
return [...keys].filter((key) => currentSnapshot.get(key) !== baselineSnapshot.get(key)).map((key) => `${key}: ${baselineSnapshot.get(key) ?? "<none>"} -> ${currentSnapshot.get(key) ?? "<none>"}`);
|
|
6833
|
+
}
|
|
6834
|
+
function isMissingStepDetailCapability(error) {
|
|
6835
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
6836
|
+
return message.includes('capability "config.step_detail_template.export" is not allowed for profile') && message.includes("server did not grant this capability");
|
|
6837
|
+
}
|
|
6838
|
+
async function readFlowTemplateBaselineFromMeta(meta) {
|
|
6839
|
+
if (!isRecord4(meta) || meta.domain !== "flow-template" || typeof meta.raw_file !== "string" || typeof meta.base_hash !== "string") {
|
|
6840
|
+
return void 0;
|
|
6841
|
+
}
|
|
6842
|
+
const candidates = [
|
|
6843
|
+
path5.resolve(meta.raw_file),
|
|
6844
|
+
...typeof meta.meta_file === "string" ? [path5.resolve(path5.dirname(meta.meta_file), meta.raw_file)] : []
|
|
6845
|
+
];
|
|
6846
|
+
for (const candidate of [...new Set(candidates)]) {
|
|
6847
|
+
try {
|
|
6848
|
+
const raw = await readJsonFile(candidate);
|
|
6849
|
+
if (isRecord4(raw) && hashJson(raw) === meta.base_hash) return raw;
|
|
6850
|
+
} catch {
|
|
6851
|
+
}
|
|
6852
|
+
}
|
|
6853
|
+
return void 0;
|
|
6854
|
+
}
|
|
6855
|
+
async function inferFlowTemplateBaselineFromWorkFile(file) {
|
|
6856
|
+
if (path5.basename(path5.dirname(file)) !== "work") return void 0;
|
|
6857
|
+
const stem = path5.basename(file, path5.extname(file));
|
|
6858
|
+
const metaFile = path5.join(path5.dirname(path5.dirname(file)), "meta", `${stem}.meta.json`);
|
|
6859
|
+
try {
|
|
6860
|
+
const meta = await readJsonFile(metaFile);
|
|
6861
|
+
if (!isRecord4(meta)) return void 0;
|
|
6862
|
+
if (typeof meta.work_file === "string" && path5.resolve(meta.work_file) !== path5.resolve(file)) {
|
|
6863
|
+
return void 0;
|
|
6864
|
+
}
|
|
6865
|
+
return readFlowTemplateBaselineFromMeta({ ...meta, meta_file: metaFile });
|
|
6866
|
+
} catch {
|
|
6867
|
+
return void 0;
|
|
6868
|
+
}
|
|
6869
|
+
}
|
|
6870
|
+
async function auditFlowStepDetailReferences(flowWork, profile, baseline) {
|
|
6813
6871
|
const errors = [];
|
|
6814
6872
|
const warnings = [];
|
|
6815
6873
|
const references = [];
|
|
@@ -6833,40 +6891,60 @@ async function auditFlowStepDetailReferences(flowWork, profile) {
|
|
|
6833
6891
|
if (directId) ids.add(directId);
|
|
6834
6892
|
});
|
|
6835
6893
|
const templates = /* @__PURE__ */ new Map();
|
|
6894
|
+
let baselineFallback = false;
|
|
6895
|
+
let capabilityUnavailable = false;
|
|
6836
6896
|
if (ids.size) {
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
analysis: null,
|
|
6853
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6854
|
-
};
|
|
6855
|
-
}
|
|
6856
|
-
}));
|
|
6857
|
-
remoteResults.forEach((result) => {
|
|
6858
|
-
if (result.error || !result.remote || !result.analysis) {
|
|
6859
|
-
errors.push(`step_detail_id=${result.id} \u65E0\u6CD5\u5728\u5F53\u524D profile \u56DE\u8BFB\u4E3A type=6 \u73AF\u8282\u8BE6\u60C5\u6A21\u677F\uFF1A${result.error || "\u8FDC\u7AEF\u54CD\u5E94\u65E0\u6548"}\u3002`);
|
|
6860
|
-
return;
|
|
6897
|
+
try {
|
|
6898
|
+
await ensureConfigCapability(profile, "config.step_detail_template.export");
|
|
6899
|
+
} catch (error) {
|
|
6900
|
+
if (!isMissingStepDetailCapability(error)) throw error;
|
|
6901
|
+
const changes = baseline ? flowStepDetailBindingChanges(flowWork, baseline) : [];
|
|
6902
|
+
if (baseline && changes.length === 0) {
|
|
6903
|
+
baselineFallback = true;
|
|
6904
|
+
warnings.push(
|
|
6905
|
+
"[server_cli_capability_mismatch] \u670D\u52A1\u7AEF\u672A\u6CE8\u518C config.step_detail_template.export\uFF1B\u5F53\u524D step_detail_id \u7ED1\u5B9A\u4E0E\u5BFC\u51FA\u57FA\u7EBF\u4E00\u81F4\uFF0C\u672C\u6B21\u8DF3\u8FC7 type=6 \u6A21\u677F\u6DF1\u5EA6\u56DE\u8BFB\u3002\u63D0\u4EA4\u540E\u5FC5\u987B\u4F7F\u7528\u771F\u5B9E\u73AF\u8282\u9875\u9762\u5B8C\u6210\u8FD0\u884C\u6001\u9A8C\u6536\u3002"
|
|
6906
|
+
);
|
|
6907
|
+
} else {
|
|
6908
|
+
capabilityUnavailable = true;
|
|
6909
|
+
errors.push(
|
|
6910
|
+
"[server_cli_capability_mismatch] \u670D\u52A1\u7AEF\u672A\u6CE8\u518C config.step_detail_template.export\uFF0CCLI \u65E0\u6CD5\u6DF1\u5EA6\u6821\u9A8C type=6 \u73AF\u8282\u8BE6\u60C5\u6A21\u677F\u3002" + (baseline ? ` \u68C0\u6D4B\u5230 step_detail_id \u7ED1\u5B9A\u53D8\u5316\uFF1A${changes.join("; ")}\u3002\u8BF7\u5148\u5347\u7EA7\u670D\u52A1\u7AEF capability manifest\uFF0C\u6216\u6062\u590D\u4E3A\u5BFC\u51FA\u57FA\u7EBF\u540E\u518D\u5904\u7406\u65E0\u5173\u6D41\u7A0B\u4FEE\u6539\u3002` : " \u672A\u627E\u5230\u53EF\u4FE1\u5BFC\u51FA\u57FA\u7EBF\uFF0C\u4E0D\u80FD\u628A\u8BE5\u9519\u8BEF\u964D\u7EA7\u4E3A warning\uFF1B\u8BF7\u4F7F\u7528 config flow-template export \u751F\u6210\u6807\u51C6 raw/work/meta \u6587\u4EF6\u540E\u91CD\u8BD5\u3002")
|
|
6911
|
+
);
|
|
6861
6912
|
}
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6913
|
+
}
|
|
6914
|
+
if (!baselineFallback && !capabilityUnavailable) {
|
|
6915
|
+
const definition = CONFIG_DOMAINS["step-detail-template"];
|
|
6916
|
+
const remoteResults = await Promise.all([...ids].map(async (id) => {
|
|
6917
|
+
try {
|
|
6918
|
+
const remote = await readRemoteConfigDomain(profile, "step-detail-template", id, definition);
|
|
6919
|
+
validateExpectedType("step-detail-template", definition, remote);
|
|
6920
|
+
if (!isRecord4(remote)) {
|
|
6921
|
+
throw new Error("\u8FDC\u7AEF\u54CD\u5E94\u4E0D\u662F\u6A21\u677F\u5BF9\u8C61");
|
|
6922
|
+
}
|
|
6923
|
+
const analysis = analyzeStepDetailTemplate(remote, { allowUndeclaredCustomModules: true });
|
|
6924
|
+
return { id, remote, analysis, error: null };
|
|
6925
|
+
} catch (error) {
|
|
6926
|
+
return {
|
|
6927
|
+
id,
|
|
6928
|
+
remote: null,
|
|
6929
|
+
analysis: null,
|
|
6930
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6931
|
+
};
|
|
6932
|
+
}
|
|
6933
|
+
}));
|
|
6934
|
+
remoteResults.forEach((result) => {
|
|
6935
|
+
if (result.error || !result.remote || !result.analysis) {
|
|
6936
|
+
errors.push(`step_detail_id=${result.id} \u65E0\u6CD5\u5728\u5F53\u524D profile \u56DE\u8BFB\u4E3A type=6 \u73AF\u8282\u8BE6\u60C5\u6A21\u677F\uFF1A${result.error || "\u8FDC\u7AEF\u54CD\u5E94\u65E0\u6548"}\u3002`);
|
|
6937
|
+
return;
|
|
6938
|
+
}
|
|
6939
|
+
errors.push(...result.analysis.errors.map((message) => `step_detail_id=${result.id}: ${message}`));
|
|
6940
|
+
warnings.push(...result.analysis.warnings.map((message) => `step_detail_id=${result.id}: ${message}`));
|
|
6941
|
+
templates.set(result.id, {
|
|
6942
|
+
record: result.remote,
|
|
6943
|
+
analysis: result.analysis,
|
|
6944
|
+
structuralOk: result.analysis.errors.length === 0
|
|
6945
|
+
});
|
|
6868
6946
|
});
|
|
6869
|
-
}
|
|
6947
|
+
}
|
|
6870
6948
|
}
|
|
6871
6949
|
if (metaConfigured) {
|
|
6872
6950
|
const template = metaId ? templates.get(metaId) : void 0;
|
|
@@ -6875,7 +6953,7 @@ async function auditFlowStepDetailReferences(flowWork, profile) {
|
|
|
6875
6953
|
source: metaId ? "flow_default" : "invalid_flow_default",
|
|
6876
6954
|
configured_value: meta.step_detail_id,
|
|
6877
6955
|
effective_id: metaId,
|
|
6878
|
-
status: metaId
|
|
6956
|
+
status: !metaId ? "invalid" : template?.structuralOk ? "verified" : baselineFallback ? "baseline_confirmed" : capabilityUnavailable ? "unverified" : "invalid",
|
|
6879
6957
|
template_name: template?.record.name ?? null,
|
|
6880
6958
|
template_type: template?.record.type ?? null,
|
|
6881
6959
|
template_structural_ok: template ? template.structuralOk : null,
|
|
@@ -6883,7 +6961,7 @@ async function auditFlowStepDetailReferences(flowWork, profile) {
|
|
|
6883
6961
|
modules: template?.analysis.moduleNames ?? [],
|
|
6884
6962
|
unknown_modules: template?.analysis.unknownModules ?? [],
|
|
6885
6963
|
custom_modules: template?.analysis.customModules ?? [],
|
|
6886
|
-
runtime_proof_required: template?.analysis.requiresRuntimeProof ?? false
|
|
6964
|
+
runtime_proof_required: baselineFallback || (template?.analysis.requiresRuntimeProof ?? false)
|
|
6887
6965
|
});
|
|
6888
6966
|
}
|
|
6889
6967
|
nodes.forEach(({ node, index }) => {
|
|
@@ -6896,7 +6974,7 @@ async function auditFlowStepDetailReferences(flowWork, profile) {
|
|
|
6896
6974
|
const hideStepDetail = node.hide_step_detail === true;
|
|
6897
6975
|
const hasStepForm = !isEmptyTemplateReference(node.form_template);
|
|
6898
6976
|
const enableRelatedProjectForm = node.enable_relate_project_form === true;
|
|
6899
|
-
let suitability = hideStepDetail ? "hidden" : source === "invalid_node_reference" || source === "invalid_flow_default" ? "invalid" : effectiveId ? template?.structuralOk ? "verified" : "mismatch" : "platform_default_layout";
|
|
6977
|
+
let suitability = hideStepDetail ? "hidden" : source === "invalid_node_reference" || source === "invalid_flow_default" ? "invalid" : effectiveId ? template?.structuralOk ? "verified" : baselineFallback ? "runtime_proof_required" : capabilityUnavailable ? "unverified" : "mismatch" : "platform_default_layout";
|
|
6900
6978
|
if (hideStepDetail && effectiveId) {
|
|
6901
6979
|
warnings.push(`${nodeName} \u5DF2\u8BBE\u7F6E hide_step_detail=true\uFF0C\u4F46\u4ECD\u7ED1\u5B9A step_detail_id=${effectiveId}\uFF1B\u8BE5\u6A21\u677F\u4E0D\u4F1A\u4F5C\u4E3A\u6B63\u5E38\u73AF\u8282\u8BE6\u60C5\u5165\u53E3\u5C55\u793A\u3002`);
|
|
6902
6980
|
}
|
|
@@ -6924,7 +7002,7 @@ async function auditFlowStepDetailReferences(flowWork, profile) {
|
|
|
6924
7002
|
hide_step_detail: hideStepDetail,
|
|
6925
7003
|
form_template: node.form_template ?? null,
|
|
6926
7004
|
enable_relate_project_form: enableRelatedProjectForm,
|
|
6927
|
-
status: source === "invalid_node_reference" || source === "invalid_flow_default" ? "invalid" : effectiveId ? template?.structuralOk ? "verified" : "invalid" : "not_configured",
|
|
7005
|
+
status: source === "invalid_node_reference" || source === "invalid_flow_default" ? "invalid" : effectiveId ? template?.structuralOk ? "verified" : baselineFallback ? "baseline_confirmed" : capabilityUnavailable ? "unverified" : "invalid" : "not_configured",
|
|
6928
7006
|
suitability,
|
|
6929
7007
|
template_name: template?.record.name ?? null,
|
|
6930
7008
|
template_type: template?.record.type ?? null,
|
|
@@ -6933,7 +7011,7 @@ async function auditFlowStepDetailReferences(flowWork, profile) {
|
|
|
6933
7011
|
modules: template?.analysis.moduleNames ?? [],
|
|
6934
7012
|
unknown_modules: template?.analysis.unknownModules ?? [],
|
|
6935
7013
|
custom_modules: template?.analysis.customModules ?? [],
|
|
6936
|
-
runtime_proof_required: template?.analysis.requiresRuntimeProof ?? false
|
|
7014
|
+
runtime_proof_required: baselineFallback || (template?.analysis.requiresRuntimeProof ?? false)
|
|
6937
7015
|
});
|
|
6938
7016
|
});
|
|
6939
7017
|
return { errors, warnings, references };
|
|
@@ -7208,23 +7286,23 @@ function lintConsoleTemplateDataSource(dataSource, moduleLabel, errors) {
|
|
|
7208
7286
|
errors.push(`${moduleLabel} \u4E0D\u80FD\u76F4\u63A5\u4F7F\u7528 /bpmax/project/list\u3001/api/project/list \u6216 ESProjectList\uFF1B\u5982\u786E\u9700\u7528\u6237\u8303\u56F4\u67E5\u8BE2\uFF0C\u811A\u672C\u4E2D\u5FC5\u987B\u5199\u660E bpmax-allow-user-scope-project-list: <reason>\u3002`);
|
|
7209
7287
|
}
|
|
7210
7288
|
}
|
|
7211
|
-
function lintConsoleTemplateWildcardFallback(value,
|
|
7289
|
+
function lintConsoleTemplateWildcardFallback(value, path20, errors) {
|
|
7212
7290
|
if (typeof value === "string") {
|
|
7213
7291
|
const scriptedWildcard = /(?:wildcard|value)\s*:\s*(['\"])(\*{1,2})\1(?=\s*(?:[,};)\]]|$))/i.exec(value);
|
|
7214
7292
|
if (scriptedWildcard) {
|
|
7215
|
-
errors.push(`${
|
|
7293
|
+
errors.push(`${path20}.wildcard \u4E0D\u80FD\u7528 ${scriptedWildcard[2]} \u4F5C\u4E3A\u975E\u7A7A\u6216\u515C\u5E95\u7ED3\u679C\uFF1B\u8BF7\u5199\u660E\u786E\u7684\u7A7A\u6001\u3001\u6761\u4EF6\u6216\u805A\u5408\u7ED3\u679C\u3002`);
|
|
7216
7294
|
}
|
|
7217
7295
|
return;
|
|
7218
7296
|
}
|
|
7219
7297
|
if (Array.isArray(value)) {
|
|
7220
|
-
value.forEach((item, index) => lintConsoleTemplateWildcardFallback(item, `${
|
|
7298
|
+
value.forEach((item, index) => lintConsoleTemplateWildcardFallback(item, `${path20}[${index}]`, errors));
|
|
7221
7299
|
return;
|
|
7222
7300
|
}
|
|
7223
7301
|
if (!isRecord4(value)) {
|
|
7224
7302
|
return;
|
|
7225
7303
|
}
|
|
7226
7304
|
Object.entries(value).forEach(([key, item]) => {
|
|
7227
|
-
const nextPath = `${
|
|
7305
|
+
const nextPath = `${path20}.${key}`;
|
|
7228
7306
|
if ((key === "wildcard" || key === "value") && (item === "*" || item === "**")) {
|
|
7229
7307
|
errors.push(`${nextPath} \u4E0D\u80FD\u7528 ${String(item)} \u4F5C\u4E3A\u975E\u7A7A\u6216\u515C\u5E95\u7ED3\u679C\uFF1B\u8BF7\u5199\u660E\u786E\u7684\u7A7A\u6001\u3001\u6761\u4EF6\u6216\u805A\u5408\u7ED3\u679C\u3002`);
|
|
7230
7308
|
}
|
|
@@ -12610,24 +12688,24 @@ function normalizeTypedReadbackComparable(domain, value) {
|
|
|
12610
12688
|
}
|
|
12611
12689
|
function jsonSubsetMismatches(expected, actual) {
|
|
12612
12690
|
const mismatches = [];
|
|
12613
|
-
const compare = (left, right,
|
|
12691
|
+
const compare = (left, right, path20 = "") => {
|
|
12614
12692
|
if (Array.isArray(left)) {
|
|
12615
12693
|
if (!Array.isArray(right) || left.length !== right.length) {
|
|
12616
|
-
mismatches.push(
|
|
12694
|
+
mismatches.push(path20 || "/");
|
|
12617
12695
|
return;
|
|
12618
12696
|
}
|
|
12619
|
-
left.forEach((item, index) => compare(item, right[index], `${
|
|
12697
|
+
left.forEach((item, index) => compare(item, right[index], `${path20}/${index}`));
|
|
12620
12698
|
return;
|
|
12621
12699
|
}
|
|
12622
12700
|
if (isRecord4(left)) {
|
|
12623
12701
|
if (!isRecord4(right)) {
|
|
12624
|
-
mismatches.push(
|
|
12702
|
+
mismatches.push(path20 || "/");
|
|
12625
12703
|
return;
|
|
12626
12704
|
}
|
|
12627
|
-
for (const [key, item] of Object.entries(left)) compare(item, right[key], `${
|
|
12705
|
+
for (const [key, item] of Object.entries(left)) compare(item, right[key], `${path20}/${key}`);
|
|
12628
12706
|
return;
|
|
12629
12707
|
}
|
|
12630
|
-
if (JSON.stringify(left) !== JSON.stringify(right)) mismatches.push(
|
|
12708
|
+
if (JSON.stringify(left) !== JSON.stringify(right)) mismatches.push(path20 || "/");
|
|
12631
12709
|
};
|
|
12632
12710
|
compare(expected, actual);
|
|
12633
12711
|
return mismatches;
|
|
@@ -13493,7 +13571,11 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
13493
13571
|
if (flowCategoryReferenceAudit.errors.length) {
|
|
13494
13572
|
throw new Error(`flow-template category reference gate failed: ${flowCategoryReferenceAudit.errors.join("; ")}`);
|
|
13495
13573
|
}
|
|
13496
|
-
stepDetailReferenceAudit = await auditFlowStepDetailReferences(
|
|
13574
|
+
stepDetailReferenceAudit = await auditFlowStepDetailReferences(
|
|
13575
|
+
work,
|
|
13576
|
+
options.pluginLint.profile,
|
|
13577
|
+
isRecord4(raw) ? raw : void 0
|
|
13578
|
+
);
|
|
13497
13579
|
if (stepDetailReferenceAudit.errors.length) {
|
|
13498
13580
|
throw new Error(`flow-template step-detail reference gate failed: ${stepDetailReferenceAudit.errors.join("; ")}`);
|
|
13499
13581
|
}
|
|
@@ -13711,6 +13793,7 @@ function hasPotentialFlowTemplatePluginExtension(flowWork) {
|
|
|
13711
13793
|
}
|
|
13712
13794
|
async function lintConfigWorkFile(file, options = {}) {
|
|
13713
13795
|
const value = await readJsonFile(file);
|
|
13796
|
+
const flowTemplateBaseline = options.domain === "flow-template" ? await inferFlowTemplateBaselineFromWorkFile(file) : void 0;
|
|
13714
13797
|
const errors = [];
|
|
13715
13798
|
const warnings = [];
|
|
13716
13799
|
let pluginLint;
|
|
@@ -13791,7 +13874,7 @@ async function lintConfigWorkFile(file, options = {}) {
|
|
|
13791
13874
|
if (profile) {
|
|
13792
13875
|
flowCategoryReferenceAudit = await auditFlowCategoryReference(flowWork, profile);
|
|
13793
13876
|
errors.push(...flowCategoryReferenceAudit.errors.filter((error) => !errors.includes(error)));
|
|
13794
|
-
stepDetailReferenceAudit = await auditFlowStepDetailReferences(flowWork, profile);
|
|
13877
|
+
stepDetailReferenceAudit = await auditFlowStepDetailReferences(flowWork, profile, flowTemplateBaseline);
|
|
13795
13878
|
errors.push(...stepDetailReferenceAudit.errors.filter((error) => !errors.includes(error)));
|
|
13796
13879
|
warnings.push(...stepDetailReferenceAudit.warnings);
|
|
13797
13880
|
flowReportReferenceAudit = await auditFlowReportReferences(flowWork, profile);
|
|
@@ -14348,7 +14431,11 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
14348
14431
|
if (flowCategoryReferenceAudit.errors.length) {
|
|
14349
14432
|
throw new Error(`flow-template category reference gate failed: ${flowCategoryReferenceAudit.errors.join("; ")}`);
|
|
14350
14433
|
}
|
|
14351
|
-
stepDetailReferenceAudit = await auditFlowStepDetailReferences(
|
|
14434
|
+
stepDetailReferenceAudit = await auditFlowStepDetailReferences(
|
|
14435
|
+
submit.payload,
|
|
14436
|
+
profile,
|
|
14437
|
+
await readFlowTemplateBaselineFromMeta(submit.meta)
|
|
14438
|
+
);
|
|
14352
14439
|
if (stepDetailReferenceAudit.errors.length) {
|
|
14353
14440
|
throw new Error(`flow-template step-detail reference gate failed: ${stepDetailReferenceAudit.errors.join("; ")}`);
|
|
14354
14441
|
}
|
|
@@ -17859,9 +17946,9 @@ function registerConfigCommands(program2) {
|
|
|
17859
17946
|
}
|
|
17860
17947
|
|
|
17861
17948
|
// src/commands/e2e.ts
|
|
17862
|
-
import { createHash as
|
|
17863
|
-
import { mkdir as
|
|
17864
|
-
import
|
|
17949
|
+
import { createHash as createHash8 } from "crypto";
|
|
17950
|
+
import { mkdir as mkdir12, readFile as readFile16, readdir as readdir5, stat as stat9, writeFile as writeFile12 } from "fs/promises";
|
|
17951
|
+
import path15 from "path";
|
|
17865
17952
|
import axios7 from "axios";
|
|
17866
17953
|
|
|
17867
17954
|
// src/core/e2e-browser-runner.ts
|
|
@@ -18170,7 +18257,7 @@ var PRIORITIES = /* @__PURE__ */ new Set(["P0", "P1", "P2"]);
|
|
|
18170
18257
|
var CASE_TYPES = /* @__PURE__ */ new Set(["positive", "negative", "boundary", "permission", "data_consistency", "regression"]);
|
|
18171
18258
|
var STATUSES = /* @__PURE__ */ new Set(["active", "deprecated", "draft"]);
|
|
18172
18259
|
var CASE_STEP_RUNNERS = /* @__PURE__ */ new Set(["browser", "browser_action", "identity", "e2e_create_page", "e2e_step_run", "observe"]);
|
|
18173
|
-
var IDENTITY_STEP_RE = /(
|
|
18260
|
+
var IDENTITY_STEP_RE = /(?:切换|恢复|检查|核对|验证|确认|读取).{0,12}(?:身份|用户|管理员)|(?:mock|unmock|模拟用户)/i;
|
|
18174
18261
|
var CASE_STEP_ACTION_VERBS = [
|
|
18175
18262
|
"\u6253\u5F00",
|
|
18176
18263
|
"\u8FDB\u5165",
|
|
@@ -18270,9 +18357,18 @@ var YBS_NONZERO_DETAIL_RE = /https:\/\/yaditest\.yitaiyitai\.com\/w:ybs\/project
|
|
|
18270
18357
|
var YBS_PC_CREATE_WRONG_RE = /https:\/\/yaditest\.yitaiyitai\.com\/w:ybs\/pages\/projectCreate\/projectCreate\?flow_type=/;
|
|
18271
18358
|
var IDENTITY_MOCK_CASE_RE = /(非处理人|越权|只读|多角色|角色隔离|无权限|低权限|unauthorized|limited|readonly|permission)/;
|
|
18272
18359
|
var IDENTITY_MOCK_VALUE_RE = /(mock|模拟).*(unmock|退出模拟|恢复)|bpmax-user-mock-operator/;
|
|
18360
|
+
var IDENTITY_BROWSER_BRIDGE_RE = /(identity_transport\s*=\s*chrome_bridge|chrome identity bridge|Chrome Control 身份桥|浏览器身份桥)/i;
|
|
18361
|
+
var IDENTITY_COOKIE_TRANSPORT_RE = /(BPMAX_COOKIE_HEADER|cookie[_ -]?env|cookie transport|导出.*Cookie|复制.*Cookie)/i;
|
|
18273
18362
|
var E2E_REUSABLE_ASSET_RE = /bpmax-cli\s+e2e|record-from-evidence|create-page-submit|step-run|browser-template|scenario\s+plan|data\s+profile|reusable\s+step|复用模板|可复用|首次运行沉淀|沉淀模板/;
|
|
18274
18363
|
var ERROR_CAPTURE_CASE_RE = /(negative|boundary|异常|错误|失败|报错|无效|非法|invalid|error|扫码.*(异常|错误|无效)|错误\s*SN|异常\s*SN|无效\s*SN)/i;
|
|
18275
18364
|
var ERROR_CAPTURE_EVIDENCE_RE = /(expected_error_text|error_capture_required|错误提示|提示文案|报错文案|toast|校验文案).*(screenshot|截图)|截图.*(错误提示|提示文案|报错文案|toast|校验文案)/i;
|
|
18365
|
+
function identityStepOperation(step) {
|
|
18366
|
+
const text5 = [step.action, step.target, step.input_data, step.expected_result].join(" ");
|
|
18367
|
+
if (/(unmock|退出模拟|恢复原始|恢复管理员)/i.test(text5)) return "unmock";
|
|
18368
|
+
if (/(status|当前身份|身份回读|(?:确认|检查|读取|核对).{0,8}身份)/i.test(text5)) return "status";
|
|
18369
|
+
if (/(mock|模拟用户|切换.{0,8}(?:身份|用户))/i.test(text5)) return "mock";
|
|
18370
|
+
return null;
|
|
18371
|
+
}
|
|
18276
18372
|
var BROWSER_TOOL_RE = /(Chrome Control|chrome:control-chrome|Chrome DevTools|DevTools|Playwright|AppleScript)/i;
|
|
18277
18373
|
var REPORT_EVIDENCE_PLACEHOLDER_RE = /^(?:n\/?a|none|null|todo|tbd|xxx|unknown|pending|待补|暂无|无|未执行|跳过|-+)$/i;
|
|
18278
18374
|
var LIVE_DRAFT_RE = /(live|draft|已发布|草稿|发布态|live_draft=)/i;
|
|
@@ -18864,16 +18960,16 @@ function validateCaseSteps(filePath, cases, steps) {
|
|
|
18864
18960
|
if (step.runner === "e2e_step_run" && !/(context|submit|readback|step)/i.test(step.evidence_required)) {
|
|
18865
18961
|
fail(`${location}: e2e_step_run \u6B65\u9AA4\u5FC5\u987B\u8981\u6C42 context/submit/readback \u8BC1\u636E`, { rule_id: "test_suite.case_step.cli_evidence", path: filePath });
|
|
18866
18962
|
}
|
|
18867
|
-
const
|
|
18868
|
-
if (step.runner
|
|
18869
|
-
fail(`${location}: identity
|
|
18963
|
+
const identityOperation = identityStepOperation(step);
|
|
18964
|
+
if (step.runner !== "identity" && identityOperation) {
|
|
18965
|
+
fail(`${location}: identity ${identityOperation} \u4E0D\u80FD\u58F0\u660E\u4E3A runner=${step.runner}\uFF1B\u8BF7\u4F7F\u7528 runner=identity`, {
|
|
18870
18966
|
rule_id: "test_suite.case_step.identity_runner",
|
|
18871
18967
|
path: filePath,
|
|
18872
18968
|
suggestion: "Set runner=identity and require identity operation plus readback evidence."
|
|
18873
18969
|
});
|
|
18874
18970
|
}
|
|
18875
18971
|
if (step.runner === "identity") {
|
|
18876
|
-
if (!
|
|
18972
|
+
if (!identityOperation) {
|
|
18877
18973
|
fail(`${location}: runner=identity \u53EA\u80FD\u7528\u4E8E\u8EAB\u4EFD mock/status/unmock \u6B65\u9AA4`, {
|
|
18878
18974
|
rule_id: "test_suite.case_step.identity_action",
|
|
18879
18975
|
path: filePath
|
|
@@ -18885,6 +18981,25 @@ function validateCaseSteps(filePath, cases, steps) {
|
|
|
18885
18981
|
path: filePath
|
|
18886
18982
|
});
|
|
18887
18983
|
}
|
|
18984
|
+
const identityContractText = [step.input_data, step.evidence_required].join(" ");
|
|
18985
|
+
if (!IDENTITY_BROWSER_BRIDGE_RE.test(identityContractText)) {
|
|
18986
|
+
fail(`${location}: \u6B63\u5F0F identity \u6B65\u9AA4\u5FC5\u987B\u5728 input_data \u58F0\u660E identity_transport=chrome_bridge\uFF0C\u5E76\u7531 Chrome Control \u8EAB\u4EFD\u6865\u6267\u884C`, {
|
|
18987
|
+
rule_id: "test_suite.case_step.identity_browser_bridge",
|
|
18988
|
+
path: filePath
|
|
18989
|
+
});
|
|
18990
|
+
}
|
|
18991
|
+
if (IDENTITY_COOKIE_TRANSPORT_RE.test(identityContractText)) {
|
|
18992
|
+
fail(`${location}: \u6B63\u5F0F identity \u6B65\u9AA4\u7981\u6B62 Cookie transport\uFF1B\u4E0D\u5F97\u5BFC\u51FA\u6216\u590D\u5236\u6D4F\u89C8\u5668 Cookie`, {
|
|
18993
|
+
rule_id: "test_suite.case_step.identity_cookie_transport",
|
|
18994
|
+
path: filePath
|
|
18995
|
+
});
|
|
18996
|
+
}
|
|
18997
|
+
if (!/screenshot|截图/i.test(step.evidence_required)) {
|
|
18998
|
+
fail(`${location}: identity \u6B65\u9AA4\u5FC5\u987B\u8981\u6C42\u672C\u8F6E Chrome \u8EAB\u4EFD\u622A\u56FE`, {
|
|
18999
|
+
rule_id: "test_suite.case_step.identity_screenshot",
|
|
19000
|
+
path: filePath
|
|
19001
|
+
});
|
|
19002
|
+
}
|
|
18888
19003
|
}
|
|
18889
19004
|
const values = grouped.get(caseId) ?? [];
|
|
18890
19005
|
values.push(step);
|
|
@@ -18901,6 +19016,48 @@ function validateCaseSteps(filePath, cases, steps) {
|
|
|
18901
19016
|
fail(`${filePath}:${row.case_id}: step_no \u5FC5\u987B\u4ECE 1 \u5F00\u59CB\u8FDE\u7EED\u9012\u589E`, { rule_id: "test_suite.case_step.sequence", path: filePath });
|
|
18902
19017
|
}
|
|
18903
19018
|
});
|
|
19019
|
+
let statusReady = false;
|
|
19020
|
+
let activeMock = null;
|
|
19021
|
+
for (const step of caseSteps.filter((item) => item.runner === "identity")) {
|
|
19022
|
+
const operation = identityStepOperation(step);
|
|
19023
|
+
if (operation === "status") {
|
|
19024
|
+
statusReady = true;
|
|
19025
|
+
continue;
|
|
19026
|
+
}
|
|
19027
|
+
if (operation === "mock") {
|
|
19028
|
+
if (!statusReady) {
|
|
19029
|
+
fail(`${filePath}:${row.case_id}:${step.step_id}: mock \u524D\u5FC5\u987B\u6709\u672C\u8F6E\u72EC\u7ACB identity status \u6B65\u9AA4`, {
|
|
19030
|
+
rule_id: "test_suite.case_step.identity_status_before_mock",
|
|
19031
|
+
path: filePath
|
|
19032
|
+
});
|
|
19033
|
+
}
|
|
19034
|
+
if (activeMock) {
|
|
19035
|
+
fail(`${filePath}:${row.case_id}:${step.step_id}: \u524D\u4E00\u4E2A mock ${activeMock.step_id} \u5C1A\u672A unmock\uFF0C\u7981\u6B62\u53E0\u52A0\u8EAB\u4EFD\u79DF\u7EA6`, {
|
|
19036
|
+
rule_id: "test_suite.case_step.identity_nested_mock",
|
|
19037
|
+
path: filePath
|
|
19038
|
+
});
|
|
19039
|
+
}
|
|
19040
|
+
activeMock = step;
|
|
19041
|
+
statusReady = false;
|
|
19042
|
+
continue;
|
|
19043
|
+
}
|
|
19044
|
+
if (operation === "unmock") {
|
|
19045
|
+
if (!activeMock) {
|
|
19046
|
+
fail(`${filePath}:${row.case_id}:${step.step_id}: unmock \u5FC5\u987B\u5BF9\u5E94\u5F53\u524D\u7528\u4F8B\u4E2D\u66F4\u65E9\u7684 mock \u6B65\u9AA4`, {
|
|
19047
|
+
rule_id: "test_suite.case_step.identity_unmock_without_mock",
|
|
19048
|
+
path: filePath
|
|
19049
|
+
});
|
|
19050
|
+
}
|
|
19051
|
+
activeMock = null;
|
|
19052
|
+
statusReady = false;
|
|
19053
|
+
}
|
|
19054
|
+
}
|
|
19055
|
+
if (activeMock) {
|
|
19056
|
+
fail(`${filePath}:${row.case_id}:${activeMock.step_id}: \u6BCF\u4E2A mock \u5FC5\u987B\u5728\u7528\u4F8B\u7ED3\u675F\u524D\u6709\u540E\u7EED identity unmock \u6B65\u9AA4`, {
|
|
19057
|
+
rule_id: "test_suite.case_step.identity_unmock_required",
|
|
19058
|
+
path: filePath
|
|
19059
|
+
});
|
|
19060
|
+
}
|
|
18904
19061
|
grouped.set(row.case_id.trim(), caseSteps);
|
|
18905
19062
|
}
|
|
18906
19063
|
return grouped;
|
|
@@ -19318,11 +19475,12 @@ async function evidenceJsonRecords(evidencePath) {
|
|
|
19318
19475
|
}
|
|
19319
19476
|
return records;
|
|
19320
19477
|
}
|
|
19321
|
-
async function browserEvidenceScreenshots(manifest, manifestPath, step, evidencePath, expectedResult = "pass") {
|
|
19478
|
+
async function browserEvidenceScreenshots(manifest, manifestPath, step, evidencePath, expectedResult = "pass", recordFilter) {
|
|
19322
19479
|
const jsonRecords = await evidenceJsonRecords(evidencePath);
|
|
19323
19480
|
const screenshotPaths = [];
|
|
19324
19481
|
let matchedRecord = false;
|
|
19325
19482
|
for (const { value, source } of jsonRecords) {
|
|
19483
|
+
if (recordFilter && !recordFilter(value)) continue;
|
|
19326
19484
|
if (value.browser_verified !== true) continue;
|
|
19327
19485
|
if (value.case_id !== step.case_id || value.case_step_id !== step.step_id) continue;
|
|
19328
19486
|
const runtimeUrl = typeof value.runtime_url === "string" ? value.runtime_url.trim() : "";
|
|
@@ -19412,7 +19570,8 @@ async function hasStructuredTerminalEvidence(manifest, step, evidencePath, resul
|
|
|
19412
19570
|
if (result === "blocked") return hasStructuredBlockedEvidence(manifest, step, evidencePath);
|
|
19413
19571
|
for (const { value, source } of await evidenceJsonRecords(evidencePath)) {
|
|
19414
19572
|
if (value.case_id !== step.case_id || value.case_step_id !== step.step_id) continue;
|
|
19415
|
-
|
|
19573
|
+
const terminalStatus = String(value.status || value.result || "").toLowerCase();
|
|
19574
|
+
if (value.failed !== true && !["fail", "failed", "error"].includes(terminalStatus)) continue;
|
|
19416
19575
|
const failure = asRecord(value.failure);
|
|
19417
19576
|
const error = asRecord(value.error);
|
|
19418
19577
|
const detail = Object.keys(failure).length > 0 ? failure : error;
|
|
@@ -19446,7 +19605,7 @@ async function browserReportEvidence(manifest) {
|
|
|
19446
19605
|
const result = { assertions: [], screenshots: [] };
|
|
19447
19606
|
const priority = { page: 1, project: 2, step: 3 };
|
|
19448
19607
|
for (const step of manifest.steps) {
|
|
19449
|
-
if (step.status === "planned" || !["browser", "browser_action", "e2e_create_page"].includes(step.runner)) continue;
|
|
19608
|
+
if (step.status === "planned" || !["browser", "browser_action", "e2e_create_page", "identity"].includes(step.runner)) continue;
|
|
19450
19609
|
for (const evidencePath of step.evidence) {
|
|
19451
19610
|
for (const { value, source } of await evidenceJsonRecords(evidencePath)) {
|
|
19452
19611
|
if (value.case_id !== step.case_id || value.case_step_id !== step.step_id || value.browser_verified !== true) continue;
|
|
@@ -19454,13 +19613,18 @@ async function browserReportEvidence(manifest) {
|
|
|
19454
19613
|
if (!["page", "project", "step"].includes(scope)) continue;
|
|
19455
19614
|
const environment = String(value.runtime_environment || "profile");
|
|
19456
19615
|
if (!["profile", "local-browser"].includes(environment)) continue;
|
|
19457
|
-
if (!result.scope || priority[scope] >= priority[result.scope]) {
|
|
19616
|
+
if (step.runner !== "identity" && (!result.scope || priority[scope] >= priority[result.scope])) {
|
|
19458
19617
|
result.scope = scope;
|
|
19459
19618
|
result.environment = environment;
|
|
19460
19619
|
result.runtimeUrl = String(value.runtime_url || "").trim() || result.runtimeUrl;
|
|
19461
19620
|
result.browserTool = String(value.browser_tool || "").trim() || result.browserTool;
|
|
19462
19621
|
result.projectId = String(value.project_id ?? "").trim() || void 0;
|
|
19463
19622
|
result.stepId = String(value.step_id ?? "").trim() || void 0;
|
|
19623
|
+
} else if (step.runner === "identity" && !result.scope) {
|
|
19624
|
+
result.scope = scope;
|
|
19625
|
+
result.environment = environment;
|
|
19626
|
+
result.runtimeUrl = String(value.runtime_url || "").trim() || result.runtimeUrl;
|
|
19627
|
+
result.browserTool = String(value.browser_tool || "").trim() || result.browserTool;
|
|
19464
19628
|
}
|
|
19465
19629
|
const assertions = Array.isArray(value.assertions) ? value.assertions.map(asRecord) : [];
|
|
19466
19630
|
for (const assertion of assertions) {
|
|
@@ -19549,7 +19713,7 @@ async function previousBrowserScreenshotHashes(manifest, step) {
|
|
|
19549
19713
|
const hashes = /* @__PURE__ */ new Set();
|
|
19550
19714
|
for (const previous of manifest.steps) {
|
|
19551
19715
|
if (previous.step_no === step.step_no) break;
|
|
19552
|
-
if (previous.status !== "pass" || !["browser", "browser_action", "e2e_create_page"].includes(previous.runner)) continue;
|
|
19716
|
+
if (previous.status !== "pass" || !["browser", "browser_action", "e2e_create_page", "identity"].includes(previous.runner)) continue;
|
|
19553
19717
|
for (const previousEvidence of previous.evidence) {
|
|
19554
19718
|
for (const { value, source } of await evidenceJsonRecords(previousEvidence)) {
|
|
19555
19719
|
const screenshot = typeof value.screenshot === "string" ? value.screenshot.trim() : "";
|
|
@@ -19572,22 +19736,49 @@ async function assertFormalExecutionEvidence(manifest, manifestPath, step, evide
|
|
|
19572
19736
|
fail("e2e_step_run pass evidence must prove a confirmed submitted operation", { rule_id: "test_suite.run.unexecuted_evidence", path: evidencePath });
|
|
19573
19737
|
}
|
|
19574
19738
|
if (step.runner === "identity") {
|
|
19739
|
+
const expectedIdentityOperation = identityStepOperation(step);
|
|
19575
19740
|
const validIdentityEvidence = jsonRecords.some(({ value }) => {
|
|
19741
|
+
if (value.case_id !== step.case_id || value.case_step_id !== step.step_id || value.transport !== "chrome_identity_bridge" || value.browser_tool !== "chrome:control-chrome" || value.browser_verified !== true || value.readback_confirmed !== true) {
|
|
19742
|
+
return false;
|
|
19743
|
+
}
|
|
19744
|
+
const assertions = Array.isArray(value.assertions) ? value.assertions.map(asRecord).filter((assertion) => Object.keys(assertion).length > 0) : [];
|
|
19745
|
+
if (assertions.length === 0 || assertions.some((assertion) => assertion.passed !== true)) return false;
|
|
19576
19746
|
const operation = String(value.operation || "").toLowerCase();
|
|
19747
|
+
if (!expectedIdentityOperation || operation !== expectedIdentityOperation) return false;
|
|
19577
19748
|
if (operation === "status") {
|
|
19578
|
-
return ["observed", "verified"].includes(String(value.result || value.status || "").toLowerCase()) && Object.keys(asRecord(value.current_user)).length > 0;
|
|
19749
|
+
return ["observed", "verified"].includes(String(value.result || value.status || "").toLowerCase()) && value.mutation_attempted !== true && value.operation_executed === false && value.remote_submitted === false && Object.keys(asRecord(value.current_user)).length > 0;
|
|
19579
19750
|
}
|
|
19580
19751
|
if (operation === "mock" || operation === "unmock") {
|
|
19581
|
-
|
|
19752
|
+
const currentUser = asRecord(value.current_user);
|
|
19753
|
+
return value.operation_executed === true && value.mutation_attempted === true && value.remote_submitted === true && value.readback_confirmed === true && (operation === "mock" ? currentUser.mock === true : currentUser.mock === false);
|
|
19582
19754
|
}
|
|
19583
19755
|
return false;
|
|
19584
19756
|
});
|
|
19585
19757
|
if (!validIdentityEvidence) {
|
|
19586
|
-
fail("identity pass evidence must
|
|
19758
|
+
fail("identity pass evidence must use the Chrome identity bridge and include browser_verified=true, a matching case/step, passed assertions, screenshot, and confirmed status/mock/unmock readback", {
|
|
19587
19759
|
rule_id: "test_suite.run.unexecuted_evidence",
|
|
19588
19760
|
path: evidencePath
|
|
19589
19761
|
});
|
|
19590
19762
|
}
|
|
19763
|
+
const screenshots = await browserEvidenceScreenshots(
|
|
19764
|
+
manifest,
|
|
19765
|
+
manifestPath,
|
|
19766
|
+
step,
|
|
19767
|
+
evidencePath,
|
|
19768
|
+
"pass",
|
|
19769
|
+
(value) => value.transport === "chrome_identity_bridge" && value.browser_tool === "chrome:control-chrome"
|
|
19770
|
+
);
|
|
19771
|
+
if (identityStepOperation(step) !== "unmock") {
|
|
19772
|
+
const previousHashes = await previousBrowserScreenshotHashes(manifest, step);
|
|
19773
|
+
for (const screenshot of screenshots) {
|
|
19774
|
+
if (previousHashes.has(await sha256(screenshot))) {
|
|
19775
|
+
fail("identity pass evidence reuses an identical screenshot from an earlier step in this run", {
|
|
19776
|
+
rule_id: "test_suite.run.duplicate_screenshot",
|
|
19777
|
+
path: screenshot
|
|
19778
|
+
});
|
|
19779
|
+
}
|
|
19780
|
+
}
|
|
19781
|
+
}
|
|
19591
19782
|
}
|
|
19592
19783
|
if (step.runner === "browser" || step.runner === "browser_action" || step.runner === "e2e_create_page") {
|
|
19593
19784
|
const screenshots = await browserEvidenceScreenshots(manifest, manifestPath, step, evidencePath);
|
|
@@ -19623,6 +19814,57 @@ async function assertFormalExecutionEvidence(manifest, manifestPath, step, evide
|
|
|
19623
19814
|
if (!validObservation) fail("observe pass evidence must include only passed assertions and an existing source_evidence artifact", { rule_id: "test_suite.run.unexecuted_evidence", path: evidencePath });
|
|
19624
19815
|
}
|
|
19625
19816
|
}
|
|
19817
|
+
async function assertIdentityLeaseForRecordedStep(manifestPath, step) {
|
|
19818
|
+
if (step.runner !== "identity") return;
|
|
19819
|
+
const operation = identityStepOperation(step);
|
|
19820
|
+
if (operation !== "mock" && operation !== "unmock") return;
|
|
19821
|
+
const leasePath = path12.join(path12.dirname(path12.resolve(manifestPath)), "identity-lease.json");
|
|
19822
|
+
if (!await exists3(leasePath)) {
|
|
19823
|
+
fail(`${operation} pass evidence requires the current-run identity lease`, {
|
|
19824
|
+
rule_id: "test_suite.run.identity_lease_missing",
|
|
19825
|
+
path: leasePath
|
|
19826
|
+
});
|
|
19827
|
+
}
|
|
19828
|
+
let lease;
|
|
19829
|
+
try {
|
|
19830
|
+
lease = asRecord(JSON.parse(await readText(leasePath)));
|
|
19831
|
+
} catch (error) {
|
|
19832
|
+
fail(`identity lease is invalid: ${error instanceof Error ? error.message : String(error)}`, {
|
|
19833
|
+
rule_id: "test_suite.run.identity_lease_invalid",
|
|
19834
|
+
path: leasePath
|
|
19835
|
+
});
|
|
19836
|
+
}
|
|
19837
|
+
const expectedState = operation === "mock" ? "active" : "released";
|
|
19838
|
+
if (lease.state !== expectedState) {
|
|
19839
|
+
fail(`${operation} pass evidence requires identity lease state=${expectedState}, got ${String(lease.state || "<missing>")}`, {
|
|
19840
|
+
rule_id: "test_suite.run.identity_lease_state",
|
|
19841
|
+
path: leasePath
|
|
19842
|
+
});
|
|
19843
|
+
}
|
|
19844
|
+
if (lease.browser_tool !== "chrome:control-chrome") {
|
|
19845
|
+
fail(`${operation} pass evidence requires a Chrome Control identity lease`, {
|
|
19846
|
+
rule_id: "test_suite.run.identity_lease_tool",
|
|
19847
|
+
path: leasePath
|
|
19848
|
+
});
|
|
19849
|
+
}
|
|
19850
|
+
const binding = asRecord(operation === "mock" ? lease.binding : lease.release_binding);
|
|
19851
|
+
const expectedManifest = path12.resolve(manifestPath);
|
|
19852
|
+
const actualManifest = typeof binding.execution_manifest === "string" ? path12.resolve(binding.execution_manifest) : "";
|
|
19853
|
+
if (binding.case_id !== step.case_id || binding.case_step_id !== step.step_id || binding.profile !== (await readExecutionManifest(manifestPath)).profile || actualManifest !== expectedManifest) {
|
|
19854
|
+
fail(`${operation} identity lease does not match the current manifest/case/step/profile`, {
|
|
19855
|
+
rule_id: "test_suite.run.identity_lease_binding",
|
|
19856
|
+
path: leasePath
|
|
19857
|
+
});
|
|
19858
|
+
}
|
|
19859
|
+
const recoveryRequired = lease.recovery_required === true;
|
|
19860
|
+
if (operation === "mock" && !recoveryRequired || operation === "unmock" && recoveryRequired) {
|
|
19861
|
+
fail(`${operation} identity lease recovery_required state is inconsistent`, {
|
|
19862
|
+
rule_id: "test_suite.run.identity_lease_recovery",
|
|
19863
|
+
path: leasePath
|
|
19864
|
+
});
|
|
19865
|
+
}
|
|
19866
|
+
await assertCurrentRunArtifact(await readExecutionManifest(manifestPath), leasePath);
|
|
19867
|
+
}
|
|
19626
19868
|
async function writeExecutionManifest(manifestPath, manifest, incrementRevision = false) {
|
|
19627
19869
|
if (incrementRevision) manifest.revision = (manifest.revision ?? 0) + 1;
|
|
19628
19870
|
else manifest.revision ??= 0;
|
|
@@ -19845,7 +20087,10 @@ async function recordTestSuiteRunStep(options) {
|
|
|
19845
20087
|
const validated = await validateExecutionManifestStep(options);
|
|
19846
20088
|
const evidencePath = path12.resolve(options.evidence);
|
|
19847
20089
|
await assertCurrentRunEvidence(validated.manifest, validated.manifestPath, evidencePath);
|
|
19848
|
-
if (options.result === "pass")
|
|
20090
|
+
if (options.result === "pass") {
|
|
20091
|
+
await assertFormalExecutionEvidence(validated.manifest, validated.manifestPath, validated.step, evidencePath);
|
|
20092
|
+
await assertIdentityLeaseForRecordedStep(validated.manifestPath, validated.step);
|
|
20093
|
+
}
|
|
19849
20094
|
if (options.result !== "pass" && !["browser", "browser_action", "e2e_create_page"].includes(validated.step.runner)) {
|
|
19850
20095
|
if (!await hasStructuredTerminalEvidence(validated.manifest, validated.step, evidencePath, options.result)) {
|
|
19851
20096
|
fail("non-browser fail/blocked evidence must identify the current case/step and include structured failure.kind/message or blocker.kind/message", {
|
|
@@ -21061,6 +21306,37 @@ async function lintReport(root = DEFAULT_REPORT_ROOT, options = {}) {
|
|
|
21061
21306
|
errors.push(`[test_suite.report.diagnostic_evidence] ${reportPath}: diagnostic \u8BC1\u636E\u4E0D\u80FD\u8FDB\u5165\u5B8C\u6574 E2E \u901A\u8FC7\u62A5\u544A`);
|
|
21062
21307
|
}
|
|
21063
21308
|
}
|
|
21309
|
+
const identityMockSteps = manifest.steps.filter((step) => step.runner === "identity" && identityStepOperation(step) === "mock");
|
|
21310
|
+
const identityLeasePath = path12.join(runDir, "identity-lease.json");
|
|
21311
|
+
if (await exists3(identityLeasePath)) {
|
|
21312
|
+
try {
|
|
21313
|
+
const identityLease = asRecord(JSON.parse(await readText(identityLeasePath)));
|
|
21314
|
+
const leaseState = String(identityLease.state || "");
|
|
21315
|
+
if (leaseState === "active" || leaseState === "uncertain") {
|
|
21316
|
+
errors.push(`[test_suite.report.identity_lease_open] ${reportPath}: identity lease \u4ECD\u4E3A ${leaseState}\uFF0C\u5FC5\u987B\u5148\u6062\u590D\u539F\u59CB\u8EAB\u4EFD\u5E76\u786E\u8BA4 released`);
|
|
21317
|
+
}
|
|
21318
|
+
if (reportClaimsCompleteResult(resultValue) && identityMockSteps.length > 0 && leaseState !== "released") {
|
|
21319
|
+
errors.push(`[test_suite.report.identity_lease_not_released] ${reportPath}: \u591A\u8EAB\u4EFD\u5B8C\u6574\u901A\u8FC7\u8981\u6C42 identity lease state=released\uFF0C\u5F53\u524D\u4E3A ${leaseState || "<missing>"}`);
|
|
21320
|
+
}
|
|
21321
|
+
if (reportClaimsCompleteResult(resultValue) && identityMockSteps.length > 0 && leaseState === "released") {
|
|
21322
|
+
const lastMockStep = identityMockSteps.at(-1);
|
|
21323
|
+
const lastUnmockStep = manifest.steps.filter((step) => step.runner === "identity" && identityStepOperation(step) === "unmock").at(-1);
|
|
21324
|
+
const mockBinding = asRecord(identityLease.binding);
|
|
21325
|
+
const releaseBinding = asRecord(identityLease.release_binding);
|
|
21326
|
+
const bindingMatches = (binding, step) => {
|
|
21327
|
+
if (!step || typeof binding.execution_manifest !== "string") return false;
|
|
21328
|
+
return path12.resolve(binding.execution_manifest) === path12.resolve(manifestPath) && binding.profile === manifest.profile && binding.case_id === step.case_id && binding.case_step_id === step.step_id;
|
|
21329
|
+
};
|
|
21330
|
+
if (identityLease.kind !== "bpmax_identity_lease" || identityLease.schema_version !== 1 || identityLease.browser_tool !== "chrome:control-chrome" || identityLease.recovery_required !== false || !bindingMatches(mockBinding, lastMockStep) || !bindingMatches(releaseBinding, lastUnmockStep)) {
|
|
21331
|
+
errors.push(`[test_suite.report.identity_lease_binding] ${reportPath}: released identity lease \u5FC5\u987B\u7ED1\u5B9A\u672C\u8F6E\u6700\u540E\u4E00\u6B21 mock/unmock\u3001\u5F53\u524D profile \u548C execution manifest`);
|
|
21332
|
+
}
|
|
21333
|
+
}
|
|
21334
|
+
} catch (error) {
|
|
21335
|
+
errors.push(`[test_suite.report.identity_lease_invalid] ${reportPath}: identity lease \u65E0\u6CD5\u89E3\u6790: ${error instanceof Error ? error.message : String(error)}`);
|
|
21336
|
+
}
|
|
21337
|
+
} else if (reportClaimsCompleteResult(resultValue) && identityMockSteps.length > 0) {
|
|
21338
|
+
errors.push(`[test_suite.report.identity_lease_missing] ${reportPath}: \u591A\u8EAB\u4EFD\u5B8C\u6574\u901A\u8FC7\u7F3A\u5C11\u672C\u8F6E identity-lease.json`);
|
|
21339
|
+
}
|
|
21064
21340
|
} catch (error) {
|
|
21065
21341
|
errors.push(`[test_suite.report.execution_manifest_invalid] ${reportPath}: execution_manifest \u65E0\u6CD5\u89E3\u6790: ${error instanceof Error ? error.message : String(error)}`);
|
|
21066
21342
|
}
|
|
@@ -21858,6 +22134,563 @@ async function runBrowserAutomation(options) {
|
|
|
21858
22134
|
}
|
|
21859
22135
|
}
|
|
21860
22136
|
|
|
22137
|
+
// src/core/e2e-identity-bridge.ts
|
|
22138
|
+
import { createHash as createHash7, randomUUID as randomUUID4 } from "crypto";
|
|
22139
|
+
import { chmod as chmod2, lstat, mkdir as mkdir11, readFile as readFile15, realpath as realpath3, rename as rename2, stat as stat8, unlink as unlink2, writeFile as writeFile11 } from "fs/promises";
|
|
22140
|
+
import path14 from "path";
|
|
22141
|
+
var REQUEST_TTL_SECONDS = 180;
|
|
22142
|
+
var RESULT_MAX_DURATION_MS = 15 * 60 * 1e3;
|
|
22143
|
+
var COMPLETION_CLAIM_TTL_MS = 5 * 60 * 1e3;
|
|
22144
|
+
var DEFAULT_LEASE_TTL_SECONDS = 900;
|
|
22145
|
+
var MIN_LEASE_TTL_SECONDS = 60;
|
|
22146
|
+
var MAX_LEASE_TTL_SECONDS = 3600;
|
|
22147
|
+
function isRecord10(value) {
|
|
22148
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22149
|
+
}
|
|
22150
|
+
function stringValue3(value) {
|
|
22151
|
+
if (value === void 0 || value === null) return void 0;
|
|
22152
|
+
const result = String(value).trim();
|
|
22153
|
+
return result || void 0;
|
|
22154
|
+
}
|
|
22155
|
+
function integerValue(value) {
|
|
22156
|
+
const result = Number(value);
|
|
22157
|
+
return Number.isSafeInteger(result) && result > 0 ? result : null;
|
|
22158
|
+
}
|
|
22159
|
+
function booleanValue(value) {
|
|
22160
|
+
if (value === true || value === 1 || value === "1" || value === "true") return true;
|
|
22161
|
+
if (value === false || value === 0 || value === "0" || value === "false") return false;
|
|
22162
|
+
return null;
|
|
22163
|
+
}
|
|
22164
|
+
function pathInside2(parent, child) {
|
|
22165
|
+
const relative = path14.relative(parent, child);
|
|
22166
|
+
return relative === "" || !relative.startsWith("..") && !path14.isAbsolute(relative);
|
|
22167
|
+
}
|
|
22168
|
+
function safeOrigin(value) {
|
|
22169
|
+
const parsed = new URL(value);
|
|
22170
|
+
if (!["http:", "https:"].includes(parsed.protocol)) {
|
|
22171
|
+
throw new Error("e2e.identity.browser.invalid_origin: profile origin \u5FC5\u987B\u662F HTTP(S) \u5730\u5740\u3002");
|
|
22172
|
+
}
|
|
22173
|
+
return parsed.origin;
|
|
22174
|
+
}
|
|
22175
|
+
function safeHrefPath(value) {
|
|
22176
|
+
const next = value.trim();
|
|
22177
|
+
if (!next.startsWith("/") || next.startsWith("//") || next.includes("\\")) {
|
|
22178
|
+
throw new Error("e2e.identity.browser.invalid_href: --href-path \u5FC5\u987B\u662F BPMAX \u7AD9\u5185\u7EDD\u5BF9\u8DEF\u5F84\u3002");
|
|
22179
|
+
}
|
|
22180
|
+
const parsed = new URL(next, "https://bpmax.invalid");
|
|
22181
|
+
if (parsed.origin !== "https://bpmax.invalid") {
|
|
22182
|
+
throw new Error("e2e.identity.browser.invalid_href: --href-path \u4E0D\u80FD\u5207\u6362\u5230\u5916\u90E8 origin\u3002");
|
|
22183
|
+
}
|
|
22184
|
+
return `${parsed.pathname}${parsed.search}${parsed.hash}`;
|
|
22185
|
+
}
|
|
22186
|
+
function normalizeLeaseTtl(value) {
|
|
22187
|
+
const ttl = value ?? DEFAULT_LEASE_TTL_SECONDS;
|
|
22188
|
+
if (!Number.isSafeInteger(ttl) || ttl < MIN_LEASE_TTL_SECONDS || ttl > MAX_LEASE_TTL_SECONDS) {
|
|
22189
|
+
throw new Error(`e2e.identity.browser.invalid_lease_ttl: lease TTL \u5FC5\u987B\u5728 ${MIN_LEASE_TTL_SECONDS}-${MAX_LEASE_TTL_SECONDS} \u79D2\u4E4B\u95F4\u3002`);
|
|
22190
|
+
}
|
|
22191
|
+
return ttl;
|
|
22192
|
+
}
|
|
22193
|
+
function safeIdentity(value) {
|
|
22194
|
+
if (!isRecord10(value)) return null;
|
|
22195
|
+
const sourceValue = stringValue3(value.source);
|
|
22196
|
+
const source = sourceValue === "vuex" || sourceValue === "profile_route" || sourceValue === "dom" ? sourceValue : "unknown";
|
|
22197
|
+
return {
|
|
22198
|
+
id: integerValue(value.id),
|
|
22199
|
+
name: stringValue3(value.name) ?? null,
|
|
22200
|
+
organization_id: integerValue(value.organization_id),
|
|
22201
|
+
mock: booleanValue(value.mock) === true,
|
|
22202
|
+
mock_by_user: integerValue(isRecord10(value.mock_by_user) ? value.mock_by_user.id : value.mock_by_user),
|
|
22203
|
+
can_mock: booleanValue(value.can_mock),
|
|
22204
|
+
source
|
|
22205
|
+
};
|
|
22206
|
+
}
|
|
22207
|
+
async function readJson(file) {
|
|
22208
|
+
return JSON.parse(await readFile15(file, "utf8"));
|
|
22209
|
+
}
|
|
22210
|
+
async function lstatOptional(file) {
|
|
22211
|
+
try {
|
|
22212
|
+
return await lstat(file);
|
|
22213
|
+
} catch (error) {
|
|
22214
|
+
if (error.code === "ENOENT") return null;
|
|
22215
|
+
throw error;
|
|
22216
|
+
}
|
|
22217
|
+
}
|
|
22218
|
+
async function assertSafeExistingFile(file, label) {
|
|
22219
|
+
const info = await lstatOptional(file);
|
|
22220
|
+
if (!info) return;
|
|
22221
|
+
if (info.isSymbolicLink() || !info.isFile()) {
|
|
22222
|
+
throw new Error(`e2e.identity.browser.${label}_unsafe: ${label} \u5FC5\u987B\u662F\u5F53\u524D run \u5185\u7684\u666E\u901A\u6587\u4EF6\uFF0C\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\u3002`);
|
|
22223
|
+
}
|
|
22224
|
+
}
|
|
22225
|
+
async function readOptionalLease(file) {
|
|
22226
|
+
try {
|
|
22227
|
+
await assertSafeExistingFile(file, "lease");
|
|
22228
|
+
const value = await readJson(file);
|
|
22229
|
+
if (!isRecord10(value) || value.kind !== "bpmax_identity_lease" || value.schema_version !== 1) {
|
|
22230
|
+
throw new Error("invalid identity lease state");
|
|
22231
|
+
}
|
|
22232
|
+
const state = stringValue3(value.state);
|
|
22233
|
+
if (!state || !["active", "uncertain", "released"].includes(state)) {
|
|
22234
|
+
throw new Error("invalid identity lease state");
|
|
22235
|
+
}
|
|
22236
|
+
const lease = value;
|
|
22237
|
+
if (!stringValue3(lease.lease_id) || lease.browser_tool !== "chrome:control-chrome" || typeof lease.recovery_required !== "boolean" || !isRecord10(lease.binding)) {
|
|
22238
|
+
throw new Error("invalid identity lease binding");
|
|
22239
|
+
}
|
|
22240
|
+
return lease;
|
|
22241
|
+
} catch (error) {
|
|
22242
|
+
if (error.code === "ENOENT") return null;
|
|
22243
|
+
throw new Error(`e2e.identity.browser.lease_invalid: ${error instanceof Error ? error.message : String(error)}`);
|
|
22244
|
+
}
|
|
22245
|
+
}
|
|
22246
|
+
async function atomicJson(file, value, exclusive = false) {
|
|
22247
|
+
await mkdir11(path14.dirname(file), { recursive: true });
|
|
22248
|
+
if (exclusive) {
|
|
22249
|
+
await writeFile11(file, `${JSON.stringify(value, null, 2)}
|
|
22250
|
+
`, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
22251
|
+
await chmod2(file, 384);
|
|
22252
|
+
return;
|
|
22253
|
+
}
|
|
22254
|
+
const temp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
22255
|
+
await writeFile11(temp, `${JSON.stringify(value, null, 2)}
|
|
22256
|
+
`, { encoding: "utf8", mode: 384 });
|
|
22257
|
+
await chmod2(temp, 384);
|
|
22258
|
+
await rename2(temp, file);
|
|
22259
|
+
}
|
|
22260
|
+
function requestAllowedActions(operation) {
|
|
22261
|
+
if (operation === "status") return ["read_current_identity"];
|
|
22262
|
+
if (operation === "mock") return ["read_current_identity", "filter_target_name", "verify_exact_user_id", "click_simulation", "click_exit_simulation"];
|
|
22263
|
+
return ["read_current_identity", "click_exit_simulation"];
|
|
22264
|
+
}
|
|
22265
|
+
function assertWorkspaceKey(value) {
|
|
22266
|
+
const workspace = value.replace(/^w:/, "").trim();
|
|
22267
|
+
if (!workspace || !/^[A-Za-z0-9._-]+$/.test(workspace)) {
|
|
22268
|
+
throw new Error("e2e.identity.browser.workspace_invalid: profile workspace \u5FC5\u987B\u662F\u5355\u4E00 BPMAX workspace key\u3002");
|
|
22269
|
+
}
|
|
22270
|
+
return workspace;
|
|
22271
|
+
}
|
|
22272
|
+
function expectedIdentityUrls(origin, workspace, hrefPath) {
|
|
22273
|
+
return {
|
|
22274
|
+
userManagementUrl: `${origin}/w:${encodeURIComponent(workspace)}/userManagement`,
|
|
22275
|
+
returnUrl: new URL(hrefPath, origin).toString()
|
|
22276
|
+
};
|
|
22277
|
+
}
|
|
22278
|
+
async function prepareIdentityBrowserBridge(options) {
|
|
22279
|
+
const origin = safeOrigin(options.origin);
|
|
22280
|
+
const workspace = assertWorkspaceKey(options.workspace);
|
|
22281
|
+
const hrefPath = safeHrefPath(options.hrefPath?.trim() || `/w:${workspace}`);
|
|
22282
|
+
const targetUserId = options.operation === "mock" ? integerValue(options.targetUserId) : null;
|
|
22283
|
+
const targetUserName = options.operation === "mock" ? stringValue3(options.targetUserName) : void 0;
|
|
22284
|
+
const targetOrganizationId = options.operation === "mock" ? integerValue(options.targetOrganizationId) : null;
|
|
22285
|
+
if (options.operation === "mock" && !targetUserId) {
|
|
22286
|
+
throw new Error("e2e.identity.browser.invalid_user_id: browser mock \u5FC5\u987B\u63D0\u4F9B\u7CBE\u786E\u6B63\u6574\u6570 --user-id\u3002");
|
|
22287
|
+
}
|
|
22288
|
+
if (options.operation === "mock" && !targetUserName) {
|
|
22289
|
+
throw new Error("e2e.identity.browser.target_readback_required: browser mock \u5FC5\u987B\u5148\u901A\u8FC7 typed user readback \u83B7\u53D6\u76EE\u6807\u7528\u6237\u59D3\u540D\u3002");
|
|
22290
|
+
}
|
|
22291
|
+
const evidenceDir = path14.resolve(options.evidenceDir);
|
|
22292
|
+
const runDir = options.binding.execution_manifest ? path14.dirname(path14.resolve(options.binding.execution_manifest)) : evidenceDir;
|
|
22293
|
+
const leaseFile = path14.resolve(options.leaseFile);
|
|
22294
|
+
if (!pathInside2(runDir, evidenceDir)) {
|
|
22295
|
+
throw new Error("e2e.identity.browser.evidence_scope: identity evidence \u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D run \u76EE\u5F55\u5185\u3002");
|
|
22296
|
+
}
|
|
22297
|
+
if (!pathInside2(runDir, leaseFile)) {
|
|
22298
|
+
throw new Error("e2e.identity.browser.lease_scope: identity lease \u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D run/evidence \u76EE\u5F55\u5185\u3002");
|
|
22299
|
+
}
|
|
22300
|
+
await mkdir11(evidenceDir, { recursive: true });
|
|
22301
|
+
await mkdir11(path14.dirname(leaseFile), { recursive: true });
|
|
22302
|
+
const [realRunDir, realEvidenceDir, realLeaseParent] = await Promise.all([
|
|
22303
|
+
realpath3(runDir),
|
|
22304
|
+
realpath3(evidenceDir),
|
|
22305
|
+
realpath3(path14.dirname(leaseFile))
|
|
22306
|
+
]);
|
|
22307
|
+
if (!pathInside2(realRunDir, realEvidenceDir) || !pathInside2(realRunDir, realLeaseParent)) {
|
|
22308
|
+
throw new Error("e2e.identity.browser.output_scope: identity evidence/lease \u7684\u771F\u5B9E\u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D run \u5185\u3002");
|
|
22309
|
+
}
|
|
22310
|
+
await assertSafeExistingFile(leaseFile, "lease");
|
|
22311
|
+
const activeLease = await readOptionalLease(leaseFile);
|
|
22312
|
+
if (options.operation === "mock" && activeLease && ["active", "uncertain"].includes(activeLease.state)) {
|
|
22313
|
+
const expired = activeLease.expires_at ? Date.parse(activeLease.expires_at) <= Date.now() : false;
|
|
22314
|
+
throw new Error(expired ? `e2e.identity.browser.expired_lease_recovery_required: lease ${activeLease.lease_id} \u5DF2\u8FC7\u671F\u4F46\u672A\u786E\u8BA4\u6062\u590D\uFF0C\u5FC5\u987B\u5148\u6267\u884C browser unmock\u3002` : `e2e.identity.browser.active_lease: lease ${activeLease.lease_id} \u4ECD\u5728\u4F7F\u7528\uFF0C\u7981\u6B62\u53E0\u52A0 mock\u3002`);
|
|
22315
|
+
}
|
|
22316
|
+
if (options.operation === "unmock" && !options.binding.diagnostic && (!activeLease || !["active", "uncertain"].includes(activeLease.state))) {
|
|
22317
|
+
throw new Error("e2e.identity.browser.unmock_without_lease: \u6B63\u5F0F unmock \u5FC5\u987B\u5BF9\u5E94\u672C\u8F6E active/uncertain identity lease\u3002");
|
|
22318
|
+
}
|
|
22319
|
+
const ttlSeconds = normalizeLeaseTtl(options.leaseTtlSeconds);
|
|
22320
|
+
const now = /* @__PURE__ */ new Date();
|
|
22321
|
+
const requestId2 = randomUUID4();
|
|
22322
|
+
const leaseId = options.operation === "unmock" && activeLease ? activeLease.lease_id : randomUUID4();
|
|
22323
|
+
const stem = `identity-browser-${options.operation}-${now.toISOString().replace(/[:.]/g, "-")}-${requestId2.slice(0, 8)}`;
|
|
22324
|
+
const requestPath = path14.join(evidenceDir, `${stem}.request.json`);
|
|
22325
|
+
const resultPath = path14.join(evidenceDir, `${stem}.result.json`);
|
|
22326
|
+
const screenshotDir = options.binding.execution_manifest ? path14.join(runDir, "screenshots") : evidenceDir;
|
|
22327
|
+
await mkdir11(screenshotDir, { recursive: true });
|
|
22328
|
+
const realScreenshotDir = await realpath3(screenshotDir);
|
|
22329
|
+
if (!pathInside2(realRunDir, realScreenshotDir)) {
|
|
22330
|
+
throw new Error("e2e.identity.browser.screenshot_scope: identity screenshot \u7684\u771F\u5B9E\u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D run \u5185\u3002");
|
|
22331
|
+
}
|
|
22332
|
+
const screenshotPath = path14.join(screenshotDir, `${stem}.jpg`);
|
|
22333
|
+
const leaseExpiresAt = options.operation === "mock" ? new Date(now.getTime() + ttlSeconds * 1e3).toISOString() : activeLease?.expires_at;
|
|
22334
|
+
const expectedUrls = expectedIdentityUrls(origin, workspace, hrefPath);
|
|
22335
|
+
const request = {
|
|
22336
|
+
schema_version: 1,
|
|
22337
|
+
kind: "bpmax_identity_browser_request",
|
|
22338
|
+
transport: "chrome_control_ui",
|
|
22339
|
+
request_id: requestId2,
|
|
22340
|
+
nonce: randomUUID4(),
|
|
22341
|
+
operation: options.operation,
|
|
22342
|
+
created_at: now.toISOString(),
|
|
22343
|
+
expires_at: new Date(now.getTime() + REQUEST_TTL_SECONDS * 1e3).toISOString(),
|
|
22344
|
+
origin,
|
|
22345
|
+
workspace,
|
|
22346
|
+
language: options.language || "zhCN",
|
|
22347
|
+
href_path: hrefPath,
|
|
22348
|
+
user_management_url: expectedUrls.userManagementUrl,
|
|
22349
|
+
return_url: expectedUrls.returnUrl,
|
|
22350
|
+
...targetUserId ? { target_user_id: targetUserId } : {},
|
|
22351
|
+
...targetUserName ? { target_user_name: targetUserName } : {},
|
|
22352
|
+
...targetOrganizationId ? { target_organization_id: targetOrganizationId } : {},
|
|
22353
|
+
run_dir: runDir,
|
|
22354
|
+
evidence_dir: evidenceDir,
|
|
22355
|
+
result_path: resultPath,
|
|
22356
|
+
screenshot_path: screenshotPath,
|
|
22357
|
+
screenshot_mime: "image/jpeg",
|
|
22358
|
+
binding: options.binding,
|
|
22359
|
+
lease: {
|
|
22360
|
+
lease_id: leaseId,
|
|
22361
|
+
lease_file: leaseFile,
|
|
22362
|
+
ttl_seconds: ttlSeconds,
|
|
22363
|
+
...leaseExpiresAt ? { expires_at: leaseExpiresAt } : {},
|
|
22364
|
+
requires_dedicated_tab: true,
|
|
22365
|
+
recovery_required: true,
|
|
22366
|
+
...activeLease?.original_user ? { expected_original_user: activeLease.original_user } : {}
|
|
22367
|
+
},
|
|
22368
|
+
allowed_ui_actions: requestAllowedActions(options.operation)
|
|
22369
|
+
};
|
|
22370
|
+
await atomicJson(requestPath, request, true);
|
|
22371
|
+
return {
|
|
22372
|
+
request,
|
|
22373
|
+
request_path: requestPath,
|
|
22374
|
+
result_path: resultPath,
|
|
22375
|
+
screenshot_path: screenshotPath,
|
|
22376
|
+
lease_file: leaseFile,
|
|
22377
|
+
active_lease: activeLease
|
|
22378
|
+
};
|
|
22379
|
+
}
|
|
22380
|
+
async function readIdentityBrowserRequest(file, options = {}) {
|
|
22381
|
+
const requestPath = path14.resolve(file);
|
|
22382
|
+
const value = await readJson(requestPath);
|
|
22383
|
+
if (!isRecord10(value) || value.schema_version !== 1 || value.kind !== "bpmax_identity_browser_request" || value.transport !== "chrome_control_ui") {
|
|
22384
|
+
throw new Error("e2e.identity.browser.request_invalid: \u4E0D\u652F\u6301\u7684 identity browser request\u3002");
|
|
22385
|
+
}
|
|
22386
|
+
const request = value;
|
|
22387
|
+
if (!request.request_id || !request.nonce || !["status", "mock", "unmock"].includes(request.operation) || !request.run_dir || !request.evidence_dir || !request.result_path || !request.screenshot_path || request.screenshot_mime !== "image/jpeg" || !request.lease?.lease_file || !request.binding || request.operation === "mock" && (!integerValue(request.target_user_id) || !stringValue3(request.target_user_name))) {
|
|
22388
|
+
throw new Error("e2e.identity.browser.request_invalid: request \u7F3A\u5C11\u8EAB\u4EFD\u6865\u7ED1\u5B9A\u5B57\u6BB5\u3002");
|
|
22389
|
+
}
|
|
22390
|
+
const runDir = path14.resolve(request.run_dir);
|
|
22391
|
+
const evidenceDir = path14.resolve(request.evidence_dir);
|
|
22392
|
+
const realRunDir = await realpath3(runDir);
|
|
22393
|
+
const realEvidenceDir = await realpath3(evidenceDir);
|
|
22394
|
+
const realRequestPath = await realpath3(requestPath);
|
|
22395
|
+
const requestLinkInfo = await lstat(requestPath);
|
|
22396
|
+
const requestInfo = await stat8(realRequestPath);
|
|
22397
|
+
const [realResultParent, realScreenshotParent, realLeaseParent] = await Promise.all([
|
|
22398
|
+
realpath3(path14.dirname(path14.resolve(request.result_path))),
|
|
22399
|
+
realpath3(path14.dirname(path14.resolve(request.screenshot_path))),
|
|
22400
|
+
realpath3(path14.dirname(path14.resolve(request.lease.lease_file)))
|
|
22401
|
+
]);
|
|
22402
|
+
if (!pathInside2(realRunDir, realEvidenceDir) || !pathInside2(realEvidenceDir, realRequestPath) || !pathInside2(realEvidenceDir, realResultParent) || !pathInside2(realRunDir, realScreenshotParent) || !pathInside2(realRunDir, realLeaseParent)) {
|
|
22403
|
+
throw new Error("e2e.identity.browser.request_scope: identity request/result/screenshot/lease \u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D run \u76EE\u5F55\u5185\u3002");
|
|
22404
|
+
}
|
|
22405
|
+
if (requestLinkInfo.isSymbolicLink() || (requestInfo.mode & 63) !== 0) {
|
|
22406
|
+
throw new Error("e2e.identity.browser.request_permissions: identity browser request \u5FC5\u987B\u4FDD\u6301 mode 0600\u3002");
|
|
22407
|
+
}
|
|
22408
|
+
await Promise.all([
|
|
22409
|
+
assertSafeExistingFile(path14.resolve(request.result_path), "result"),
|
|
22410
|
+
assertSafeExistingFile(path14.resolve(request.screenshot_path), "screenshot"),
|
|
22411
|
+
assertSafeExistingFile(path14.resolve(request.lease.lease_file), "lease")
|
|
22412
|
+
]);
|
|
22413
|
+
const origin = safeOrigin(request.origin);
|
|
22414
|
+
const workspace = assertWorkspaceKey(request.workspace);
|
|
22415
|
+
const hrefPath = safeHrefPath(request.href_path);
|
|
22416
|
+
const expectedUrls = expectedIdentityUrls(origin, workspace, hrefPath);
|
|
22417
|
+
if (request.user_management_url !== expectedUrls.userManagementUrl || request.return_url !== expectedUrls.returnUrl) {
|
|
22418
|
+
throw new Error("e2e.identity.browser.request_url_mismatch: identity browser request \u7684\u7BA1\u7406\u9875\u6216\u8FD4\u56DE\u9875\u5DF2\u88AB\u7BE1\u6539\u3002");
|
|
22419
|
+
}
|
|
22420
|
+
const expectedActions = requestAllowedActions(request.operation);
|
|
22421
|
+
if (!Array.isArray(request.allowed_ui_actions) || request.allowed_ui_actions.length !== expectedActions.length || request.allowed_ui_actions.some((item, index) => item !== expectedActions[index])) {
|
|
22422
|
+
throw new Error("e2e.identity.browser.request_actions_mismatch: identity browser request \u7684\u5141\u8BB8\u52A8\u4F5C\u5DF2\u88AB\u7BE1\u6539\u3002");
|
|
22423
|
+
}
|
|
22424
|
+
const createdAt = Date.parse(request.created_at);
|
|
22425
|
+
const expiresAt = Date.parse(request.expires_at);
|
|
22426
|
+
if (!Number.isFinite(createdAt) || !Number.isFinite(expiresAt) || expiresAt <= createdAt || !options.allowExpired && Date.now() > expiresAt) {
|
|
22427
|
+
throw new Error("e2e.identity.browser.request_expired: identity browser request \u5DF2\u8FC7\u671F\uFF0C\u5FC5\u987B\u91CD\u65B0\u751F\u6210\u3002");
|
|
22428
|
+
}
|
|
22429
|
+
return request;
|
|
22430
|
+
}
|
|
22431
|
+
function identityAssertion(name, passed, actual, expected) {
|
|
22432
|
+
return { name, passed, actual, expected };
|
|
22433
|
+
}
|
|
22434
|
+
function resultError(value) {
|
|
22435
|
+
const error = isRecord10(value.error) ? value.error : {};
|
|
22436
|
+
return {
|
|
22437
|
+
kind: stringValue3(error.kind) ?? "browser_identity_failed",
|
|
22438
|
+
message: (stringValue3(error.message) ?? "Chrome identity bridge failed").slice(0, 500)
|
|
22439
|
+
};
|
|
22440
|
+
}
|
|
22441
|
+
async function validateScreenshot(request, result) {
|
|
22442
|
+
const screenshot = path14.resolve(stringValue3(result.screenshot_path) ?? "");
|
|
22443
|
+
if (screenshot !== path14.resolve(request.screenshot_path)) {
|
|
22444
|
+
throw new Error("e2e.identity.browser.screenshot_mismatch: result screenshot \u4E0E request \u4E0D\u4E00\u81F4\u3002");
|
|
22445
|
+
}
|
|
22446
|
+
if (stringValue3(result.screenshot_mime) !== request.screenshot_mime || path14.extname(screenshot).toLowerCase() !== ".jpg") {
|
|
22447
|
+
throw new Error("e2e.identity.browser.screenshot_mismatch: screenshot MIME \u6216\u6269\u5C55\u540D\u4E0E request \u4E0D\u4E00\u81F4\u3002");
|
|
22448
|
+
}
|
|
22449
|
+
await assertSafeExistingFile(screenshot, "screenshot");
|
|
22450
|
+
const realScreenshot = await realpath3(screenshot);
|
|
22451
|
+
const realRunDir = await realpath3(request.run_dir);
|
|
22452
|
+
if (!pathInside2(realRunDir, realScreenshot)) {
|
|
22453
|
+
throw new Error("e2e.identity.browser.screenshot_scope: Chrome identity screenshot \u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D run \u5185\u3002");
|
|
22454
|
+
}
|
|
22455
|
+
const info = await stat8(realScreenshot);
|
|
22456
|
+
if (!info.isFile() || info.size < 100) {
|
|
22457
|
+
throw new Error("e2e.identity.browser.screenshot_invalid: Chrome identity screenshot \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A\u3002");
|
|
22458
|
+
}
|
|
22459
|
+
const content = Buffer.from(await readFile15(realScreenshot));
|
|
22460
|
+
const signature = content.subarray(0, 3);
|
|
22461
|
+
if (!signature.equals(Buffer.from([255, 216, 255]))) {
|
|
22462
|
+
throw new Error("e2e.identity.browser.screenshot_invalid: Chrome identity screenshot \u5FC5\u987B\u662F\u771F\u5B9E JPEG\u3002");
|
|
22463
|
+
}
|
|
22464
|
+
const startedAt = Date.parse(stringValue3(result.started_at) ?? "");
|
|
22465
|
+
const finishedAt = Date.parse(stringValue3(result.finished_at) ?? "");
|
|
22466
|
+
if (info.mtimeMs < startedAt - 1e3 || info.mtimeMs > finishedAt + 6e4) {
|
|
22467
|
+
throw new Error("e2e.identity.browser.screenshot_stale: Chrome identity screenshot \u4E0D\u662F\u672C\u6B21 request \u4EA7\u751F\u7684\u65B0\u8BC1\u636E\u3002");
|
|
22468
|
+
}
|
|
22469
|
+
return {
|
|
22470
|
+
path: realScreenshot,
|
|
22471
|
+
mime: "image/jpeg",
|
|
22472
|
+
sha256: createHash7("sha256").update(content).digest("hex")
|
|
22473
|
+
};
|
|
22474
|
+
}
|
|
22475
|
+
function validateResultEnvelope(request, value) {
|
|
22476
|
+
if (value.schema_version !== 1 || value.kind !== "bpmax_identity_browser_result" || value.transport !== "chrome_control_ui" || value.browser_tool !== "chrome:control-chrome" || value.request_id !== request.request_id || value.nonce !== request.nonce || value.operation !== request.operation) {
|
|
22477
|
+
throw new Error("e2e.identity.browser.result_binding: Chrome identity result \u4E0E\u4E00\u6B21\u6027 request \u4E0D\u5339\u914D\u3002");
|
|
22478
|
+
}
|
|
22479
|
+
const runtimeUrl = stringValue3(value.runtime_url);
|
|
22480
|
+
if (!runtimeUrl || safeOrigin(runtimeUrl) !== request.origin) {
|
|
22481
|
+
throw new Error("e2e.identity.browser.result_origin: Chrome identity result \u4E0D\u662F\u5F53\u524D profile origin\u3002");
|
|
22482
|
+
}
|
|
22483
|
+
const finishedAt = Date.parse(stringValue3(value.finished_at) ?? "");
|
|
22484
|
+
const startedAt = Date.parse(stringValue3(value.started_at) ?? "");
|
|
22485
|
+
const createdAt = Date.parse(request.created_at);
|
|
22486
|
+
const expiresAt = Date.parse(request.expires_at);
|
|
22487
|
+
if (!Number.isFinite(finishedAt) || !Number.isFinite(startedAt) || startedAt < createdAt - 1e3 || startedAt > expiresAt || finishedAt < startedAt || finishedAt - startedAt > RESULT_MAX_DURATION_MS || finishedAt > Date.now() + 6e4) {
|
|
22488
|
+
throw new Error("e2e.identity.browser.result_expired: Chrome identity result \u5DF2\u8FC7\u671F\uFF0C\u5FC5\u987B\u91CD\u65B0\u751F\u6210 request\u3002");
|
|
22489
|
+
}
|
|
22490
|
+
}
|
|
22491
|
+
function expectedOriginalIdentityId(request, before) {
|
|
22492
|
+
return request.lease.expected_original_user?.id ?? before?.mock_by_user ?? null;
|
|
22493
|
+
}
|
|
22494
|
+
function restoredIdentityMatches(request, before, after) {
|
|
22495
|
+
const expectedOriginalId = expectedOriginalIdentityId(request, before);
|
|
22496
|
+
return Boolean(after && !after.mock && (expectedOriginalId === null || after.id === expectedOriginalId));
|
|
22497
|
+
}
|
|
22498
|
+
function operationSucceeded(request, value, before, after) {
|
|
22499
|
+
if (value.ok !== true || value.readback_confirmed !== true || !after) return false;
|
|
22500
|
+
if (request.operation === "status") {
|
|
22501
|
+
return value.operation_executed === false && value.remote_submitted === false && after.id !== null && Boolean(after.name);
|
|
22502
|
+
}
|
|
22503
|
+
if (request.operation === "mock") {
|
|
22504
|
+
const permission = isRecord10(value.permission_preflight) ? booleanValue(value.permission_preflight.granted) : null;
|
|
22505
|
+
const originalIdentityBound = after.mock_by_user === before?.id || after.mock_by_user === null && after.source === "profile_route" && before?.id !== null;
|
|
22506
|
+
return permission === true && value.operation_executed === true && value.remote_submitted === true && before?.mock === false && after.mock === true && after.id === request.target_user_id && before?.id !== null && originalIdentityBound && isRecord10(value.lease) && value.lease.lease_id === request.lease.lease_id && value.lease.recovery_required === true;
|
|
22507
|
+
}
|
|
22508
|
+
const expectedOriginalId = expectedOriginalIdentityId(request, before);
|
|
22509
|
+
if (value.already_restored === true) {
|
|
22510
|
+
return value.operation_executed === false && value.remote_submitted === false && before?.mock === false && after.mock === false && expectedOriginalId !== null && before?.id === expectedOriginalId && after.id === expectedOriginalId;
|
|
22511
|
+
}
|
|
22512
|
+
return value.operation_executed === true && value.remote_submitted === true && before?.mock === true && restoredIdentityMatches(request, before, after);
|
|
22513
|
+
}
|
|
22514
|
+
async function completeIdentityBrowserBridge(requestFile) {
|
|
22515
|
+
const requestPath = path14.resolve(requestFile);
|
|
22516
|
+
const request = await readIdentityBrowserRequest(requestPath, { allowExpired: true });
|
|
22517
|
+
const receiptPath = `${requestPath}.completed.json`;
|
|
22518
|
+
try {
|
|
22519
|
+
await stat8(receiptPath);
|
|
22520
|
+
throw new Error("e2e.identity.browser.request_consumed: identity browser request \u5DF2\u88AB\u9A8C\u6536\uFF0C\u7981\u6B62\u590D\u7528\u3002");
|
|
22521
|
+
} catch (error) {
|
|
22522
|
+
if (error.code !== "ENOENT") throw error;
|
|
22523
|
+
}
|
|
22524
|
+
await assertSafeExistingFile(request.result_path, "result");
|
|
22525
|
+
const realResultPath = await realpath3(request.result_path);
|
|
22526
|
+
const realEvidenceDir = await realpath3(request.evidence_dir);
|
|
22527
|
+
if (!pathInside2(realEvidenceDir, realResultPath)) {
|
|
22528
|
+
throw new Error("e2e.identity.browser.result_scope: Chrome identity result \u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D evidence \u76EE\u5F55\u5185\u3002");
|
|
22529
|
+
}
|
|
22530
|
+
const value = await readJson(realResultPath);
|
|
22531
|
+
if (!isRecord10(value)) throw new Error("e2e.identity.browser.result_invalid: Chrome identity result \u5FC5\u987B\u662F JSON object\u3002");
|
|
22532
|
+
validateResultEnvelope(request, value);
|
|
22533
|
+
const screenshot = await validateScreenshot(request, value);
|
|
22534
|
+
const before = safeIdentity(value.before);
|
|
22535
|
+
const after = safeIdentity(value.after ?? value.current_user);
|
|
22536
|
+
const ok = operationSucceeded(request, value, before, after);
|
|
22537
|
+
const failure = ok ? void 0 : resultError(value);
|
|
22538
|
+
const cleanup = isRecord10(value.cleanup) ? value.cleanup : {};
|
|
22539
|
+
let lease = await readOptionalLease(request.lease.lease_file);
|
|
22540
|
+
if (request.operation === "mock" && ok) {
|
|
22541
|
+
lease = {
|
|
22542
|
+
schema_version: 1,
|
|
22543
|
+
kind: "bpmax_identity_lease",
|
|
22544
|
+
lease_id: request.lease.lease_id,
|
|
22545
|
+
state: "active",
|
|
22546
|
+
operation_request_id: request.request_id,
|
|
22547
|
+
created_at: request.created_at,
|
|
22548
|
+
...request.lease.expires_at ? { expires_at: request.lease.expires_at } : {},
|
|
22549
|
+
target_user: after,
|
|
22550
|
+
original_user: before,
|
|
22551
|
+
browser_tool: "chrome:control-chrome",
|
|
22552
|
+
recovery_required: true,
|
|
22553
|
+
binding: request.binding
|
|
22554
|
+
};
|
|
22555
|
+
await atomicJson(request.lease.lease_file, lease);
|
|
22556
|
+
} else if (request.operation === "mock" && (value.remote_submitted === true || value.mutation_attempted === true) && cleanup.readback_confirmed !== true) {
|
|
22557
|
+
lease = {
|
|
22558
|
+
schema_version: 1,
|
|
22559
|
+
kind: "bpmax_identity_lease",
|
|
22560
|
+
lease_id: request.lease.lease_id,
|
|
22561
|
+
state: "uncertain",
|
|
22562
|
+
operation_request_id: request.request_id,
|
|
22563
|
+
created_at: request.created_at,
|
|
22564
|
+
...request.lease.expires_at ? { expires_at: request.lease.expires_at } : {},
|
|
22565
|
+
target_user: after,
|
|
22566
|
+
original_user: before,
|
|
22567
|
+
browser_tool: "chrome:control-chrome",
|
|
22568
|
+
recovery_required: true,
|
|
22569
|
+
binding: request.binding
|
|
22570
|
+
};
|
|
22571
|
+
await atomicJson(request.lease.lease_file, lease);
|
|
22572
|
+
} else if (request.operation === "unmock" && ok && lease) {
|
|
22573
|
+
lease = {
|
|
22574
|
+
...lease,
|
|
22575
|
+
state: "released",
|
|
22576
|
+
released_at: stringValue3(value.finished_at) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
22577
|
+
recovery_required: false,
|
|
22578
|
+
release_operation_request_id: request.request_id,
|
|
22579
|
+
release_binding: request.binding
|
|
22580
|
+
};
|
|
22581
|
+
await atomicJson(request.lease.lease_file, lease);
|
|
22582
|
+
} else if (request.operation === "unmock" && !ok && lease && (value.remote_submitted === true || value.mutation_attempted === true)) {
|
|
22583
|
+
lease = {
|
|
22584
|
+
...lease,
|
|
22585
|
+
state: "uncertain",
|
|
22586
|
+
recovery_required: true,
|
|
22587
|
+
release_operation_request_id: request.request_id,
|
|
22588
|
+
release_binding: request.binding
|
|
22589
|
+
};
|
|
22590
|
+
await atomicJson(request.lease.lease_file, lease);
|
|
22591
|
+
}
|
|
22592
|
+
const assertions = request.operation === "status" ? [identityAssertion("\u5F53\u524D\u6D4F\u89C8\u5668\u8EAB\u4EFD\u5DF2\u56DE\u8BFB", Boolean(after?.id && after.name), after, "non-empty current identity")] : request.operation === "mock" ? [
|
|
22593
|
+
identityAssertion("\u539F\u8D26\u53F7\u5177\u5907\u6A21\u62DF\u8EAB\u4EFD\u6743\u9650", isRecord10(value.permission_preflight) && value.permission_preflight.granted === true, isRecord10(value.permission_preflight) ? value.permission_preflight.granted : null, true),
|
|
22594
|
+
identityAssertion("\u6D4F\u89C8\u5668\u5DF2\u5207\u6362\u5230\u7CBE\u786E\u76EE\u6807\u7528\u6237", Boolean(after?.mock && after.id === request.target_user_id), after?.id, request.target_user_id),
|
|
22595
|
+
identityAssertion("\u539F\u8EAB\u4EFD\u6062\u590D\u95E8\u7981\u5DF2\u542F\u7528", isRecord10(value.lease) && value.lease.recovery_required === true, isRecord10(value.lease) ? value.lease.recovery_required : null, true)
|
|
22596
|
+
] : [identityAssertion(
|
|
22597
|
+
"\u6D4F\u89C8\u5668\u5DF2\u6062\u590D\u539F\u59CB\u8EAB\u4EFD",
|
|
22598
|
+
restoredIdentityMatches(request, before, after),
|
|
22599
|
+
after,
|
|
22600
|
+
request.lease.expected_original_user ?? "original identity"
|
|
22601
|
+
)];
|
|
22602
|
+
const evidence = {
|
|
22603
|
+
schema_version: 1,
|
|
22604
|
+
status: ok ? request.operation === "status" ? "observed" : request.operation === "mock" ? "mocked" : "restored" : "failed",
|
|
22605
|
+
result: ok ? request.operation === "status" ? "observed" : request.operation === "mock" ? "mocked" : "restored" : "failed",
|
|
22606
|
+
transport: "chrome_identity_bridge",
|
|
22607
|
+
browser_tool: "chrome:control-chrome",
|
|
22608
|
+
browser_verified: true,
|
|
22609
|
+
operation: request.operation,
|
|
22610
|
+
mutation_attempted: value.mutation_attempted === true,
|
|
22611
|
+
operation_executed: value.operation_executed === true,
|
|
22612
|
+
remote_submitted: value.remote_submitted === true,
|
|
22613
|
+
readback_confirmed: value.readback_confirmed === true,
|
|
22614
|
+
request_id: request.request_id,
|
|
22615
|
+
current_user: after,
|
|
22616
|
+
before,
|
|
22617
|
+
after,
|
|
22618
|
+
...isRecord10(value.permission_preflight) ? { permission_preflight: value.permission_preflight } : {},
|
|
22619
|
+
...isRecord10(value.lease) ? { lease: value.lease } : {},
|
|
22620
|
+
...failure ? { failure } : {},
|
|
22621
|
+
runtime_scope: "page",
|
|
22622
|
+
runtime_environment: "profile",
|
|
22623
|
+
runtime_url: stringValue3(value.runtime_url),
|
|
22624
|
+
screenshot: path14.relative(request.evidence_dir, screenshot.path),
|
|
22625
|
+
screenshot_mime: screenshot.mime,
|
|
22626
|
+
screenshot_sha256: screenshot.sha256,
|
|
22627
|
+
assertions,
|
|
22628
|
+
browser_action_log: Array.isArray(value.actions) ? value.actions.slice(0, 20) : [],
|
|
22629
|
+
...request.binding.case_id ? { case_id: request.binding.case_id } : {},
|
|
22630
|
+
...request.binding.case_step_id ? { case_step_id: request.binding.case_step_id } : {}
|
|
22631
|
+
};
|
|
22632
|
+
return { ok, request, operation: request.operation, evidence, lease, ...failure ? { failure } : {} };
|
|
22633
|
+
}
|
|
22634
|
+
async function claimIdentityBrowserRequestCompletion(requestFile) {
|
|
22635
|
+
const requestPath = path14.resolve(requestFile);
|
|
22636
|
+
const request = await readIdentityBrowserRequest(requestPath, { allowExpired: true });
|
|
22637
|
+
const receiptPath = `${requestPath}.completed.json`;
|
|
22638
|
+
if (await lstatOptional(receiptPath)) {
|
|
22639
|
+
throw new Error("e2e.identity.browser.request_consumed: identity browser request \u5DF2\u88AB\u9A8C\u6536\uFF0C\u7981\u6B62\u590D\u7528\u3002");
|
|
22640
|
+
}
|
|
22641
|
+
const claimPath = `${requestPath}.completion-claim.json`;
|
|
22642
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
22643
|
+
const now = /* @__PURE__ */ new Date();
|
|
22644
|
+
const claimId = randomUUID4();
|
|
22645
|
+
try {
|
|
22646
|
+
await atomicJson(claimPath, {
|
|
22647
|
+
schema_version: 1,
|
|
22648
|
+
kind: "bpmax_identity_completion_claim",
|
|
22649
|
+
claim_id: claimId,
|
|
22650
|
+
request_id: request.request_id,
|
|
22651
|
+
created_at: now.toISOString(),
|
|
22652
|
+
expires_at: new Date(now.getTime() + COMPLETION_CLAIM_TTL_MS).toISOString()
|
|
22653
|
+
}, true);
|
|
22654
|
+
return { claim_id: claimId, claim_path: claimPath, request_id: request.request_id };
|
|
22655
|
+
} catch (error) {
|
|
22656
|
+
if (error.code !== "EEXIST") throw error;
|
|
22657
|
+
await assertSafeExistingFile(claimPath, "completion_claim");
|
|
22658
|
+
const existing = await readJson(claimPath).catch(() => null);
|
|
22659
|
+
const expiresAt = isRecord10(existing) ? Date.parse(stringValue3(existing.expires_at) ?? "") : Number.NaN;
|
|
22660
|
+
if (Number.isFinite(expiresAt) && expiresAt > Date.now()) {
|
|
22661
|
+
throw new Error("e2e.identity.browser.completion_in_progress: identity browser request \u6B63\u5728\u9A8C\u6536\uFF0C\u7981\u6B62\u5E76\u53D1 complete\u3002");
|
|
22662
|
+
}
|
|
22663
|
+
await rename2(claimPath, `${claimPath}.stale-${Date.now()}-${randomUUID4()}`).catch((renameError) => {
|
|
22664
|
+
if (renameError.code !== "ENOENT") throw renameError;
|
|
22665
|
+
});
|
|
22666
|
+
}
|
|
22667
|
+
}
|
|
22668
|
+
throw new Error("e2e.identity.browser.completion_claim_failed: \u65E0\u6CD5\u53D6\u5F97 identity browser request \u9A8C\u6536\u9501\u3002");
|
|
22669
|
+
}
|
|
22670
|
+
async function releaseIdentityBrowserRequestCompletionClaim(claim) {
|
|
22671
|
+
await assertSafeExistingFile(claim.claim_path, "completion_claim");
|
|
22672
|
+
const current = await readJson(claim.claim_path).catch(() => null);
|
|
22673
|
+
if (isRecord10(current) && current.claim_id === claim.claim_id && current.request_id === claim.request_id) {
|
|
22674
|
+
await unlink2(claim.claim_path).catch((error) => {
|
|
22675
|
+
if (error.code !== "ENOENT") throw error;
|
|
22676
|
+
});
|
|
22677
|
+
}
|
|
22678
|
+
}
|
|
22679
|
+
async function markIdentityBrowserRequestCompleted(requestFile, ok, knownRequest) {
|
|
22680
|
+
const request = knownRequest ?? await readIdentityBrowserRequest(requestFile, { allowExpired: true });
|
|
22681
|
+
const receiptPath = `${path14.resolve(requestFile)}.completed.json`;
|
|
22682
|
+
await atomicJson(receiptPath, {
|
|
22683
|
+
schema_version: 1,
|
|
22684
|
+
request_id: request.request_id,
|
|
22685
|
+
completed_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
22686
|
+
ok
|
|
22687
|
+
}, true);
|
|
22688
|
+
return receiptPath;
|
|
22689
|
+
}
|
|
22690
|
+
async function identityLeaseStatus(file) {
|
|
22691
|
+
return readOptionalLease(path14.resolve(file));
|
|
22692
|
+
}
|
|
22693
|
+
|
|
21861
22694
|
// src/core/form-schema.ts
|
|
21862
22695
|
var FIELD_KEY_NAMES = [
|
|
21863
22696
|
"key",
|
|
@@ -21877,7 +22710,7 @@ var OPTION_NAMES = ["options", "items", "choices", "values"];
|
|
|
21877
22710
|
var REQUIRED_NAMES = ["required", "is_required", "isRequired", "require", "must", "validateRequired"];
|
|
21878
22711
|
var HIDDEN_NAMES = ["hidden", "is_hidden", "isHidden", "hide", "hideInForm"];
|
|
21879
22712
|
var VISIBLE_NAMES = ["visible", "display", "show"];
|
|
21880
|
-
function
|
|
22713
|
+
function isRecord11(value) {
|
|
21881
22714
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21882
22715
|
}
|
|
21883
22716
|
function pickString(source, keys) {
|
|
@@ -21904,10 +22737,10 @@ function pickBoolean(source, keys) {
|
|
|
21904
22737
|
}
|
|
21905
22738
|
const rules = source.rules;
|
|
21906
22739
|
if (Array.isArray(rules)) {
|
|
21907
|
-
return rules.some((rule) =>
|
|
22740
|
+
return rules.some((rule) => isRecord11(rule) && pickBoolean(rule, REQUIRED_NAMES));
|
|
21908
22741
|
}
|
|
21909
22742
|
const validateMap = source.validateMap;
|
|
21910
|
-
if (
|
|
22743
|
+
if (isRecord11(validateMap) && pickBoolean(validateMap, REQUIRED_NAMES)) {
|
|
21911
22744
|
return true;
|
|
21912
22745
|
}
|
|
21913
22746
|
return false;
|
|
@@ -21931,7 +22764,7 @@ function optionValue(option) {
|
|
|
21931
22764
|
if (typeof option === "string" || typeof option === "number") {
|
|
21932
22765
|
return String(option);
|
|
21933
22766
|
}
|
|
21934
|
-
if (!
|
|
22767
|
+
if (!isRecord11(option)) {
|
|
21935
22768
|
return null;
|
|
21936
22769
|
}
|
|
21937
22770
|
return pickString(option, ["value", "key", "id", "name", "label", "title"]) ?? null;
|
|
@@ -21949,7 +22782,7 @@ function pickOptions(source) {
|
|
|
21949
22782
|
}
|
|
21950
22783
|
for (const containerKey of ["props", "config", "setting", "value"]) {
|
|
21951
22784
|
const container = source[containerKey];
|
|
21952
|
-
if (
|
|
22785
|
+
if (isRecord11(container)) {
|
|
21953
22786
|
const nested = pickOptions(container);
|
|
21954
22787
|
if (nested?.length) {
|
|
21955
22788
|
return nested;
|
|
@@ -22005,7 +22838,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
22005
22838
|
}
|
|
22006
22839
|
return;
|
|
22007
22840
|
}
|
|
22008
|
-
if (!
|
|
22841
|
+
if (!isRecord11(value)) {
|
|
22009
22842
|
return;
|
|
22010
22843
|
}
|
|
22011
22844
|
const field = fieldFromRecord(value);
|
|
@@ -22013,7 +22846,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
22013
22846
|
if (isSubFormField(field)) {
|
|
22014
22847
|
const childFields = /* @__PURE__ */ new Map();
|
|
22015
22848
|
for (const child of Object.values(value)) {
|
|
22016
|
-
if (
|
|
22849
|
+
if (isRecord11(child) || Array.isArray(child)) {
|
|
22017
22850
|
collectFieldCandidates(child, childFields, depth + 1);
|
|
22018
22851
|
}
|
|
22019
22852
|
}
|
|
@@ -22027,7 +22860,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
22027
22860
|
fields.set(field.key, mergeField(fields.get(field.key), field));
|
|
22028
22861
|
}
|
|
22029
22862
|
for (const child of Object.values(value)) {
|
|
22030
|
-
if (
|
|
22863
|
+
if (isRecord11(child) || Array.isArray(child)) {
|
|
22031
22864
|
collectFieldCandidates(child, fields, depth + 1);
|
|
22032
22865
|
}
|
|
22033
22866
|
}
|
|
@@ -22045,7 +22878,7 @@ function validateComplexSelector(field, value) {
|
|
|
22045
22878
|
if (!isComplexSelectorType(type)) {
|
|
22046
22879
|
return null;
|
|
22047
22880
|
}
|
|
22048
|
-
const validObject = (item) =>
|
|
22881
|
+
const validObject = (item) => isRecord11(item);
|
|
22049
22882
|
const hint = complexSelectorHint(field);
|
|
22050
22883
|
if (Array.isArray(value)) {
|
|
22051
22884
|
return value.every(validObject) ? null : `${field.key} must contain selector option object(s), not scalar values. ${hint}`;
|
|
@@ -22062,7 +22895,7 @@ function isEnumSelectType(type) {
|
|
|
22062
22895
|
return /enum_select/.test(type);
|
|
22063
22896
|
}
|
|
22064
22897
|
function optionComparableValue(value) {
|
|
22065
|
-
if (
|
|
22898
|
+
if (isRecord11(value) && ("value" in value || "label" in value)) {
|
|
22066
22899
|
return value.value ?? value.label;
|
|
22067
22900
|
}
|
|
22068
22901
|
return value;
|
|
@@ -22076,7 +22909,7 @@ function validateType(field, value) {
|
|
|
22076
22909
|
if (!Array.isArray(value)) {
|
|
22077
22910
|
return `${field.key} must be a JSON array of row objects`;
|
|
22078
22911
|
}
|
|
22079
|
-
const invalidRowIndex = value.findIndex((row) => !
|
|
22912
|
+
const invalidRowIndex = value.findIndex((row) => !isRecord11(row));
|
|
22080
22913
|
return invalidRowIndex >= 0 ? `${field.key}[${invalidRowIndex}] must be a row object` : null;
|
|
22081
22914
|
}
|
|
22082
22915
|
const selectorError = validateComplexSelector(field, value);
|
|
@@ -22102,7 +22935,7 @@ function validateType(field, value) {
|
|
|
22102
22935
|
if (/(array|multi|multiple)/.test(type) && !Array.isArray(value)) {
|
|
22103
22936
|
return `${field.key} must be an array`;
|
|
22104
22937
|
}
|
|
22105
|
-
if (isEnumSelectType(type) &&
|
|
22938
|
+
if (isEnumSelectType(type) && isRecord11(value)) {
|
|
22106
22939
|
const optionValue2 = value.value ?? value.label;
|
|
22107
22940
|
return typeof optionValue2 === "string" || typeof optionValue2 === "number" ? null : `${field.key} must be an enum option object with a scalar value`;
|
|
22108
22941
|
}
|
|
@@ -22132,7 +22965,7 @@ function validateFormEntries(form, fields, prefix = "") {
|
|
|
22132
22965
|
}
|
|
22133
22966
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
22134
22967
|
for (const [index, row] of value.entries()) {
|
|
22135
|
-
if (
|
|
22968
|
+
if (isRecord11(row)) {
|
|
22136
22969
|
errors.push(...validateFormEntries(row, field.children, `${prefix}${field.key}[${index}].`));
|
|
22137
22970
|
}
|
|
22138
22971
|
}
|
|
@@ -22210,10 +23043,10 @@ function explainFormValidationSchema(fields) {
|
|
|
22210
23043
|
}
|
|
22211
23044
|
|
|
22212
23045
|
// src/commands/step.ts
|
|
22213
|
-
function
|
|
23046
|
+
function isRecord12(value) {
|
|
22214
23047
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22215
23048
|
}
|
|
22216
|
-
function
|
|
23049
|
+
function stringValue4(value) {
|
|
22217
23050
|
if (value === void 0 || value === null) {
|
|
22218
23051
|
return void 0;
|
|
22219
23052
|
}
|
|
@@ -22221,7 +23054,7 @@ function stringValue3(value) {
|
|
|
22221
23054
|
return next ? next : void 0;
|
|
22222
23055
|
}
|
|
22223
23056
|
function idValue(value) {
|
|
22224
|
-
const next =
|
|
23057
|
+
const next = stringValue4(value);
|
|
22225
23058
|
return next && /^\d+$/.test(next) ? next : void 0;
|
|
22226
23059
|
}
|
|
22227
23060
|
function hasMeaningfulValue(value) {
|
|
@@ -22237,7 +23070,7 @@ function hasMeaningfulValue(value) {
|
|
|
22237
23070
|
if (Array.isArray(value)) {
|
|
22238
23071
|
return value.some(hasMeaningfulValue);
|
|
22239
23072
|
}
|
|
22240
|
-
if (
|
|
23073
|
+
if (isRecord12(value)) {
|
|
22241
23074
|
return Object.values(value).some(hasMeaningfulValue);
|
|
22242
23075
|
}
|
|
22243
23076
|
return false;
|
|
@@ -22246,11 +23079,11 @@ function isEmptyValue(value) {
|
|
|
22246
23079
|
return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
22247
23080
|
}
|
|
22248
23081
|
function projectIdOfStep(step) {
|
|
22249
|
-
const nestedProjectId =
|
|
23082
|
+
const nestedProjectId = isRecord12(step.project) ? step.project.id : void 0;
|
|
22250
23083
|
return idValue(step.project_id ?? step.projectId ?? nestedProjectId);
|
|
22251
23084
|
}
|
|
22252
23085
|
function stepFlowNodeId(step) {
|
|
22253
|
-
return
|
|
23086
|
+
return stringValue4(step.flow_step_id ?? step.flowStepId ?? step.flow_node_id ?? step.flowNodeId);
|
|
22254
23087
|
}
|
|
22255
23088
|
function isStepFinished(step) {
|
|
22256
23089
|
if (step.real_end_time || step.end_time) {
|
|
@@ -22274,12 +23107,12 @@ function collectRecords(value, output = [], seen = /* @__PURE__ */ new Set()) {
|
|
|
22274
23107
|
value.forEach((item) => collectRecords(item, output, seen));
|
|
22275
23108
|
return output;
|
|
22276
23109
|
}
|
|
22277
|
-
if (!
|
|
23110
|
+
if (!isRecord12(value)) {
|
|
22278
23111
|
return output;
|
|
22279
23112
|
}
|
|
22280
23113
|
output.push(value);
|
|
22281
23114
|
for (const child of Object.values(value)) {
|
|
22282
|
-
if (Array.isArray(child) ||
|
|
23115
|
+
if (Array.isArray(child) || isRecord12(child)) {
|
|
22283
23116
|
collectRecords(child, output, seen);
|
|
22284
23117
|
}
|
|
22285
23118
|
}
|
|
@@ -22301,7 +23134,7 @@ function findFlowNode(project, step) {
|
|
|
22301
23134
|
project.config
|
|
22302
23135
|
];
|
|
22303
23136
|
for (const candidate of candidates) {
|
|
22304
|
-
const match = collectRecords(candidate).find((item) =>
|
|
23137
|
+
const match = collectRecords(candidate).find((item) => stringValue4(item.id) === flowStepId);
|
|
22305
23138
|
if (match) {
|
|
22306
23139
|
return match;
|
|
22307
23140
|
}
|
|
@@ -22363,7 +23196,7 @@ function formListOfStep(step) {
|
|
|
22363
23196
|
return values.filter(hasMeaningfulValue);
|
|
22364
23197
|
}
|
|
22365
23198
|
function unwrapFormValue(value) {
|
|
22366
|
-
if (!
|
|
23199
|
+
if (!isRecord12(value)) {
|
|
22367
23200
|
return value;
|
|
22368
23201
|
}
|
|
22369
23202
|
if ("value" in value && Object.keys(value).length <= 3) {
|
|
@@ -22380,10 +23213,10 @@ function collectFormValues(value, output = {}, seen = /* @__PURE__ */ new Set())
|
|
|
22380
23213
|
value.forEach((item) => collectFormValues(item, output, seen));
|
|
22381
23214
|
return output;
|
|
22382
23215
|
}
|
|
22383
|
-
if (!
|
|
23216
|
+
if (!isRecord12(value)) {
|
|
22384
23217
|
return output;
|
|
22385
23218
|
}
|
|
22386
|
-
const key =
|
|
23219
|
+
const key = stringValue4(value.key ?? value.field_key ?? value.fieldKey ?? value.name);
|
|
22387
23220
|
if (key && "value" in value) {
|
|
22388
23221
|
const nextValue = unwrapFormValue(value.value);
|
|
22389
23222
|
if (hasMeaningfulValue(nextValue)) {
|
|
@@ -22391,7 +23224,7 @@ function collectFormValues(value, output = {}, seen = /* @__PURE__ */ new Set())
|
|
|
22391
23224
|
}
|
|
22392
23225
|
}
|
|
22393
23226
|
for (const child of Object.values(value)) {
|
|
22394
|
-
if (Array.isArray(child) ||
|
|
23227
|
+
if (Array.isArray(child) || isRecord12(child)) {
|
|
22395
23228
|
collectFormValues(child, output, seen);
|
|
22396
23229
|
}
|
|
22397
23230
|
}
|
|
@@ -22438,7 +23271,7 @@ function collectMissingRequiredInputs(fields, values) {
|
|
|
22438
23271
|
continue;
|
|
22439
23272
|
}
|
|
22440
23273
|
value.forEach((row, index) => {
|
|
22441
|
-
if (!
|
|
23274
|
+
if (!isRecord12(row)) {
|
|
22442
23275
|
return;
|
|
22443
23276
|
}
|
|
22444
23277
|
for (const child of field.children ?? []) {
|
|
@@ -22492,7 +23325,7 @@ function ownerIdsFromStep(step) {
|
|
|
22492
23325
|
];
|
|
22493
23326
|
const ids = /* @__PURE__ */ new Set();
|
|
22494
23327
|
for (const owner of owners) {
|
|
22495
|
-
if (
|
|
23328
|
+
if (isRecord12(owner)) {
|
|
22496
23329
|
const id = idValue(owner.owner_id ?? owner.user_id ?? owner.id);
|
|
22497
23330
|
if (id) {
|
|
22498
23331
|
ids.add(id);
|
|
@@ -22531,7 +23364,7 @@ function ownerDiagnosticsFromStep(step, currentUser) {
|
|
|
22531
23364
|
const values = Array.isArray(value) ? value : [value];
|
|
22532
23365
|
for (const item of values) {
|
|
22533
23366
|
let id;
|
|
22534
|
-
if (
|
|
23367
|
+
if (isRecord12(item)) {
|
|
22535
23368
|
id = idValue(item.owner_id ?? item.user_id ?? item.id);
|
|
22536
23369
|
} else {
|
|
22537
23370
|
id = idValue(item);
|
|
@@ -22654,12 +23487,12 @@ function extractSubmitInputValues(data) {
|
|
|
22654
23487
|
const candidates = [data.form, data.form_data, data.formData, data.fields, data.values];
|
|
22655
23488
|
const values = {};
|
|
22656
23489
|
for (const candidate of candidates) {
|
|
22657
|
-
if (
|
|
23490
|
+
if (isRecord12(candidate)) {
|
|
22658
23491
|
Object.assign(values, candidate);
|
|
22659
23492
|
}
|
|
22660
23493
|
}
|
|
22661
23494
|
for (const [key, value] of Object.entries(data)) {
|
|
22662
|
-
if (!SUBMIT_NON_FORM_KEYS.has(key) && !
|
|
23495
|
+
if (!SUBMIT_NON_FORM_KEYS.has(key) && !isRecord12(value) && !Array.isArray(value)) {
|
|
22663
23496
|
values[key] = value;
|
|
22664
23497
|
}
|
|
22665
23498
|
}
|
|
@@ -22802,7 +23635,8 @@ async function requireE2eExecutionBinding(options, runners, evidenceDir) {
|
|
|
22802
23635
|
manifest: options.executionManifest,
|
|
22803
23636
|
caseId: options.caseId,
|
|
22804
23637
|
caseStepId: options.caseStepId,
|
|
22805
|
-
runners
|
|
23638
|
+
runners,
|
|
23639
|
+
...options.profile ? { profile: options.profile } : {}
|
|
22806
23640
|
});
|
|
22807
23641
|
if (evidenceDir) {
|
|
22808
23642
|
await preflightExecutionEvidenceDirectory({
|
|
@@ -22821,10 +23655,10 @@ async function appendE2eExecutionEvidence(options, evidence, runners) {
|
|
|
22821
23655
|
runners
|
|
22822
23656
|
});
|
|
22823
23657
|
}
|
|
22824
|
-
function
|
|
23658
|
+
function isRecord13(value) {
|
|
22825
23659
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22826
23660
|
}
|
|
22827
|
-
function
|
|
23661
|
+
function stringValue5(value) {
|
|
22828
23662
|
if (value === void 0 || value === null) {
|
|
22829
23663
|
return void 0;
|
|
22830
23664
|
}
|
|
@@ -22842,18 +23676,18 @@ function timestampSlug() {
|
|
|
22842
23676
|
return (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
22843
23677
|
}
|
|
22844
23678
|
async function ensureDir(dir) {
|
|
22845
|
-
const resolved =
|
|
22846
|
-
await
|
|
23679
|
+
const resolved = path15.resolve(dir);
|
|
23680
|
+
await mkdir12(resolved, { recursive: true });
|
|
22847
23681
|
return resolved;
|
|
22848
23682
|
}
|
|
22849
23683
|
async function writeEvidence(dir, name, value) {
|
|
22850
|
-
const file =
|
|
22851
|
-
await
|
|
23684
|
+
const file = path15.join(await ensureDir(dir), name);
|
|
23685
|
+
await writeFile12(file, `${JSON.stringify(redactAuditValue(value), null, 2)}
|
|
22852
23686
|
`, "utf8");
|
|
22853
23687
|
return file;
|
|
22854
23688
|
}
|
|
22855
23689
|
function summarizeRemoteResult(value) {
|
|
22856
|
-
if (!
|
|
23690
|
+
if (!isRecord13(value)) return value;
|
|
22857
23691
|
const summary = {};
|
|
22858
23692
|
for (const key of ["id", "project_id", "step_id", "status", "state", "code", "msg", "message", "next", "action"]) {
|
|
22859
23693
|
if (value[key] !== void 0) summary[key] = value[key];
|
|
@@ -22861,34 +23695,37 @@ function summarizeRemoteResult(value) {
|
|
|
22861
23695
|
return Object.keys(summary).length > 0 ? redactAuditValue(summary) : { received: true };
|
|
22862
23696
|
}
|
|
22863
23697
|
function stepReadbackConfirmed(before, after) {
|
|
22864
|
-
const beforeStatus =
|
|
22865
|
-
const afterStatus =
|
|
22866
|
-
const beforeProjectStep =
|
|
22867
|
-
const afterProjectStep =
|
|
23698
|
+
const beforeStatus = isRecord13(before.step) ? before.step.status : void 0;
|
|
23699
|
+
const afterStatus = isRecord13(after.step) ? after.step.status : void 0;
|
|
23700
|
+
const beforeProjectStep = isRecord13(before.project) ? before.project.current_flow_step_id : void 0;
|
|
23701
|
+
const afterProjectStep = isRecord13(after.project) ? after.project.current_flow_step_id : void 0;
|
|
22868
23702
|
return after.step_finished === true || beforeStatus !== afterStatus || beforeProjectStep !== afterProjectStep;
|
|
22869
23703
|
}
|
|
22870
23704
|
function evidenceMime(buffer, file) {
|
|
22871
23705
|
if (buffer.length >= 8 && buffer.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) return "image/png";
|
|
22872
23706
|
if (buffer.length >= 3 && buffer[0] === 255 && buffer[1] === 216 && buffer[2] === 255) return "image/jpeg";
|
|
22873
23707
|
if (buffer.length >= 12 && buffer.subarray(0, 4).toString("ascii") === "RIFF" && buffer.subarray(8, 12).toString("ascii") === "WEBP") return "image/webp";
|
|
22874
|
-
if (
|
|
22875
|
-
if ([".txt", ".md", ".log"].includes(
|
|
23708
|
+
if (path15.extname(file).toLowerCase() === ".json") return "application/json";
|
|
23709
|
+
if ([".txt", ".md", ".log"].includes(path15.extname(file).toLowerCase())) return "text/plain";
|
|
22876
23710
|
return "application/octet-stream";
|
|
22877
23711
|
}
|
|
22878
|
-
async function writeEvidenceManifest(evidenceDir, details) {
|
|
23712
|
+
async function writeEvidenceManifest(evidenceDir, details, extraFiles = []) {
|
|
22879
23713
|
const files = await readdir5(evidenceDir, { withFileTypes: true });
|
|
23714
|
+
const artifactFiles = [
|
|
23715
|
+
...files.filter((entry) => entry.isFile() && entry.name !== "evidence-manifest.json" && !entry.name.includes(".completion-claim.json") && !entry.name.includes(".completion-claim.json.stale-")).map((entry) => path15.join(evidenceDir, entry.name)),
|
|
23716
|
+
...extraFiles.map((file) => path15.resolve(file))
|
|
23717
|
+
];
|
|
22880
23718
|
const artifacts = [];
|
|
22881
|
-
for (const
|
|
22882
|
-
|
|
22883
|
-
const
|
|
22884
|
-
const
|
|
22885
|
-
const
|
|
22886
|
-
const extension = path14.extname(entry.name).toLowerCase();
|
|
23719
|
+
for (const file of [...new Set(artifactFiles)]) {
|
|
23720
|
+
const buffer = await readFile16(file);
|
|
23721
|
+
const relativePath = path15.relative(evidenceDir, file);
|
|
23722
|
+
const mimeType = evidenceMime(buffer, relativePath);
|
|
23723
|
+
const extension = path15.extname(relativePath).toLowerCase();
|
|
22887
23724
|
const expectedMime = extension === ".png" ? "image/png" : [".jpg", ".jpeg"].includes(extension) ? "image/jpeg" : extension === ".webp" ? "image/webp" : void 0;
|
|
22888
23725
|
artifacts.push({
|
|
22889
|
-
path:
|
|
23726
|
+
path: relativePath,
|
|
22890
23727
|
size: buffer.length,
|
|
22891
|
-
sha256:
|
|
23728
|
+
sha256: createHash8("sha256").update(buffer).digest("hex"),
|
|
22892
23729
|
mime_type: mimeType,
|
|
22893
23730
|
...expectedMime && expectedMime !== mimeType ? { extension_mismatch: true, expected_mime: expectedMime } : {}
|
|
22894
23731
|
});
|
|
@@ -22896,19 +23733,19 @@ async function writeEvidenceManifest(evidenceDir, details) {
|
|
|
22896
23733
|
return writeEvidence(evidenceDir, "evidence-manifest.json", {
|
|
22897
23734
|
schema_version: 1,
|
|
22898
23735
|
generated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
22899
|
-
evidence_dir:
|
|
23736
|
+
evidence_dir: path15.resolve(evidenceDir),
|
|
22900
23737
|
...details,
|
|
22901
23738
|
artifacts
|
|
22902
23739
|
});
|
|
22903
23740
|
}
|
|
22904
23741
|
function cacheRoot() {
|
|
22905
|
-
return
|
|
23742
|
+
return path15.resolve(".codex/cache/bpmax-e2e");
|
|
22906
23743
|
}
|
|
22907
23744
|
function safeSegment(value) {
|
|
22908
23745
|
return value.trim().replace(/[^a-zA-Z0-9._:-]+/g, "_") || "default";
|
|
22909
23746
|
}
|
|
22910
|
-
function
|
|
22911
|
-
if (!
|
|
23747
|
+
function safeIdentity2(value) {
|
|
23748
|
+
if (!isRecord13(value)) return null;
|
|
22912
23749
|
return {
|
|
22913
23750
|
id: value.id,
|
|
22914
23751
|
name: value.name,
|
|
@@ -22949,14 +23786,14 @@ async function browserSessionRequest(profile, cookie, method, apiPath2, data, hr
|
|
|
22949
23786
|
response.status
|
|
22950
23787
|
);
|
|
22951
23788
|
}
|
|
22952
|
-
if (
|
|
23789
|
+
if (isRecord13(body) && typeof body.code === "number" && body.code !== 0) {
|
|
22953
23790
|
throw new BrowserSessionRejectedError(
|
|
22954
23791
|
`e2e.identity.api_error: ${String(body.msg ?? body.message ?? body.code)}`,
|
|
22955
23792
|
response.status,
|
|
22956
23793
|
body.code
|
|
22957
23794
|
);
|
|
22958
23795
|
}
|
|
22959
|
-
return
|
|
23796
|
+
return isRecord13(body) && Object.prototype.hasOwnProperty.call(body, "data") ? body.data : body;
|
|
22960
23797
|
}
|
|
22961
23798
|
function identityCookie(cookieEnv) {
|
|
22962
23799
|
const cookie = process.env[cookieEnv]?.trim();
|
|
@@ -22965,6 +23802,78 @@ function identityCookie(cookieEnv) {
|
|
|
22965
23802
|
}
|
|
22966
23803
|
return cookie;
|
|
22967
23804
|
}
|
|
23805
|
+
async function restoreBrowserSessionIdentity(profile, cookie, current, hrefPath) {
|
|
23806
|
+
const primaryEndpoint = "/user/current?identity_action=unmock";
|
|
23807
|
+
try {
|
|
23808
|
+
await browserSessionRequest(profile, cookie, "PUT", primaryEndpoint, { unmock: true }, hrefPath);
|
|
23809
|
+
return { compatibility_fallback: false, endpoint: primaryEndpoint };
|
|
23810
|
+
} catch (error) {
|
|
23811
|
+
const currentUserId = Number(current?.id);
|
|
23812
|
+
if (!(error instanceof BrowserSessionRejectedError) || error.status !== 403 && error.apiCode !== 403 || !/organization\.admin/.test(error.message) || current?.mock !== true || !Number.isSafeInteger(currentUserId) || currentUserId <= 0) {
|
|
23813
|
+
throw error;
|
|
23814
|
+
}
|
|
23815
|
+
const legacyEndpoint = `/user/${currentUserId}`;
|
|
23816
|
+
await browserSessionRequest(profile, cookie, "PUT", legacyEndpoint, { unmock: true }, hrefPath);
|
|
23817
|
+
return { compatibility_fallback: true, endpoint: legacyEndpoint };
|
|
23818
|
+
}
|
|
23819
|
+
}
|
|
23820
|
+
function assertRestoredIdentity(before, after, errorCode) {
|
|
23821
|
+
if (!after || after.mock === true || before?.mock_by_user && Number(after.id) !== Number(before.mock_by_user)) {
|
|
23822
|
+
throw new Error(`${errorCode}: unmock \u5DF2\u63D0\u4EA4\uFF0C\u4F46\u672A\u786E\u8BA4\u6062\u590D\u539F\u59CB\u8EAB\u4EFD\uFF0C\u5FC5\u987B\u505C\u6B62\u540E\u7EED\u7528\u4F8B\u3002`);
|
|
23823
|
+
}
|
|
23824
|
+
}
|
|
23825
|
+
function requireLegacyIdentityDiagnostic(options) {
|
|
23826
|
+
if (!options.diagnostic) {
|
|
23827
|
+
throw new Error(
|
|
23828
|
+
"e2e.identity.legacy_cookie_diagnostic_only: Cookie transport \u53EA\u4FDD\u7559\u663E\u5F0F --diagnostic \u6392\u969C\uFF1B\u6B63\u5F0F\u591A\u89D2\u8272 E2E \u5FC5\u987B\u4F7F\u7528 `e2e identity browser status|mock|unmock`\u3002"
|
|
23829
|
+
);
|
|
23830
|
+
}
|
|
23831
|
+
if (options.executionManifest || options.caseId || options.caseStepId) {
|
|
23832
|
+
throw new Error(
|
|
23833
|
+
"e2e.identity.legacy_cookie_formal_binding_forbidden: Cookie transport \u4E0D\u5F97\u7ED1\u5B9A execution manifest/case/step\uFF0C\u4E5F\u4E0D\u80FD\u5F62\u6210\u6B63\u5F0F\u901A\u8FC7\u8BC1\u636E\u3002"
|
|
23834
|
+
);
|
|
23835
|
+
}
|
|
23836
|
+
}
|
|
23837
|
+
function identityBridgeBinding(options) {
|
|
23838
|
+
return {
|
|
23839
|
+
diagnostic: options.diagnostic === true,
|
|
23840
|
+
...options.executionManifest ? { execution_manifest: path15.resolve(options.executionManifest) } : {},
|
|
23841
|
+
...options.caseId ? { case_id: options.caseId } : {},
|
|
23842
|
+
...options.caseStepId ? { case_step_id: options.caseStepId } : {}
|
|
23843
|
+
};
|
|
23844
|
+
}
|
|
23845
|
+
function identityLeaseFile(options, evidenceDir) {
|
|
23846
|
+
return path15.join(
|
|
23847
|
+
options.executionManifest ? path15.dirname(path15.resolve(options.executionManifest)) : path15.resolve(evidenceDir),
|
|
23848
|
+
"identity-lease.json"
|
|
23849
|
+
);
|
|
23850
|
+
}
|
|
23851
|
+
async function identityBridgeTargetUser(profile, userId) {
|
|
23852
|
+
const result = await apiRequest(createApiClient(profile), "GET", "/user", {
|
|
23853
|
+
params: {
|
|
23854
|
+
ids: String(userId),
|
|
23855
|
+
subRelations: "role",
|
|
23856
|
+
field_filter: "id,name,status,is_del,organization_id"
|
|
23857
|
+
},
|
|
23858
|
+
capability: "user.readback"
|
|
23859
|
+
});
|
|
23860
|
+
const rows2 = Array.isArray(result) ? result.filter(isRecord13) : isRecord13(result) && Array.isArray(result.data) ? result.data.filter(isRecord13) : isRecord13(result) && result.id !== void 0 ? [result] : [];
|
|
23861
|
+
const matched = rows2.find((item) => Number(item.id) === userId);
|
|
23862
|
+
if (!matched) throw new Error(`e2e.identity.browser.target_not_found: typed user readback \u672A\u627E\u5230\u7528\u6237 ${userId}\u3002`);
|
|
23863
|
+
const name = stringValue5(matched.name);
|
|
23864
|
+
if (!name) throw new Error(`e2e.identity.browser.target_name_missing: \u7528\u6237 ${userId} \u7F3A\u5C11\u53EF\u7528\u4E8E\u9875\u9762\u7CBE\u786E\u5B9A\u4F4D\u7684\u59D3\u540D\u3002`);
|
|
23865
|
+
const status = Number(matched.status);
|
|
23866
|
+
const deleted = matched.is_del !== void 0 && Number(matched.is_del) !== 0;
|
|
23867
|
+
if (status !== 0 || deleted) {
|
|
23868
|
+
throw new Error(`e2e.identity.browser.target_inactive: \u7528\u6237 ${userId} \u4E0D\u662F\u53EF\u6A21\u62DF\u7684\u6709\u6548\u72B6\u6001\u3002`);
|
|
23869
|
+
}
|
|
23870
|
+
const organizationId = Number(matched.organization_id);
|
|
23871
|
+
return {
|
|
23872
|
+
id: userId,
|
|
23873
|
+
name,
|
|
23874
|
+
...Number.isSafeInteger(organizationId) && organizationId > 0 ? { organization_id: organizationId } : {}
|
|
23875
|
+
};
|
|
23876
|
+
}
|
|
22968
23877
|
function shellQuote5(value) {
|
|
22969
23878
|
if (/^[a-zA-Z0-9_@%+=:,./-]+$/.test(value)) {
|
|
22970
23879
|
return value;
|
|
@@ -22989,7 +23898,7 @@ function valuesEqual(left, right) {
|
|
|
22989
23898
|
}
|
|
22990
23899
|
function pathValue(source, dottedPath) {
|
|
22991
23900
|
return dottedPath.split(".").reduce((current, segment) => {
|
|
22992
|
-
if (!
|
|
23901
|
+
if (!isRecord13(current)) {
|
|
22993
23902
|
return void 0;
|
|
22994
23903
|
}
|
|
22995
23904
|
return current[segment];
|
|
@@ -22999,10 +23908,10 @@ function normalizeExpectedChecks(value) {
|
|
|
22999
23908
|
if (!Array.isArray(value)) {
|
|
23000
23909
|
return [];
|
|
23001
23910
|
}
|
|
23002
|
-
return value.filter(
|
|
23003
|
-
...
|
|
23004
|
-
path:
|
|
23005
|
-
op:
|
|
23911
|
+
return value.filter(isRecord13).map((item) => ({
|
|
23912
|
+
...stringValue5(item.name) ? { name: stringValue5(item.name) } : {},
|
|
23913
|
+
path: stringValue5(item.path) ?? "",
|
|
23914
|
+
op: stringValue5(item.op) ?? "equals",
|
|
23006
23915
|
...Object.prototype.hasOwnProperty.call(item, "value") ? { value: item.value } : {},
|
|
23007
23916
|
...Array.isArray(item.values) ? { values: item.values } : {}
|
|
23008
23917
|
})).filter((item) => item.path);
|
|
@@ -23074,13 +23983,13 @@ function buildExpectedChecks(options) {
|
|
|
23074
23983
|
];
|
|
23075
23984
|
}
|
|
23076
23985
|
function flowCachePath(profileName, flowId) {
|
|
23077
|
-
return
|
|
23986
|
+
return path15.join(cacheRoot(), "profiles", safeSegment(profileName), "flows", `${safeSegment(flowId)}.json`);
|
|
23078
23987
|
}
|
|
23079
23988
|
async function readOptionalJson(file) {
|
|
23080
23989
|
try {
|
|
23081
|
-
const raw = await
|
|
23990
|
+
const raw = await readFile16(file, "utf8");
|
|
23082
23991
|
const parsed = JSON.parse(raw);
|
|
23083
|
-
return
|
|
23992
|
+
return isRecord13(parsed) ? parsed : null;
|
|
23084
23993
|
} catch (error) {
|
|
23085
23994
|
if (error.code === "ENOENT") {
|
|
23086
23995
|
return null;
|
|
@@ -23102,34 +24011,34 @@ function stepsFromProfile(profile) {
|
|
|
23102
24011
|
if (!profile) {
|
|
23103
24012
|
return [];
|
|
23104
24013
|
}
|
|
23105
|
-
if (
|
|
24014
|
+
if (stringValue5(profile.step_id ?? profile.stepId)) {
|
|
23106
24015
|
return [profile];
|
|
23107
24016
|
}
|
|
23108
24017
|
const steps = profile.steps;
|
|
23109
24018
|
if (Array.isArray(steps)) {
|
|
23110
|
-
return steps.filter(
|
|
24019
|
+
return steps.filter(isRecord13);
|
|
23111
24020
|
}
|
|
23112
|
-
if (
|
|
24021
|
+
if (isRecord13(steps)) {
|
|
23113
24022
|
return Object.entries(steps).map(([stepId, value]) => ({
|
|
23114
|
-
...
|
|
24023
|
+
...isRecord13(value) ? value : { data: value },
|
|
23115
24024
|
step_id: stepId
|
|
23116
24025
|
}));
|
|
23117
24026
|
}
|
|
23118
24027
|
return [];
|
|
23119
24028
|
}
|
|
23120
24029
|
function normalizeStepPlan(input, defaults) {
|
|
23121
|
-
const stepId =
|
|
24030
|
+
const stepId = stringValue5(input.step_id ?? input.stepId ?? defaults.stepId);
|
|
23122
24031
|
if (!stepId) {
|
|
23123
24032
|
throw new Error("e2e step-run requires --step-id or data-profile steps[].step_id.");
|
|
23124
24033
|
}
|
|
23125
24034
|
const rawData = input.data ?? input.payload_template ?? input.payloadTemplate ?? input.form ?? input.values ?? {};
|
|
23126
|
-
const data =
|
|
24035
|
+
const data = isRecord13(rawData) ? rawData : {};
|
|
23127
24036
|
return {
|
|
23128
24037
|
step_id: stepId,
|
|
23129
|
-
action:
|
|
23130
|
-
...
|
|
23131
|
-
...
|
|
23132
|
-
...
|
|
24038
|
+
action: stringValue5(input.action) ?? defaults.action,
|
|
24039
|
+
...stringValue5(input.label) ? { label: stringValue5(input.label) } : {},
|
|
24040
|
+
...stringValue5(input.target_step ?? input.targetStep) ? { target_step: stringValue5(input.target_step ?? input.targetStep) } : {},
|
|
24041
|
+
...stringValue5(input.comments) ?? defaults.comments ? { comments: stringValue5(input.comments) ?? defaults.comments } : {},
|
|
23133
24042
|
urgency: numberValue(input.urgency, defaults.urgency),
|
|
23134
24043
|
data,
|
|
23135
24044
|
expected_checks: normalizeExpectedChecks(input.expected_checks ?? input.expectedChecks)
|
|
@@ -23163,7 +24072,7 @@ function dataProfilePath(input) {
|
|
|
23163
24072
|
if (!input?.startsWith("@")) {
|
|
23164
24073
|
return void 0;
|
|
23165
24074
|
}
|
|
23166
|
-
return
|
|
24075
|
+
return path15.resolve(input.slice(1));
|
|
23167
24076
|
}
|
|
23168
24077
|
function refreshedStepTemplate(options) {
|
|
23169
24078
|
return {
|
|
@@ -23187,15 +24096,15 @@ function refreshedStepTemplate(options) {
|
|
|
23187
24096
|
variables: Object.keys(options.plan.data).filter((key) => !["project_id", "action", "urgency"].includes(key)),
|
|
23188
24097
|
payload_template: options.plan.data,
|
|
23189
24098
|
source_evidence: {
|
|
23190
|
-
evidence_dir:
|
|
23191
|
-
context:
|
|
24099
|
+
evidence_dir: path15.resolve(options.evidenceDir),
|
|
24100
|
+
context: path15.basename(options.contextFile)
|
|
23192
24101
|
}
|
|
23193
24102
|
};
|
|
23194
24103
|
}
|
|
23195
24104
|
async function writeRefreshedCache(file, template) {
|
|
23196
|
-
const out =
|
|
23197
|
-
await
|
|
23198
|
-
await
|
|
24105
|
+
const out = path15.resolve(file);
|
|
24106
|
+
await mkdir12(path15.dirname(out), { recursive: true });
|
|
24107
|
+
await writeFile12(out, `${JSON.stringify(redactAuditValue(template), null, 2)}
|
|
23199
24108
|
`, "utf8");
|
|
23200
24109
|
return out;
|
|
23201
24110
|
}
|
|
@@ -23218,7 +24127,7 @@ function blockedReason(context2, canSubmit) {
|
|
|
23218
24127
|
return void 0;
|
|
23219
24128
|
}
|
|
23220
24129
|
function handoffUrlFromInput(input) {
|
|
23221
|
-
const url =
|
|
24130
|
+
const url = stringValue5(input.handoff_url ?? input.handoffUrl ?? input.url);
|
|
23222
24131
|
if (!url) {
|
|
23223
24132
|
throw new Error("handoff JSON must contain handoff_url, handoffUrl, or url.");
|
|
23224
24133
|
}
|
|
@@ -23275,13 +24184,13 @@ test(${JSON.stringify(options.title)}, async ({ page }) => {
|
|
|
23275
24184
|
async function writeBrowserTemplate(options) {
|
|
23276
24185
|
const handoffUrl = handoffUrlFromInput(options.handoff);
|
|
23277
24186
|
const assertFields = (options.assertFields ?? "").split(",").map((item) => item.trim()).filter(Boolean);
|
|
23278
|
-
const out =
|
|
23279
|
-
await
|
|
23280
|
-
await
|
|
24187
|
+
const out = path15.resolve(options.out);
|
|
24188
|
+
await mkdir12(path15.dirname(out), { recursive: true });
|
|
24189
|
+
await writeFile12(out, playwrightTemplate({
|
|
23281
24190
|
title: options.title ?? "BPMAX create page handoff submit",
|
|
23282
24191
|
handoffUrl,
|
|
23283
24192
|
assertFields,
|
|
23284
|
-
evidenceDir:
|
|
24193
|
+
evidenceDir: path15.resolve(options.evidenceDir)
|
|
23285
24194
|
}), "utf8");
|
|
23286
24195
|
return { out, handoff_url: handoffUrl, assert_fields: assertFields };
|
|
23287
24196
|
}
|
|
@@ -23289,15 +24198,15 @@ async function updateAutomationFromRecordedTrace(options) {
|
|
|
23289
24198
|
if (!options.caseId || !options.caseStepId) {
|
|
23290
24199
|
throw new Error("--automation-out requires --case-id and --case-step-id");
|
|
23291
24200
|
}
|
|
23292
|
-
const tracePath =
|
|
24201
|
+
const tracePath = path15.join(path15.resolve(options.evidenceDir), "browser-action-trace.json");
|
|
23293
24202
|
const trace = await readOptionalJson(tracePath);
|
|
23294
|
-
if (!trace || !
|
|
24203
|
+
if (!trace || !isRecord13(trace) || !Array.isArray(trace.actions) || !Array.isArray(trace.expected_checks) || !isRecord13(trace.page_fingerprint)) {
|
|
23295
24204
|
throw new Error("browser-action-trace.json must contain page_fingerprint, actions, and expected_checks before automation can be generated");
|
|
23296
24205
|
}
|
|
23297
|
-
const out =
|
|
24206
|
+
const out = path15.resolve(options.automationOut);
|
|
23298
24207
|
const existing = await readOptionalJson(out);
|
|
23299
|
-
const document2 = existing &&
|
|
23300
|
-
if (!
|
|
24208
|
+
const document2 = existing && isRecord13(existing) ? existing : { version: 1, ...options.scenario ? { scenario: options.scenario } : {}, steps: {} };
|
|
24209
|
+
if (!isRecord13(document2.steps)) document2.steps = {};
|
|
23301
24210
|
document2.steps[automationStepKey(options.caseId, options.caseStepId)] = {
|
|
23302
24211
|
runner: "browser_action",
|
|
23303
24212
|
page_fingerprint: trace.page_fingerprint,
|
|
@@ -23310,8 +24219,8 @@ async function updateAutomationFromRecordedTrace(options) {
|
|
|
23310
24219
|
throw new Error(`recorded browser automation requires review:
|
|
23311
24220
|
${details}`);
|
|
23312
24221
|
}
|
|
23313
|
-
await
|
|
23314
|
-
await
|
|
24222
|
+
await mkdir12(path15.dirname(out), { recursive: true });
|
|
24223
|
+
await writeFile12(out, `${JSON.stringify(document2, null, 2)}
|
|
23315
24224
|
`, "utf8");
|
|
23316
24225
|
return out;
|
|
23317
24226
|
}
|
|
@@ -23320,20 +24229,21 @@ function scenarioRecords(plan) {
|
|
|
23320
24229
|
if (!Array.isArray(records)) {
|
|
23321
24230
|
return [];
|
|
23322
24231
|
}
|
|
23323
|
-
return records.filter(
|
|
24232
|
+
return records.filter(isRecord13);
|
|
23324
24233
|
}
|
|
23325
24234
|
function recordKey(record, index) {
|
|
23326
|
-
return
|
|
24235
|
+
return stringValue5(record.demo_no ?? record.id ?? record.case_id ?? record.subject) ?? `record-${index + 1}`;
|
|
23327
24236
|
}
|
|
23328
24237
|
function registerE2eCommands(program2) {
|
|
23329
24238
|
const e2e = program2.command("e2e").description("BPMAX E2E acceleration helpers with evidence-first safety gates");
|
|
23330
|
-
const identity = e2e.command("identity").description("Control browser-session mock identity for
|
|
24239
|
+
const identity = e2e.command("identity").description("Control browser-session mock identity for multi-role E2E");
|
|
23331
24240
|
const addIdentityOptions = (command) => command.requiredOption("--evidence-dir <dir>", "Current-run identity evidence directory").option("--execution-manifest <file>", "Formal test-suite execution manifest").option("--case-id <id>", "Formal test-suite case id").option("--case-step-id <id>", "Formal test-suite case step id").option("--diagnostic", "Run without a formal manifest; cannot become pass evidence").option("--profile <profile>", "Profile providing origin and workspace").option("--cookie-env <name>", "Environment variable containing current browser Cookie", "BPMAX_COOKIE_HEADER").option("--href-path <path>", "BPMAX page path used for Referer and x-href").option("--format <format>", "Output format", "json");
|
|
23332
|
-
addIdentityOptions(identity.command("status").description("
|
|
24241
|
+
addIdentityOptions(identity.command("status").description("Legacy Cookie diagnostic: read current browser-session identity")).action(async (options) => {
|
|
24242
|
+
requireLegacyIdentityDiagnostic(options);
|
|
23333
24243
|
await requireE2eExecutionBinding(options, ["identity", "browser", "observe"], options.evidenceDir);
|
|
23334
24244
|
const config = await loadConfig();
|
|
23335
24245
|
const profile = resolveProfile(config, options.profile);
|
|
23336
|
-
const current =
|
|
24246
|
+
const current = safeIdentity2(await browserSessionRequest(
|
|
23337
24247
|
profile,
|
|
23338
24248
|
identityCookie(options.cookieEnv),
|
|
23339
24249
|
"GET",
|
|
@@ -23357,7 +24267,8 @@ function registerE2eCommands(program2) {
|
|
|
23357
24267
|
evidence
|
|
23358
24268
|
});
|
|
23359
24269
|
});
|
|
23360
|
-
addIdentityOptions(identity.command("mock").description("
|
|
24270
|
+
addIdentityOptions(identity.command("mock").description("Legacy Cookie diagnostic: switch the browser session to one exact BPMAX user")).requiredOption("--user-id <id>", "Exact target BPMAX user id").action(async (options) => {
|
|
24271
|
+
requireLegacyIdentityDiagnostic(options);
|
|
23361
24272
|
const userId = Number(options.userId);
|
|
23362
24273
|
if (!Number.isSafeInteger(userId) || userId <= 0) {
|
|
23363
24274
|
throw new Error("e2e.identity.invalid_user_id: --user-id \u5FC5\u987B\u662F\u6B63\u6574\u6570\u3002");
|
|
@@ -23371,7 +24282,30 @@ function registerE2eCommands(program2) {
|
|
|
23371
24282
|
target_user_id: userId,
|
|
23372
24283
|
remote_submitted: false
|
|
23373
24284
|
});
|
|
23374
|
-
const
|
|
24285
|
+
const initialBefore = safeIdentity2(await browserSessionRequest(profile, cookie, "GET", "/user/current", void 0, options.hrefPath));
|
|
24286
|
+
let before = initialBefore;
|
|
24287
|
+
let preMockRestore = null;
|
|
24288
|
+
if (before?.mock === true) {
|
|
24289
|
+
let restoreResult;
|
|
24290
|
+
try {
|
|
24291
|
+
restoreResult = await restoreBrowserSessionIdentity(profile, cookie, before, options.hrefPath);
|
|
24292
|
+
} catch (error) {
|
|
24293
|
+
throw new Error(
|
|
24294
|
+
`e2e.identity.pre_mock_restore_failed: \u5F53\u524D\u4F1A\u8BDD\u4ECD\u5904\u4E8E mock \u72B6\u6001\uFF0C\u5207\u6362\u4E0B\u4E00\u89D2\u8272\u524D\u6062\u590D\u539F\u8EAB\u4EFD\u5931\u8D25\uFF1B\u672A\u63D0\u4EA4\u65B0\u7684 mock\u3002${error instanceof Error ? error.message : String(error)}`
|
|
24295
|
+
);
|
|
24296
|
+
}
|
|
24297
|
+
const restored = safeIdentity2(await browserSessionRequest(profile, cookie, "GET", "/user/current", void 0, options.hrefPath));
|
|
24298
|
+
assertRestoredIdentity(before, restored, "e2e.identity.pre_mock_restore_verify_failed");
|
|
24299
|
+
preMockRestore = {
|
|
24300
|
+
operation: "unmock_before_mock",
|
|
24301
|
+
operation_executed: true,
|
|
24302
|
+
readback_confirmed: true,
|
|
24303
|
+
...restoreResult,
|
|
24304
|
+
before,
|
|
24305
|
+
after: restored
|
|
24306
|
+
};
|
|
24307
|
+
before = restored;
|
|
24308
|
+
}
|
|
23375
24309
|
let after = null;
|
|
23376
24310
|
try {
|
|
23377
24311
|
await browserSessionRequest(profile, cookie, "PUT", `/user/${userId}?identity_action=mock`, { mock: true }, options.hrefPath);
|
|
@@ -23385,7 +24319,7 @@ function registerE2eCommands(program2) {
|
|
|
23385
24319
|
throw new Error(`e2e.identity.mock_outcome_unknown: mock \u8BF7\u6C42\u6216\u5199\u540E\u56DE\u8BFB\u5931\u8D25\uFF0CCLI \u5DF2\u5C1D\u8BD5\u81EA\u52A8 unmock\uFF1B\u4E0D\u5F97\u91CD\u590D\u6267\u884C\u5F53\u524D\u6B65\u9AA4\uFF0C\u5148\u8FD0\u884C identity status \u786E\u8BA4\u4F1A\u8BDD\u8EAB\u4EFD\u3002${error instanceof Error ? error.message : String(error)}`);
|
|
23386
24320
|
}
|
|
23387
24321
|
try {
|
|
23388
|
-
after =
|
|
24322
|
+
after = safeIdentity2(await browserSessionRequest(profile, cookie, "GET", "/user/current", void 0, options.hrefPath));
|
|
23389
24323
|
} catch (error) {
|
|
23390
24324
|
await browserSessionRequest(profile, cookie, "PUT", "/user/current?identity_action=unmock", { unmock: true }, options.hrefPath).catch(() => void 0);
|
|
23391
24325
|
throw new Error(`e2e.identity.mock_outcome_unknown: mock \u5DF2\u63D0\u4EA4\u4F46\u5199\u540E\u56DE\u8BFB\u5931\u8D25\uFF0CCLI \u5DF2\u5C1D\u8BD5\u81EA\u52A8 unmock\uFF1B\u4E0D\u5F97\u91CD\u590D\u6267\u884C\u5F53\u524D\u6B65\u9AA4\uFF0C\u5148\u8FD0\u884C identity status \u786E\u8BA4\u4F1A\u8BDD\u8EAB\u4EFD\u3002${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -23407,13 +24341,13 @@ function registerE2eCommands(program2) {
|
|
|
23407
24341
|
target_user_id: userId
|
|
23408
24342
|
});
|
|
23409
24343
|
} catch (error) {
|
|
23410
|
-
await
|
|
24344
|
+
await restoreBrowserSessionIdentity(profile, cookie, after, options.hrefPath).catch(() => void 0);
|
|
23411
24345
|
throw new Error(`e2e.identity.evidence_failed: mock \u540E\u8BC1\u636E\u5199\u5165\u5931\u8D25\uFF0C\u5DF2\u5C1D\u8BD5\u6062\u590D\u539F\u8EAB\u4EFD\u3002${error instanceof Error ? error.message : String(error)}`);
|
|
23412
24346
|
}
|
|
23413
24347
|
try {
|
|
23414
24348
|
await appendE2eExecutionEvidence(options, evidence, ["identity", "browser"]);
|
|
23415
24349
|
} catch (error) {
|
|
23416
|
-
await
|
|
24350
|
+
await restoreBrowserSessionIdentity(profile, cookie, after, options.hrefPath).catch(() => void 0);
|
|
23417
24351
|
throw new Error(`e2e.identity.manifest_evidence_failed: mock \u5DF2\u6267\u884C\u4F46\u7528\u4F8B\u8BC1\u636E\u767B\u8BB0\u5931\u8D25\uFF0CCLI \u5DF2\u5C1D\u8BD5\u81EA\u52A8 unmock\u3002${error instanceof Error ? error.message : String(error)}`);
|
|
23418
24352
|
}
|
|
23419
24353
|
printResult(options.format, {
|
|
@@ -23424,11 +24358,13 @@ function registerE2eCommands(program2) {
|
|
|
23424
24358
|
remote_submitted: true,
|
|
23425
24359
|
readback_confirmed: true,
|
|
23426
24360
|
current_user: after,
|
|
24361
|
+
pre_mock_restore: preMockRestore,
|
|
23427
24362
|
evidence,
|
|
23428
24363
|
preflight_evidence: preflightEvidence
|
|
23429
24364
|
});
|
|
23430
24365
|
});
|
|
23431
|
-
addIdentityOptions(identity.command("unmock").description("
|
|
24366
|
+
addIdentityOptions(identity.command("unmock").description("Legacy Cookie diagnostic: restore the original browser-session identity")).action(async (options) => {
|
|
24367
|
+
requireLegacyIdentityDiagnostic(options);
|
|
23432
24368
|
await requireE2eExecutionBinding(options, ["identity", "browser"], options.evidenceDir);
|
|
23433
24369
|
const config = await loadConfig();
|
|
23434
24370
|
const profile = resolveProfile(config, options.profile);
|
|
@@ -23437,12 +24373,10 @@ function registerE2eCommands(program2) {
|
|
|
23437
24373
|
operation: "unmock",
|
|
23438
24374
|
remote_submitted: false
|
|
23439
24375
|
});
|
|
23440
|
-
const before =
|
|
23441
|
-
await
|
|
23442
|
-
const after =
|
|
23443
|
-
|
|
23444
|
-
throw new Error("e2e.identity.unmock_verify_failed: unmock \u5DF2\u63D0\u4EA4\uFF0C\u4F46\u672A\u786E\u8BA4\u6062\u590D\u539F\u59CB\u8EAB\u4EFD\uFF0C\u5FC5\u987B\u505C\u6B62\u540E\u7EED\u7528\u4F8B\u3002");
|
|
23445
|
-
}
|
|
24376
|
+
const before = safeIdentity2(await browserSessionRequest(profile, cookie, "GET", "/user/current", void 0, options.hrefPath));
|
|
24377
|
+
const restoreResult = await restoreBrowserSessionIdentity(profile, cookie, before, options.hrefPath);
|
|
24378
|
+
const after = safeIdentity2(await browserSessionRequest(profile, cookie, "GET", "/user/current", void 0, options.hrefPath));
|
|
24379
|
+
assertRestoredIdentity(before, after, "e2e.identity.unmock_verify_failed");
|
|
23446
24380
|
const evidence = await writeEvidence(options.evidenceDir, `identity-unmock-${timestampSlug()}.json`, {
|
|
23447
24381
|
result: options.diagnostic ? "diagnostic" : "restored",
|
|
23448
24382
|
operation: "unmock",
|
|
@@ -23450,7 +24384,8 @@ function registerE2eCommands(program2) {
|
|
|
23450
24384
|
remote_submitted: true,
|
|
23451
24385
|
readback_confirmed: true,
|
|
23452
24386
|
before,
|
|
23453
|
-
after
|
|
24387
|
+
after,
|
|
24388
|
+
...restoreResult
|
|
23454
24389
|
});
|
|
23455
24390
|
await appendE2eExecutionEvidence(options, evidence, ["identity", "browser"]);
|
|
23456
24391
|
printResult(options.format, {
|
|
@@ -23461,9 +24396,134 @@ function registerE2eCommands(program2) {
|
|
|
23461
24396
|
remote_submitted: true,
|
|
23462
24397
|
readback_confirmed: true,
|
|
23463
24398
|
current_user: after,
|
|
24399
|
+
...restoreResult,
|
|
23464
24400
|
evidence
|
|
23465
24401
|
});
|
|
23466
24402
|
});
|
|
24403
|
+
const identityBrowser = identity.command("browser").description("Prepare and verify Chrome Control identity switching without exporting browser Cookie");
|
|
24404
|
+
const addIdentityBrowserPrepareOptions = (command) => command.requiredOption("--evidence-dir <dir>", "Current-run identity evidence directory").option("--execution-manifest <file>", "Formal test-suite execution manifest").option("--case-id <id>", "Formal test-suite case id").option("--case-step-id <id>", "Formal test-suite case step id").option("--diagnostic", "Run without a formal manifest; cannot become pass evidence").option("--profile <profile>", "Profile providing origin and workspace").option("--href-path <path>", "BPMAX page restored after identity switching").option("--lease-ttl <seconds>", "Recovery lease TTL before further mock operations are blocked", "900").option("--format <format>", "Output format", "json");
|
|
24405
|
+
const registerIdentityBrowserPrepare = (operation, command) => {
|
|
24406
|
+
addIdentityBrowserPrepareOptions(command).action(async (options) => {
|
|
24407
|
+
const targetUserId = options.userId === void 0 ? void 0 : Number(options.userId);
|
|
24408
|
+
if (operation === "mock" && (!Number.isSafeInteger(targetUserId) || Number(targetUserId) <= 0)) {
|
|
24409
|
+
throw new Error("e2e.identity.browser.invalid_user_id: --user-id \u5FC5\u987B\u662F\u6B63\u6574\u6570\u3002");
|
|
24410
|
+
}
|
|
24411
|
+
await requireE2eExecutionBinding(options, ["identity"], options.evidenceDir);
|
|
24412
|
+
const evidenceDir = await ensureDir(options.evidenceDir);
|
|
24413
|
+
const config = await loadConfig();
|
|
24414
|
+
const profile = resolveProfile(config, options.profile);
|
|
24415
|
+
const targetUser = operation === "mock" && targetUserId ? await identityBridgeTargetUser(profile, targetUserId) : void 0;
|
|
24416
|
+
const prepared = await prepareIdentityBrowserBridge({
|
|
24417
|
+
operation,
|
|
24418
|
+
origin: profile.config.origin,
|
|
24419
|
+
workspace: profile.config.workspace,
|
|
24420
|
+
language: profile.config.language,
|
|
24421
|
+
hrefPath: options.hrefPath,
|
|
24422
|
+
...targetUser ? {
|
|
24423
|
+
targetUserId: targetUser.id,
|
|
24424
|
+
targetUserName: targetUser.name,
|
|
24425
|
+
...targetUser.organization_id ? { targetOrganizationId: targetUser.organization_id } : {}
|
|
24426
|
+
} : {},
|
|
24427
|
+
evidenceDir,
|
|
24428
|
+
leaseFile: identityLeaseFile(options, evidenceDir),
|
|
24429
|
+
binding: { ...identityBridgeBinding(options), profile: profile.name },
|
|
24430
|
+
leaseTtlSeconds: Number(options.leaseTtl)
|
|
24431
|
+
});
|
|
24432
|
+
printResult(options.format, {
|
|
24433
|
+
ok: true,
|
|
24434
|
+
result: "browser_action_required",
|
|
24435
|
+
operation,
|
|
24436
|
+
transport: "chrome_identity_bridge",
|
|
24437
|
+
browser_tool: "chrome:control-chrome",
|
|
24438
|
+
cookie_export_required: false,
|
|
24439
|
+
request: prepared.request_path,
|
|
24440
|
+
result_out: prepared.result_path,
|
|
24441
|
+
screenshot_out: prepared.screenshot_path,
|
|
24442
|
+
lease_file: prepared.lease_file,
|
|
24443
|
+
lease_expires_at: prepared.request.lease.expires_at ?? null,
|
|
24444
|
+
...targetUser ? { target_user: targetUser } : {},
|
|
24445
|
+
helper: "bpmax-user-mock-operator/scripts/chrome_identity_bridge.mjs",
|
|
24446
|
+
next_action: "Use chrome:control-chrome in a dedicated BPMAX tab to execute the fixed identity bridge helper, then run `bpmax-cli e2e identity browser complete --request <request>`."
|
|
24447
|
+
});
|
|
24448
|
+
});
|
|
24449
|
+
};
|
|
24450
|
+
registerIdentityBrowserPrepare(
|
|
24451
|
+
"status",
|
|
24452
|
+
identityBrowser.command("status").description("Prepare a Chrome Control current-identity readback")
|
|
24453
|
+
);
|
|
24454
|
+
registerIdentityBrowserPrepare(
|
|
24455
|
+
"mock",
|
|
24456
|
+
identityBrowser.command("mock").description("Prepare an exact-user Chrome Control identity switch").requiredOption("--user-id <id>", "Exact target BPMAX user id")
|
|
24457
|
+
);
|
|
24458
|
+
registerIdentityBrowserPrepare(
|
|
24459
|
+
"unmock",
|
|
24460
|
+
identityBrowser.command("unmock").description("Prepare Chrome Control recovery to the original identity")
|
|
24461
|
+
);
|
|
24462
|
+
identityBrowser.command("complete").description("Verify one Chrome Control identity result, update the lease, and attach current-run evidence").requiredOption("--request <file>", "Identity browser request generated by status/mock/unmock").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
24463
|
+
const request = await readIdentityBrowserRequest(options.request, { allowExpired: true });
|
|
24464
|
+
const executionOptions = {
|
|
24465
|
+
diagnostic: request.binding.diagnostic,
|
|
24466
|
+
profile: request.binding.profile,
|
|
24467
|
+
executionManifest: request.binding.execution_manifest,
|
|
24468
|
+
caseId: request.binding.case_id,
|
|
24469
|
+
caseStepId: request.binding.case_step_id
|
|
24470
|
+
};
|
|
24471
|
+
await requireE2eExecutionBinding(executionOptions, ["identity"], request.evidence_dir);
|
|
24472
|
+
const config = await loadConfig();
|
|
24473
|
+
const profile = resolveProfile(config, request.binding.profile);
|
|
24474
|
+
const profileOrigin = new URL(profile.config.origin).origin;
|
|
24475
|
+
const profileWorkspace = normalizeWorkspaceForApi(profile.config.workspace) || "";
|
|
24476
|
+
if (profileOrigin !== request.origin || profileWorkspace !== request.workspace) {
|
|
24477
|
+
throw new Error(`e2e.identity.browser.profile_drift: request \u76EE\u6807 ${request.origin}/w:${request.workspace} \u4E0E\u5F53\u524D profile ${profileOrigin}/w:${profileWorkspace} \u4E0D\u4E00\u81F4\u3002`);
|
|
24478
|
+
}
|
|
24479
|
+
const claim = await claimIdentityBrowserRequestCompletion(options.request);
|
|
24480
|
+
try {
|
|
24481
|
+
const completed = await completeIdentityBrowserBridge(options.request);
|
|
24482
|
+
const evidence = await writeEvidence(
|
|
24483
|
+
request.evidence_dir,
|
|
24484
|
+
`identity-browser-${completed.operation}-${completed.request.request_id}.json`,
|
|
24485
|
+
completed.evidence
|
|
24486
|
+
);
|
|
24487
|
+
await appendE2eExecutionEvidence(executionOptions, evidence, ["identity"]);
|
|
24488
|
+
const evidenceManifest = await writeEvidenceManifest(request.evidence_dir, {
|
|
24489
|
+
status: completed.ok ? "completed" : "failed",
|
|
24490
|
+
operation: completed.operation,
|
|
24491
|
+
transport: "chrome_identity_bridge",
|
|
24492
|
+
remote_submitted: completed.evidence.remote_submitted === true,
|
|
24493
|
+
readback_confirmed: completed.evidence.readback_confirmed === true
|
|
24494
|
+
}, [request.screenshot_path]);
|
|
24495
|
+
const receipt = await markIdentityBrowserRequestCompleted(options.request, completed.ok, completed.request);
|
|
24496
|
+
if (!completed.ok) {
|
|
24497
|
+
throw new Error(`e2e.identity.browser.operation_failed: ${completed.failure?.kind ?? "unknown"}: ${completed.failure?.message ?? "identity operation failed"}\u3002evidence=${evidence}`);
|
|
24498
|
+
}
|
|
24499
|
+
printResult(options.format, {
|
|
24500
|
+
ok: true,
|
|
24501
|
+
result: completed.evidence.result,
|
|
24502
|
+
operation: completed.operation,
|
|
24503
|
+
transport: "chrome_identity_bridge",
|
|
24504
|
+
browser_tool: "chrome:control-chrome",
|
|
24505
|
+
remote_submitted: completed.evidence.remote_submitted,
|
|
24506
|
+
readback_confirmed: completed.evidence.readback_confirmed,
|
|
24507
|
+
current_user: completed.evidence.current_user,
|
|
24508
|
+
lease: completed.lease,
|
|
24509
|
+
evidence,
|
|
24510
|
+
evidence_manifest: evidenceManifest,
|
|
24511
|
+
receipt
|
|
24512
|
+
});
|
|
24513
|
+
} finally {
|
|
24514
|
+
await releaseIdentityBrowserRequestCompletionClaim(claim);
|
|
24515
|
+
}
|
|
24516
|
+
});
|
|
24517
|
+
identityBrowser.command("lease-status").description("Inspect the current run identity lease without changing browser identity").option("--execution-manifest <file>", "Formal test-suite execution manifest").option("--evidence-dir <dir>", "Diagnostic evidence directory", ".codex/tmp/e2e/identity").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
24518
|
+
const leaseFile = identityLeaseFile({ executionManifest: options.executionManifest }, options.evidenceDir);
|
|
24519
|
+
const lease = await identityLeaseStatus(leaseFile);
|
|
24520
|
+
printResult(options.format, {
|
|
24521
|
+
ok: true,
|
|
24522
|
+
result: lease ? lease.state : "none",
|
|
24523
|
+
lease_file: leaseFile,
|
|
24524
|
+
lease
|
|
24525
|
+
});
|
|
24526
|
+
});
|
|
23467
24527
|
e2e.command("step-run").description("Run one or more BPMAX step safe-chain submissions with evidence files").requiredOption("--project-id <projectId>", "Project id").option("--step-id <stepId>", "Step id for single-step mode").option("--action <action>", "Step action", "approve").option("--data <json>", "Single-step submit data JSON or @file").option("--data-profile <json>", "Reusable step profile JSON or @file; supports steps[] or steps object").option("--auto-refresh-cache", "Write a refreshed cache template when expected checks are missing or stale").option("--cache-out <file>", "Refreshed cache template output; defaults to --data-profile @file when possible").option("--comments <comments>", "Step comments").option("--urgency <urgency>", "Urgency value", "1").option("--confirm <confirmation>", "Actually submit; otherwise dry-run only").option("--profile <profile>", "Profile name").option("--execution-manifest <file>", "Formal test-suite execution manifest").option("--case-id <id>", "Formal test-suite case id").option("--case-step-id <id>", "Formal test-suite case step id").option("--diagnostic", "Run without a formal manifest; result cannot be used as pass evidence").option("--evidence-dir <dir>", "Evidence directory", `.codex/tmp/e2e/${timestampSlug()}`).option("--format <format>", "Output format", "json").action(async (options) => {
|
|
23468
24528
|
await requireE2eExecutionBinding(options, ["e2e_step_run"], options.evidenceDir);
|
|
23469
24529
|
const config = await loadConfig();
|
|
@@ -23682,7 +24742,7 @@ function registerE2eCommands(program2) {
|
|
|
23682
24742
|
mode: "handoff_command_hint",
|
|
23683
24743
|
browser: options.browser,
|
|
23684
24744
|
next_command: `bpmax-cli project create ${flowFlag}${jsonFlag}${profileFlag} --handoff-only --format json > handoff.json`,
|
|
23685
|
-
next_after_handoff: `bpmax-cli e2e create-page-submit --handoff-json @handoff.json --browser ${options.browser} --evidence-dir ${
|
|
24745
|
+
next_after_handoff: `bpmax-cli e2e create-page-submit --handoff-json @handoff.json --browser ${options.browser} --evidence-dir ${path15.resolve(options.evidenceDir)} --format json`,
|
|
23686
24746
|
note: "create-page-submit does not raw-create a project. First generate a handoff URL, then execute the generated browser template and keep screenshots/result JSON as evidence."
|
|
23687
24747
|
});
|
|
23688
24748
|
return;
|
|
@@ -23704,7 +24764,7 @@ function registerE2eCommands(program2) {
|
|
|
23704
24764
|
browser_verified: false,
|
|
23705
24765
|
browser: options.browser,
|
|
23706
24766
|
...generated,
|
|
23707
|
-
evidence_dir:
|
|
24767
|
+
evidence_dir: path15.resolve(options.evidenceDir),
|
|
23708
24768
|
next_command: `npx playwright test ${generated.out}`,
|
|
23709
24769
|
note: "This command does not raw-create a project. Run the generated Playwright script against a logged-in browser context and keep its screenshots/result JSON as browser evidence."
|
|
23710
24770
|
});
|
|
@@ -23714,7 +24774,7 @@ function registerE2eCommands(program2) {
|
|
|
23714
24774
|
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
23715
24775
|
const file = flowCachePath(profile.name, options.flowId);
|
|
23716
24776
|
const cached = await readOptionalJson(file);
|
|
23717
|
-
const fileStat = await
|
|
24777
|
+
const fileStat = await stat9(file).catch(() => null);
|
|
23718
24778
|
printResult(options.format, {
|
|
23719
24779
|
ok: true,
|
|
23720
24780
|
profile: profile.name,
|
|
@@ -23748,15 +24808,15 @@ function registerE2eCommands(program2) {
|
|
|
23748
24808
|
if (!result) {
|
|
23749
24809
|
throw new Error(`Flow ${options.flowId} was not found.`);
|
|
23750
24810
|
}
|
|
23751
|
-
const sourceUpdateTime =
|
|
23752
|
-
const cacheKey =
|
|
24811
|
+
const sourceUpdateTime = stringValue5(result.update_time ?? result.updateTime ?? result.updated_at ?? result.updatedAt);
|
|
24812
|
+
const cacheKey = createHash8("sha256").update(JSON.stringify({
|
|
23753
24813
|
flow_id: options.flowId,
|
|
23754
24814
|
update_time: sourceUpdateTime,
|
|
23755
24815
|
template_id: result.template_id ?? result.templateId
|
|
23756
24816
|
})).digest("hex").slice(0, 16);
|
|
23757
24817
|
const file = flowCachePath(profile.name, options.flowId);
|
|
23758
|
-
await
|
|
23759
|
-
await
|
|
24818
|
+
await mkdir12(path15.dirname(file), { recursive: true });
|
|
24819
|
+
await writeFile12(file, `${JSON.stringify(redactAuditValue({
|
|
23760
24820
|
cache_key: cacheKey,
|
|
23761
24821
|
cached_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
23762
24822
|
profile: profile.name,
|
|
@@ -23790,7 +24850,7 @@ function registerE2eCommands(program2) {
|
|
|
23790
24850
|
printResult(options.format, {
|
|
23791
24851
|
ok: true,
|
|
23792
24852
|
...generated,
|
|
23793
|
-
evidence_dir:
|
|
24853
|
+
evidence_dir: path15.resolve(options.evidenceDir),
|
|
23794
24854
|
next_command: `npx playwright test ${generated.out}`
|
|
23795
24855
|
});
|
|
23796
24856
|
});
|
|
@@ -23803,13 +24863,13 @@ function registerE2eCommands(program2) {
|
|
|
23803
24863
|
if (inferredStepId && !contextFile && !submitFile) {
|
|
23804
24864
|
throw new Error(`No step evidence files found for step ${inferredStepId} in ${options.evidenceDir}.`);
|
|
23805
24865
|
}
|
|
23806
|
-
const context2 = contextFile ? await readOptionalJson(
|
|
23807
|
-
const submit = submitFile ? await readOptionalJson(
|
|
23808
|
-
const requirements =
|
|
23809
|
-
const requiredInputs = Array.isArray(requirements.required_inputs) ? requirements.required_inputs.filter(
|
|
23810
|
-
const missingInputs = Array.isArray(requirements.missing_required_inputs) ? requirements.missing_required_inputs.filter(
|
|
23811
|
-
const requestData =
|
|
23812
|
-
const recordedAction =
|
|
24866
|
+
const context2 = contextFile ? await readOptionalJson(path15.join(options.evidenceDir, contextFile)) : null;
|
|
24867
|
+
const submit = submitFile ? await readOptionalJson(path15.join(options.evidenceDir, submitFile)) : null;
|
|
24868
|
+
const requirements = isRecord13(context2?.requirements) ? context2.requirements : {};
|
|
24869
|
+
const requiredInputs = Array.isArray(requirements.required_inputs) ? requirements.required_inputs.filter(isRecord13) : [];
|
|
24870
|
+
const missingInputs = Array.isArray(requirements.missing_required_inputs) ? requirements.missing_required_inputs.filter(isRecord13) : [];
|
|
24871
|
+
const requestData = isRecord13(submit?.request) && isRecord13(submit.request.data) ? submit.request.data : {};
|
|
24872
|
+
const recordedAction = stringValue5(requestData.action);
|
|
23813
24873
|
const expectedChecks = buildExpectedChecks({
|
|
23814
24874
|
context: context2,
|
|
23815
24875
|
requirements: {
|
|
@@ -23847,16 +24907,16 @@ function registerE2eCommands(program2) {
|
|
|
23847
24907
|
variables: Object.keys(requestData).filter((key) => !["project_id", "action", "urgency"].includes(key)),
|
|
23848
24908
|
payload_template: requestData,
|
|
23849
24909
|
source_evidence: {
|
|
23850
|
-
evidence_dir:
|
|
24910
|
+
evidence_dir: path15.resolve(options.evidenceDir),
|
|
23851
24911
|
...contextFile ? { context: contextFile } : {},
|
|
23852
24912
|
...submitFile ? { submit: submitFile } : {}
|
|
23853
24913
|
}
|
|
23854
24914
|
} : {
|
|
23855
|
-
name: options.name ??
|
|
24915
|
+
name: options.name ?? path15.basename(path15.resolve(options.evidenceDir)),
|
|
23856
24916
|
generated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
23857
24917
|
submit_mode: "browser_evidence_bootstrap",
|
|
23858
24918
|
source_evidence: {
|
|
23859
|
-
evidence_dir:
|
|
24919
|
+
evidence_dir: path15.resolve(options.evidenceDir),
|
|
23860
24920
|
files: evidenceFiles
|
|
23861
24921
|
},
|
|
23862
24922
|
reuse_requirements: [
|
|
@@ -23869,9 +24929,9 @@ function registerE2eCommands(program2) {
|
|
|
23869
24929
|
template.result = "diagnostic";
|
|
23870
24930
|
template.diagnostic = true;
|
|
23871
24931
|
}
|
|
23872
|
-
const out =
|
|
23873
|
-
await
|
|
23874
|
-
await
|
|
24932
|
+
const out = path15.resolve(options.out);
|
|
24933
|
+
await mkdir12(path15.dirname(out), { recursive: true });
|
|
24934
|
+
await writeFile12(out, `${JSON.stringify(redactAuditValue(template), null, 2)}
|
|
23875
24935
|
`, "utf8");
|
|
23876
24936
|
const automationOut = options.automationOut ? await updateAutomationFromRecordedTrace({
|
|
23877
24937
|
evidenceDir: options.evidenceDir,
|
|
@@ -23894,15 +24954,15 @@ function registerE2eCommands(program2) {
|
|
|
23894
24954
|
scenario.command("execute").description("Execute deterministic browser_action steps for the current formal scenario run").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("--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("--resume", "Continue only the same unfinished manifest").option("--until-blocked", "Continue consecutive browser_action steps until another runner or failure").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
23895
24955
|
const plan = await parseJsonFileOrInput(options.plan, "--plan");
|
|
23896
24956
|
const state = await nextTestSuiteRunStep(options.executionManifest, options.profile);
|
|
23897
|
-
const execution =
|
|
23898
|
-
if (
|
|
23899
|
-
throw new Error(`e2e.scenario.plan_mismatch: plan scenario ${
|
|
24957
|
+
const execution = isRecord13(state.execution) ? state.execution : {};
|
|
24958
|
+
if (stringValue5(plan.scenario) && stringValue5(execution.scenario_id) !== stringValue5(plan.scenario)) {
|
|
24959
|
+
throw new Error(`e2e.scenario.plan_mismatch: plan scenario ${stringValue5(plan.scenario)} does not match execution manifest ${stringValue5(execution.scenario_id)}`);
|
|
23900
24960
|
}
|
|
23901
24961
|
const result = await runBrowserAutomation(options);
|
|
23902
24962
|
printResult(options.format, {
|
|
23903
24963
|
...result,
|
|
23904
24964
|
scenario: plan.scenario,
|
|
23905
|
-
plan:
|
|
24965
|
+
plan: path15.resolve(options.plan)
|
|
23906
24966
|
});
|
|
23907
24967
|
});
|
|
23908
24968
|
scenario.command("run").description("Validate or dry-run a scenario plan and produce a resumable status matrix").requiredOption("--plan <file>", "Scenario plan JSON file").option("--from <id>", "Start record id/demo_no").option("--to <id>", "End record id/demo_no").option("--resume", "Skip records already marked complete in existing status").option("--execution-manifest <file>", "Formal test-suite execution manifest").option("--case-id <id>", "Formal test-suite case id").option("--case-step-id <id>", "Formal test-suite case step id").option("--diagnostic", "Run without a formal manifest; result cannot be used as pass evidence").option("--evidence-dir <dir>", "Scenario evidence directory", `.codex/tmp/e2e/scenario-${timestampSlug()}`).option("--format <format>", "Output format", "json").action(async (options) => {
|
|
@@ -23921,7 +24981,7 @@ function registerE2eCommands(program2) {
|
|
|
23921
24981
|
});
|
|
23922
24982
|
const status = selected.map((record, index) => ({
|
|
23923
24983
|
record: recordKey(record, index),
|
|
23924
|
-
subject:
|
|
24984
|
+
subject: stringValue5(record.subject),
|
|
23925
24985
|
status: "bootstrap_required",
|
|
23926
24986
|
next_action: "If no reusable cache/template exists yet, run the first real browser create-page-submit or safe step-run for this record, save evidence, then run e2e record-from-evidence before repeat runs."
|
|
23927
24987
|
}));
|
|
@@ -23955,11 +25015,11 @@ function registerE2eCommands(program2) {
|
|
|
23955
25015
|
}
|
|
23956
25016
|
|
|
23957
25017
|
// src/core/project-search.ts
|
|
23958
|
-
function
|
|
25018
|
+
function isRecord14(value) {
|
|
23959
25019
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23960
25020
|
}
|
|
23961
25021
|
function hasRawProjectSearchBody(value) {
|
|
23962
|
-
return
|
|
25022
|
+
return isRecord14(value) && Object.prototype.hasOwnProperty.call(value, "body");
|
|
23963
25023
|
}
|
|
23964
25024
|
function assertProjectSearchBody(value) {
|
|
23965
25025
|
if (hasRawProjectSearchBody(value)) {
|
|
@@ -23973,13 +25033,13 @@ function isProjectListEsQuery(value) {
|
|
|
23973
25033
|
}
|
|
23974
25034
|
function splitProjectListPagination(body, options) {
|
|
23975
25035
|
const data = { ...body };
|
|
23976
|
-
const normalizePositiveInteger = (value,
|
|
25036
|
+
const normalizePositiveInteger = (value, path20) => {
|
|
23977
25037
|
if (typeof value === "string" && value.trim() === "") {
|
|
23978
|
-
throw new Error(`project search ${
|
|
25038
|
+
throw new Error(`project search ${path20} \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 1 \u7684\u6574\u6570\uFF0C\u4E0D\u80FD\u662F\u7A7A\u5B57\u7B26\u4E32\u3002`);
|
|
23979
25039
|
}
|
|
23980
25040
|
const number = typeof value === "number" ? value : Number(value);
|
|
23981
25041
|
if (!Number.isSafeInteger(number) || number < 1) {
|
|
23982
|
-
throw new Error(`project search ${
|
|
25042
|
+
throw new Error(`project search ${path20} \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 1 \u7684\u6574\u6570\uFF0C\u5F53\u524D\u503C\u4E3A ${String(value)}\u3002`);
|
|
23983
25043
|
}
|
|
23984
25044
|
return number;
|
|
23985
25045
|
};
|
|
@@ -24110,7 +25170,7 @@ function registerFlowCommands(program2) {
|
|
|
24110
25170
|
const client = createApiClient(profile);
|
|
24111
25171
|
if (options.flowType) {
|
|
24112
25172
|
const bindings = await getWorkspaceFlowBindings(client, profile, options);
|
|
24113
|
-
const
|
|
25173
|
+
const path20 = options.flowKey ? "/flow/options" : "/flow/flow_type";
|
|
24114
25174
|
const params = options.flowKey ? {
|
|
24115
25175
|
detail: "1"
|
|
24116
25176
|
} : {
|
|
@@ -24120,7 +25180,7 @@ function registerFlowCommands(program2) {
|
|
|
24120
25180
|
const result2 = await apiRequest(
|
|
24121
25181
|
client,
|
|
24122
25182
|
"GET",
|
|
24123
|
-
|
|
25183
|
+
path20,
|
|
24124
25184
|
{
|
|
24125
25185
|
params
|
|
24126
25186
|
}
|
|
@@ -24356,7 +25416,7 @@ function registerInitCommand(program2, deps = {}) {
|
|
|
24356
25416
|
}
|
|
24357
25417
|
|
|
24358
25418
|
// src/commands/issue.ts
|
|
24359
|
-
import { readFile as
|
|
25419
|
+
import { readFile as readFile17 } from "fs/promises";
|
|
24360
25420
|
|
|
24361
25421
|
// src/core/issues.ts
|
|
24362
25422
|
import axios8, { AxiosHeaders as AxiosHeaders3 } from "axios";
|
|
@@ -24532,7 +25592,7 @@ async function readDescription(options) {
|
|
|
24532
25592
|
if (!options.descriptionFile) {
|
|
24533
25593
|
return options.description;
|
|
24534
25594
|
}
|
|
24535
|
-
return
|
|
25595
|
+
return readFile17(options.descriptionFile, "utf8");
|
|
24536
25596
|
}
|
|
24537
25597
|
function parseAssigneeIds(values) {
|
|
24538
25598
|
return (values || []).flatMap(
|
|
@@ -24631,10 +25691,10 @@ async function parseOptionalJson(input, label) {
|
|
|
24631
25691
|
}
|
|
24632
25692
|
return parseJsonInput(input, label);
|
|
24633
25693
|
}
|
|
24634
|
-
async function memoryRequest(options, method,
|
|
25694
|
+
async function memoryRequest(options, method, path20, capability, data, params) {
|
|
24635
25695
|
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
24636
25696
|
const client = createApiClient(profile);
|
|
24637
|
-
return apiRequest(client, method,
|
|
25697
|
+
return apiRequest(client, method, path20, {
|
|
24638
25698
|
capability,
|
|
24639
25699
|
data: redactAuditValue(data),
|
|
24640
25700
|
params: params ? redactAuditValue(params) : void 0
|
|
@@ -24689,7 +25749,7 @@ function registerMemoryCommands(program2) {
|
|
|
24689
25749
|
}
|
|
24690
25750
|
|
|
24691
25751
|
// src/commands/matrix.ts
|
|
24692
|
-
import { readFile as
|
|
25752
|
+
import { readFile as readFile18 } from "fs/promises";
|
|
24693
25753
|
var UUID_VALUE_PATTERN2 = /\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/i;
|
|
24694
25754
|
var UUID_PATH_PATTERN = /uuid'[^'"\s/]+/i;
|
|
24695
25755
|
async function parseSeedRules(input) {
|
|
@@ -24697,7 +25757,7 @@ async function parseSeedRules(input) {
|
|
|
24697
25757
|
if (source === "") {
|
|
24698
25758
|
throw new Error("--rules file path is empty.");
|
|
24699
25759
|
}
|
|
24700
|
-
const raw = source ? await
|
|
25760
|
+
const raw = source ? await readFile18(source, "utf8") : input;
|
|
24701
25761
|
let parsed;
|
|
24702
25762
|
try {
|
|
24703
25763
|
parsed = JSON.parse(raw);
|
|
@@ -24716,15 +25776,15 @@ async function parseSeedRules(input) {
|
|
|
24716
25776
|
});
|
|
24717
25777
|
return rules;
|
|
24718
25778
|
}
|
|
24719
|
-
function collectUuidPaths(value,
|
|
25779
|
+
function collectUuidPaths(value, path20 = "$") {
|
|
24720
25780
|
if (typeof value === "string") {
|
|
24721
|
-
return UUID_VALUE_PATTERN2.test(value) || UUID_PATH_PATTERN.test(value) ? [
|
|
25781
|
+
return UUID_VALUE_PATTERN2.test(value) || UUID_PATH_PATTERN.test(value) ? [path20] : [];
|
|
24722
25782
|
}
|
|
24723
25783
|
if (Array.isArray(value)) {
|
|
24724
|
-
return value.flatMap((item, index) => collectUuidPaths(item, `${
|
|
25784
|
+
return value.flatMap((item, index) => collectUuidPaths(item, `${path20}[${index}]`));
|
|
24725
25785
|
}
|
|
24726
25786
|
if (typeof value === "object" && value !== null) {
|
|
24727
|
-
return Object.entries(value).flatMap(([key, child]) => collectUuidPaths(child, `${
|
|
25787
|
+
return Object.entries(value).flatMap(([key, child]) => collectUuidPaths(child, `${path20}.${key}`));
|
|
24728
25788
|
}
|
|
24729
25789
|
return [];
|
|
24730
25790
|
}
|
|
@@ -24747,20 +25807,20 @@ function isEmptyApproverValue(value) {
|
|
|
24747
25807
|
function shellQuote7(value) {
|
|
24748
25808
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
24749
25809
|
}
|
|
24750
|
-
var
|
|
25810
|
+
var isRecord15 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24751
25811
|
function dataArray(value) {
|
|
24752
25812
|
if (Array.isArray(value)) return value;
|
|
24753
|
-
if (
|
|
24754
|
-
if (
|
|
24755
|
-
if (
|
|
25813
|
+
if (isRecord15(value) && Array.isArray(value.data)) return value.data;
|
|
25814
|
+
if (isRecord15(value) && Array.isArray(value.list)) return value.list;
|
|
25815
|
+
if (isRecord15(value) && Array.isArray(value.rows)) return value.rows;
|
|
24756
25816
|
return [];
|
|
24757
25817
|
}
|
|
24758
25818
|
function predictedNodes(value) {
|
|
24759
|
-
if (!
|
|
24760
|
-
return dataArray(value.predicted_nodes).filter(
|
|
25819
|
+
if (!isRecord15(value)) return [];
|
|
25820
|
+
return dataArray(value.predicted_nodes).filter(isRecord15);
|
|
24761
25821
|
}
|
|
24762
25822
|
function safePredictedOwners(value) {
|
|
24763
|
-
return (Array.isArray(value) ? value : []).filter(
|
|
25823
|
+
return (Array.isArray(value) ? value : []).filter(isRecord15).map((owner) => ({
|
|
24764
25824
|
id: owner.id ?? owner.user_id ?? owner.owner_id,
|
|
24765
25825
|
name: owner.name ?? null
|
|
24766
25826
|
}));
|
|
@@ -24775,7 +25835,7 @@ async function fetchAllMatrixRuleRecords(client, flowType) {
|
|
|
24775
25835
|
data: { flow_type: flowType, page, page_size: pageSize },
|
|
24776
25836
|
capability: "project.list"
|
|
24777
25837
|
});
|
|
24778
|
-
const rows2 = dataArray(result).filter(
|
|
25838
|
+
const rows2 = dataArray(result).filter(isRecord15);
|
|
24779
25839
|
records.push(...rows2);
|
|
24780
25840
|
const total = Number(result.count ?? result.total ?? records.length);
|
|
24781
25841
|
if (rows2.length < pageSize || records.length >= total) break;
|
|
@@ -24794,23 +25854,23 @@ async function hydrateMatrixRuleRecords(client, records) {
|
|
|
24794
25854
|
for (let index = 0; index < records.length; index += 10) {
|
|
24795
25855
|
const chunk = records.slice(index, index + 10);
|
|
24796
25856
|
hydrated.push(...await Promise.all(chunk.map(async (record) => {
|
|
24797
|
-
if (
|
|
25857
|
+
if (isRecord15(record.metaForm) || Array.isArray(record.formList)) return record;
|
|
24798
25858
|
const id = Number(record.id ?? record.project_id);
|
|
24799
25859
|
return Number.isSafeInteger(id) && id > 0 ? apiRequest(client, "GET", `/project/${id}`) : record;
|
|
24800
25860
|
})));
|
|
24801
25861
|
}
|
|
24802
25862
|
return hydrated;
|
|
24803
25863
|
}
|
|
24804
|
-
function collectMatrixOwnerPaths(value,
|
|
25864
|
+
function collectMatrixOwnerPaths(value, path20 = "$") {
|
|
24805
25865
|
if (Array.isArray(value)) {
|
|
24806
|
-
return value.flatMap((item, index) => collectMatrixOwnerPaths(item, `${
|
|
25866
|
+
return value.flatMap((item, index) => collectMatrixOwnerPaths(item, `${path20}[${index}]`));
|
|
24807
25867
|
}
|
|
24808
|
-
if (!
|
|
25868
|
+
if (!isRecord15(value)) {
|
|
24809
25869
|
return [];
|
|
24810
25870
|
}
|
|
24811
25871
|
const matches = [];
|
|
24812
25872
|
Object.entries(value).forEach(([key, child]) => {
|
|
24813
|
-
const childPath = `${
|
|
25873
|
+
const childPath = `${path20}.${key}`;
|
|
24814
25874
|
if (key.includes("matrix_owner") || typeof child === "string" && child.includes("matrix_owner")) {
|
|
24815
25875
|
matches.push({ path: childPath, value: child });
|
|
24816
25876
|
}
|
|
@@ -24819,25 +25879,25 @@ function collectMatrixOwnerPaths(value, path19 = "$") {
|
|
|
24819
25879
|
return matches;
|
|
24820
25880
|
}
|
|
24821
25881
|
function projectFormKeys(project) {
|
|
24822
|
-
const metaForm =
|
|
25882
|
+
const metaForm = isRecord15(project.metaForm) ? project.metaForm : {};
|
|
24823
25883
|
const values = dataArray(metaForm.value ?? project.formList);
|
|
24824
|
-
return values.filter(
|
|
25884
|
+
return values.filter(isRecord15).map((item) => String(item.key ?? item.field_key ?? "")).filter(Boolean);
|
|
24825
25885
|
}
|
|
24826
25886
|
function findFlowNode2(flow, nodeId) {
|
|
24827
|
-
const data =
|
|
24828
|
-
return dataArray(data.nodes).filter(
|
|
25887
|
+
const data = isRecord15(flow.data) ? flow.data : {};
|
|
25888
|
+
return dataArray(data.nodes).filter(isRecord15).find((node) => String(node.id ?? node.key ?? node.flow_step_id ?? "") === nodeId);
|
|
24829
25889
|
}
|
|
24830
25890
|
function flowCategory(flow) {
|
|
24831
|
-
const data =
|
|
24832
|
-
const meta =
|
|
25891
|
+
const data = isRecord15(flow.data) ? flow.data : {};
|
|
25892
|
+
const meta = isRecord15(data.meta) ? data.meta : {};
|
|
24833
25893
|
return String(flow.category ?? data.category ?? meta.category ?? "");
|
|
24834
25894
|
}
|
|
24835
25895
|
function hasIdentifier(value) {
|
|
24836
25896
|
return value !== void 0 && value !== null && String(value).trim() !== "" && String(value) !== "0";
|
|
24837
25897
|
}
|
|
24838
25898
|
function matrixAppSummary(flow, listTemplates = [], filterTemplates = [], datasets = [], workspaceBound = false) {
|
|
24839
|
-
const data =
|
|
24840
|
-
const meta =
|
|
25899
|
+
const data = isRecord15(flow.data) ? flow.data : {};
|
|
25900
|
+
const meta = isRecord15(data.meta) ? data.meta : {};
|
|
24841
25901
|
const refs = {
|
|
24842
25902
|
form_template_id: meta.form_template ?? flow.form_template_id,
|
|
24843
25903
|
list_template_ids: listTemplates.map((item) => item.id ?? item.flow_page_template_id).filter(hasIdentifier),
|
|
@@ -24878,7 +25938,7 @@ function matrixAppSummary(flow, listTemplates = [], filterTemplates = [], datase
|
|
|
24878
25938
|
suggestion: "\u4ECE\u6700\u65B0 workspace-flow \u56DE\u8BFB merge \u540E\u901A\u8FC7 typed CLI \u63D0\u4EA4\u7ED1\u5B9A\u3002"
|
|
24879
25939
|
});
|
|
24880
25940
|
}
|
|
24881
|
-
const nodes = dataArray(data.nodes).filter(
|
|
25941
|
+
const nodes = dataArray(data.nodes).filter(isRecord15);
|
|
24882
25942
|
const activeNodes = nodes.filter((node) => {
|
|
24883
25943
|
const name = String(node.name ?? "").trim();
|
|
24884
25944
|
return name === "\u751F\u6548\u4E2D" || name === "\u8FDB\u884C\u4E2D" || Number(node.status) === 1;
|
|
@@ -24927,10 +25987,10 @@ async function inspectMatrixAppDefinition(profile, flowType, workspace, includeR
|
|
|
24927
25987
|
apiRequest(client, "GET", "/flow_page_template", { params: { type: 3, flow_type: flowType, flow_key: "", skip_i18n: true }, capability: "config.filter_template.export" }),
|
|
24928
25988
|
apiRequest(client, "GET", "/workspace/by_key", { params: { key: workspace }, capability: "config.workspace_flow.export" })
|
|
24929
25989
|
]);
|
|
24930
|
-
const flowData =
|
|
24931
|
-
const meta =
|
|
24932
|
-
const listRows = dataArray(listResult).filter(
|
|
24933
|
-
const filterRows = dataArray(filterResult).filter(
|
|
25990
|
+
const flowData = isRecord15(flow.data) ? flow.data : {};
|
|
25991
|
+
const meta = isRecord15(flowData.meta) ? flowData.meta : {};
|
|
25992
|
+
const listRows = dataArray(listResult).filter(isRecord15);
|
|
25993
|
+
const filterRows = dataArray(filterResult).filter(isRecord15);
|
|
24934
25994
|
const listIds = uniqueIds([meta.table_list_template, ...listRows.map((item) => item.id ?? item.flow_page_template_id)]);
|
|
24935
25995
|
const filterIds = uniqueIds([meta.table_filter_template, ...filterRows.map((item) => item.id ?? item.flow_page_template_id)]);
|
|
24936
25996
|
const formId = String(meta.form_template ?? flow.form_template_id ?? "");
|
|
@@ -24948,7 +26008,7 @@ async function inspectMatrixAppDefinition(profile, flowType, workspace, includeR
|
|
|
24948
26008
|
if (strict) {
|
|
24949
26009
|
assertNoMatrixErrors(summary.errors);
|
|
24950
26010
|
}
|
|
24951
|
-
const formRecord =
|
|
26011
|
+
const formRecord = isRecord15(form) ? form : {};
|
|
24952
26012
|
const exactReadback = {
|
|
24953
26013
|
flow: { id: flowType, readback_hash: matrixHash(flow), ...includeRaw ? { readback: flow } : {} },
|
|
24954
26014
|
form_template: { id: formId, draft_id: formRecord.origin_template_id ?? formRecord.id ?? null, readback_hash: matrixHash(formRecord), ...includeRaw ? { readback: formRecord } : {} },
|
|
@@ -24960,8 +26020,8 @@ async function inspectMatrixAppDefinition(profile, flowType, workspace, includeR
|
|
|
24960
26020
|
return { ok: summary.errors.length === 0, domain: "approval-matrix", action: "app.inspect", flow_type: flowType, workspace, ...summary, exact_readback: exactReadback };
|
|
24961
26021
|
}
|
|
24962
26022
|
function workspaceHasFlow(value, flowType) {
|
|
24963
|
-
if (!
|
|
24964
|
-
const rows2 = Array.isArray(value.workspace_flow) ? value.workspace_flow.filter(
|
|
26023
|
+
if (!isRecord15(value)) return false;
|
|
26024
|
+
const rows2 = Array.isArray(value.workspace_flow) ? value.workspace_flow.filter(isRecord15) : isRecord15(value.data) && Array.isArray(value.data.workspace_flow) ? value.data.workspace_flow.filter(isRecord15) : [];
|
|
24965
26025
|
return rows2.some((item) => String(item.flow_type ?? "") === flowType && Number(item.is_del ?? 0) === 0);
|
|
24966
26026
|
}
|
|
24967
26027
|
function matrixConsumerSummary(node, expectedMatrixFlowType) {
|
|
@@ -24977,8 +26037,8 @@ function matrixConsumerSummary(node, expectedMatrixFlowType) {
|
|
|
24977
26037
|
});
|
|
24978
26038
|
return { errors, owner: null, cc: null };
|
|
24979
26039
|
}
|
|
24980
|
-
const owner =
|
|
24981
|
-
const cc =
|
|
26040
|
+
const owner = isRecord15(node.matrix_owner) ? node.matrix_owner : null;
|
|
26041
|
+
const cc = isRecord15(node.cc_matrix) ? node.cc_matrix : null;
|
|
24982
26042
|
const normalizeFlowRef = (value) => String(value ?? "").trim().replace(/:$/, "");
|
|
24983
26043
|
if (node.auto_range_type === "matrix") {
|
|
24984
26044
|
if (!owner || !String(owner.flow ?? owner.matrix_flow_type ?? "").trim()) {
|
|
@@ -25009,16 +26069,16 @@ function matrixConsumerSummary(node, expectedMatrixFlowType) {
|
|
|
25009
26069
|
return { errors, owner, cc };
|
|
25010
26070
|
}
|
|
25011
26071
|
function projectField(project, key) {
|
|
25012
|
-
const metaForm =
|
|
25013
|
-
const values = dataArray(metaForm.value ?? project.formList).filter(
|
|
26072
|
+
const metaForm = isRecord15(project.metaForm) ? project.metaForm : {};
|
|
26073
|
+
const values = dataArray(metaForm.value ?? project.formList).filter(isRecord15);
|
|
25014
26074
|
const row = values.find((item) => String(item.key ?? item.field_key ?? "") === key);
|
|
25015
26075
|
if (!row) return void 0;
|
|
25016
26076
|
const value = row.value;
|
|
25017
|
-
return
|
|
26077
|
+
return isRecord15(value) && Object.prototype.hasOwnProperty.call(value, "value") ? value.value : value;
|
|
25018
26078
|
}
|
|
25019
26079
|
function collectUserIds(value) {
|
|
25020
26080
|
if (Array.isArray(value)) return [...new Set(value.flatMap(collectUserIds))];
|
|
25021
|
-
if (
|
|
26081
|
+
if (isRecord15(value)) {
|
|
25022
26082
|
const direct2 = Number(value.id ?? value.user_id ?? value.value);
|
|
25023
26083
|
if (Number.isSafeInteger(direct2) && direct2 > 0) return [direct2];
|
|
25024
26084
|
return [...new Set(Object.values(value).flatMap(collectUserIds))];
|
|
@@ -25039,7 +26099,7 @@ async function readMatrixApprovers(client, ids) {
|
|
|
25039
26099
|
},
|
|
25040
26100
|
capability: "user.readback"
|
|
25041
26101
|
});
|
|
25042
|
-
users.push(...dataArray(result).filter(
|
|
26102
|
+
users.push(...dataArray(result).filter(isRecord15));
|
|
25043
26103
|
}
|
|
25044
26104
|
return users;
|
|
25045
26105
|
}
|
|
@@ -25123,7 +26183,7 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
25123
26183
|
const matrixOwnerConfig = node ? collectMatrixOwnerPaths(node) : [];
|
|
25124
26184
|
const predictedNode = predictedNodes(prediction).find((item) => String(item.node_id ?? item.id ?? "") === options.node);
|
|
25125
26185
|
const owners = safePredictedOwners(predictedNode?.owners);
|
|
25126
|
-
const ownerResolution = predictedNode &&
|
|
26186
|
+
const ownerResolution = predictedNode && isRecord15(predictedNode.owner_resolution) ? predictedNode.owner_resolution : { status: predictedNode ? "resolved" : "missing" };
|
|
25127
26187
|
const projectFlowType = String(project.flow_type ?? "");
|
|
25128
26188
|
const flowMatchesProject = !projectFlowType || projectFlowType === options.flowType;
|
|
25129
26189
|
printResult(options.format, {
|
|
@@ -25214,14 +26274,14 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
25214
26274
|
if (!workspace) throw new Error("matrix.app.workspace_required: \u8BF7\u63D0\u4F9B --workspace \u4EE5\u5220\u9664\u77E9\u9635\u5E94\u7528\u3002");
|
|
25215
26275
|
const definition = await inspectMatrixAppDefinition(profile, options.flowType, workspace, true, false);
|
|
25216
26276
|
const exact = definition.exact_readback;
|
|
25217
|
-
const listItems = Array.isArray(exact.list_templates) ? exact.list_templates.filter(
|
|
25218
|
-
const filterItems = Array.isArray(exact.filter_templates) ? exact.filter_templates.filter(
|
|
25219
|
-
const datasetItems = Array.isArray(exact.datasets) ? exact.datasets.filter(
|
|
26277
|
+
const listItems = Array.isArray(exact.list_templates) ? exact.list_templates.filter(isRecord15) : [];
|
|
26278
|
+
const filterItems = Array.isArray(exact.filter_templates) ? exact.filter_templates.filter(isRecord15) : [];
|
|
26279
|
+
const datasetItems = Array.isArray(exact.datasets) ? exact.datasets.filter(isRecord15) : [];
|
|
25220
26280
|
const datasetFieldIds = uniqueIds(datasetItems.flatMap((item) => {
|
|
25221
|
-
const readback =
|
|
25222
|
-
return Array.isArray(readback.dataSetFields) ? readback.dataSetFields.filter(
|
|
26281
|
+
const readback = isRecord15(item.readback) ? item.readback : {};
|
|
26282
|
+
return Array.isArray(readback.dataSetFields) ? readback.dataSetFields.filter(isRecord15).map((field) => field.id) : [];
|
|
25223
26283
|
}));
|
|
25224
|
-
const formItem =
|
|
26284
|
+
const formItem = isRecord15(exact.form_template) ? exact.form_template : {};
|
|
25225
26285
|
const formDraftId = String(formItem.draft_id ?? formItem.id ?? "");
|
|
25226
26286
|
const expectedConfirm = `delete matrix app ${options.flowType} from ${workspace}`;
|
|
25227
26287
|
const plan = [
|
|
@@ -25283,8 +26343,8 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
25283
26343
|
apiRequest(client, "GET", "/flow_page_template", { params: { type: 3, flow_type: options.matrixFlowType, flow_key: "", skip_i18n: true }, capability: "config.filter_template.export" }),
|
|
25284
26344
|
apiRequest(client, "GET", "/workspace/by_key", { params: { key: workspace }, capability: "config.workspace_flow.export" })
|
|
25285
26345
|
]);
|
|
25286
|
-
const listRows = dataArray(listResult).filter(
|
|
25287
|
-
const filterRows = dataArray(filterResult).filter(
|
|
26346
|
+
const listRows = dataArray(listResult).filter(isRecord15);
|
|
26347
|
+
const filterRows = dataArray(filterResult).filter(isRecord15);
|
|
25288
26348
|
const listTemplates = await Promise.all(uniqueIds(listRows.map((item) => item.id ?? item.flow_page_template_id)).map((id) => apiRequest(client, "GET", `/flow_page_template/${encodeURIComponent(id)}?skip_i18n=true`, { capability: "config.list_template.export" })));
|
|
25289
26349
|
const filterTemplates = await Promise.all(uniqueIds(filterRows.map((item) => item.id ?? item.flow_page_template_id)).map((id) => apiRequest(client, "GET", `/flow_page_template/${encodeURIComponent(id)}?skip_i18n=true`, { capability: "config.filter_template.export" })));
|
|
25290
26350
|
const datasetIds = uniqueIds([...listTemplates.map((item) => item.data_set_id), ...filterTemplates.map((item) => item.data_set_id)]);
|
|
@@ -25318,7 +26378,7 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
25318
26378
|
}
|
|
25319
26379
|
const predictedNode = predictedNodes(prediction).find((item) => String(item.node_id ?? item.id ?? "") === options.node);
|
|
25320
26380
|
const predictedOwners = safePredictedOwners(predictedNode?.owners);
|
|
25321
|
-
const ownerResolution = predictedNode &&
|
|
26381
|
+
const ownerResolution = predictedNode && isRecord15(predictedNode.owner_resolution) ? predictedNode.owner_resolution : { status: predictedNode ? "resolved" : "missing" };
|
|
25322
26382
|
if (ownerResolution.status === "error") {
|
|
25323
26383
|
errors.push({ code: "matrix.consumer.owner_resolution_error", rule_id: "matrix.consumer.owner_resolution_error", domain: "approval-matrix", path: "$.predicted_nodes[].owner_resolution", message: `\u7EDF\u4E00 owner resolver \u6267\u884C\u5931\u8D25\uFF1A${String(ownerResolution.error_code ?? "unknown")}\u3002`, suggestion: "\u4FEE\u590D\u77E9\u9635/\u5B57\u6BB5/\u89D2\u8272 owner \u89E3\u6790\u9519\u8BEF\u540E\u91CD\u65B0 verify\uFF0C\u4E0D\u5F97\u5C06\u7A7A owners \u5F53\u6210\u6B63\u5E38\u65E0\u4EBA\u3002" });
|
|
25324
26384
|
} else if (!predictedNode || predictedOwners.length === 0) {
|
|
@@ -25342,13 +26402,13 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
25342
26402
|
}
|
|
25343
26403
|
|
|
25344
26404
|
// src/commands/organization.ts
|
|
25345
|
-
function
|
|
26405
|
+
function isRecord16(value) {
|
|
25346
26406
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25347
26407
|
}
|
|
25348
26408
|
function rows(value) {
|
|
25349
|
-
if (Array.isArray(value)) return value.filter(
|
|
25350
|
-
if (!
|
|
25351
|
-
if (Array.isArray(value.data)) return value.data.filter(
|
|
26409
|
+
if (Array.isArray(value)) return value.filter(isRecord16);
|
|
26410
|
+
if (!isRecord16(value)) return [];
|
|
26411
|
+
if (Array.isArray(value.data)) return value.data.filter(isRecord16);
|
|
25352
26412
|
return value.id ? [value] : [];
|
|
25353
26413
|
}
|
|
25354
26414
|
function positiveId(value, errorCode) {
|
|
@@ -25372,7 +26432,7 @@ function safeDepartment(group) {
|
|
|
25372
26432
|
function departmentRows(value) {
|
|
25373
26433
|
const result = [];
|
|
25374
26434
|
const visit = (item) => {
|
|
25375
|
-
if (!
|
|
26435
|
+
if (!isRecord16(item)) return;
|
|
25376
26436
|
if (item.id !== void 0) result.push(safeDepartment(item));
|
|
25377
26437
|
if (Array.isArray(item.children)) item.children.forEach(visit);
|
|
25378
26438
|
};
|
|
@@ -25381,7 +26441,7 @@ function departmentRows(value) {
|
|
|
25381
26441
|
}
|
|
25382
26442
|
function relationDepartments(value) {
|
|
25383
26443
|
if (!Array.isArray(value)) return [];
|
|
25384
|
-
return value.filter(
|
|
26444
|
+
return value.filter(isRecord16).map(safeDepartment);
|
|
25385
26445
|
}
|
|
25386
26446
|
function safeUser(user) {
|
|
25387
26447
|
const status = user.status === void 0 ? null : Number(user.status);
|
|
@@ -25428,8 +26488,8 @@ async function readDepartments(client, ids) {
|
|
|
25428
26488
|
function pathIds(departments) {
|
|
25429
26489
|
const ids = /* @__PURE__ */ new Set();
|
|
25430
26490
|
for (const department of departments) {
|
|
25431
|
-
const
|
|
25432
|
-
for (const part of
|
|
26491
|
+
const path20 = String(department.path ?? "");
|
|
26492
|
+
for (const part of path20.split(/[|,]/)) {
|
|
25433
26493
|
const id = Number(part);
|
|
25434
26494
|
if (Number.isSafeInteger(id) && id > 0) ids.add(id);
|
|
25435
26495
|
}
|
|
@@ -25439,7 +26499,7 @@ function pathIds(departments) {
|
|
|
25439
26499
|
function mainDepartmentId(raw) {
|
|
25440
26500
|
for (const key of ["main_department_id", "main_group_id", "main_department"]) {
|
|
25441
26501
|
const value = raw[key];
|
|
25442
|
-
if (
|
|
26502
|
+
if (isRecord16(value)) {
|
|
25443
26503
|
const id2 = Number(value.id);
|
|
25444
26504
|
if (Number.isSafeInteger(id2) && id2 > 0) return id2;
|
|
25445
26505
|
}
|
|
@@ -25451,7 +26511,7 @@ function mainDepartmentId(raw) {
|
|
|
25451
26511
|
function branchId(raw) {
|
|
25452
26512
|
for (const key of ["branch_id", "branch_group_id", "branch"]) {
|
|
25453
26513
|
const value = raw[key];
|
|
25454
|
-
if (
|
|
26514
|
+
if (isRecord16(value)) {
|
|
25455
26515
|
const id2 = Number(value.id);
|
|
25456
26516
|
if (Number.isSafeInteger(id2) && id2 > 0) return id2;
|
|
25457
26517
|
}
|
|
@@ -25969,15 +27029,15 @@ async function promptProjectCreateForm(input) {
|
|
|
25969
27029
|
}
|
|
25970
27030
|
|
|
25971
27031
|
// src/core/project-form.ts
|
|
25972
|
-
function
|
|
27032
|
+
function isRecord17(value) {
|
|
25973
27033
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25974
27034
|
}
|
|
25975
27035
|
function clone(value) {
|
|
25976
27036
|
return JSON.parse(JSON.stringify(value));
|
|
25977
27037
|
}
|
|
25978
27038
|
function getFlowFormTemplateId(flowDetail) {
|
|
25979
|
-
const data =
|
|
25980
|
-
const meta =
|
|
27039
|
+
const data = isRecord17(flowDetail?.data) ? flowDetail.data : void 0;
|
|
27040
|
+
const meta = isRecord17(data?.meta) ? data.meta : void 0;
|
|
25981
27041
|
const templateId = meta?.form_template;
|
|
25982
27042
|
if (typeof templateId === "number" && Number.isFinite(templateId)) {
|
|
25983
27043
|
return templateId;
|
|
@@ -26002,7 +27062,7 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
26002
27062
|
if (Array.isArray(value)) {
|
|
26003
27063
|
return value.some((item) => hasAutoInitLambda(item, seen));
|
|
26004
27064
|
}
|
|
26005
|
-
if (!
|
|
27065
|
+
if (!isRecord17(value)) {
|
|
26006
27066
|
return false;
|
|
26007
27067
|
}
|
|
26008
27068
|
if (seen.has(value)) {
|
|
@@ -26017,14 +27077,14 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
26017
27077
|
function setControlValue(control, value) {
|
|
26018
27078
|
const next = clone(control);
|
|
26019
27079
|
next.value = {
|
|
26020
|
-
...
|
|
27080
|
+
...isRecord17(next.value) ? next.value : {},
|
|
26021
27081
|
type: next.value?.type ?? next.field_type,
|
|
26022
27082
|
value
|
|
26023
27083
|
};
|
|
26024
27084
|
return next;
|
|
26025
27085
|
}
|
|
26026
27086
|
function applyRowValues(rowTemplate, rowValue) {
|
|
26027
|
-
const source =
|
|
27087
|
+
const source = isRecord17(rowValue) ? rowValue : {};
|
|
26028
27088
|
return rowTemplate.map((control) => {
|
|
26029
27089
|
if (control.key && Object.prototype.hasOwnProperty.call(source, control.key)) {
|
|
26030
27090
|
return setControlValue(control, source[control.key]);
|
|
@@ -26310,17 +27370,17 @@ function assertStepProjectFormWritable(fields, form, prefix = "") {
|
|
|
26310
27370
|
for (const [key, value] of Object.entries(form)) {
|
|
26311
27371
|
const field = fieldsByKey.get(key);
|
|
26312
27372
|
if (!field) continue;
|
|
26313
|
-
const
|
|
27373
|
+
const path20 = `${prefix}${key}`;
|
|
26314
27374
|
if (field.hidden) {
|
|
26315
|
-
throw new Error(`Step project form handoff cannot write hidden field ${
|
|
27375
|
+
throw new Error(`Step project form handoff cannot write hidden field ${path20}.`);
|
|
26316
27376
|
}
|
|
26317
27377
|
if (isUnsupportedStepPrefillField(field)) {
|
|
26318
|
-
throw new Error(`Step project form handoff cannot write system or manual field ${
|
|
27378
|
+
throw new Error(`Step project form handoff cannot write system or manual field ${path20} (${field.type || "unknown"}).`);
|
|
26319
27379
|
}
|
|
26320
27380
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
26321
27381
|
value.forEach((row, index) => {
|
|
26322
27382
|
if (isRecordValue(row)) {
|
|
26323
|
-
assertStepProjectFormWritable(field.children ?? [], row, `${
|
|
27383
|
+
assertStepProjectFormWritable(field.children ?? [], row, `${path20}[${index}].`);
|
|
26324
27384
|
}
|
|
26325
27385
|
});
|
|
26326
27386
|
}
|
|
@@ -26582,8 +27642,8 @@ function fieldsForValidation(flowDetail, projectFormTemplate) {
|
|
|
26582
27642
|
}));
|
|
26583
27643
|
}
|
|
26584
27644
|
function metaUsesTemplateProjectName(flowDetail) {
|
|
26585
|
-
const data =
|
|
26586
|
-
const meta =
|
|
27645
|
+
const data = isRecord18(flowDetail?.data) ? flowDetail.data : void 0;
|
|
27646
|
+
const meta = isRecord18(data?.meta) ? data.meta : void 0;
|
|
26587
27647
|
const hideFields = Array.isArray(meta?.hide_fields) ? meta.hide_fields.map(String) : [];
|
|
26588
27648
|
return meta?.use_template_project_name === true || hideFields.includes("project.name");
|
|
26589
27649
|
}
|
|
@@ -26677,9 +27737,9 @@ function contextField(field, reason, options = {}) {
|
|
|
26677
27737
|
function collectPrefillContextForFields(fields, form, result, options = {}) {
|
|
26678
27738
|
for (const field of fields) {
|
|
26679
27739
|
const value = form[field.key];
|
|
26680
|
-
const
|
|
27740
|
+
const path20 = options.prefix ? `${options.prefix}.${field.key}` : field.key;
|
|
26681
27741
|
const fieldOptions = {
|
|
26682
|
-
path:
|
|
27742
|
+
path: path20,
|
|
26683
27743
|
rootKey: options.rootKey ?? field.key,
|
|
26684
27744
|
parentKey: options.parentKey
|
|
26685
27745
|
};
|
|
@@ -26692,7 +27752,7 @@ function collectPrefillContextForFields(fields, form, result, options = {}) {
|
|
|
26692
27752
|
result.filled_fields.push(contextField(field, "prefilled", fieldOptions));
|
|
26693
27753
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
26694
27754
|
value.forEach((row, index) => {
|
|
26695
|
-
if (
|
|
27755
|
+
if (isRecord18(row)) {
|
|
26696
27756
|
collectPrefillContextForFields(field.children ?? [], row, result, {
|
|
26697
27757
|
prefix: `${field.key}[${index}]`,
|
|
26698
27758
|
rootKey: field.key,
|
|
@@ -26719,7 +27779,7 @@ function buildPrefillContext(fields, form) {
|
|
|
26719
27779
|
}
|
|
26720
27780
|
};
|
|
26721
27781
|
}
|
|
26722
|
-
function
|
|
27782
|
+
function isRecord18(value) {
|
|
26723
27783
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26724
27784
|
}
|
|
26725
27785
|
function isEndedStep(step) {
|
|
@@ -26742,7 +27802,7 @@ function stepIdOf(step) {
|
|
|
26742
27802
|
function pickStepFormPayload(step) {
|
|
26743
27803
|
const formList = Array.isArray(step.formList) ? step.formList : [];
|
|
26744
27804
|
const forms = Array.isArray(step.forms) ? step.forms : [];
|
|
26745
|
-
const metaForm =
|
|
27805
|
+
const metaForm = isRecord18(step.metaForm) ? step.metaForm : void 0;
|
|
26746
27806
|
return {
|
|
26747
27807
|
step_id: step.id,
|
|
26748
27808
|
flow_step_id: step.flow_step_id,
|
|
@@ -26759,7 +27819,7 @@ function pickStepFormPayload(step) {
|
|
|
26759
27819
|
}
|
|
26760
27820
|
async function buildApprovalContext(client, projectId, options) {
|
|
26761
27821
|
const projectDetail = await apiRequest(client, "GET", `/project/${projectId}`);
|
|
26762
|
-
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(
|
|
27822
|
+
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(isRecord18) : [];
|
|
26763
27823
|
const targetStepIds = /* @__PURE__ */ new Set();
|
|
26764
27824
|
for (const step of steps) {
|
|
26765
27825
|
const id = stepIdOf(step);
|
|
@@ -26785,7 +27845,7 @@ async function buildApprovalContext(client, projectId, options) {
|
|
|
26785
27845
|
}
|
|
26786
27846
|
return {
|
|
26787
27847
|
project: projectDetail,
|
|
26788
|
-
project_form:
|
|
27848
|
+
project_form: isRecord18(projectDetail.metaForm) ? projectDetail.metaForm : null,
|
|
26789
27849
|
inspected_step_count: stepForms.length,
|
|
26790
27850
|
step_forms: stepForms,
|
|
26791
27851
|
failed_steps: failedSteps
|
|
@@ -27123,8 +28183,8 @@ import { spawn as spawn2 } from "child_process";
|
|
|
27123
28183
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
27124
28184
|
|
|
27125
28185
|
// src/core/recipes.ts
|
|
27126
|
-
import { access, mkdir as
|
|
27127
|
-
import
|
|
28186
|
+
import { access, mkdir as mkdir13, readdir as readdir6, readFile as readFile19, writeFile as writeFile13 } from "fs/promises";
|
|
28187
|
+
import path16 from "path";
|
|
27128
28188
|
var RECIPE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
27129
28189
|
var TEMPLATE_PATTERN = /{{\s*([a-zA-Z0-9_.-]+)\s*}}/g;
|
|
27130
28190
|
function assertSafeName(kind, value) {
|
|
@@ -27148,14 +28208,14 @@ function resolveRecipeLocation(options) {
|
|
|
27148
28208
|
workspace,
|
|
27149
28209
|
workspaceDirName,
|
|
27150
28210
|
recipeName: options.recipeName,
|
|
27151
|
-
recipeDir:
|
|
28211
|
+
recipeDir: path16.join(profileDir, "recipes", workspaceDirName, options.recipeName)
|
|
27152
28212
|
};
|
|
27153
28213
|
}
|
|
27154
28214
|
function getRecipesDir(options) {
|
|
27155
28215
|
const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
|
|
27156
|
-
return
|
|
28216
|
+
return path16.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
|
|
27157
28217
|
}
|
|
27158
|
-
function
|
|
28218
|
+
function isRecord19(value) {
|
|
27159
28219
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27160
28220
|
}
|
|
27161
28221
|
function asString(value, fieldName) {
|
|
@@ -27165,7 +28225,7 @@ function asString(value, fieldName) {
|
|
|
27165
28225
|
return value;
|
|
27166
28226
|
}
|
|
27167
28227
|
function parseRecipeDefinition(input) {
|
|
27168
|
-
if (!
|
|
28228
|
+
if (!isRecord19(input)) {
|
|
27169
28229
|
throw new Error("recipe.json must be a JSON object.");
|
|
27170
28230
|
}
|
|
27171
28231
|
if (input.version !== 1) {
|
|
@@ -27173,7 +28233,7 @@ function parseRecipeDefinition(input) {
|
|
|
27173
28233
|
}
|
|
27174
28234
|
const name = asString(input.name, "recipe.name");
|
|
27175
28235
|
assertSafeName("Recipe name", name);
|
|
27176
|
-
if (!
|
|
28236
|
+
if (!isRecord19(input.command)) {
|
|
27177
28237
|
throw new Error("recipe.command must be an object.");
|
|
27178
28238
|
}
|
|
27179
28239
|
const argv = input.command.argv;
|
|
@@ -27181,7 +28241,7 @@ function parseRecipeDefinition(input) {
|
|
|
27181
28241
|
throw new Error("recipe.command.argv must be a non-empty string array.");
|
|
27182
28242
|
}
|
|
27183
28243
|
const variables = Array.isArray(input.variables) ? input.variables.map((item, index) => {
|
|
27184
|
-
if (!
|
|
28244
|
+
if (!isRecord19(item)) {
|
|
27185
28245
|
throw new Error(`recipe.variables[${index}] must be an object.`);
|
|
27186
28246
|
}
|
|
27187
28247
|
const variableName = asString(item.name, `recipe.variables[${index}].name`);
|
|
@@ -27205,7 +28265,7 @@ function parseRecipeDefinition(input) {
|
|
|
27205
28265
|
};
|
|
27206
28266
|
}
|
|
27207
28267
|
async function loadRecipe(recipeDir) {
|
|
27208
|
-
const raw = await
|
|
28268
|
+
const raw = await readFile19(path16.join(recipeDir, "recipe.json"), "utf8");
|
|
27209
28269
|
return parseRecipeDefinition(JSON.parse(raw));
|
|
27210
28270
|
}
|
|
27211
28271
|
async function listRecipes(recipesDir) {
|
|
@@ -27223,7 +28283,7 @@ async function listRecipes(recipesDir) {
|
|
|
27223
28283
|
if (!RECIPE_NAME_PATTERN.test(entry)) {
|
|
27224
28284
|
continue;
|
|
27225
28285
|
}
|
|
27226
|
-
const recipeDir =
|
|
28286
|
+
const recipeDir = path16.join(recipesDir, entry);
|
|
27227
28287
|
try {
|
|
27228
28288
|
const recipe = await loadRecipe(recipeDir);
|
|
27229
28289
|
summaries.push({
|
|
@@ -27257,7 +28317,7 @@ function parseVarsJson(input) {
|
|
|
27257
28317
|
return {};
|
|
27258
28318
|
}
|
|
27259
28319
|
const parsed = JSON.parse(input);
|
|
27260
|
-
if (!
|
|
28320
|
+
if (!isRecord19(parsed)) {
|
|
27261
28321
|
throw new Error("--vars must be a JSON object.");
|
|
27262
28322
|
}
|
|
27263
28323
|
const variables = {};
|
|
@@ -27289,12 +28349,12 @@ function renderTemplate(template, variables) {
|
|
|
27289
28349
|
}
|
|
27290
28350
|
function resolveRecipeFile(recipeDir, token) {
|
|
27291
28351
|
const relative = token.slice(1);
|
|
27292
|
-
if (!relative || relative.includes("..") ||
|
|
28352
|
+
if (!relative || relative.includes("..") || path16.isAbsolute(relative)) {
|
|
27293
28353
|
throw new Error(`Unsafe recipe file reference: ${token}`);
|
|
27294
28354
|
}
|
|
27295
|
-
const resolved =
|
|
27296
|
-
const root =
|
|
27297
|
-
if (resolved !== root && !resolved.startsWith(`${root}${
|
|
28355
|
+
const resolved = path16.resolve(recipeDir, relative);
|
|
28356
|
+
const root = path16.resolve(recipeDir);
|
|
28357
|
+
if (resolved !== root && !resolved.startsWith(`${root}${path16.sep}`)) {
|
|
27298
28358
|
throw new Error(`Recipe file reference escapes recipe directory: ${token}`);
|
|
27299
28359
|
}
|
|
27300
28360
|
return resolved;
|
|
@@ -27304,7 +28364,7 @@ async function renderArgv(options) {
|
|
|
27304
28364
|
const rendered = [];
|
|
27305
28365
|
for (const token of options.recipe.command.argv) {
|
|
27306
28366
|
if (token.startsWith("@")) {
|
|
27307
|
-
const raw = await
|
|
28367
|
+
const raw = await readFile19(resolveRecipeFile(options.recipeDir, token), "utf8");
|
|
27308
28368
|
rendered.push(renderTemplate(raw, options.variables));
|
|
27309
28369
|
} else {
|
|
27310
28370
|
rendered.push(renderTemplate(token, options.variables));
|
|
@@ -27330,7 +28390,7 @@ async function ensureEmptyOrForce(targetDir, force = false) {
|
|
|
27330
28390
|
}
|
|
27331
28391
|
async function writeRecipeScaffold(options) {
|
|
27332
28392
|
await ensureEmptyOrForce(options.location.recipeDir, options.force);
|
|
27333
|
-
await
|
|
28393
|
+
await mkdir13(options.location.recipeDir, { recursive: true });
|
|
27334
28394
|
const title = options.title || options.location.recipeName;
|
|
27335
28395
|
const recipe = {
|
|
27336
28396
|
version: 1,
|
|
@@ -27347,16 +28407,16 @@ async function writeRecipeScaffold(options) {
|
|
|
27347
28407
|
mutating: true
|
|
27348
28408
|
}
|
|
27349
28409
|
};
|
|
27350
|
-
await
|
|
28410
|
+
await writeFile13(path16.join(options.location.recipeDir, "recipe.json"), `${JSON.stringify(recipe, null, 2)}
|
|
27351
28411
|
`, "utf8");
|
|
27352
|
-
await
|
|
27353
|
-
|
|
28412
|
+
await writeFile13(
|
|
28413
|
+
path16.join(options.location.recipeDir, "payload.json"),
|
|
27354
28414
|
`${JSON.stringify({ form: {} }, null, 2)}
|
|
27355
28415
|
`,
|
|
27356
28416
|
"utf8"
|
|
27357
28417
|
);
|
|
27358
|
-
await
|
|
27359
|
-
|
|
28418
|
+
await writeFile13(
|
|
28419
|
+
path16.join(options.location.recipeDir, "README.md"),
|
|
27360
28420
|
[`# ${title}`, "", "Describe the BPMAX flow, field mapping, prerequisites, and verification steps for this recipe.", ""].join("\n"),
|
|
27361
28421
|
"utf8"
|
|
27362
28422
|
);
|
|
@@ -27791,8 +28851,8 @@ function registerSetupCommand(program2, deps = {}) {
|
|
|
27791
28851
|
}
|
|
27792
28852
|
|
|
27793
28853
|
// src/core/taskbook.ts
|
|
27794
|
-
import { mkdir as
|
|
27795
|
-
import
|
|
28854
|
+
import { mkdir as mkdir14, readFile as readFile20, writeFile as writeFile14 } from "fs/promises";
|
|
28855
|
+
import path17 from "path";
|
|
27796
28856
|
var TaskbookError = class extends Error {
|
|
27797
28857
|
};
|
|
27798
28858
|
var REQUIRED_TASKBOOK_TERMS = [
|
|
@@ -28008,19 +29068,19 @@ function hasDomainWriteEvidence(domain, evidenceText, patterns) {
|
|
|
28008
29068
|
function uuidValues(text5) {
|
|
28009
29069
|
return [...new Set([...text5.matchAll(UUID_PATTERN)].map((match) => match[0]))];
|
|
28010
29070
|
}
|
|
28011
|
-
function addUuidIssues(text5, issues,
|
|
29071
|
+
function addUuidIssues(text5, issues, path20) {
|
|
28012
29072
|
for (const value of uuidValues(text5)) {
|
|
28013
29073
|
addTaskbookIssue(
|
|
28014
29074
|
issues,
|
|
28015
29075
|
"uuid_not_allowed",
|
|
28016
29076
|
"taskbook.config.no_uuid",
|
|
28017
29077
|
`BPMAX \u914D\u7F6E\u4EFB\u52A1\u4E0D\u80FD\u4F7F\u7528 UUID\uFF1A${value}\u3002`,
|
|
28018
|
-
{ path:
|
|
29078
|
+
{ path: path20, suggestion: "\u4F7F\u7528\u5E73\u53F0\u8FD4\u56DE\u7684\u6570\u5B57 ID \u6216 flow<number>\uFF1B\u521B\u5EFA\u524D\u4F7F\u7528 new-flow:<name>\uFF0C\u521B\u5EFA\u540E\u56DE\u586B\u771F\u5B9E flow_type\u3002" }
|
|
28019
29079
|
);
|
|
28020
29080
|
}
|
|
28021
29081
|
}
|
|
28022
29082
|
async function readTaskbookText(file) {
|
|
28023
|
-
const raw = await
|
|
29083
|
+
const raw = await readFile20(file, "utf8");
|
|
28024
29084
|
try {
|
|
28025
29085
|
const parsed = JSON.parse(raw);
|
|
28026
29086
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
@@ -28047,7 +29107,7 @@ function findNavigationStrategy(text5) {
|
|
|
28047
29107
|
const matches = [...text5.matchAll(/导航入口策略\s*[::]\s*(nav-config:(?:included|skipped:[^\s|,。]+|deferred:[^\s|,。]+))/gi)];
|
|
28048
29108
|
return matches.at(-1)?.[1] || null;
|
|
28049
29109
|
}
|
|
28050
|
-
function validateNavigationStrategy(text5, issues,
|
|
29110
|
+
function validateNavigationStrategy(text5, issues, path20, subject) {
|
|
28051
29111
|
const strategy = findNavigationStrategy(text5);
|
|
28052
29112
|
if (!strategy) {
|
|
28053
29113
|
addTaskbookIssue(
|
|
@@ -28055,7 +29115,7 @@ function validateNavigationStrategy(text5, issues, path19, subject) {
|
|
|
28055
29115
|
"missing_navigation_strategy",
|
|
28056
29116
|
"taskbook.nav.strategy",
|
|
28057
29117
|
`${subject}\u7F3A\u5C11\u660E\u786E\u7684\u5BFC\u822A\u5165\u53E3\u7B56\u7565\u3002`,
|
|
28058
|
-
{ path:
|
|
29118
|
+
{ path: path20, suggestion: "\u5199\u660E \u5BFC\u822A\u5165\u53E3\u7B56\u7565\uFF1Anav-config:included\u3001nav-config:skipped:<reason> \u6216 nav-config:deferred:<reason>\u3002" }
|
|
28059
29119
|
);
|
|
28060
29120
|
return null;
|
|
28061
29121
|
}
|
|
@@ -28065,7 +29125,7 @@ function validateNavigationStrategy(text5, issues, path19, subject) {
|
|
|
28065
29125
|
"empty_navigation_strategy_reason",
|
|
28066
29126
|
"taskbook.nav.strategy_reason",
|
|
28067
29127
|
`${subject}\u5BFC\u822A\u5165\u53E3\u7B56\u7565\u8DF3\u8FC7\u6216\u5EF6\u540E\u65F6\u5FC5\u987B\u5199\u660E\u539F\u56E0\u3002`,
|
|
28068
|
-
{ path:
|
|
29128
|
+
{ path: path20, suggestion: "\u4F7F\u7528 nav-config:skipped:<\u771F\u5B9E\u539F\u56E0> \u6216 nav-config:deferred:<\u771F\u5B9E\u539F\u56E0>\u3002" }
|
|
28069
29129
|
);
|
|
28070
29130
|
}
|
|
28071
29131
|
if (/(待完成范围确认后回填|待确认|TODO|TBD|占位)/i.test(strategy)) {
|
|
@@ -28074,7 +29134,7 @@ function validateNavigationStrategy(text5, issues, path19, subject) {
|
|
|
28074
29134
|
"placeholder_navigation_strategy",
|
|
28075
29135
|
"taskbook.nav.strategy_placeholder",
|
|
28076
29136
|
`${subject}\u5BFC\u822A\u5165\u53E3\u7B56\u7565\u4ECD\u662F\u5360\u4F4D\u5185\u5BB9\u3002`,
|
|
28077
|
-
{ path:
|
|
29137
|
+
{ path: path20, suggestion: "\u66FF\u6362\u4E3A included\u3001skipped:<\u771F\u5B9E\u539F\u56E0> \u6216 deferred:<\u771F\u5B9E\u539F\u56E0>\u3002" }
|
|
28078
29138
|
);
|
|
28079
29139
|
}
|
|
28080
29140
|
return strategy;
|
|
@@ -28626,8 +29686,8 @@ function taskbookTemplate(title = "BPMAX AI \u5B9E\u65BD\u7F16\u6392\u4EFB\u52A1
|
|
|
28626
29686
|
}
|
|
28627
29687
|
async function initTaskbook(outFile, title) {
|
|
28628
29688
|
const content = taskbookTemplate(title);
|
|
28629
|
-
await
|
|
28630
|
-
await
|
|
29689
|
+
await mkdir14(path17.dirname(outFile), { recursive: true });
|
|
29690
|
+
await writeFile14(outFile, content, "utf8");
|
|
28631
29691
|
return { out: outFile, bytes: Buffer.byteLength(content) };
|
|
28632
29692
|
}
|
|
28633
29693
|
function splitMarkdownRow(line) {
|
|
@@ -28716,8 +29776,8 @@ async function initTaskbookProgress(source, outFile) {
|
|
|
28716
29776
|
fields.join(","),
|
|
28717
29777
|
...rows2.map((row) => fields.map((field) => csvEscape(field === "status" ? "\u672A\u5F00\u59CB" : row[field] || "")).join(","))
|
|
28718
29778
|
].join("\n") + "\n";
|
|
28719
|
-
await
|
|
28720
|
-
await
|
|
29779
|
+
await mkdir14(path17.dirname(outFile), { recursive: true });
|
|
29780
|
+
await writeFile14(outFile, csv, "utf8");
|
|
28721
29781
|
return { source, out: outFile, task_count: rows2.length };
|
|
28722
29782
|
}
|
|
28723
29783
|
|
|
@@ -28759,8 +29819,8 @@ function registerTaskbookCommands(program2) {
|
|
|
28759
29819
|
}
|
|
28760
29820
|
|
|
28761
29821
|
// src/commands/test-suite.ts
|
|
28762
|
-
import { readFile as
|
|
28763
|
-
import
|
|
29822
|
+
import { readFile as readFile21 } from "fs/promises";
|
|
29823
|
+
import path18 from "path";
|
|
28764
29824
|
function collect2(value, previous = []) {
|
|
28765
29825
|
previous.push(value);
|
|
28766
29826
|
return previous;
|
|
@@ -28770,8 +29830,8 @@ function effectiveProfileOption(options, command) {
|
|
|
28770
29830
|
}
|
|
28771
29831
|
async function resolveE2eSkillSource(sourceSkill) {
|
|
28772
29832
|
if (sourceSkill) {
|
|
28773
|
-
const resolved =
|
|
28774
|
-
const content = await
|
|
29833
|
+
const resolved = path18.resolve(sourceSkill);
|
|
29834
|
+
const content = await readFile21(resolved, "utf8").catch(() => "");
|
|
28775
29835
|
if (!content.includes('name: "bpmax-e2e-flow-test-operator"') && !content.includes("name: bpmax-e2e-flow-test-operator")) {
|
|
28776
29836
|
throw new TestSuiteError("source skill is not bpmax-e2e-flow-test-operator", {
|
|
28777
29837
|
rule_id: "test_suite.run.skill_source_invalid",
|
|
@@ -28873,8 +29933,8 @@ function registerTestSuiteCommands(program2) {
|
|
|
28873
29933
|
}
|
|
28874
29934
|
|
|
28875
29935
|
// src/core/update.ts
|
|
28876
|
-
import { access as access2, mkdir as
|
|
28877
|
-
import
|
|
29936
|
+
import { access as access2, mkdir as mkdir15, readFile as readFile22, realpath as realpath4, writeFile as writeFile15 } from "fs/promises";
|
|
29937
|
+
import path19 from "path";
|
|
28878
29938
|
var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/";
|
|
28879
29939
|
var UPDATE_STATE_FILE = "update-state.json";
|
|
28880
29940
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -28990,11 +30050,11 @@ async function fetchLatestVersion(options = {}) {
|
|
|
28990
30050
|
}
|
|
28991
30051
|
}
|
|
28992
30052
|
function updateStatePath(configDir = getConfigDir()) {
|
|
28993
|
-
return
|
|
30053
|
+
return path19.join(configDir, UPDATE_STATE_FILE);
|
|
28994
30054
|
}
|
|
28995
30055
|
async function readUpdateState(configDir) {
|
|
28996
30056
|
try {
|
|
28997
|
-
const raw = await
|
|
30057
|
+
const raw = await readFile22(updateStatePath(configDir), "utf8");
|
|
28998
30058
|
const parsed = JSON.parse(raw);
|
|
28999
30059
|
if (typeof parsed.latest_version !== "string" || typeof parsed.checked_at !== "number") {
|
|
29000
30060
|
return null;
|
|
@@ -29009,8 +30069,8 @@ async function readUpdateState(configDir) {
|
|
|
29009
30069
|
}
|
|
29010
30070
|
}
|
|
29011
30071
|
async function writeUpdateState(state, configDir = getConfigDir()) {
|
|
29012
|
-
await
|
|
29013
|
-
await
|
|
30072
|
+
await mkdir15(configDir, { recursive: true });
|
|
30073
|
+
await writeFile15(updateStatePath(configDir), JSON.stringify(state), "utf8");
|
|
29014
30074
|
}
|
|
29015
30075
|
async function checkCachedUpdate(currentVersion, configDir = getConfigDir()) {
|
|
29016
30076
|
if (process.env.BPMAX_CLI_NO_UPDATE_NOTIFIER) {
|
|
@@ -29056,7 +30116,7 @@ async function executablePath() {
|
|
|
29056
30116
|
return "";
|
|
29057
30117
|
}
|
|
29058
30118
|
try {
|
|
29059
|
-
return await
|
|
30119
|
+
return await realpath4(candidate);
|
|
29060
30120
|
} catch {
|
|
29061
30121
|
return candidate;
|
|
29062
30122
|
}
|
|
@@ -29071,7 +30131,7 @@ async function findNpmPath() {
|
|
|
29071
30131
|
}
|
|
29072
30132
|
function detectInstallMethod(input) {
|
|
29073
30133
|
const resolvedPath = input.executablePath || "";
|
|
29074
|
-
const method = resolvedPath.includes(`node_modules${
|
|
30134
|
+
const method = resolvedPath.includes(`node_modules${path19.sep}`) || resolvedPath.includes("node_modules/") ? "npm" : "manual";
|
|
29075
30135
|
return {
|
|
29076
30136
|
method,
|
|
29077
30137
|
resolvedPath,
|
|
@@ -29312,17 +30372,17 @@ function registerUrlCommands(program2, deps = {}) {
|
|
|
29312
30372
|
}
|
|
29313
30373
|
|
|
29314
30374
|
// src/commands/user.ts
|
|
29315
|
-
function
|
|
30375
|
+
function isRecord20(value) {
|
|
29316
30376
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29317
30377
|
}
|
|
29318
30378
|
function userRows(value) {
|
|
29319
|
-
if (Array.isArray(value)) return value.filter(
|
|
29320
|
-
if (!
|
|
29321
|
-
if (Array.isArray(value.data)) return value.data.filter(
|
|
30379
|
+
if (Array.isArray(value)) return value.filter(isRecord20);
|
|
30380
|
+
if (!isRecord20(value)) return [];
|
|
30381
|
+
if (Array.isArray(value.data)) return value.data.filter(isRecord20);
|
|
29322
30382
|
return value.id ? [value] : [];
|
|
29323
30383
|
}
|
|
29324
30384
|
function safeUser2(user) {
|
|
29325
|
-
const roles = Array.isArray(user.role) ? user.role.filter(
|
|
30385
|
+
const roles = Array.isArray(user.role) ? user.role.filter(isRecord20).map((role) => ({
|
|
29326
30386
|
id: role.id,
|
|
29327
30387
|
key: role.key,
|
|
29328
30388
|
name: role.name
|