bpmax-cli 0.2.1-beta.54 → 0.2.1-beta.55
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 +2215 -427
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-dataset-field-template-editor/SKILL.md +6 -2
- package/skills/bpmax-dataset-field-template-editor/references/nested-field-patterns.md +8 -8
- package/skills/bpmax-dataset-template-editor/SKILL.md +10 -4
- package/skills/bpmax-dataset-template-editor/references/dataset-script-runtime-matrix.md +11 -0
- package/skills/bpmax-dataset-template-editor/references/runtime-gotchas.md +12 -0
- package/skills/bpmax-e2e-flow-test-operator-v2/SKILL.md +7 -2
- package/skills/bpmax-e2e-flow-test-operator-v2/references/browser-action-runner.md +5 -1
- package/skills/bpmax-e2e-flow-test-operator-v2/references/browser-recording-and-replay.md +27 -1
- package/skills/bpmax-e2e-flow-test-operator-v2/references/identity-and-failure-routing.md +11 -5
- package/skills/bpmax-e2e-flow-test-operator-v2/references/step-restartability-and-state.md +6 -0
- package/skills/bpmax-e2e-flow-test-operator-v2/references/test-data-and-selector-contract.md +23 -0
- package/skills/bpmax-flow-template-editor/SKILL.md +1 -0
- package/skills/bpmax-user-mock-operator/SKILL.md +33 -26
- package/skills/bpmax-user-mock-operator/scripts/chrome_identity_bridge.mjs +202 -86
package/dist/bin.js
CHANGED
|
@@ -373,6 +373,7 @@ function capabilityForRequest(method, path25) {
|
|
|
373
373
|
if (normalizedMethod === "GET" && normalizedPath === "/project/my_step") return "project.my-step";
|
|
374
374
|
if (normalizedMethod === "GET" && /^\/project\/[^/]+$/.test(normalizedPath)) return "project.get";
|
|
375
375
|
if (normalizedMethod === "GET" && /^\/step\/[^/]+$/.test(normalizedPath)) return "step.get";
|
|
376
|
+
if (normalizedMethod === "PUT" && normalizedPath === "/step/open-api/next") return "step.submit";
|
|
376
377
|
if (normalizedMethod === "PUT" && /^\/step\/[^/]+$/.test(normalizedPath)) return "step.submit";
|
|
377
378
|
if (normalizedMethod === "GET" && normalizedPath === "/business_skill") return "bbs.list";
|
|
378
379
|
if (normalizedMethod === "POST" && normalizedPath === "/business_skill") return "bbs.create";
|
|
@@ -498,7 +499,7 @@ function pluginAgentCapabilityForRequest(method, normalizedPath) {
|
|
|
498
499
|
// package.json
|
|
499
500
|
var package_default = {
|
|
500
501
|
name: "bpmax-cli",
|
|
501
|
-
version: "0.2.1-beta.
|
|
502
|
+
version: "0.2.1-beta.55",
|
|
502
503
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
503
504
|
type: "module",
|
|
504
505
|
bin: {
|
|
@@ -1680,6 +1681,7 @@ var knownBpmCommands = {
|
|
|
1680
1681
|
schema: /* @__PURE__ */ new Set(["list", "show"]),
|
|
1681
1682
|
setup: null,
|
|
1682
1683
|
step: /* @__PURE__ */ new Set(["get", "context", "actions", "requirements", "submit"]),
|
|
1684
|
+
"test-fixture": /* @__PURE__ */ new Set(["plan", "create", "verify"]),
|
|
1683
1685
|
update: null,
|
|
1684
1686
|
url: /* @__PURE__ */ new Set(["workspace", "project-create", "project-list", "project-detail", "project-step"]),
|
|
1685
1687
|
user: /* @__PURE__ */ new Set(["current"])
|
|
@@ -1926,6 +1928,23 @@ async function lintBusinessSkillDirectory(skillDir, options = {}) {
|
|
|
1926
1928
|
if (/\bcurl\b/i.test(skillMarkdown)) {
|
|
1927
1929
|
issues.push(issue("warning", "curl_usage", "curl usage found; prefer bpmax-cli commands for BPMAX APIs."));
|
|
1928
1930
|
}
|
|
1931
|
+
const shellNormalizedMarkdown = skillMarkdown.replace(/\\\r?\n\s*/g, " ");
|
|
1932
|
+
if (/bpmax-cli\s+test-fixture\s+create\b/i.test(shellNormalizedMarkdown)) {
|
|
1933
|
+
if (!/bpmax-cli\s+test-fixture\s+create\b[^\n`]*\s--manifest\b/i.test(shellNormalizedMarkdown) || !/bpmax-cli\s+test-fixture\s+create\b[^\n`]*\s--json\b/i.test(shellNormalizedMarkdown)) {
|
|
1934
|
+
issues.push(issue(
|
|
1935
|
+
"error",
|
|
1936
|
+
"fixture_bbs_missing_run_binding",
|
|
1937
|
+
"E2E fixture BBS must call test-fixture create with both --manifest and --json so creation is bound to the confirmed scoped run."
|
|
1938
|
+
));
|
|
1939
|
+
}
|
|
1940
|
+
if (/--handoff-only\b|Chrome Control|Playwright[^\n]*(?:create|创建)|浏览器[^\n]*(?:造数据|创建前置)/i.test(skillMarkdown)) {
|
|
1941
|
+
issues.push(issue(
|
|
1942
|
+
"error",
|
|
1943
|
+
"fixture_bbs_browser_creation_forbidden",
|
|
1944
|
+
"E2E fixture BBS must create prerequisite data through typed CLI, not browser handoff or browser exploration."
|
|
1945
|
+
));
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1929
1948
|
if (isApprovalSkill(skillMarkdown, manifest)) {
|
|
1930
1949
|
const lower = skillMarkdown.toLowerCase();
|
|
1931
1950
|
if (!hasAny(lower, [/confirm|confirmation|explicit|明确|确认/])) {
|
|
@@ -4360,6 +4379,7 @@ import { createHash as createHash5 } from "crypto";
|
|
|
4360
4379
|
import { mkdir as mkdir5, readdir as readdir3, readFile as readFile8, writeFile as writeFile5 } from "fs/promises";
|
|
4361
4380
|
import path5 from "path";
|
|
4362
4381
|
import { isDeepStrictEqual } from "util";
|
|
4382
|
+
import { parse as parse2 } from "acorn";
|
|
4363
4383
|
|
|
4364
4384
|
// src/core/flow-report-template.ts
|
|
4365
4385
|
import JSZip3 from "jszip";
|
|
@@ -5249,7 +5269,504 @@ function diffJsonComparable(domain, before, after, normalize) {
|
|
|
5249
5269
|
};
|
|
5250
5270
|
}
|
|
5251
5271
|
var DATASET_FIELD_TYPES = /* @__PURE__ */ new Set(["keyword", "text", "integer", "float", "date", "dynamic", "nested"]);
|
|
5272
|
+
var DATASET_PLATFORM_NESTED_FIELDS = /* @__PURE__ */ new Set(["__step_owners", "__project_owner", "__pending_taskusers"]);
|
|
5273
|
+
var DATASET_PLATFORM_RESERVED_MAPPING_TYPES = /* @__PURE__ */ new Map([
|
|
5274
|
+
["__step_owners", "nested"],
|
|
5275
|
+
["__project_owner", "nested"],
|
|
5276
|
+
["__pending_taskusers", "nested"],
|
|
5277
|
+
["__create_time", "date"]
|
|
5278
|
+
]);
|
|
5279
|
+
var DATASET_NESTED_LIMIT = 50;
|
|
5280
|
+
var DATASET_NESTED_WARNING_THRESHOLD = 40;
|
|
5281
|
+
var ES_MAPPING_TYPES = /* @__PURE__ */ new Set([
|
|
5282
|
+
"aggregate_metric_double",
|
|
5283
|
+
"alias",
|
|
5284
|
+
"binary",
|
|
5285
|
+
"boolean",
|
|
5286
|
+
"byte",
|
|
5287
|
+
"completion",
|
|
5288
|
+
"constant_keyword",
|
|
5289
|
+
"date",
|
|
5290
|
+
"date_nanos",
|
|
5291
|
+
"date_range",
|
|
5292
|
+
"dense_vector",
|
|
5293
|
+
"double",
|
|
5294
|
+
"double_range",
|
|
5295
|
+
"flattened",
|
|
5296
|
+
"float",
|
|
5297
|
+
"float_range",
|
|
5298
|
+
"geo_point",
|
|
5299
|
+
"geo_shape",
|
|
5300
|
+
"half_float",
|
|
5301
|
+
"histogram",
|
|
5302
|
+
"integer",
|
|
5303
|
+
"integer_range",
|
|
5304
|
+
"ip",
|
|
5305
|
+
"ip_range",
|
|
5306
|
+
"join",
|
|
5307
|
+
"keyword",
|
|
5308
|
+
"long",
|
|
5309
|
+
"long_range",
|
|
5310
|
+
"murmur3",
|
|
5311
|
+
"nested",
|
|
5312
|
+
"object",
|
|
5313
|
+
"percolator",
|
|
5314
|
+
"point",
|
|
5315
|
+
"rank_feature",
|
|
5316
|
+
"rank_features",
|
|
5317
|
+
"scaled_float",
|
|
5318
|
+
"search_as_you_type",
|
|
5319
|
+
"shape",
|
|
5320
|
+
"short",
|
|
5321
|
+
"sparse_vector",
|
|
5322
|
+
"text",
|
|
5323
|
+
"token_count",
|
|
5324
|
+
"unsigned_long",
|
|
5325
|
+
"version",
|
|
5326
|
+
"wildcard"
|
|
5327
|
+
]);
|
|
5328
|
+
var DATASET_FIELD_AUDIT_FILTER_KEYS = /* @__PURE__ */ new Set([
|
|
5329
|
+
"backfill_from",
|
|
5330
|
+
"lookup_stable_key",
|
|
5331
|
+
"draft_candidate_only_not_remote_evidence"
|
|
5332
|
+
]);
|
|
5333
|
+
var DATASET_SOURCE_TABLE_COLUMNS = /* @__PURE__ */ new Map([
|
|
5334
|
+
["think_project", /* @__PURE__ */ new Set([
|
|
5335
|
+
"id",
|
|
5336
|
+
"name",
|
|
5337
|
+
"customer_name",
|
|
5338
|
+
"brief",
|
|
5339
|
+
"qualification",
|
|
5340
|
+
"project_type_ids",
|
|
5341
|
+
"address",
|
|
5342
|
+
"status",
|
|
5343
|
+
"end_flow_step_id",
|
|
5344
|
+
"end_step_id",
|
|
5345
|
+
"computed",
|
|
5346
|
+
"delay_level",
|
|
5347
|
+
"create_time",
|
|
5348
|
+
"update_time",
|
|
5349
|
+
"plan_end_time",
|
|
5350
|
+
"user_id",
|
|
5351
|
+
"project_id",
|
|
5352
|
+
"step_id",
|
|
5353
|
+
"app_id",
|
|
5354
|
+
"key",
|
|
5355
|
+
"flow_type",
|
|
5356
|
+
"contract_id",
|
|
5357
|
+
"customer_id",
|
|
5358
|
+
"path",
|
|
5359
|
+
"owner_id",
|
|
5360
|
+
"flow_id",
|
|
5361
|
+
"organization_id",
|
|
5362
|
+
"is_del",
|
|
5363
|
+
"archive_time",
|
|
5364
|
+
"time_cost",
|
|
5365
|
+
"ext_config",
|
|
5366
|
+
"visibility",
|
|
5367
|
+
"visibility_scope",
|
|
5368
|
+
"guid"
|
|
5369
|
+
])],
|
|
5370
|
+
["think_form_field", /* @__PURE__ */ new Set([
|
|
5371
|
+
"id",
|
|
5372
|
+
"is_del",
|
|
5373
|
+
"organization_id",
|
|
5374
|
+
"create_time",
|
|
5375
|
+
"update_time",
|
|
5376
|
+
"guid",
|
|
5377
|
+
"form_id",
|
|
5378
|
+
"title",
|
|
5379
|
+
"field",
|
|
5380
|
+
"key",
|
|
5381
|
+
"validateMap",
|
|
5382
|
+
"value",
|
|
5383
|
+
"search_value",
|
|
5384
|
+
"search_value_1",
|
|
5385
|
+
"search_value_2",
|
|
5386
|
+
"search_value_json",
|
|
5387
|
+
"template_id",
|
|
5388
|
+
"project_id",
|
|
5389
|
+
"step_id",
|
|
5390
|
+
"flow_step_id",
|
|
5391
|
+
"field_type"
|
|
5392
|
+
])]
|
|
5393
|
+
]);
|
|
5252
5394
|
var STANDARD_MAIN_FLOW_TYPE = /^flow\d+$/;
|
|
5395
|
+
function datasetFieldSourceView(value) {
|
|
5396
|
+
return isRecord4(value.source) ? value.source : value;
|
|
5397
|
+
}
|
|
5398
|
+
function datasetFieldValue(value, source, aliases) {
|
|
5399
|
+
for (const key of aliases) {
|
|
5400
|
+
if (source[key] !== void 0) return source[key];
|
|
5401
|
+
if (value[key] !== void 0) return value[key];
|
|
5402
|
+
}
|
|
5403
|
+
return void 0;
|
|
5404
|
+
}
|
|
5405
|
+
function parseDatasetSourceFilter(value) {
|
|
5406
|
+
if (value === null || value === void 0 || value === "") return { value: {} };
|
|
5407
|
+
const parsed = typeof value === "string" ? (() => {
|
|
5408
|
+
try {
|
|
5409
|
+
return JSON.parse(value);
|
|
5410
|
+
} catch {
|
|
5411
|
+
return void 0;
|
|
5412
|
+
}
|
|
5413
|
+
})() : value;
|
|
5414
|
+
if (!isRecord4(parsed)) {
|
|
5415
|
+
return { error: "[dataset-field.source_filter.invalid_json_object] dataset-field source_filter must be an empty value or a valid JSON object." };
|
|
5416
|
+
}
|
|
5417
|
+
return { value: parsed };
|
|
5418
|
+
}
|
|
5419
|
+
function validateDatasetFieldWork(value) {
|
|
5420
|
+
const errors = [];
|
|
5421
|
+
const warnings = [];
|
|
5422
|
+
const type = value.type;
|
|
5423
|
+
if (typeof type !== "string" || !DATASET_FIELD_TYPES.has(type)) {
|
|
5424
|
+
errors.push(`[dataset-field.type.invalid] dataset-field.type must be one of: ${Array.from(DATASET_FIELD_TYPES).join(", ")}.`);
|
|
5425
|
+
}
|
|
5426
|
+
const source = datasetFieldSourceView(value);
|
|
5427
|
+
const classify = String(value.classify ?? "");
|
|
5428
|
+
const sourceTable = String(datasetFieldValue(value, source, ["table", "sourceTable", "source_table"]) ?? "").trim();
|
|
5429
|
+
const sourceField = String(datasetFieldValue(value, source, ["field", "sourceField", "source_field"]) ?? "").trim();
|
|
5430
|
+
const sourceFk = String(datasetFieldValue(value, source, ["fk", "sourceFk", "source_fk"]) ?? "").trim();
|
|
5431
|
+
const sourceFilter = datasetFieldValue(value, source, ["filter", "sourceFilter", "source_filter"]);
|
|
5432
|
+
const columns = DATASET_SOURCE_TABLE_COLUMNS.get(sourceTable);
|
|
5433
|
+
if (classify !== "virtual" && sourceTable && !columns) {
|
|
5434
|
+
warnings.push(`[dataset-field.source.schema_unknown] source table ${sourceTable} has no bundled authoritative schema; runtime source columns must be verified.`);
|
|
5435
|
+
}
|
|
5436
|
+
if (columns) {
|
|
5437
|
+
if (sourceField && !columns.has(sourceField)) {
|
|
5438
|
+
errors.push(`[dataset-field.source_field.unknown] ${sourceTable}.${sourceField} is not a known source column.`);
|
|
5439
|
+
}
|
|
5440
|
+
if (sourceFk && !columns.has(sourceFk)) {
|
|
5441
|
+
errors.push(`[dataset-field.source_fk.unknown] ${sourceTable}.${sourceFk} is not a known source column.`);
|
|
5442
|
+
}
|
|
5443
|
+
}
|
|
5444
|
+
const parsedFilter = parseDatasetSourceFilter(sourceFilter);
|
|
5445
|
+
if (parsedFilter.error) {
|
|
5446
|
+
errors.push(parsedFilter.error);
|
|
5447
|
+
} else if (parsedFilter.value) {
|
|
5448
|
+
for (const key of Object.keys(parsedFilter.value)) {
|
|
5449
|
+
if (DATASET_FIELD_AUDIT_FILTER_KEYS.has(key) || /(?:^|_)not_remote_evidence$/.test(key)) {
|
|
5450
|
+
errors.push(`[dataset-field.source_filter.audit_metadata] source_filter key ${key} is audit/evidence metadata, not a runtime source-table filter.`);
|
|
5451
|
+
} else if (columns && !columns.has(key)) {
|
|
5452
|
+
errors.push(`[dataset-field.source_filter.unknown_column] source_filter key ${sourceTable}.${key} is not a known source column.`);
|
|
5453
|
+
}
|
|
5454
|
+
}
|
|
5455
|
+
}
|
|
5456
|
+
return { errors, warnings };
|
|
5457
|
+
}
|
|
5458
|
+
function datasetFieldSnapshots(value) {
|
|
5459
|
+
for (const candidate of [value.fields, value.dataSetFields, value.data_set_fields, value.relationFields]) {
|
|
5460
|
+
const items = Array.isArray(candidate) ? candidate : isRecord4(candidate) && Array.isArray(candidate.selected) ? candidate.selected : null;
|
|
5461
|
+
if (!items) continue;
|
|
5462
|
+
return items.flatMap((item) => {
|
|
5463
|
+
if (typeof item === "string") return [{ key: item, type: "" }];
|
|
5464
|
+
if (!isRecord4(item)) return [];
|
|
5465
|
+
return [{ key: String(item.key ?? item.field ?? ""), type: String(item.type ?? "") }];
|
|
5466
|
+
});
|
|
5467
|
+
}
|
|
5468
|
+
return [];
|
|
5469
|
+
}
|
|
5470
|
+
function astMemberPath(node) {
|
|
5471
|
+
if (!node) return null;
|
|
5472
|
+
if (node.type === "Identifier") return [String(node.name)];
|
|
5473
|
+
if (node.type !== "MemberExpression") return null;
|
|
5474
|
+
const objectPath = astMemberPath(node.object);
|
|
5475
|
+
if (!objectPath) return null;
|
|
5476
|
+
if (!node.computed && node.property?.type === "Identifier") {
|
|
5477
|
+
return [...objectPath, String(node.property.name)];
|
|
5478
|
+
}
|
|
5479
|
+
if (node.computed && node.property?.type === "Literal" && typeof node.property.value === "string") {
|
|
5480
|
+
return [...objectPath, String(node.property.value)];
|
|
5481
|
+
}
|
|
5482
|
+
return [...objectPath, null];
|
|
5483
|
+
}
|
|
5484
|
+
function astStaticString(node, strings) {
|
|
5485
|
+
if (!node) return null;
|
|
5486
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.value;
|
|
5487
|
+
if (node.type === "Identifier") return strings.get(String(node.name)) ?? null;
|
|
5488
|
+
return null;
|
|
5489
|
+
}
|
|
5490
|
+
function astMappingType(node, mappings) {
|
|
5491
|
+
if (!node) return null;
|
|
5492
|
+
if (node.type === "Identifier") return mappings.get(String(node.name)) ?? null;
|
|
5493
|
+
if (node.type !== "ObjectExpression") return null;
|
|
5494
|
+
for (const property of node.properties) {
|
|
5495
|
+
if (property.type !== "Property") continue;
|
|
5496
|
+
const key = property.computed ? astStaticString(property.key, /* @__PURE__ */ new Map()) : String(property.key.name ?? property.key.value ?? "");
|
|
5497
|
+
if (key === "type") return astStaticString(property.value, /* @__PURE__ */ new Map());
|
|
5498
|
+
}
|
|
5499
|
+
return null;
|
|
5500
|
+
}
|
|
5501
|
+
function walkAst(node, visit, parent) {
|
|
5502
|
+
if (!node || typeof node.type !== "string") return;
|
|
5503
|
+
visit(node, parent);
|
|
5504
|
+
for (const [key, child] of Object.entries(node)) {
|
|
5505
|
+
if (key === "type" || key === "start" || key === "end" || key === "loc") continue;
|
|
5506
|
+
if (Array.isArray(child)) {
|
|
5507
|
+
for (const item of child) {
|
|
5508
|
+
if (item && typeof item === "object" && typeof item.type === "string") walkAst(item, visit, node);
|
|
5509
|
+
}
|
|
5510
|
+
} else if (child && typeof child === "object" && typeof child.type === "string") {
|
|
5511
|
+
walkAst(child, visit, node);
|
|
5512
|
+
}
|
|
5513
|
+
}
|
|
5514
|
+
}
|
|
5515
|
+
function astHasRuntimeControl(node, parents, allowedCallback) {
|
|
5516
|
+
const runtimeControlTypes = /* @__PURE__ */ new Set([
|
|
5517
|
+
"IfStatement",
|
|
5518
|
+
"ConditionalExpression",
|
|
5519
|
+
"SwitchCase",
|
|
5520
|
+
"TryStatement",
|
|
5521
|
+
"CatchClause",
|
|
5522
|
+
"WhileStatement",
|
|
5523
|
+
"DoWhileStatement",
|
|
5524
|
+
"ForStatement",
|
|
5525
|
+
"ForInStatement",
|
|
5526
|
+
"ForOfStatement",
|
|
5527
|
+
"LogicalExpression"
|
|
5528
|
+
]);
|
|
5529
|
+
let current = parents.get(node);
|
|
5530
|
+
while (current) {
|
|
5531
|
+
if (current === allowedCallback) {
|
|
5532
|
+
current = parents.get(current);
|
|
5533
|
+
continue;
|
|
5534
|
+
}
|
|
5535
|
+
if (runtimeControlTypes.has(current.type)) return true;
|
|
5536
|
+
if (["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"].includes(current.type)) return true;
|
|
5537
|
+
current = parents.get(current);
|
|
5538
|
+
}
|
|
5539
|
+
return false;
|
|
5540
|
+
}
|
|
5541
|
+
function analyzeDatasetMapping(value) {
|
|
5542
|
+
const fields = datasetFieldSnapshots(value);
|
|
5543
|
+
const fieldTypes = /* @__PURE__ */ new Map();
|
|
5544
|
+
let missingFieldTypes = false;
|
|
5545
|
+
for (const field of fields) {
|
|
5546
|
+
const key = field.key.trim();
|
|
5547
|
+
const type = String(field.type ?? "").trim();
|
|
5548
|
+
if (key && type) fieldTypes.set(key, type);
|
|
5549
|
+
else if (key) missingFieldTypes = true;
|
|
5550
|
+
}
|
|
5551
|
+
const baseNestedCount = Array.from(fieldTypes.entries()).filter(([field, type]) => type === "nested" && !DATASET_PLATFORM_RESERVED_MAPPING_TYPES.has(field)).length;
|
|
5552
|
+
const scriptSource = isRecord4(value.scripts) ? value.scripts.postEsMapping ?? value.scripts.post_es_mapping ?? "" : value.post_es_mapping ?? value.postEsMapping ?? "";
|
|
5553
|
+
const script = normalizeText(scriptSource).trim();
|
|
5554
|
+
const warnings = [];
|
|
5555
|
+
const errors = [];
|
|
5556
|
+
const mappingOverrides = /* @__PURE__ */ new Map();
|
|
5557
|
+
let analyzable = !missingFieldTypes;
|
|
5558
|
+
if (missingFieldTypes) {
|
|
5559
|
+
warnings.push("[dataset.mapping.field_types_incomplete] dataset field definitions are incomplete; nested budget requires runtime verification.");
|
|
5560
|
+
}
|
|
5561
|
+
if (script) {
|
|
5562
|
+
let root;
|
|
5563
|
+
try {
|
|
5564
|
+
root = parse2(script, {
|
|
5565
|
+
ecmaVersion: "latest",
|
|
5566
|
+
sourceType: "script",
|
|
5567
|
+
allowAwaitOutsideFunction: true,
|
|
5568
|
+
allowReturnOutsideFunction: true
|
|
5569
|
+
});
|
|
5570
|
+
} catch (error) {
|
|
5571
|
+
errors.push(`[dataset.mapping.script_syntax] post_es_mapping is not valid JavaScript: ${error instanceof Error ? error.message : String(error)}.`);
|
|
5572
|
+
analyzable = false;
|
|
5573
|
+
root = { type: "Program", body: [] };
|
|
5574
|
+
}
|
|
5575
|
+
const stringBindings = /* @__PURE__ */ new Map();
|
|
5576
|
+
const arrayBindings = /* @__PURE__ */ new Map();
|
|
5577
|
+
const mappingBindings = /* @__PURE__ */ new Map();
|
|
5578
|
+
const parents = /* @__PURE__ */ new Map();
|
|
5579
|
+
walkAst(root, (node, parent) => {
|
|
5580
|
+
if (parent) parents.set(node, parent);
|
|
5581
|
+
});
|
|
5582
|
+
const mutableBindings = /* @__PURE__ */ new Set();
|
|
5583
|
+
const mutatingMethods = /* @__PURE__ */ new Set(["copyWithin", "fill", "pop", "push", "reverse", "shift", "sort", "splice", "unshift"]);
|
|
5584
|
+
walkAst(root, (node) => {
|
|
5585
|
+
if (node.type === "AssignmentExpression" || node.type === "UpdateExpression") {
|
|
5586
|
+
const target = node.type === "AssignmentExpression" ? node.left : node.argument;
|
|
5587
|
+
const path25 = astMemberPath(target);
|
|
5588
|
+
if (path25?.length) mutableBindings.add(String(path25[0]));
|
|
5589
|
+
else if (target.type === "Identifier") mutableBindings.add(String(target.name));
|
|
5590
|
+
return;
|
|
5591
|
+
}
|
|
5592
|
+
if (node.type === "UnaryExpression" && node.operator === "delete") {
|
|
5593
|
+
const path25 = astMemberPath(node.argument);
|
|
5594
|
+
if (path25?.length) mutableBindings.add(String(path25[0]));
|
|
5595
|
+
return;
|
|
5596
|
+
}
|
|
5597
|
+
if (node.type !== "CallExpression") return;
|
|
5598
|
+
const calleePath = astMemberPath(node.callee);
|
|
5599
|
+
if (calleePath?.length === 2 && mutatingMethods.has(String(calleePath[1]))) {
|
|
5600
|
+
mutableBindings.add(String(calleePath[0]));
|
|
5601
|
+
}
|
|
5602
|
+
for (const argument of node.arguments) {
|
|
5603
|
+
if (argument?.type === "Identifier") mutableBindings.add(String(argument.name));
|
|
5604
|
+
}
|
|
5605
|
+
});
|
|
5606
|
+
walkAst(root, (node) => {
|
|
5607
|
+
if (node.type !== "VariableDeclarator" || node.id?.type !== "Identifier") return;
|
|
5608
|
+
const name = String(node.id.name);
|
|
5609
|
+
const declaration = parents.get(node);
|
|
5610
|
+
if (declaration?.type !== "VariableDeclaration" || declaration.kind !== "const" || mutableBindings.has(name)) return;
|
|
5611
|
+
const init = node.init;
|
|
5612
|
+
const stringValue6 = astStaticString(init, stringBindings);
|
|
5613
|
+
if (stringValue6 !== null) stringBindings.set(name, stringValue6);
|
|
5614
|
+
if (init?.type === "ArrayExpression") {
|
|
5615
|
+
const values = init.elements.map((item) => astStaticString(item ?? void 0, stringBindings));
|
|
5616
|
+
if (values.every((item) => item !== null)) arrayBindings.set(name, values);
|
|
5617
|
+
}
|
|
5618
|
+
const mappingType = astMappingType(init, mappingBindings);
|
|
5619
|
+
if (mappingType) mappingBindings.set(name, mappingType);
|
|
5620
|
+
});
|
|
5621
|
+
const handledAssignments = /* @__PURE__ */ new Set();
|
|
5622
|
+
walkAst(root, (node) => {
|
|
5623
|
+
if (node.type !== "CallExpression") return;
|
|
5624
|
+
const calleePath = astMemberPath(node.callee);
|
|
5625
|
+
if (!calleePath || calleePath.length !== 2 || calleePath[1] !== "forEach") return;
|
|
5626
|
+
const fieldsForLoop = arrayBindings.get(String(calleePath[0]));
|
|
5627
|
+
const callback = node.arguments[0];
|
|
5628
|
+
if (!fieldsForLoop || !callback || !["ArrowFunctionExpression", "FunctionExpression"].includes(callback.type)) return;
|
|
5629
|
+
const parameter = callback.params[0];
|
|
5630
|
+
if (!parameter || parameter.type !== "Identifier") return;
|
|
5631
|
+
walkAst(callback.body, (child) => {
|
|
5632
|
+
if (child.type !== "AssignmentExpression" || child.operator !== "=") return;
|
|
5633
|
+
const targetPath = astMemberPath(child.left);
|
|
5634
|
+
if (!targetPath || targetPath.length !== 4 || targetPath[0] !== "ctx" || targetPath[1] !== "mapping" || targetPath[2] !== "properties" || targetPath[3] !== null) return;
|
|
5635
|
+
const member = child.left;
|
|
5636
|
+
const property = member.property;
|
|
5637
|
+
if (property.type !== "Identifier" || property.name !== parameter.name) return;
|
|
5638
|
+
if (astHasRuntimeControl(child, parents, callback)) {
|
|
5639
|
+
analyzable = false;
|
|
5640
|
+
handledAssignments.add(child);
|
|
5641
|
+
return;
|
|
5642
|
+
}
|
|
5643
|
+
const mappingType = astMappingType(child.right, mappingBindings);
|
|
5644
|
+
if (!mappingType) {
|
|
5645
|
+
analyzable = false;
|
|
5646
|
+
return;
|
|
5647
|
+
}
|
|
5648
|
+
for (const field of fieldsForLoop) mappingOverrides.set(field, mappingType);
|
|
5649
|
+
handledAssignments.add(child);
|
|
5650
|
+
});
|
|
5651
|
+
});
|
|
5652
|
+
walkAst(root, (node) => {
|
|
5653
|
+
if (node.type === "UnaryExpression" && node.operator === "delete") {
|
|
5654
|
+
const path25 = astMemberPath(node.argument);
|
|
5655
|
+
if (path25?.[0] !== "ctx" || path25[1] !== "mapping") return;
|
|
5656
|
+
if (path25.length === 2 || path25.length === 3 && path25[2] === "properties") {
|
|
5657
|
+
errors.push("[dataset.mapping.destructive_delete] post_es_mapping must not delete ctx.mapping or ctx.mapping.properties.");
|
|
5658
|
+
} else if (path25.length === 4 && path25[2] === "properties" && typeof path25[3] === "string") {
|
|
5659
|
+
if (DATASET_PLATFORM_RESERVED_MAPPING_TYPES.has(path25[3])) {
|
|
5660
|
+
errors.push(`[dataset.mapping.reserved_field.deleted] reserved mapping field ${path25[3]} must not be deleted.`);
|
|
5661
|
+
} else {
|
|
5662
|
+
analyzable = false;
|
|
5663
|
+
}
|
|
5664
|
+
} else {
|
|
5665
|
+
analyzable = false;
|
|
5666
|
+
}
|
|
5667
|
+
return;
|
|
5668
|
+
}
|
|
5669
|
+
if (node.type !== "AssignmentExpression" || handledAssignments.has(node)) return;
|
|
5670
|
+
const targetPath = astMemberPath(node.left);
|
|
5671
|
+
if (!targetPath || targetPath[0] !== "ctx" || targetPath[1] !== "mapping") return;
|
|
5672
|
+
if (targetPath.length === 2 || targetPath.length === 3 && targetPath[2] === "properties") {
|
|
5673
|
+
errors.push("[dataset.mapping.destructive_replace] post_es_mapping must not replace ctx.mapping or ctx.mapping.properties.");
|
|
5674
|
+
return;
|
|
5675
|
+
}
|
|
5676
|
+
if (node.operator !== "=") {
|
|
5677
|
+
analyzable = false;
|
|
5678
|
+
return;
|
|
5679
|
+
}
|
|
5680
|
+
if (targetPath.length !== 4 || targetPath[2] !== "properties" || targetPath[3] === null) {
|
|
5681
|
+
analyzable = false;
|
|
5682
|
+
return;
|
|
5683
|
+
}
|
|
5684
|
+
if (astHasRuntimeControl(node, parents)) {
|
|
5685
|
+
analyzable = false;
|
|
5686
|
+
return;
|
|
5687
|
+
}
|
|
5688
|
+
const mappingType = astMappingType(node.right, mappingBindings);
|
|
5689
|
+
if (!mappingType) {
|
|
5690
|
+
analyzable = false;
|
|
5691
|
+
return;
|
|
5692
|
+
}
|
|
5693
|
+
mappingOverrides.set(String(targetPath[3]), mappingType);
|
|
5694
|
+
});
|
|
5695
|
+
}
|
|
5696
|
+
for (const [field, type] of fieldTypes) {
|
|
5697
|
+
const reservedType = DATASET_PLATFORM_RESERVED_MAPPING_TYPES.get(field);
|
|
5698
|
+
if (reservedType && type !== reservedType) {
|
|
5699
|
+
errors.push(`[dataset.mapping.reserved_field.incompatible] reserved mapping field ${field} must remain type ${reservedType}, got dataset-field type ${type}.`);
|
|
5700
|
+
}
|
|
5701
|
+
}
|
|
5702
|
+
for (const [field, type] of mappingOverrides) {
|
|
5703
|
+
if (!ES_MAPPING_TYPES.has(type)) {
|
|
5704
|
+
errors.push(`[dataset.mapping.type.invalid] mapping field ${field} uses unsupported Elasticsearch type ${type}.`);
|
|
5705
|
+
}
|
|
5706
|
+
const reservedType = DATASET_PLATFORM_RESERVED_MAPPING_TYPES.get(field);
|
|
5707
|
+
if (reservedType && type !== reservedType) {
|
|
5708
|
+
errors.push(`[dataset.mapping.reserved_field.incompatible] reserved mapping field ${field} must remain type ${reservedType}, got ${type}.`);
|
|
5709
|
+
}
|
|
5710
|
+
}
|
|
5711
|
+
const addedNestedFields = Array.from(mappingOverrides.entries()).filter(([field, type]) => type === "nested" && fieldTypes.get(field) !== "nested" && !DATASET_PLATFORM_NESTED_FIELDS.has(field)).map(([field]) => field).sort();
|
|
5712
|
+
const downgradedNestedFields = Array.from(mappingOverrides.entries()).filter(([field, type]) => fieldTypes.get(field) === "nested" && type !== "nested").map(([field]) => field).sort();
|
|
5713
|
+
const effectiveNestedCount = analyzable ? baseNestedCount + DATASET_PLATFORM_NESTED_FIELDS.size + addedNestedFields.length - downgradedNestedFields.length : null;
|
|
5714
|
+
const headroom = effectiveNestedCount === null ? null : DATASET_NESTED_LIMIT - effectiveNestedCount;
|
|
5715
|
+
if (effectiveNestedCount !== null && effectiveNestedCount > DATASET_NESTED_LIMIT) {
|
|
5716
|
+
errors.push(`[dataset.mapping.nested_limit_exceeded] effective nested field count ${effectiveNestedCount} exceeds Elasticsearch limit ${DATASET_NESTED_LIMIT}.`);
|
|
5717
|
+
} else if (effectiveNestedCount !== null && effectiveNestedCount >= DATASET_NESTED_WARNING_THRESHOLD) {
|
|
5718
|
+
warnings.push(`[dataset.mapping.nested_limit_near] effective nested field count ${effectiveNestedCount} is near Elasticsearch limit ${DATASET_NESTED_LIMIT}; headroom=${headroom}.`);
|
|
5719
|
+
}
|
|
5720
|
+
if (!analyzable) {
|
|
5721
|
+
warnings.push("[dataset.mapping.runtime_verification_required] post_es_mapping or field types cannot be fully analyzed; verify index creation, writeToES, query, and page visibility after refresh.");
|
|
5722
|
+
}
|
|
5723
|
+
return {
|
|
5724
|
+
base_nested_count: baseNestedCount,
|
|
5725
|
+
platform_reserved_nested_count: DATASET_PLATFORM_NESTED_FIELDS.size,
|
|
5726
|
+
added_nested_fields: addedNestedFields,
|
|
5727
|
+
downgraded_nested_fields: downgradedNestedFields,
|
|
5728
|
+
effective_nested_count: effectiveNestedCount,
|
|
5729
|
+
limit: DATASET_NESTED_LIMIT,
|
|
5730
|
+
headroom,
|
|
5731
|
+
analyzable,
|
|
5732
|
+
runtime_verification_required: !analyzable,
|
|
5733
|
+
warnings,
|
|
5734
|
+
errors,
|
|
5735
|
+
mapping_overrides: Object.fromEntries(Array.from(mappingOverrides.entries()).sort(([a], [b]) => a.localeCompare(b)))
|
|
5736
|
+
};
|
|
5737
|
+
}
|
|
5738
|
+
function datasetValidationArtifact(value, mapping) {
|
|
5739
|
+
const fields = datasetFieldSnapshots(value);
|
|
5740
|
+
const postEsMapping = isRecord4(value.scripts) ? normalizeText(value.scripts.postEsMapping ?? value.scripts.post_es_mapping ?? "") : normalizeText(value.post_es_mapping ?? value.postEsMapping ?? "");
|
|
5741
|
+
const input = { fields, post_es_mapping: postEsMapping };
|
|
5742
|
+
return { version: 1, input, input_hash: hashJson(input), analysis_hash: hashJson(mapping) };
|
|
5743
|
+
}
|
|
5744
|
+
function validateDatasetSubmitArtifact(submit) {
|
|
5745
|
+
if (!isRecord4(submit.payload) || !isRecord4(submit.dataset_validation)) {
|
|
5746
|
+
throw new Error("[dataset.validation.artifact_missing] dataset submit requires a validation artifact produced by typed build.");
|
|
5747
|
+
}
|
|
5748
|
+
const artifact = submit.dataset_validation;
|
|
5749
|
+
if (artifact.version !== 1 || !isRecord4(artifact.input) || typeof artifact.input_hash !== "string" || typeof artifact.analysis_hash !== "string") {
|
|
5750
|
+
throw new Error("[dataset.validation.artifact_invalid] dataset validation artifact is malformed; rebuild the submit file.");
|
|
5751
|
+
}
|
|
5752
|
+
if (hashJson(artifact.input) !== artifact.input_hash) {
|
|
5753
|
+
throw new Error("[dataset.validation.artifact_tampered] dataset validation artifact input hash does not match; rebuild the submit file.");
|
|
5754
|
+
}
|
|
5755
|
+
const fields = Array.isArray(artifact.input.fields) ? artifact.input.fields.filter(isRecord4) : [];
|
|
5756
|
+
const payloadFields = Array.isArray(submit.payload.fields) ? submit.payload.fields.map(String) : [];
|
|
5757
|
+
const artifactFields = fields.map((field) => String(field.key ?? ""));
|
|
5758
|
+
if (!isDeepStrictEqual(payloadFields, artifactFields) || normalizeText(submit.payload.post_es_mapping ?? "") !== normalizeText(artifact.input.post_es_mapping ?? "")) {
|
|
5759
|
+
throw new Error("[dataset.validation.payload_tampered] dataset payload no longer matches its validated fields or post_es_mapping; rebuild the submit file.");
|
|
5760
|
+
}
|
|
5761
|
+
const mapping = analyzeDatasetMapping({ dataSetFields: fields, post_es_mapping: artifact.input.post_es_mapping });
|
|
5762
|
+
if (hashJson(mapping) !== artifact.analysis_hash) {
|
|
5763
|
+
throw new Error("[dataset.validation.analysis_drift] dataset mapping analysis changed or was tampered with; rebuild the submit file.");
|
|
5764
|
+
}
|
|
5765
|
+
if (mapping.errors.length) {
|
|
5766
|
+
throw new Error(`dataset mapping lint failed: ${mapping.errors.join("; ")}`);
|
|
5767
|
+
}
|
|
5768
|
+
return mapping;
|
|
5769
|
+
}
|
|
5253
5770
|
function collectTemplateFieldKeys(value, keys = /* @__PURE__ */ new Set()) {
|
|
5254
5771
|
if (Array.isArray(value)) {
|
|
5255
5772
|
for (const item of value) {
|
|
@@ -5273,11 +5790,10 @@ function collectTemplateFieldKeys(value, keys = /* @__PURE__ */ new Set()) {
|
|
|
5273
5790
|
}
|
|
5274
5791
|
return keys;
|
|
5275
5792
|
}
|
|
5276
|
-
function lintDatasetFieldWork(value, errors) {
|
|
5277
|
-
const
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
}
|
|
5793
|
+
function lintDatasetFieldWork(value, errors, warnings = []) {
|
|
5794
|
+
const validation = validateDatasetFieldWork(value);
|
|
5795
|
+
errors.push(...validation.errors);
|
|
5796
|
+
warnings.push(...validation.warnings);
|
|
5281
5797
|
}
|
|
5282
5798
|
function isFlowTemplateWork(value) {
|
|
5283
5799
|
const data = value.data;
|
|
@@ -5327,6 +5843,22 @@ function hasConfiguredFormTemplate(meta) {
|
|
|
5327
5843
|
function hasConfiguredFlowTemplateFormSource(value, meta) {
|
|
5328
5844
|
return hasConfiguredFormTemplate(meta) || !isEmptyTemplateReference(value.meta_form_id);
|
|
5329
5845
|
}
|
|
5846
|
+
function validateFlowTemplateProjectNameTemplate(value, errors) {
|
|
5847
|
+
const data = isRecord4(value.data) ? value.data : {};
|
|
5848
|
+
const meta = isRecord4(data.meta) ? data.meta : {};
|
|
5849
|
+
if (meta.use_template_project_name !== true) {
|
|
5850
|
+
return;
|
|
5851
|
+
}
|
|
5852
|
+
if (typeof meta.project_name_template === "string" && meta.project_name_template.trim()) {
|
|
5853
|
+
return;
|
|
5854
|
+
}
|
|
5855
|
+
const message = "flow-template project name template gate failed: data.meta.project_name_template must be a non-empty string when data.meta.use_template_project_name is true.";
|
|
5856
|
+
if (errors) {
|
|
5857
|
+
errors.push(message);
|
|
5858
|
+
return;
|
|
5859
|
+
}
|
|
5860
|
+
throw new Error(message);
|
|
5861
|
+
}
|
|
5330
5862
|
function validateFlowTemplateFormDrivenCreateBaseline(value, errors, options = {}) {
|
|
5331
5863
|
const data = isRecord4(value.data) ? value.data : {};
|
|
5332
5864
|
const meta = isRecord4(data.meta) ? data.meta : {};
|
|
@@ -8681,6 +9213,7 @@ function normalizeFlowTemplatePayload(work) {
|
|
|
8681
9213
|
meta.form_template = work.meta_form_id;
|
|
8682
9214
|
}
|
|
8683
9215
|
data.meta = meta;
|
|
9216
|
+
validateFlowTemplateProjectNameTemplate({ ...work, data });
|
|
8684
9217
|
validateFlowTemplateRemoteTemplateRefs({ ...work, data });
|
|
8685
9218
|
validateFlowTemplateExpectedChildFlows({ ...work, data });
|
|
8686
9219
|
validateFlowTemplateProjectAfterCreatePath({ ...work, data });
|
|
@@ -11847,6 +12380,7 @@ async function createFlowTemplateFromWork(config, profile, workFile, confirm3, o
|
|
|
11847
12380
|
validateFlowTemplateRuntimeScripts(work);
|
|
11848
12381
|
validateFlowTemplateFeishuChatPlugin(work);
|
|
11849
12382
|
validateFlowTemplateFormDrivenCreateBaseline(work, void 0, { context: "flow-template create" });
|
|
12383
|
+
validateFlowTemplateProjectNameTemplate(work);
|
|
11850
12384
|
validateNonEmptyFlowCreatePayload(work);
|
|
11851
12385
|
const createShell = {
|
|
11852
12386
|
name: String(work.name || ""),
|
|
@@ -13181,6 +13715,7 @@ async function verifyConfigDomain(config, profile, domain, id, options = {}) {
|
|
|
13181
13715
|
verificationWarnings.push(...flowReportAnalysis.warnings);
|
|
13182
13716
|
}
|
|
13183
13717
|
if (domain === "flow-template" && isRecord4(actual)) {
|
|
13718
|
+
validateFlowTemplateProjectNameTemplate(actual, semanticErrors);
|
|
13184
13719
|
flowCategoryReferenceAudit = await auditFlowCategoryReference(actual, profile);
|
|
13185
13720
|
semanticErrors.push(...flowCategoryReferenceAudit.errors);
|
|
13186
13721
|
stepDetailReferenceAudit = await auditFlowStepDetailReferences(actual, profile);
|
|
@@ -13611,6 +14146,9 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
13611
14146
|
let flowReportAnalysis;
|
|
13612
14147
|
let flowReportReferenceAudit;
|
|
13613
14148
|
let flowCategoryReferenceAudit;
|
|
14149
|
+
let datasetMapping;
|
|
14150
|
+
let datasetValidation;
|
|
14151
|
+
let datasetFieldWarnings = [];
|
|
13614
14152
|
if (domain === "flow-template" && isRecord4(work)) {
|
|
13615
14153
|
const pluginLint = await runFlowTemplatePluginLint(work, options.pluginLint);
|
|
13616
14154
|
if (pluginLint?.errors.length) {
|
|
@@ -13674,6 +14212,20 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
13674
14212
|
throw new Error(`flow-detail-template lint failed: ${errors.join("; ")}`);
|
|
13675
14213
|
}
|
|
13676
14214
|
}
|
|
14215
|
+
if (domain === "dataset-field" && isRecord4(work)) {
|
|
14216
|
+
const validation = validateDatasetFieldWork(work);
|
|
14217
|
+
datasetFieldWarnings = validation.warnings;
|
|
14218
|
+
if (validation.errors.length) {
|
|
14219
|
+
throw new Error(`dataset-field lint failed: ${validation.errors.join("; ")}`);
|
|
14220
|
+
}
|
|
14221
|
+
}
|
|
14222
|
+
if (domain === "dataset" && isRecord4(work)) {
|
|
14223
|
+
datasetMapping = analyzeDatasetMapping(work);
|
|
14224
|
+
if (datasetMapping.errors.length) {
|
|
14225
|
+
throw new Error(`dataset mapping lint failed: ${datasetMapping.errors.join("; ")}`);
|
|
14226
|
+
}
|
|
14227
|
+
datasetValidation = datasetValidationArtifact(work, datasetMapping);
|
|
14228
|
+
}
|
|
13677
14229
|
const payloadWork = (domain === "dataset" || domain === "dataset-field") && createMode && isRecord4(work) ? { ...work, mode: "create" } : work;
|
|
13678
14230
|
const payload = buildDomainSubmitPayload(domain, payloadWork, options, raw);
|
|
13679
14231
|
if (domain === "flow-template" && options.publishLive) {
|
|
@@ -13682,6 +14234,13 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
13682
14234
|
if (!Object.keys(payload).length) {
|
|
13683
14235
|
throw new Error(`Config build produced an empty payload for ${domain}.`);
|
|
13684
14236
|
}
|
|
14237
|
+
if (domain === "dataset-field") {
|
|
14238
|
+
const validation = validateDatasetFieldWork(payload);
|
|
14239
|
+
datasetFieldWarnings = Array.from(/* @__PURE__ */ new Set([...datasetFieldWarnings, ...validation.warnings]));
|
|
14240
|
+
if (validation.errors.length) {
|
|
14241
|
+
throw new Error(`dataset-field lint failed: ${validation.errors.join("; ")}`);
|
|
14242
|
+
}
|
|
14243
|
+
}
|
|
13685
14244
|
validateExpectedType(domain, definition, payload);
|
|
13686
14245
|
const submitMeta = isRecord4(meta) ? { ...meta } : {};
|
|
13687
14246
|
if (options.usage) {
|
|
@@ -13696,6 +14255,8 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
13696
14255
|
meta: submitMeta,
|
|
13697
14256
|
base_hash: createMode ? null : typeof meta.base_hash === "string" ? meta.base_hash : null,
|
|
13698
14257
|
payload,
|
|
14258
|
+
...datasetValidation ? { dataset_validation: datasetValidation } : {},
|
|
14259
|
+
...datasetMapping ? { dataset_mapping: datasetMapping } : {},
|
|
13699
14260
|
...flowCategoryReferenceAudit ? { flow_category_reference: flowCategoryReferenceEvidence(flowCategoryReferenceAudit) } : {},
|
|
13700
14261
|
...formTemplateWarnings.length ? { form_template_warnings: formTemplateWarnings } : {},
|
|
13701
14262
|
...flowDetailTemplateWarnings.length ? { flow_detail_template_warnings: flowDetailTemplateWarnings } : {},
|
|
@@ -13732,6 +14293,12 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
13732
14293
|
work_file: workFile,
|
|
13733
14294
|
submit_file: outFile,
|
|
13734
14295
|
payload_keys: Object.keys(payload),
|
|
14296
|
+
...datasetMapping ? {
|
|
14297
|
+
dataset_mapping: datasetMapping,
|
|
14298
|
+
warnings: datasetMapping.warnings,
|
|
14299
|
+
runtime_verification_required: datasetMapping.runtime_verification_required
|
|
14300
|
+
} : {},
|
|
14301
|
+
...datasetFieldWarnings.length ? { warnings: datasetFieldWarnings } : {},
|
|
13735
14302
|
...formTemplateWarnings.length ? { warnings: formTemplateWarnings } : {},
|
|
13736
14303
|
...flowDetailTemplateWarnings.length ? { warnings: flowDetailTemplateWarnings } : {},
|
|
13737
14304
|
...stepDetailReferenceAudit ? {
|
|
@@ -13862,11 +14429,12 @@ async function lintConfigWorkFile(file, options = {}) {
|
|
|
13862
14429
|
let stepDetailReferenceAudit;
|
|
13863
14430
|
let flowReportAnalysis;
|
|
13864
14431
|
let flowReportReferenceAudit;
|
|
14432
|
+
let datasetMapping;
|
|
13865
14433
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
13866
14434
|
errors.push("Config work file must be a JSON object.");
|
|
13867
14435
|
} else {
|
|
13868
|
-
if (Object.prototype.hasOwnProperty.call(value, "classify") && Object.prototype.hasOwnProperty.call(value, "source_table")) {
|
|
13869
|
-
lintDatasetFieldWork(value, errors);
|
|
14436
|
+
if (options.domain === "dataset-field" || Object.prototype.hasOwnProperty.call(value, "classify") && (Object.prototype.hasOwnProperty.call(value, "source_table") || isRecord4(value.source))) {
|
|
14437
|
+
lintDatasetFieldWork(value, errors, warnings);
|
|
13870
14438
|
}
|
|
13871
14439
|
if (options.domain === "dataset") {
|
|
13872
14440
|
try {
|
|
@@ -13874,6 +14442,9 @@ async function lintConfigWorkFile(file, options = {}) {
|
|
|
13874
14442
|
} catch (error) {
|
|
13875
14443
|
errors.push(error instanceof Error ? error.message : String(error));
|
|
13876
14444
|
}
|
|
14445
|
+
datasetMapping = analyzeDatasetMapping(value);
|
|
14446
|
+
errors.push(...datasetMapping.errors);
|
|
14447
|
+
warnings.push(...datasetMapping.warnings);
|
|
13877
14448
|
}
|
|
13878
14449
|
if (options.domain === "team" || options.domain === "user" || options.domain === "user-model" || options.domain === "group-model") {
|
|
13879
14450
|
try {
|
|
@@ -13946,6 +14517,10 @@ async function lintConfigWorkFile(file, options = {}) {
|
|
|
13946
14517
|
} else {
|
|
13947
14518
|
validateFlowTemplateStandardFlowType(flowWork, errors);
|
|
13948
14519
|
}
|
|
14520
|
+
const flowMeta = isRecord4(flowWork.data) && isRecord4(flowWork.data.meta) ? flowWork.data.meta : {};
|
|
14521
|
+
if (!(options.mode === "create" || flowWork.mode === "create") || !hasConfiguredFlowTemplateFormSource(flowWork, flowMeta)) {
|
|
14522
|
+
validateFlowTemplateProjectNameTemplate(flowWork, errors);
|
|
14523
|
+
}
|
|
13949
14524
|
}
|
|
13950
14525
|
}
|
|
13951
14526
|
return {
|
|
@@ -13984,6 +14559,7 @@ async function lintConfigWorkFile(file, options = {}) {
|
|
|
13984
14559
|
runtime_proof_required: flowReportReferenceAudit.references.length > 0 || flowStepDetailRuntimeProofRequired(stepDetailReferenceAudit)
|
|
13985
14560
|
} : {},
|
|
13986
14561
|
...pluginLint ? { plugin_lints: pluginLint.plugin_lints } : {},
|
|
14562
|
+
...datasetMapping ? { dataset_mapping: datasetMapping } : {},
|
|
13987
14563
|
checked_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
13988
14564
|
};
|
|
13989
14565
|
}
|
|
@@ -14265,6 +14841,7 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
14265
14841
|
let stepDetailAnalysis;
|
|
14266
14842
|
let flowReportAnalysis;
|
|
14267
14843
|
let flowReportActivation;
|
|
14844
|
+
let datasetMapping;
|
|
14268
14845
|
const submitMode = isRecord4(meta) ? meta.mode : void 0;
|
|
14269
14846
|
if (domain === "team" || domain === "user" || domain === "user-model" || domain === "group-model") {
|
|
14270
14847
|
const validationWork = { ...submit.payload, mode: submitMode };
|
|
@@ -14273,6 +14850,20 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
14273
14850
|
for (const key of Object.keys(submit.payload)) delete submit.payload[key];
|
|
14274
14851
|
Object.assign(submit.payload, normalizedPayload);
|
|
14275
14852
|
}
|
|
14853
|
+
if (domain === "dataset") {
|
|
14854
|
+
const datasetMode = submitMode === "create" ? "create" : "edit";
|
|
14855
|
+
validateDatasetPayload(submit.payload, datasetMode);
|
|
14856
|
+
if (datasetMode === "edit" && String(submit.payload.id) !== id) {
|
|
14857
|
+
throw new Error(`dataset edit identity mismatch; request id, payload.id, and readback id must all equal ${id}.`);
|
|
14858
|
+
}
|
|
14859
|
+
datasetMapping = validateDatasetSubmitArtifact(submit);
|
|
14860
|
+
}
|
|
14861
|
+
if (domain === "dataset-field") {
|
|
14862
|
+
const validation = validateDatasetFieldWork(submit.payload);
|
|
14863
|
+
if (validation.errors.length) {
|
|
14864
|
+
throw new Error(`dataset-field lint failed: ${validation.errors.join("; ")}`);
|
|
14865
|
+
}
|
|
14866
|
+
}
|
|
14276
14867
|
if (submitMode === "create" && domain !== "form-template") {
|
|
14277
14868
|
if (!definition.createPath || !definition.createMethod) {
|
|
14278
14869
|
throw new Error(`${domain} create is not implemented in the typed adapter.`);
|
|
@@ -14288,6 +14879,7 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
14288
14879
|
}
|
|
14289
14880
|
}
|
|
14290
14881
|
if (domain === "flow-template") {
|
|
14882
|
+
validateFlowTemplateProjectNameTemplate(submit.payload);
|
|
14291
14883
|
validateNonEmptyFlowCreatePayload(submit.payload);
|
|
14292
14884
|
}
|
|
14293
14885
|
if (domain === "console-template") {
|
|
@@ -14316,9 +14908,6 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
14316
14908
|
if (domain === "dataset-field") {
|
|
14317
14909
|
validateDatasetFieldCreatePayload(submit.payload);
|
|
14318
14910
|
}
|
|
14319
|
-
if (domain === "dataset") {
|
|
14320
|
-
validateDatasetPayload(submit.payload, "create");
|
|
14321
|
-
}
|
|
14322
14911
|
await ensureConfigCapability(profile, `${definition.capability}.create`);
|
|
14323
14912
|
const expectedConfirm2 = `submit ${domain} ${id}`;
|
|
14324
14913
|
if (confirm3 !== expectedConfirm2) {
|
|
@@ -14329,6 +14918,11 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
14329
14918
|
endpoint: definition.createPath,
|
|
14330
14919
|
method: definition.createMethod,
|
|
14331
14920
|
payload: configPayloadForOutput(domain, submit.payload),
|
|
14921
|
+
...datasetMapping ? {
|
|
14922
|
+
dataset_mapping: datasetMapping,
|
|
14923
|
+
warnings: datasetMapping.warnings,
|
|
14924
|
+
runtime_verification_required: datasetMapping.runtime_verification_required
|
|
14925
|
+
} : {},
|
|
14332
14926
|
...stepDetailAnalysis ? {
|
|
14333
14927
|
step_detail_template: stepDetailAnalysisEvidence(stepDetailAnalysis),
|
|
14334
14928
|
warnings: stepDetailAnalysis.warnings,
|
|
@@ -14436,6 +15030,11 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
14436
15030
|
endpoint: definition.createPath,
|
|
14437
15031
|
method: definition.createMethod,
|
|
14438
15032
|
response: response2,
|
|
15033
|
+
...datasetMapping ? {
|
|
15034
|
+
dataset_mapping: datasetMapping,
|
|
15035
|
+
warnings: datasetMapping.warnings,
|
|
15036
|
+
runtime_verification_required: datasetMapping.runtime_verification_required
|
|
15037
|
+
} : {},
|
|
14439
15038
|
readback_hash: readbackHash,
|
|
14440
15039
|
...stepDetailAnalysis ? {
|
|
14441
15040
|
step_detail_template: stepDetailAnalysisEvidence(stepDetailAnalysis),
|
|
@@ -14477,6 +15076,7 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
14477
15076
|
validateFlowTemplateCodeModeMessages(submit.payload);
|
|
14478
15077
|
validateFlowTemplateRuntimeScripts(submit.payload);
|
|
14479
15078
|
validateFlowTemplateFeishuChatPlugin(submit.payload);
|
|
15079
|
+
validateFlowTemplateProjectNameTemplate(submit.payload);
|
|
14480
15080
|
validateFlowTemplateStandardFlowType(submit.payload);
|
|
14481
15081
|
validateFlowTemplateIdentityStandard(id, submit.payload);
|
|
14482
15082
|
const pluginLint = await runFlowTemplatePluginLint(submit.payload, {
|
|
@@ -14612,8 +15212,7 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
14612
15212
|
validateNonDestructiveFlowEdit(submit.payload, current);
|
|
14613
15213
|
}
|
|
14614
15214
|
if (domain === "dataset") {
|
|
14615
|
-
|
|
14616
|
-
if (String(submit.payload.id) !== id || isRecord4(current) && String(current.id) !== id) {
|
|
15215
|
+
if (isRecord4(current) && String(current.id) !== id) {
|
|
14617
15216
|
throw new Error(`dataset edit identity mismatch; request id, payload.id, and readback id must all equal ${id}.`);
|
|
14618
15217
|
}
|
|
14619
15218
|
if (isRecord4(current) && String(current.custom_key ?? "") !== String(submit.payload.custom_key ?? "")) {
|
|
@@ -14668,6 +15267,11 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
14668
15267
|
endpoint,
|
|
14669
15268
|
method: definition.submitMethod,
|
|
14670
15269
|
payload: submitPayload,
|
|
15270
|
+
...datasetMapping ? {
|
|
15271
|
+
dataset_mapping: datasetMapping,
|
|
15272
|
+
warnings: datasetMapping.warnings,
|
|
15273
|
+
runtime_verification_required: datasetMapping.runtime_verification_required
|
|
15274
|
+
} : {},
|
|
14671
15275
|
...publishMode ? { publish_mode: publishMode } : {},
|
|
14672
15276
|
...flowCategoryReferenceAudit ? { flow_category_reference: flowCategoryReferenceEvidence(flowCategoryReferenceAudit) } : {},
|
|
14673
15277
|
...stepDetailReferenceAudit ? {
|
|
@@ -18371,13 +18975,13 @@ function registerDoctorCommands(program2) {
|
|
|
18371
18975
|
}
|
|
18372
18976
|
|
|
18373
18977
|
// src/commands/e2e.ts
|
|
18374
|
-
import { createHash as
|
|
18375
|
-
import { mkdir as mkdir14, readFile as readFile18, readdir as readdir6, stat as stat13, writeFile as writeFile14 } from "fs/promises";
|
|
18978
|
+
import { createHash as createHash13 } from "crypto";
|
|
18979
|
+
import { mkdir as mkdir14, readFile as readFile18, readdir as readdir6, realpath as realpath8, stat as stat13, writeFile as writeFile14 } from "fs/promises";
|
|
18376
18980
|
import path19 from "path";
|
|
18377
18981
|
import axios7 from "axios";
|
|
18378
18982
|
|
|
18379
18983
|
// src/core/e2e-scenario-orchestrator.ts
|
|
18380
|
-
import { createHash as
|
|
18984
|
+
import { createHash as createHash11 } from "crypto";
|
|
18381
18985
|
import { chmod as chmod2, mkdir as mkdir12, readFile as readFile16, realpath as realpath6, rename as rename4, rm as rm6, stat as stat11, writeFile as writeFile12 } from "fs/promises";
|
|
18382
18986
|
import path17 from "path";
|
|
18383
18987
|
|
|
@@ -19402,7 +20006,7 @@ function validateBrowserAutomationDataProfile(step, data, stepKey) {
|
|
|
19402
20006
|
}
|
|
19403
20007
|
|
|
19404
20008
|
// src/core/e2e-browser-runner.ts
|
|
19405
|
-
import { createHash as
|
|
20009
|
+
import { createHash as createHash10 } from "crypto";
|
|
19406
20010
|
import { lstat as lstat3, mkdir as mkdir11, readFile as readFile15, realpath as realpath5, rename as rename3, stat as stat10, writeFile as writeFile11 } from "fs/promises";
|
|
19407
20011
|
import path16 from "path";
|
|
19408
20012
|
import {
|
|
@@ -19410,7 +20014,7 @@ import {
|
|
|
19410
20014
|
} from "playwright-core";
|
|
19411
20015
|
|
|
19412
20016
|
// src/core/test-suite.ts
|
|
19413
|
-
import { createHash as
|
|
20017
|
+
import { createHash as createHash9, randomBytes as randomBytes3 } from "crypto";
|
|
19414
20018
|
import {
|
|
19415
20019
|
copyFile,
|
|
19416
20020
|
cp as cp3,
|
|
@@ -19428,12 +20032,28 @@ import {
|
|
|
19428
20032
|
import path15 from "path";
|
|
19429
20033
|
import { inflateSync } from "zlib";
|
|
19430
20034
|
|
|
20035
|
+
// src/core/test-fixture-contract.ts
|
|
20036
|
+
import { createHash as createHash7 } from "crypto";
|
|
20037
|
+
function isRecord9(value) {
|
|
20038
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20039
|
+
}
|
|
20040
|
+
function canonicalJson2(value) {
|
|
20041
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson2).join(",")}]`;
|
|
20042
|
+
if (isRecord9(value)) {
|
|
20043
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson2(value[key])}`).join(",")}}`;
|
|
20044
|
+
}
|
|
20045
|
+
return JSON.stringify(value);
|
|
20046
|
+
}
|
|
20047
|
+
function fixtureManifestSha256(value) {
|
|
20048
|
+
return createHash7("sha256").update(canonicalJson2(value)).digest("hex");
|
|
20049
|
+
}
|
|
20050
|
+
|
|
19431
20051
|
// src/core/e2e-operation-lock.ts
|
|
19432
20052
|
import { lstat, realpath as realpath3 } from "fs/promises";
|
|
19433
20053
|
import path14 from "path";
|
|
19434
20054
|
|
|
19435
20055
|
// src/core/process-lock.ts
|
|
19436
|
-
import { createHash as
|
|
20056
|
+
import { createHash as createHash8, randomBytes as randomBytes2 } from "crypto";
|
|
19437
20057
|
import { mkdir as mkdir9, readFile as readFile13, rename, rm as rm4, stat as stat8, writeFile as writeFile9 } from "fs/promises";
|
|
19438
20058
|
import path13 from "path";
|
|
19439
20059
|
var ProcessLockError = class extends Error {
|
|
@@ -19462,7 +20082,7 @@ async function readOwner(lockPath, kind) {
|
|
|
19462
20082
|
if (Number.isSafeInteger(legacy.pid) && Number(legacy.pid) > 0 && !Number.isNaN(Date.parse(String(legacy.created_at || "")))) {
|
|
19463
20083
|
return {
|
|
19464
20084
|
version: 1,
|
|
19465
|
-
owner_token:
|
|
20085
|
+
owner_token: createHash8("sha256").update(content).digest("hex").slice(0, 32),
|
|
19466
20086
|
pid: Number(legacy.pid),
|
|
19467
20087
|
created_at: String(legacy.created_at)
|
|
19468
20088
|
};
|
|
@@ -19711,7 +20331,7 @@ var CASE_TYPES = /* @__PURE__ */ new Set(["positive", "negative", "boundary", "p
|
|
|
19711
20331
|
var STATUSES = /* @__PURE__ */ new Set(["active", "deprecated", "draft"]);
|
|
19712
20332
|
var CASE_STEP_RUNNERS = /* @__PURE__ */ new Set(["browser", "browser_action", "identity", "e2e_create_page", "e2e_step_run", "observe"]);
|
|
19713
20333
|
var LEGACY_FORMAL_RUNNERS = /* @__PURE__ */ new Set(["e2e_create_page", "e2e_step_run"]);
|
|
19714
|
-
var IDENTITY_STEP_RE = /(
|
|
20334
|
+
var IDENTITY_STEP_RE = /(?:确保|切换|恢复|检查|核对|验证|确认|读取).{0,12}(?:身份|用户|管理员)|(?:mock|unmock|模拟用户)/i;
|
|
19715
20335
|
var CASE_STEP_ACTION_VERBS = [
|
|
19716
20336
|
"\u6253\u5F00",
|
|
19717
20337
|
"\u8FDB\u5165",
|
|
@@ -19728,6 +20348,7 @@ var CASE_STEP_ACTION_VERBS = [
|
|
|
19728
20348
|
"\u6838\u5BF9",
|
|
19729
20349
|
"\u9A8C\u8BC1",
|
|
19730
20350
|
"\u622A\u56FE",
|
|
20351
|
+
"\u786E\u4FDD",
|
|
19731
20352
|
"\u5207\u6362",
|
|
19732
20353
|
"\u6062\u590D",
|
|
19733
20354
|
"\u521B\u5EFA",
|
|
@@ -19823,7 +20444,7 @@ function identityStepOperation(step) {
|
|
|
19823
20444
|
const text5 = [step.action, step.target, step.input_data, step.expected_result].join(" ");
|
|
19824
20445
|
if (/(unmock|退出模拟|恢复原始|恢复管理员)/i.test(text5)) return "unmock";
|
|
19825
20446
|
if (/(status|当前身份|身份回读|(?:确认|检查|读取|核对).{0,8}身份)/i.test(text5)) return "status";
|
|
19826
|
-
if (/(mock
|
|
20447
|
+
if (/(mock|模拟用户|(?:确保|切换).{0,8}(?:身份|用户))/i.test(text5)) return "mock";
|
|
19827
20448
|
return null;
|
|
19828
20449
|
}
|
|
19829
20450
|
var BROWSER_TOOL_RE = /(Chrome Control|chrome:control-chrome|Chrome DevTools|DevTools|Playwright|AppleScript|app_in_browser|App in Browser)/i;
|
|
@@ -20303,7 +20924,7 @@ async function validateScenarioAutomation(scenarioDir, steps, selectedCaseIds) {
|
|
|
20303
20924
|
suggestion: "Run test-suite automation init and compile. Do not hand-edit runner=browser_action or fabricate compile metadata."
|
|
20304
20925
|
});
|
|
20305
20926
|
}
|
|
20306
|
-
const currentCaseStepsSha256 =
|
|
20927
|
+
const currentCaseStepsSha256 = createHash9("sha256").update(await readFile14(path15.join(scenarioDir, "case_steps.csv"))).digest("hex");
|
|
20307
20928
|
if (automation.compile.case_steps_sha256 !== currentCaseStepsSha256) {
|
|
20308
20929
|
fail(`${automationPath}: compiled case_steps.csv hash does not match the current scenario`, {
|
|
20309
20930
|
rule_id: "test_suite.automation.compiled_case_steps_stale",
|
|
@@ -20396,7 +21017,7 @@ async function automationStatus(options) {
|
|
|
20396
21017
|
message: `runner contract ${String(document2.compile.contract_version)} is not compatible with v2`
|
|
20397
21018
|
});
|
|
20398
21019
|
}
|
|
20399
|
-
const caseStepsSha256 =
|
|
21020
|
+
const caseStepsSha256 = createHash9("sha256").update(await readFile14(path15.join(scenarioDir, "case_steps.csv"))).digest("hex");
|
|
20400
21021
|
if (document2.compile.case_steps_sha256 !== caseStepsSha256) {
|
|
20401
21022
|
changedInputs.push({
|
|
20402
21023
|
rule_id: "test_suite.automation.compiled_case_steps_stale",
|
|
@@ -20766,7 +21387,7 @@ function validateCaseSteps(filePath, cases, steps, options = {}) {
|
|
|
20766
21387
|
});
|
|
20767
21388
|
}
|
|
20768
21389
|
if (!/screenshot|截图/i.test(step.evidence_required)) {
|
|
20769
|
-
fail(`${location}: identity \u6B65\u9AA4\u5FC5\u987B\u8981\u6C42\u672C\u8F6E
|
|
21390
|
+
fail(`${location}: identity \u6B65\u9AA4\u5FC5\u987B\u8981\u6C42\u672C\u8F6E\u5BF9\u5E94\u6267\u884C\u9636\u6BB5\u7684\u8EAB\u4EFD\u622A\u56FE`, {
|
|
20770
21391
|
rule_id: "test_suite.case_step.identity_screenshot",
|
|
20771
21392
|
path: filePath
|
|
20772
21393
|
});
|
|
@@ -20803,21 +21424,13 @@ function validateCaseSteps(filePath, cases, steps, options = {}) {
|
|
|
20803
21424
|
}
|
|
20804
21425
|
}
|
|
20805
21426
|
});
|
|
20806
|
-
let statusReady = false;
|
|
20807
21427
|
let activeMock = null;
|
|
20808
21428
|
for (const step of caseSteps.filter((item) => item.runner === "identity")) {
|
|
20809
21429
|
const operation = identityStepOperation(step);
|
|
20810
21430
|
if (operation === "status") {
|
|
20811
|
-
statusReady = true;
|
|
20812
21431
|
continue;
|
|
20813
21432
|
}
|
|
20814
21433
|
if (operation === "mock") {
|
|
20815
|
-
if (!statusReady) {
|
|
20816
|
-
fail(`${filePath}:${row.case_id}:${step.step_id}: mock \u524D\u5FC5\u987B\u6709\u672C\u8F6E\u72EC\u7ACB identity status \u6B65\u9AA4`, {
|
|
20817
|
-
rule_id: "test_suite.case_step.identity_status_before_mock",
|
|
20818
|
-
path: filePath
|
|
20819
|
-
});
|
|
20820
|
-
}
|
|
20821
21434
|
if (activeMock) {
|
|
20822
21435
|
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`, {
|
|
20823
21436
|
rule_id: "test_suite.case_step.identity_nested_mock",
|
|
@@ -20825,7 +21438,6 @@ function validateCaseSteps(filePath, cases, steps, options = {}) {
|
|
|
20825
21438
|
});
|
|
20826
21439
|
}
|
|
20827
21440
|
activeMock = step;
|
|
20828
|
-
statusReady = false;
|
|
20829
21441
|
continue;
|
|
20830
21442
|
}
|
|
20831
21443
|
if (operation === "unmock") {
|
|
@@ -20836,7 +21448,6 @@ function validateCaseSteps(filePath, cases, steps, options = {}) {
|
|
|
20836
21448
|
});
|
|
20837
21449
|
}
|
|
20838
21450
|
activeMock = null;
|
|
20839
|
-
statusReady = false;
|
|
20840
21451
|
}
|
|
20841
21452
|
}
|
|
20842
21453
|
if (activeMock) {
|
|
@@ -21146,7 +21757,7 @@ async function initScenarioAutomationCompile(options) {
|
|
|
21146
21757
|
expectedSurfaceByStepKey: expectedSurfaceByStep(cases, deterministicSteps)
|
|
21147
21758
|
});
|
|
21148
21759
|
const metadata = validation.document ? validateBrowserAutomationCompileMetadataDetailed(validation.document) : { issues: [], warnings: [] };
|
|
21149
|
-
const currentCaseStepsSha256 =
|
|
21760
|
+
const currentCaseStepsSha256 = createHash9("sha256").update(await readFile14(stepsPath)).digest("hex");
|
|
21150
21761
|
const hashesMatch = validation.document?.compile.case_steps_sha256 === currentCaseStepsSha256 && validation.document?.compile.compiled_suite_sha256 === await compiledScenarioSha256(scenarioDir);
|
|
21151
21762
|
if (validation.document && validation.issues.length === 0 && metadata.issues.length === 0 && hashesMatch) {
|
|
21152
21763
|
reusableStepKeys = new Set(Object.keys(validation.document.steps));
|
|
@@ -21373,7 +21984,7 @@ async function compileScenarioAutomationUnlocked(options) {
|
|
|
21373
21984
|
suggestion: "Complete the pre-run read-only discovery or platform-source review; do not start a formal run or click through the case manually."
|
|
21374
21985
|
});
|
|
21375
21986
|
}
|
|
21376
|
-
const sourceSha256 =
|
|
21987
|
+
const sourceSha256 = createHash9("sha256").update(await readFile14(sourcePath)).digest("hex");
|
|
21377
21988
|
const nextSteps = steps.map((step) => requiredKeys.has(automationStepKey(step.case_id, step.step_id)) ? { ...step, runner: "browser_action" } : step);
|
|
21378
21989
|
const nextStepsText = csvText(CASE_STEP_FIELDS, nextSteps);
|
|
21379
21990
|
const compiledAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -21393,7 +22004,7 @@ async function compileScenarioAutomationUnlocked(options) {
|
|
|
21393
22004
|
source_sha256: sourceSha256,
|
|
21394
22005
|
source_suite_sha256: currentSourceSha256,
|
|
21395
22006
|
compiled_suite_sha256: await compiledScenarioSha256(scenarioDir, nextStepsText),
|
|
21396
|
-
case_steps_sha256:
|
|
22007
|
+
case_steps_sha256: createHash9("sha256").update(nextStepsText).digest("hex"),
|
|
21397
22008
|
automation_sha256: "",
|
|
21398
22009
|
compiled_at: compiledAt,
|
|
21399
22010
|
formal_execution_performed: false,
|
|
@@ -21457,7 +22068,7 @@ async function assertAutomationDraftRoot(root) {
|
|
|
21457
22068
|
}
|
|
21458
22069
|
}
|
|
21459
22070
|
async function automationCompileSourceSha256(scenarioDir) {
|
|
21460
|
-
const hash =
|
|
22071
|
+
const hash = createHash9("sha256");
|
|
21461
22072
|
for (const file of ["README.md", "cases.csv", "case_steps.csv"]) {
|
|
21462
22073
|
hash.update(file);
|
|
21463
22074
|
hash.update("\0");
|
|
@@ -21467,7 +22078,7 @@ async function automationCompileSourceSha256(scenarioDir) {
|
|
|
21467
22078
|
return hash.digest("hex");
|
|
21468
22079
|
}
|
|
21469
22080
|
async function compiledScenarioSha256(scenarioDir, caseStepsText) {
|
|
21470
|
-
const hash =
|
|
22081
|
+
const hash = createHash9("sha256");
|
|
21471
22082
|
for (const file of ["README.md", "cases.csv"]) {
|
|
21472
22083
|
hash.update(file);
|
|
21473
22084
|
hash.update("\0");
|
|
@@ -21730,8 +22341,8 @@ async function applyReviewedAutomationRepairUnlocked(options) {
|
|
|
21730
22341
|
const previousAutomationText = await readText(runAutomationPath);
|
|
21731
22342
|
const nextAutomationText = `${JSON.stringify(candidate, null, 2)}
|
|
21732
22343
|
`;
|
|
21733
|
-
const previousAutomationSha256 =
|
|
21734
|
-
const nextAutomationSha256 =
|
|
22344
|
+
const previousAutomationSha256 = createHash9("sha256").update(previousAutomationText).digest("hex");
|
|
22345
|
+
const nextAutomationSha256 = createHash9("sha256").update(nextAutomationText).digest("hex");
|
|
21735
22346
|
const reviewPath = await repairRealpath(
|
|
21736
22347
|
path15.join(candidateScenarioDir, "review.json"),
|
|
21737
22348
|
"test_suite.automation.repair_candidate_invalid",
|
|
@@ -21747,7 +22358,7 @@ async function applyReviewedAutomationRepairUnlocked(options) {
|
|
|
21747
22358
|
}
|
|
21748
22359
|
await assertAutomationRepairGuardSources(guard);
|
|
21749
22360
|
const expectedReceiptText = automationRepairReceiptText(manifestPath, manifest, guard);
|
|
21750
|
-
if (
|
|
22361
|
+
if (createHash9("sha256").update(expectedReceiptText).digest("hex") !== guard.receipt_sha256) {
|
|
21751
22362
|
fail("anchored automation repair receipt hash is inconsistent", {
|
|
21752
22363
|
rule_id: "test_suite.automation.repair_receipt_invalid",
|
|
21753
22364
|
path: guard.receipt
|
|
@@ -21823,7 +22434,7 @@ async function applyReviewedAutomationRepairUnlocked(options) {
|
|
|
21823
22434
|
anchored_manifest_revision: (manifest.revision ?? 0) + 1
|
|
21824
22435
|
};
|
|
21825
22436
|
const repairReceiptText = automationRepairReceiptText(manifestPath, manifest, guard);
|
|
21826
|
-
guard.receipt_sha256 =
|
|
22437
|
+
guard.receipt_sha256 = createHash9("sha256").update(repairReceiptText).digest("hex");
|
|
21827
22438
|
manifest.automation_repair_guard = guard;
|
|
21828
22439
|
await writeExecutionManifest(manifestPath, manifest, true);
|
|
21829
22440
|
await writeAtomicText(runAutomationPath, nextAutomationText);
|
|
@@ -21910,7 +22521,7 @@ async function consumeReviewedAutomationRepair(options) {
|
|
|
21910
22521
|
path: automationPath
|
|
21911
22522
|
});
|
|
21912
22523
|
}
|
|
21913
|
-
const automationSha256 =
|
|
22524
|
+
const automationSha256 = createHash9("sha256").update(await readFile14(automationPath)).digest("hex");
|
|
21914
22525
|
const guard = manifest.automation_repair_guard;
|
|
21915
22526
|
if (!guard && manifest.automation_hash === automationSha256) {
|
|
21916
22527
|
return { ok: true, consumed: false, automation_sha256: automationSha256 };
|
|
@@ -21936,7 +22547,7 @@ async function consumeReviewedAutomationRepair(options) {
|
|
|
21936
22547
|
});
|
|
21937
22548
|
}
|
|
21938
22549
|
const expectedReceiptText = automationRepairReceiptText(manifestPath, manifest, guard);
|
|
21939
|
-
if (
|
|
22550
|
+
if (createHash9("sha256").update(expectedReceiptText).digest("hex") !== guard.receipt_sha256 || await readText(guard.receipt) !== expectedReceiptText) {
|
|
21940
22551
|
fail("automation repair receipt content does not match the manifest anchor", {
|
|
21941
22552
|
rule_id: "test_suite.automation.repair_receipt_invalid",
|
|
21942
22553
|
path: guard.receipt
|
|
@@ -21966,23 +22577,25 @@ async function consumeReviewedAutomationRepair(options) {
|
|
|
21966
22577
|
});
|
|
21967
22578
|
}
|
|
21968
22579
|
async function suiteHash(scenarioDir, includeAutomation = true) {
|
|
21969
|
-
const hash =
|
|
22580
|
+
const hash = createHash9("sha256");
|
|
21970
22581
|
hash.update(await readText(path15.join(scenarioDir, "README.md")));
|
|
21971
22582
|
hash.update(await readText(path15.join(scenarioDir, "cases.csv")));
|
|
21972
22583
|
hash.update(await readText(path15.join(scenarioDir, "case_steps.csv")));
|
|
21973
22584
|
const automationPath = path15.join(scenarioDir, "automation.json");
|
|
21974
22585
|
if (includeAutomation && await exists3(automationPath)) hash.update(await readText(automationPath));
|
|
22586
|
+
const fixtureManifestPath = path15.join(scenarioDir, "fixtures.json");
|
|
22587
|
+
if (await exists3(fixtureManifestPath)) hash.update(await readText(fixtureManifestPath));
|
|
21975
22588
|
return hash.digest("hex");
|
|
21976
22589
|
}
|
|
21977
22590
|
async function v2ConfirmationAssetHash(scenarioDir) {
|
|
21978
|
-
const hash =
|
|
22591
|
+
const hash = createHash9("sha256");
|
|
21979
22592
|
hash.update(await suiteHash(scenarioDir));
|
|
21980
22593
|
const reviewPath = path15.join(scenarioDir, "review.json");
|
|
21981
22594
|
if (await exists3(reviewPath)) hash.update(await readText(reviewPath));
|
|
21982
22595
|
return hash.digest("hex");
|
|
21983
22596
|
}
|
|
21984
22597
|
function v2ConfirmationDigest(value) {
|
|
21985
|
-
return
|
|
22598
|
+
return createHash9("sha256").update(JSON.stringify(value)).digest("hex");
|
|
21986
22599
|
}
|
|
21987
22600
|
function normalizedCaseIds(caseIds = []) {
|
|
21988
22601
|
return [...new Set(caseIds.map((id) => id.trim()).filter(Boolean))].sort();
|
|
@@ -22138,7 +22751,7 @@ async function validateV2Confirmation(options) {
|
|
|
22138
22751
|
async function automationFileHash(scenarioDir) {
|
|
22139
22752
|
const automationPath = path15.join(scenarioDir, "automation.json");
|
|
22140
22753
|
if (!await exists3(automationPath)) return void 0;
|
|
22141
|
-
return
|
|
22754
|
+
return createHash9("sha256").update(await readFile14(automationPath)).digest("hex");
|
|
22142
22755
|
}
|
|
22143
22756
|
async function writePromotionReceipt(sourceScenarioDir, promotedScenarioDir, finalScenarioDir = promotedScenarioDir) {
|
|
22144
22757
|
const automationHash = await automationFileHash(promotedScenarioDir);
|
|
@@ -22182,7 +22795,7 @@ async function validatePromotionReceipt(scenarioDir) {
|
|
|
22182
22795
|
}
|
|
22183
22796
|
}
|
|
22184
22797
|
function executionManifestHash(manifest) {
|
|
22185
|
-
return
|
|
22798
|
+
return createHash9("sha256").update(JSON.stringify(manifest)).digest("hex");
|
|
22186
22799
|
}
|
|
22187
22800
|
function executionManifestIntegrityPaths(manifestPath) {
|
|
22188
22801
|
const resolved = path15.resolve(manifestPath);
|
|
@@ -22304,6 +22917,10 @@ function validExecutionPreconditionAnchor(value) {
|
|
|
22304
22917
|
if (!value) return true;
|
|
22305
22918
|
return ["pending", "passed"].includes(value.state) && String(value.file || "").trim().length > 0 && /^[a-f0-9]{64}$/.test(String(value.record_sha256 || "")) && (value.state !== "passed" || String(value.evidence || "").trim().length > 0 && /^[a-f0-9]{64}$/.test(String(value.evidence_sha256 || "")) && Number.isFinite(Date.parse(String(value.recorded_at || ""))));
|
|
22306
22919
|
}
|
|
22920
|
+
function validExecutionFixtureManifestAnchor(value) {
|
|
22921
|
+
if (!value) return true;
|
|
22922
|
+
return String(value.file || "").trim().length > 0 && /^[a-f0-9]{64}$/.test(String(value.sha256 || ""));
|
|
22923
|
+
}
|
|
22307
22924
|
async function readExecutionManifest(manifestPath, manifestLockHeld = false) {
|
|
22308
22925
|
if (!manifestLockHeld) {
|
|
22309
22926
|
return withExecutionManifestLock(manifestPath, () => readExecutionManifest(manifestPath, true));
|
|
@@ -22319,7 +22936,7 @@ async function readExecutionManifest(manifestPath, manifestLockHeld = false) {
|
|
|
22319
22936
|
}
|
|
22320
22937
|
const manifest = value;
|
|
22321
22938
|
const mutationGuard = manifest.mutation_attempt_guard;
|
|
22322
|
-
if (!RUN_RE.test(String(manifest.run_id || "")) || !SCENARIO_ID_RE.test(String(manifest.scenario_id || "")) || !String(manifest.case_id || "").trim() || !String(manifest.source_suite || "").trim() || !/^[a-f0-9]{64}$/.test(String(manifest.suite_hash || "")) || !/^[a-f0-9]{32}$/.test(String(manifest.evidence_nonce || "")) || manifest.skill_agent !== void 0 && !String(manifest.skill_agent || "").trim() || (manifest.skill_sources !== void 0 || manifest.skill_bundle_sha256 !== void 0) && (!Array.isArray(manifest.skill_sources) || manifest.skill_sources.length === 0 || manifest.skill_sources.some((source) => !String(source || "").trim()) || !/^[a-f0-9]{64}$/.test(String(manifest.skill_bundle_sha256 || ""))) || manifest.active_run_lease !== void 0 && (!String(manifest.active_run_lease.path || "").trim() || !/^[a-f0-9]{64}$/.test(String(manifest.active_run_lease.key || "")) || !/^[a-f0-9]{32}$/.test(String(manifest.active_run_lease.owner_token || ""))) || manifest.automation_hash !== void 0 && !String(manifest.automation_file || "").trim() || manifest.automation_hash !== void 0 && !/^[a-f0-9]{64}$/.test(String(manifest.automation_hash || "")) || !validExecutionAutomationRepairGuard(manifest.automation_repair_guard) || !validExecutionPreconditionAnchor(manifest.precondition) || !Array.isArray(manifest.steps) || !["running", "pass", "fail", "blocked"].includes(manifest.result) || mutationGuard !== void 0 && (mutationGuard.state !== "attempted_unconfirmed" || !String(mutationGuard.checkpoint || "").trim() || !String(mutationGuard.case_id || "").trim() || !String(mutationGuard.case_step_id || "").trim() || !Number.isInteger(mutationGuard.action_index) || !/^[a-f0-9]{64}$/.test(String(mutationGuard.automation_step_sha256 || "")) || !Number.isInteger(mutationGuard.checkpoint_revision) || !/^[a-f0-9]{64}$/.test(String(mutationGuard.mutation_attempt_id || "")) || Number.isNaN(Date.parse(String(mutationGuard.recorded_at || ""))) || mutationGuard.resolution_receipt !== void 0 && (!["committed", "not_committed"].includes(mutationGuard.resolution_receipt.outcome) || !String(mutationGuard.resolution_receipt.evidence || "").trim() || !/^[a-f0-9]{64}$/.test(String(mutationGuard.resolution_receipt.evidence_sha256 || "")) || !String(mutationGuard.resolution_receipt.source_evidence || "").trim() || !/^[a-f0-9]{64}$/.test(String(mutationGuard.resolution_receipt.source_evidence_sha256 || "")) || !String(mutationGuard.resolution_receipt.file_manifest || "").trim() || !/^[a-f0-9]{64}$/.test(String(mutationGuard.resolution_receipt.file_manifest_sha256 || "")) || Number.isNaN(Date.parse(String(mutationGuard.resolution_receipt.anchored_at || "")))))) {
|
|
22939
|
+
if (!RUN_RE.test(String(manifest.run_id || "")) || !SCENARIO_ID_RE.test(String(manifest.scenario_id || "")) || !String(manifest.case_id || "").trim() || !String(manifest.source_suite || "").trim() || !/^[a-f0-9]{64}$/.test(String(manifest.suite_hash || "")) || !/^[a-f0-9]{32}$/.test(String(manifest.evidence_nonce || "")) || manifest.skill_agent !== void 0 && !String(manifest.skill_agent || "").trim() || (manifest.skill_sources !== void 0 || manifest.skill_bundle_sha256 !== void 0) && (!Array.isArray(manifest.skill_sources) || manifest.skill_sources.length === 0 || manifest.skill_sources.some((source) => !String(source || "").trim()) || !/^[a-f0-9]{64}$/.test(String(manifest.skill_bundle_sha256 || ""))) || manifest.active_run_lease !== void 0 && (!String(manifest.active_run_lease.path || "").trim() || !/^[a-f0-9]{64}$/.test(String(manifest.active_run_lease.key || "")) || !/^[a-f0-9]{32}$/.test(String(manifest.active_run_lease.owner_token || ""))) || manifest.automation_hash !== void 0 && !String(manifest.automation_file || "").trim() || manifest.automation_hash !== void 0 && !/^[a-f0-9]{64}$/.test(String(manifest.automation_hash || "")) || !validExecutionAutomationRepairGuard(manifest.automation_repair_guard) || !validExecutionPreconditionAnchor(manifest.precondition) || !validExecutionFixtureManifestAnchor(manifest.fixture_manifest) || !Array.isArray(manifest.steps) || !["running", "pass", "fail", "blocked"].includes(manifest.result) || mutationGuard !== void 0 && (mutationGuard.state !== "attempted_unconfirmed" || !String(mutationGuard.checkpoint || "").trim() || !String(mutationGuard.case_id || "").trim() || !String(mutationGuard.case_step_id || "").trim() || !Number.isInteger(mutationGuard.action_index) || !/^[a-f0-9]{64}$/.test(String(mutationGuard.automation_step_sha256 || "")) || !Number.isInteger(mutationGuard.checkpoint_revision) || !/^[a-f0-9]{64}$/.test(String(mutationGuard.mutation_attempt_id || "")) || Number.isNaN(Date.parse(String(mutationGuard.recorded_at || ""))) || mutationGuard.resolution_receipt !== void 0 && (!["committed", "not_committed"].includes(mutationGuard.resolution_receipt.outcome) || !String(mutationGuard.resolution_receipt.evidence || "").trim() || !/^[a-f0-9]{64}$/.test(String(mutationGuard.resolution_receipt.evidence_sha256 || "")) || !String(mutationGuard.resolution_receipt.source_evidence || "").trim() || !/^[a-f0-9]{64}$/.test(String(mutationGuard.resolution_receipt.source_evidence_sha256 || "")) || !String(mutationGuard.resolution_receipt.file_manifest || "").trim() || !/^[a-f0-9]{64}$/.test(String(mutationGuard.resolution_receipt.file_manifest_sha256 || "")) || Number.isNaN(Date.parse(String(mutationGuard.resolution_receipt.anchored_at || "")))))) {
|
|
22323
22940
|
fail(`invalid execution manifest shape: ${manifestPath}`, { rule_id: "test_suite.execution_manifest.invalid", path: manifestPath });
|
|
22324
22941
|
}
|
|
22325
22942
|
const selectedCaseIds = manifestSelectedCaseIds(manifest);
|
|
@@ -22985,7 +23602,7 @@ async function assertRunnerEvidenceFileManifest(manifest, manifestPath, evidence
|
|
|
22985
23602
|
await assertCurrentRunPathScope(path15.dirname(manifestPath), artifactPath, "runner evidence artifact must stay inside the current report run directory");
|
|
22986
23603
|
await assertCurrentRunArtifact(manifest, artifactPath);
|
|
22987
23604
|
const content = await readFile14(artifactPath);
|
|
22988
|
-
if (entry.sha256 !==
|
|
23605
|
+
if (entry.sha256 !== createHash9("sha256").update(content).digest("hex") || Number(entry.size) !== content.length) {
|
|
22989
23606
|
fail("runner evidence artifact does not match its CLI-generated evidence-files.json hash record", {
|
|
22990
23607
|
rule_id: "test_suite.run.resolution_source_invalid",
|
|
22991
23608
|
path: artifactPath
|
|
@@ -23190,10 +23807,11 @@ async function syncTestSuiteRunReportUnlocked(manifestFile) {
|
|
|
23190
23807
|
const manifestPath = path15.resolve(manifestFile);
|
|
23191
23808
|
const manifest = await readExecutionManifest(manifestPath, true);
|
|
23192
23809
|
await assertExecutionManifestFresh(manifest, manifestPath);
|
|
23810
|
+
const stoppedOnPendingPrecondition = manifest.precondition?.state === "pending" && (manifest.result === "fail" || manifest.result === "blocked") && manifest.steps.some((step) => step.status === "fail" || step.status === "blocked");
|
|
23193
23811
|
await assertExecutionPreconditionRecord(
|
|
23194
23812
|
manifest,
|
|
23195
23813
|
manifestPath,
|
|
23196
|
-
manifest.result !== "running" || manifest.steps.some((step) => step.status !== "planned")
|
|
23814
|
+
!stoppedOnPendingPrecondition && (manifest.result !== "running" || manifest.steps.some((step) => step.status !== "planned"))
|
|
23197
23815
|
);
|
|
23198
23816
|
const runDir = path15.dirname(manifestPath);
|
|
23199
23817
|
const reportPath = path15.join(runDir, `${manifest.scenario_id}.md`);
|
|
@@ -23326,12 +23944,15 @@ async function assertFormalExecutionEvidence(manifest, manifestPath, step, evide
|
|
|
23326
23944
|
}
|
|
23327
23945
|
if (operation === "mock" || operation === "unmock") {
|
|
23328
23946
|
const currentUser = asRecord(value.current_user);
|
|
23329
|
-
|
|
23947
|
+
const resolvedFromReadback = value.resolved_from_readback === true && value.operation_executed === false && value.mutation_attempted === false;
|
|
23948
|
+
const mutationExecuted = value.operation_executed === true && value.mutation_attempted === true;
|
|
23949
|
+
const expectedUserId = step.input_data.match(/(?:user_id|用户ID|用户 id)\s*[=::]\s*(\d+)/i)?.[1];
|
|
23950
|
+
return (mutationExecuted || resolvedFromReadback) && value.remote_submitted === true && value.readback_confirmed === true && (operation === "mock" ? currentUser.mock === true && Number(currentUser.id) === Number(expectedUserId) : currentUser.mock === false);
|
|
23330
23951
|
}
|
|
23331
23952
|
return false;
|
|
23332
23953
|
});
|
|
23333
23954
|
if (!validIdentityEvidence) {
|
|
23334
|
-
fail("identity pass evidence must
|
|
23955
|
+
fail("identity pass evidence must come from the matching execution-stage identity runner and include browser_verified=true, a matching case/step, passed assertions, screenshot, and confirmed status/mock/unmock readback", {
|
|
23335
23956
|
rule_id: "test_suite.run.unexecuted_evidence",
|
|
23336
23957
|
path: evidencePath
|
|
23337
23958
|
});
|
|
@@ -23451,6 +24072,16 @@ async function assertIdentityLeaseForRecordedStep(manifestPath, step) {
|
|
|
23451
24072
|
path: leasePath
|
|
23452
24073
|
});
|
|
23453
24074
|
}
|
|
24075
|
+
if (operation === "mock") {
|
|
24076
|
+
const expectedUserId = step.input_data.match(/(?:user_id|用户ID|用户 id)\s*[=::]\s*(\d+)/i)?.[1];
|
|
24077
|
+
const targetUser = asRecord(lease.target_user);
|
|
24078
|
+
if (!expectedUserId || Number(targetUser.id) !== Number(expectedUserId)) {
|
|
24079
|
+
fail("mock identity lease target does not match the exact user_id declared by the current step", {
|
|
24080
|
+
rule_id: "test_suite.run.identity_lease_target",
|
|
24081
|
+
path: leasePath
|
|
24082
|
+
});
|
|
24083
|
+
}
|
|
24084
|
+
}
|
|
23454
24085
|
await assertCurrentRunArtifact(await readExecutionManifest(manifestPath, true), leasePath);
|
|
23455
24086
|
}
|
|
23456
24087
|
async function writeExecutionManifest(manifestPath, manifest, incrementRevision = false) {
|
|
@@ -23506,7 +24137,7 @@ function manifestCurrentCaseId(manifest) {
|
|
|
23506
24137
|
function activeRunLeaseKey(options) {
|
|
23507
24138
|
const origin = String(options.profileOrigin || "").trim().replace(/\/+$/, "").toLowerCase();
|
|
23508
24139
|
const stableScope = origin ? `origin:${origin}\0workspace:${options.workspace || ""}\0scenario:${options.scenarioId}` : `fallback:${options.scenarioRealpath}\0profile:${options.profile}\0scenario:${options.scenarioId}`;
|
|
23509
|
-
return
|
|
24140
|
+
return createHash9("sha256").update(stableScope).digest("hex");
|
|
23510
24141
|
}
|
|
23511
24142
|
function activeRunLeaseDir(options) {
|
|
23512
24143
|
return options.profileOrigin ? path15.join(getConfigDir(), "e2e-active-runs", options.key) : path15.join(path15.dirname(options.scenarioRealpath), ".bpmax-active-runs", options.key);
|
|
@@ -23746,8 +24377,12 @@ async function startTestSuiteRunUnlocked(options) {
|
|
|
23746
24377
|
const preconditionPath = path15.join(reportDir, `precondition-${runId}.json`);
|
|
23747
24378
|
const sourceAutomationPath = path15.join(scenarioDir, "automation.json");
|
|
23748
24379
|
const runAutomationPath = path15.join(reportDir, "automation.json");
|
|
24380
|
+
const sourceFixtureManifestPath = path15.join(scenarioDir, "fixtures.json");
|
|
24381
|
+
const runFixtureManifestPath = path15.join(reportDir, "fixtures.json");
|
|
23749
24382
|
const hasAutomation = await exists3(sourceAutomationPath);
|
|
24383
|
+
const hasFixtureManifest = await exists3(sourceFixtureManifestPath);
|
|
23750
24384
|
if (hasAutomation) await copyFile(sourceAutomationPath, runAutomationPath);
|
|
24385
|
+
if (hasFixtureManifest) await copyFile(sourceFixtureManifestPath, runFixtureManifestPath);
|
|
23751
24386
|
activeRun.lease.manifest = path15.resolve(manifestPath);
|
|
23752
24387
|
activeRun.lease.run_id = runId;
|
|
23753
24388
|
await writeActiveRunLease(activeRun.leaseDir, activeRun.lease);
|
|
@@ -23798,7 +24433,13 @@ async function startTestSuiteRunUnlocked(options) {
|
|
|
23798
24433
|
suite_hash_mode: "semantic_v2",
|
|
23799
24434
|
...hasAutomation ? {
|
|
23800
24435
|
automation_file: path15.resolve(runAutomationPath),
|
|
23801
|
-
automation_hash:
|
|
24436
|
+
automation_hash: createHash9("sha256").update(await readFile14(runAutomationPath)).digest("hex")
|
|
24437
|
+
} : {},
|
|
24438
|
+
...hasFixtureManifest ? {
|
|
24439
|
+
fixture_manifest: {
|
|
24440
|
+
file: path15.resolve(runFixtureManifestPath),
|
|
24441
|
+
sha256: fixtureManifestSha256(JSON.parse(await readText(runFixtureManifestPath)))
|
|
24442
|
+
}
|
|
23802
24443
|
} : {},
|
|
23803
24444
|
evidence_nonce: evidenceNonce,
|
|
23804
24445
|
precondition: {
|
|
@@ -23926,6 +24567,51 @@ async function startTestSuiteRun(options) {
|
|
|
23926
24567
|
}
|
|
23927
24568
|
return withScenarioAutomationStableLocks([scenarioDir], () => startTestSuiteRunUnlocked(options));
|
|
23928
24569
|
}
|
|
24570
|
+
async function inspectPendingTestSuiteRunPrecondition(manifestValue, profile) {
|
|
24571
|
+
const manifestPath = path15.resolve(manifestValue);
|
|
24572
|
+
const manifest = await readExecutionManifest(manifestPath);
|
|
24573
|
+
await assertExecutionManifestFresh(manifest, manifestPath);
|
|
24574
|
+
if (profile && manifest.profile !== profile) {
|
|
24575
|
+
fail(`execution manifest profile is ${manifest.profile}, not ${profile}`, {
|
|
24576
|
+
rule_id: "test_suite.run.profile_mismatch",
|
|
24577
|
+
path: manifestPath
|
|
24578
|
+
});
|
|
24579
|
+
}
|
|
24580
|
+
if (manifest.result !== "running" || !["pending", "passed"].includes(String(manifest.precondition?.state || "")) || manifest.steps.some((step) => step.status !== "planned") || manifest.mutation_attempt_guard) {
|
|
24581
|
+
fail("typed fixture creation or idempotent readback is allowed only before any case step mutation in the current run", {
|
|
24582
|
+
rule_id: "test_suite.run.precondition_fixture_too_late",
|
|
24583
|
+
path: manifestPath
|
|
24584
|
+
});
|
|
24585
|
+
}
|
|
24586
|
+
if (manifest.fixture_manifest) {
|
|
24587
|
+
const runDir = path15.dirname(manifestPath);
|
|
24588
|
+
const fixturePath = resolveRunArtifactPath(runDir, manifest.fixture_manifest.file);
|
|
24589
|
+
await assertCurrentRunPathScope(runDir, fixturePath, "fixture manifest must stay inside the current report run directory");
|
|
24590
|
+
const fixtureInfo = await lstat2(fixturePath).catch(() => void 0);
|
|
24591
|
+
if (!fixtureInfo || fixtureInfo.isSymbolicLink() || !fixtureInfo.isFile()) {
|
|
24592
|
+
fail("the reviewed fixture manifest copy is missing or is not a regular current-run file", {
|
|
24593
|
+
rule_id: "test_suite.run.fixture_manifest_invalid",
|
|
24594
|
+
path: fixturePath
|
|
24595
|
+
});
|
|
24596
|
+
}
|
|
24597
|
+
let fixtureValue;
|
|
24598
|
+
try {
|
|
24599
|
+
fixtureValue = JSON.parse(await readText(fixturePath));
|
|
24600
|
+
} catch {
|
|
24601
|
+
fail("the reviewed fixture manifest copy is not valid JSON", {
|
|
24602
|
+
rule_id: "test_suite.run.fixture_manifest_invalid",
|
|
24603
|
+
path: fixturePath
|
|
24604
|
+
});
|
|
24605
|
+
}
|
|
24606
|
+
if (fixtureManifestSha256(fixtureValue) !== manifest.fixture_manifest.sha256) {
|
|
24607
|
+
fail("the reviewed fixture manifest changed after run start", {
|
|
24608
|
+
rule_id: "test_suite.run.fixture_manifest_hash_mismatch",
|
|
24609
|
+
path: fixturePath
|
|
24610
|
+
});
|
|
24611
|
+
}
|
|
24612
|
+
}
|
|
24613
|
+
return manifest;
|
|
24614
|
+
}
|
|
23929
24615
|
async function recordTestSuiteRunPrecondition(options) {
|
|
23930
24616
|
return withExecutionManifestLock(options.manifest, async () => {
|
|
23931
24617
|
const manifestPath = path15.resolve(options.manifest);
|
|
@@ -24039,7 +24725,7 @@ async function recordTestSuiteRunPrecondition(options) {
|
|
|
24039
24725
|
};
|
|
24040
24726
|
});
|
|
24041
24727
|
}
|
|
24042
|
-
async function validateExecutionManifestStep(options, manifestLockHeld = false) {
|
|
24728
|
+
async function validateExecutionManifestStep(options, manifestLockHeld = false, allowPendingPreconditionTerminal = false) {
|
|
24043
24729
|
const manifestPath = path15.resolve(options.manifest);
|
|
24044
24730
|
const manifest = await readExecutionManifest(manifestPath, manifestLockHeld);
|
|
24045
24731
|
if (manifest.result !== "running") {
|
|
@@ -24060,7 +24746,11 @@ async function validateExecutionManifestStep(options, manifestLockHeld = false)
|
|
|
24060
24746
|
});
|
|
24061
24747
|
}
|
|
24062
24748
|
if (!manifest.mutation_attempt_guard) {
|
|
24063
|
-
await assertExecutionPreconditionRecord(
|
|
24749
|
+
await assertExecutionPreconditionRecord(
|
|
24750
|
+
manifest,
|
|
24751
|
+
manifestPath,
|
|
24752
|
+
!(allowPendingPreconditionTerminal && manifest.precondition?.state === "pending")
|
|
24753
|
+
);
|
|
24064
24754
|
}
|
|
24065
24755
|
const step = currentManifestStep(manifest);
|
|
24066
24756
|
if (!step || step.status !== "planned") fail("execution manifest has no runnable current step", { rule_id: "test_suite.run.no_current_step", path: manifestPath });
|
|
@@ -24106,7 +24796,7 @@ async function validateExecutionAutomationBinding(options) {
|
|
|
24106
24796
|
path: actualAutomation
|
|
24107
24797
|
});
|
|
24108
24798
|
}
|
|
24109
|
-
const automationSha256 =
|
|
24799
|
+
const automationSha256 = createHash9("sha256").update(await readFile14(actualAutomation)).digest("hex");
|
|
24110
24800
|
if (manifest.automation_hash && automationSha256 !== manifest.automation_hash && options.allowAutomationChange !== true) {
|
|
24111
24801
|
fail("formal execution automation changed after run start; only a paused_repairable scenario checkpoint may authorize a current/future-step repair", {
|
|
24112
24802
|
rule_id: "test_suite.run.automation_changed",
|
|
@@ -24244,7 +24934,7 @@ async function nextTestSuiteRunStep(manifestPath, profile) {
|
|
|
24244
24934
|
async function recordTestSuiteRunStep(options, trustedBrowserAction = false) {
|
|
24245
24935
|
if (!["pass", "fail", "blocked"].includes(options.result)) fail("run record result must be pass, fail, or blocked", { rule_id: "test_suite.run.result" });
|
|
24246
24936
|
return withExecutionManifestLock(options.manifest, async () => {
|
|
24247
|
-
const validated = await validateExecutionManifestStep(options, true);
|
|
24937
|
+
const validated = await validateExecutionManifestStep(options, true, options.result !== "pass");
|
|
24248
24938
|
if (options.result === "pass" && validated.step.runner === "browser_action" && !trustedBrowserAction) {
|
|
24249
24939
|
fail("browser_action pass results can only be recorded by the deterministic scenario runner", {
|
|
24250
24940
|
rule_id: "test_suite.run.browser_action_runner_required",
|
|
@@ -24361,7 +25051,7 @@ async function readLatestProof(proofPath) {
|
|
|
24361
25051
|
}
|
|
24362
25052
|
function validateLatestProofObject(proofPath, proof) {
|
|
24363
25053
|
if (!String(proof.method || "").startsWith("latest-")) fail(`${proofPath}: method must start with latest-`);
|
|
24364
|
-
if (proof.allow_dirty !==
|
|
25054
|
+
if (typeof proof.allow_dirty !== "boolean") fail(`${proofPath}: allow_dirty must be a boolean`);
|
|
24365
25055
|
for (const key of ["before", "after", "head"]) {
|
|
24366
25056
|
if (!SHA_RE.test(String(proof[key] || ""))) fail(`${proofPath}: ${key} must be a 40-character git sha`);
|
|
24367
25057
|
}
|
|
@@ -24399,11 +25089,11 @@ async function fileMap(root) {
|
|
|
24399
25089
|
return result;
|
|
24400
25090
|
}
|
|
24401
25091
|
async function sha256(filePath) {
|
|
24402
|
-
return
|
|
25092
|
+
return createHash9("sha256").update(await readFile14(filePath)).digest("hex");
|
|
24403
25093
|
}
|
|
24404
25094
|
async function readForDiff(filePath) {
|
|
24405
25095
|
const buffer = await readFile14(filePath);
|
|
24406
|
-
if (buffer.includes(0)) return [`<binary sha256=${
|
|
25096
|
+
if (buffer.includes(0)) return [`<binary sha256=${createHash9("sha256").update(buffer).digest("hex")}>
|
|
24407
25097
|
`];
|
|
24408
25098
|
return buffer.toString("utf8").split(/(?<=\n)/);
|
|
24409
25099
|
}
|
|
@@ -25887,7 +26577,7 @@ async function exists4(file) {
|
|
|
25887
26577
|
}
|
|
25888
26578
|
function comparableBrowserFormValue(value) {
|
|
25889
26579
|
if (Array.isArray(value)) return `[${value.map(comparableBrowserFormValue).join(",")}]`;
|
|
25890
|
-
if (
|
|
26580
|
+
if (isRecord10(value)) {
|
|
25891
26581
|
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${comparableBrowserFormValue(value[key])}`).join(",")}}`;
|
|
25892
26582
|
}
|
|
25893
26583
|
return JSON.stringify(value ?? "");
|
|
@@ -25896,7 +26586,7 @@ function browserFormValueMatches(actual, expected, match = "exact") {
|
|
|
25896
26586
|
if (match === "non_empty") {
|
|
25897
26587
|
if (typeof actual === "string") return actual.trim().length > 0;
|
|
25898
26588
|
if (Array.isArray(actual)) return actual.length > 0;
|
|
25899
|
-
if (
|
|
26589
|
+
if (isRecord10(actual)) return Object.keys(actual).length > 0;
|
|
25900
26590
|
return actual !== void 0 && actual !== null;
|
|
25901
26591
|
}
|
|
25902
26592
|
const actualText = actual !== null && typeof actual === "object" ? comparableBrowserFormValue(actual) : String(actual ?? "");
|
|
@@ -25910,7 +26600,7 @@ function browserUploadFixtureList(value) {
|
|
|
25910
26600
|
const values = Array.isArray(value) ? value : [value];
|
|
25911
26601
|
if (values.length === 0) throw new Error("form.upload_file requires one or more reviewed fixture objects");
|
|
25912
26602
|
return values.map((item, index) => {
|
|
25913
|
-
if (!
|
|
26603
|
+
if (!isRecord10(item)) throw new Error(`form.upload_file fixture[${index}] must be an object`);
|
|
25914
26604
|
const fixturePath = String(item.path ?? "").trim();
|
|
25915
26605
|
const sha2563 = String(item.sha256 ?? "").trim().toLowerCase();
|
|
25916
26606
|
const mime = String(item.mime ?? "").trim().toLowerCase();
|
|
@@ -25966,7 +26656,7 @@ async function validateBrowserUploadFixtures(value, scenarioRoot) {
|
|
|
25966
26656
|
name: path16.basename(realFile),
|
|
25967
26657
|
size: content.byteLength,
|
|
25968
26658
|
mime: uploadMimeFromContent(realFile, content),
|
|
25969
|
-
sha256:
|
|
26659
|
+
sha256: createHash10("sha256").update(content).digest("hex")
|
|
25970
26660
|
};
|
|
25971
26661
|
if (actual.size !== fixture.size || actual.mime !== fixture.mime || actual.sha256 !== fixture.sha256) {
|
|
25972
26662
|
throw new Error(`form.upload_file fixture metadata mismatch for ${actual.name}`);
|
|
@@ -25995,7 +26685,7 @@ async function captureBrowserDownload(options) {
|
|
|
25995
26685
|
throw new Error(`download file too small: expected at least ${options.minSize}, got ${fileStat.size}`);
|
|
25996
26686
|
}
|
|
25997
26687
|
const content = await readFile15(destination);
|
|
25998
|
-
const sha2563 =
|
|
26688
|
+
const sha2563 = createHash10("sha256").update(content).digest("hex");
|
|
25999
26689
|
if (options.expectedSha256 && sha2563 !== options.expectedSha256) {
|
|
26000
26690
|
throw new Error(`download sha256 mismatch: expected ${options.expectedSha256}, got ${sha2563}`);
|
|
26001
26691
|
}
|
|
@@ -26030,7 +26720,7 @@ function browserPageStepMatches(expected, bodyText, textVisible, runtimeUrl = ""
|
|
|
26030
26720
|
function browserEvidenceStatusIsVerified(status) {
|
|
26031
26721
|
return status !== "submitted_outcome_unknown";
|
|
26032
26722
|
}
|
|
26033
|
-
function
|
|
26723
|
+
function isRecord10(value) {
|
|
26034
26724
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26035
26725
|
}
|
|
26036
26726
|
function classifyBrowserActionFailure(message, status) {
|
|
@@ -26102,11 +26792,11 @@ async function waitForBrowserNetworkResponse(options) {
|
|
|
26102
26792
|
}
|
|
26103
26793
|
function messageRows(payload) {
|
|
26104
26794
|
if (Array.isArray(payload)) return payload;
|
|
26105
|
-
if (!
|
|
26795
|
+
if (!isRecord10(payload)) return [];
|
|
26106
26796
|
for (const key of ["data", "list", "rows"]) {
|
|
26107
26797
|
const value = payload[key];
|
|
26108
26798
|
if (Array.isArray(value)) return value;
|
|
26109
|
-
if (
|
|
26799
|
+
if (isRecord10(value)) {
|
|
26110
26800
|
const nested = messageRows(value);
|
|
26111
26801
|
if (nested.length > 0) return nested;
|
|
26112
26802
|
}
|
|
@@ -26115,7 +26805,7 @@ function messageRows(payload) {
|
|
|
26115
26805
|
}
|
|
26116
26806
|
function browserMessageDeliveryRecords(payload) {
|
|
26117
26807
|
return messageRows(payload).flatMap((raw) => {
|
|
26118
|
-
if (!
|
|
26808
|
+
if (!isRecord10(raw)) return [];
|
|
26119
26809
|
let content = raw.content;
|
|
26120
26810
|
if (typeof content === "string") {
|
|
26121
26811
|
try {
|
|
@@ -26124,9 +26814,9 @@ function browserMessageDeliveryRecords(payload) {
|
|
|
26124
26814
|
content = { content };
|
|
26125
26815
|
}
|
|
26126
26816
|
}
|
|
26127
|
-
const contentRecord =
|
|
26817
|
+
const contentRecord = isRecord10(content) ? content : {};
|
|
26128
26818
|
const actions = Array.isArray(contentRecord.actions) ? contentRecord.actions : [];
|
|
26129
|
-
const firstAction = actions.find(
|
|
26819
|
+
const firstAction = actions.find(isRecord10);
|
|
26130
26820
|
const id = String(raw.id ?? "").trim();
|
|
26131
26821
|
const recipientId = String(raw.to_user_id ?? raw.recipient_id ?? "").trim();
|
|
26132
26822
|
if (!id || !recipientId) return [];
|
|
@@ -26176,7 +26866,7 @@ function matchingMutationRequest(request, patterns) {
|
|
|
26176
26866
|
return ["POST", "PUT", "PATCH", "DELETE"].includes(request.method().toUpperCase()) && [...patterns].some((pattern) => request.url().includes(pattern));
|
|
26177
26867
|
}
|
|
26178
26868
|
function matchingMutationRecord(value, urlPattern) {
|
|
26179
|
-
if (!
|
|
26869
|
+
if (!isRecord10(value)) return false;
|
|
26180
26870
|
return ["POST", "PUT", "PATCH", "DELETE"].includes(String(value.method || "").toUpperCase()) && String(value.url || "").includes(urlPattern);
|
|
26181
26871
|
}
|
|
26182
26872
|
async function waitForMutationNetworkClosure(options) {
|
|
@@ -26201,15 +26891,15 @@ async function readJsonInput(value) {
|
|
|
26201
26891
|
if (!value) return {};
|
|
26202
26892
|
const raw = value.startsWith("@") ? await readFile15(path16.resolve(value.slice(1)), "utf8") : value;
|
|
26203
26893
|
const parsed = JSON.parse(raw);
|
|
26204
|
-
if (!
|
|
26894
|
+
if (!isRecord10(parsed)) throw new Error("browser-run data profile must be a JSON object");
|
|
26205
26895
|
return parsed;
|
|
26206
26896
|
}
|
|
26207
26897
|
function valueAt(source, dottedPath) {
|
|
26208
|
-
return dottedPath.split(".").reduce((current, segment) =>
|
|
26898
|
+
return dottedPath.split(".").reduce((current, segment) => isRecord10(current) ? current[segment] : void 0, source);
|
|
26209
26899
|
}
|
|
26210
26900
|
function interpolateString(value, variables) {
|
|
26211
26901
|
return value.replace(/\{\{\s*(data|context)\.([\w.-]+)\s*}}/g, (_match, root, key) => {
|
|
26212
|
-
const result = valueAt(
|
|
26902
|
+
const result = valueAt(isRecord10(variables[root]) ? variables[root] : {}, key);
|
|
26213
26903
|
if (result === void 0 || result === null) throw new Error(`missing browser automation variable ${root}.${key}`);
|
|
26214
26904
|
return String(result);
|
|
26215
26905
|
});
|
|
@@ -26217,7 +26907,7 @@ function interpolateString(value, variables) {
|
|
|
26217
26907
|
function interpolateValue(value, variables) {
|
|
26218
26908
|
if (typeof value === "string") return interpolateString(value, variables);
|
|
26219
26909
|
if (Array.isArray(value)) return value.map((item) => interpolateValue(item, variables));
|
|
26220
|
-
if (
|
|
26910
|
+
if (isRecord10(value)) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, interpolateValue(item, variables)]));
|
|
26221
26911
|
return value;
|
|
26222
26912
|
}
|
|
26223
26913
|
function resolvedAction(action, variables) {
|
|
@@ -26934,9 +27624,9 @@ async function executeAction(page, action, variables, runtime) {
|
|
|
26934
27624
|
};
|
|
26935
27625
|
}
|
|
26936
27626
|
case "message.assert_delivery": {
|
|
26937
|
-
const context2 =
|
|
27627
|
+
const context2 = isRecord10(variables.context) ? variables.context : {};
|
|
26938
27628
|
const rawRecords = context2.__bpmax_message_delivery_records;
|
|
26939
|
-
const records = Array.isArray(rawRecords) ? rawRecords.filter(
|
|
27629
|
+
const records = Array.isArray(rawRecords) ? rawRecords.filter(isRecord10) : [];
|
|
26940
27630
|
const matches = browserMessageDeliveryMatches(records, next);
|
|
26941
27631
|
if (matches.length !== 1) {
|
|
26942
27632
|
throw new Error(`message delivery unique match failed: expected 1, got ${matches.length}`);
|
|
@@ -27119,8 +27809,8 @@ async function contextHasAuthenticatedIdentity(context2, profileOrigin) {
|
|
|
27119
27809
|
});
|
|
27120
27810
|
if (!response.ok()) return false;
|
|
27121
27811
|
const payload = await response.json();
|
|
27122
|
-
if (!
|
|
27123
|
-
const data =
|
|
27812
|
+
if (!isRecord10(payload)) return false;
|
|
27813
|
+
const data = isRecord10(payload.data) ? payload.data : payload;
|
|
27124
27814
|
const id = Number(data.id);
|
|
27125
27815
|
return Number.isSafeInteger(id) && id > 0 && data.role !== void 0 && data.role !== null;
|
|
27126
27816
|
} catch {
|
|
@@ -27317,12 +28007,12 @@ async function openContext(options) {
|
|
|
27317
28007
|
return { context: context2, browser, owned: true };
|
|
27318
28008
|
}
|
|
27319
28009
|
function identityPayloadData(value) {
|
|
27320
|
-
if (!
|
|
28010
|
+
if (!isRecord10(value)) throw new Error("e2e.identity.playwright.invalid_response: identity response must be an object");
|
|
27321
28011
|
const code = Number(value.code ?? 0);
|
|
27322
28012
|
if (Number.isFinite(code) && code !== 0) {
|
|
27323
28013
|
throw new Error(`e2e.identity.playwright.rejected: ${String(value.msg || value.message || `code=${code}`)}`);
|
|
27324
28014
|
}
|
|
27325
|
-
return
|
|
28015
|
+
return isRecord10(value.data) ? value.data : value;
|
|
27326
28016
|
}
|
|
27327
28017
|
function playwrightIdentityRequestContext(options, origin) {
|
|
27328
28018
|
const workspace = String(options.workspace || "").trim().replace(/^w:/, "");
|
|
@@ -27364,8 +28054,8 @@ async function playwrightIdentityTarget(context2, origin, userId, options) {
|
|
|
27364
28054
|
if (!response.ok()) throw new Error(`e2e.identity.playwright.target_http_${response.status()}`);
|
|
27365
28055
|
const payload = identityPayloadData(await response.json());
|
|
27366
28056
|
const candidates = Array.isArray(payload.data) ? payload.data : Array.isArray(payload.list) ? payload.list : [];
|
|
27367
|
-
const target = candidates.find((item) =>
|
|
27368
|
-
if (!
|
|
28057
|
+
const target = candidates.find((item) => isRecord10(item) && Number(item.id) === userId);
|
|
28058
|
+
if (!isRecord10(target) || !String(target.name || "").trim()) {
|
|
27369
28059
|
throw new Error(`e2e.identity.playwright.target_not_found: typed user readback did not resolve user ${userId}`);
|
|
27370
28060
|
}
|
|
27371
28061
|
const status = Number(target.status);
|
|
@@ -27386,6 +28076,52 @@ async function playwrightIdentityMutation(context2, origin, operation, options,
|
|
|
27386
28076
|
if (!response.ok()) throw new Error(`e2e.identity.playwright.${operation}_http_${response.status()}`);
|
|
27387
28077
|
identityPayloadData(await response.json());
|
|
27388
28078
|
}
|
|
28079
|
+
function playwrightIdentityLeaseBindingMatches(lease, binding, requireStep) {
|
|
28080
|
+
if (lease.kind !== "bpmax_identity_lease" || lease.browser_tool !== "playwright" || lease.transport !== "playwright_context") return false;
|
|
28081
|
+
const leaseBinding = isRecord10(lease.binding) ? lease.binding : {};
|
|
28082
|
+
if (path16.resolve(String(leaseBinding.execution_manifest || "")) !== path16.resolve(String(binding.execution_manifest || "")) || leaseBinding.profile !== binding.profile || leaseBinding.case_id !== binding.case_id) return false;
|
|
28083
|
+
return !requireStep || leaseBinding.case_step_id === binding.case_step_id;
|
|
28084
|
+
}
|
|
28085
|
+
function playwrightIdentityMutationDecision(options) {
|
|
28086
|
+
const { operation, before, lease, binding } = options;
|
|
28087
|
+
if (operation === "mock") {
|
|
28088
|
+
const userId = Number(options.userId);
|
|
28089
|
+
const openLease = lease && ["active", "uncertain"].includes(String(lease.state || "")) ? lease : null;
|
|
28090
|
+
if (!openLease) {
|
|
28091
|
+
if (before.mock === true) {
|
|
28092
|
+
throw new Error("e2e.identity.playwright.session_already_mocked: current Playwright session is simulated without a matching current-step lease; unmock before continuing");
|
|
28093
|
+
}
|
|
28094
|
+
return "mutate";
|
|
28095
|
+
}
|
|
28096
|
+
if (!playwrightIdentityLeaseBindingMatches(openLease, binding, true)) {
|
|
28097
|
+
throw new Error("e2e.identity.playwright.lease_open: restore the existing simulated identity before another mock");
|
|
28098
|
+
}
|
|
28099
|
+
const leasedTarget2 = isRecord10(openLease.target_user) ? openLease.target_user : {};
|
|
28100
|
+
if (before.mock !== true || Number(before.id) !== userId || Number(leasedTarget2.id) !== userId) {
|
|
28101
|
+
throw new Error("e2e.identity.playwright.mock_outcome_unknown: existing lease does not read back the exact target user; do not retry mock");
|
|
28102
|
+
}
|
|
28103
|
+
return "resolve_from_readback";
|
|
28104
|
+
}
|
|
28105
|
+
if (!lease || !["active", "uncertain"].includes(String(lease.state || ""))) {
|
|
28106
|
+
throw new Error("e2e.identity.playwright.unmock_without_lease: no active current-run identity lease exists");
|
|
28107
|
+
}
|
|
28108
|
+
if (!playwrightIdentityLeaseBindingMatches(lease, binding, false)) {
|
|
28109
|
+
throw new Error("e2e.identity.playwright.lease_binding_mismatch: identity lease belongs to another run, profile, or case");
|
|
28110
|
+
}
|
|
28111
|
+
const original = isRecord10(lease.original_user) ? lease.original_user : {};
|
|
28112
|
+
if (!Number.isSafeInteger(Number(original.id)) || Number(original.id) <= 0) {
|
|
28113
|
+
throw new Error("e2e.identity.playwright.original_identity_missing: identity lease cannot prove the original user");
|
|
28114
|
+
}
|
|
28115
|
+
if (before.mock === false && Number(before.id) === Number(original.id)) return "resolve_from_readback";
|
|
28116
|
+
if (before.mock !== true) {
|
|
28117
|
+
throw new Error("e2e.identity.playwright.unmock_outcome_unknown: current identity is neither the leased target nor the exact original user");
|
|
28118
|
+
}
|
|
28119
|
+
const leasedTarget = isRecord10(lease.target_user) ? lease.target_user : {};
|
|
28120
|
+
if (Number(leasedTarget.id) > 0 && Number(before.id) !== Number(leasedTarget.id)) {
|
|
28121
|
+
throw new Error("e2e.identity.playwright.unmock_target_mismatch: current simulated user does not match the active lease");
|
|
28122
|
+
}
|
|
28123
|
+
return "mutate";
|
|
28124
|
+
}
|
|
27389
28125
|
async function runPlaywrightIdentityOperation(options) {
|
|
27390
28126
|
const evidenceDir = path16.resolve(options.evidenceDir);
|
|
27391
28127
|
const runDir = path16.dirname(path16.resolve(options.executionManifest));
|
|
@@ -27414,36 +28150,43 @@ async function runPlaywrightIdentityOperation(options) {
|
|
|
27414
28150
|
let after = before;
|
|
27415
28151
|
let lease = await readFile15(leasePath, "utf8").then((value) => JSON.parse(value)).catch(() => null);
|
|
27416
28152
|
let target;
|
|
28153
|
+
let resolvedFromReadback = false;
|
|
27417
28154
|
if (options.operation === "mock") {
|
|
27418
28155
|
if (!Number.isSafeInteger(options.userId) || Number(options.userId) <= 0) {
|
|
27419
28156
|
throw new Error("e2e.identity.playwright.invalid_user_id: mock requires an exact positive BPMAX user id");
|
|
27420
28157
|
}
|
|
27421
|
-
if (lease && ["active", "uncertain"].includes(String(lease.state || ""))) {
|
|
27422
|
-
throw new Error("e2e.identity.playwright.lease_open: restore the existing simulated identity before another mock");
|
|
27423
|
-
}
|
|
27424
|
-
if (before.mock === true) {
|
|
27425
|
-
throw new Error("e2e.identity.playwright.session_already_mocked: current Playwright session is already simulated; unmock before continuing");
|
|
27426
|
-
}
|
|
27427
28158
|
target = await playwrightIdentityTarget(session.context, origin, Number(options.userId), options);
|
|
27428
|
-
|
|
27429
|
-
|
|
27430
|
-
|
|
27431
|
-
|
|
27432
|
-
|
|
27433
|
-
|
|
27434
|
-
|
|
27435
|
-
|
|
27436
|
-
|
|
27437
|
-
|
|
27438
|
-
|
|
27439
|
-
|
|
27440
|
-
|
|
27441
|
-
|
|
27442
|
-
|
|
27443
|
-
|
|
27444
|
-
|
|
28159
|
+
const decision = playwrightIdentityMutationDecision({
|
|
28160
|
+
operation: "mock",
|
|
28161
|
+
before,
|
|
28162
|
+
lease,
|
|
28163
|
+
binding,
|
|
28164
|
+
userId: Number(options.userId)
|
|
28165
|
+
});
|
|
28166
|
+
if (decision === "resolve_from_readback") {
|
|
28167
|
+
after = before;
|
|
28168
|
+
resolvedFromReadback = true;
|
|
28169
|
+
} else {
|
|
28170
|
+
try {
|
|
28171
|
+
await playwrightIdentityMutation(session.context, origin, "mock", options, Number(options.userId));
|
|
28172
|
+
after = await playwrightIdentityReadback(session.context, origin, options);
|
|
28173
|
+
} catch (error) {
|
|
28174
|
+
lease = {
|
|
28175
|
+
schema_version: 1,
|
|
28176
|
+
kind: "bpmax_identity_lease",
|
|
28177
|
+
state: "uncertain",
|
|
28178
|
+
browser_tool: "playwright",
|
|
28179
|
+
transport: "playwright_context",
|
|
28180
|
+
recovery_required: true,
|
|
28181
|
+
original_user: before,
|
|
28182
|
+
target_user: target,
|
|
28183
|
+
binding,
|
|
28184
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
28185
|
+
};
|
|
28186
|
+
await writeFile11(leasePath, `${JSON.stringify(lease, null, 2)}
|
|
27445
28187
|
`, { mode: 384 });
|
|
27446
|
-
|
|
28188
|
+
throw error;
|
|
28189
|
+
}
|
|
27447
28190
|
}
|
|
27448
28191
|
if (after.mock !== true || Number(after.id) !== Number(options.userId)) {
|
|
27449
28192
|
lease = {
|
|
@@ -27464,33 +28207,39 @@ async function runPlaywrightIdentityOperation(options) {
|
|
|
27464
28207
|
throw new Error("e2e.identity.playwright.mock_verify_failed: Playwright session did not read back the exact simulated user");
|
|
27465
28208
|
}
|
|
27466
28209
|
lease = {
|
|
28210
|
+
...lease ?? {},
|
|
27467
28211
|
schema_version: 1,
|
|
27468
28212
|
kind: "bpmax_identity_lease",
|
|
27469
28213
|
state: "active",
|
|
27470
28214
|
browser_tool: "playwright",
|
|
27471
28215
|
transport: "playwright_context",
|
|
27472
28216
|
recovery_required: true,
|
|
27473
|
-
original_user: before,
|
|
28217
|
+
original_user: isRecord10(lease?.original_user) ? lease.original_user : before,
|
|
27474
28218
|
target_user: after,
|
|
27475
28219
|
binding,
|
|
27476
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
28220
|
+
created_at: lease?.created_at ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
28221
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
27477
28222
|
};
|
|
27478
28223
|
await writeFile11(leasePath, `${JSON.stringify(lease, null, 2)}
|
|
27479
28224
|
`, { mode: 384 });
|
|
27480
28225
|
} else if (options.operation === "unmock") {
|
|
27481
|
-
|
|
27482
|
-
|
|
27483
|
-
}
|
|
27484
|
-
|
|
27485
|
-
|
|
27486
|
-
|
|
27487
|
-
}
|
|
27488
|
-
|
|
27489
|
-
|
|
28226
|
+
const decision = playwrightIdentityMutationDecision({ operation: "unmock", before, lease, binding });
|
|
28227
|
+
lease = lease;
|
|
28228
|
+
const original = isRecord10(lease.original_user) ? lease.original_user : {};
|
|
28229
|
+
if (decision === "resolve_from_readback") {
|
|
28230
|
+
after = before;
|
|
28231
|
+
resolvedFromReadback = true;
|
|
28232
|
+
} else {
|
|
28233
|
+
try {
|
|
28234
|
+
await playwrightIdentityMutation(session.context, origin, "unmock", options);
|
|
28235
|
+
after = await playwrightIdentityReadback(session.context, origin, options);
|
|
28236
|
+
} catch (error) {
|
|
28237
|
+
lease = { ...lease, state: "uncertain", recovery_required: true, release_binding: binding, updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
28238
|
+
await writeFile11(leasePath, `${JSON.stringify(lease, null, 2)}
|
|
27490
28239
|
`, { mode: 384 });
|
|
27491
|
-
|
|
28240
|
+
throw error;
|
|
28241
|
+
}
|
|
27492
28242
|
}
|
|
27493
|
-
const original = isRecord9(lease.original_user) ? lease.original_user : {};
|
|
27494
28243
|
if (after.mock === true || Number(original.id) > 0 && Number(after.id) !== Number(original.id)) {
|
|
27495
28244
|
lease = {
|
|
27496
28245
|
...lease,
|
|
@@ -27534,14 +28283,15 @@ async function runPlaywrightIdentityOperation(options) {
|
|
|
27534
28283
|
case_id: options.caseId,
|
|
27535
28284
|
case_step_id: options.caseStepId,
|
|
27536
28285
|
operation: options.operation,
|
|
27537
|
-
result: options.operation === "status" ? "observed" : options.operation === "mock" ? "mocked" : "restored",
|
|
28286
|
+
result: options.operation === "status" ? "observed" : resolvedFromReadback ? "resolved_from_readback" : options.operation === "mock" ? "mocked" : "restored",
|
|
27538
28287
|
transport: "playwright_context",
|
|
27539
28288
|
browser_tool: "playwright",
|
|
27540
28289
|
execution_phase: "replay_or_formal",
|
|
27541
28290
|
browser_verified: true,
|
|
27542
|
-
operation_executed: options.operation !== "status",
|
|
27543
|
-
mutation_attempted: options.operation !== "status",
|
|
28291
|
+
operation_executed: options.operation !== "status" && !resolvedFromReadback,
|
|
28292
|
+
mutation_attempted: options.operation !== "status" && !resolvedFromReadback,
|
|
27544
28293
|
remote_submitted: options.operation !== "status",
|
|
28294
|
+
resolved_from_readback: resolvedFromReadback,
|
|
27545
28295
|
readback_confirmed: true,
|
|
27546
28296
|
current_user: after,
|
|
27547
28297
|
before,
|
|
@@ -27603,7 +28353,7 @@ function browserRunnerArtifactPaths(evidenceDir, caseId, stepId, artifactSuffix
|
|
|
27603
28353
|
};
|
|
27604
28354
|
}
|
|
27605
28355
|
function browserEvidenceDirectoriesForRun(manifestFile, execution, currentStepId, untilBlocked) {
|
|
27606
|
-
const steps = Array.isArray(execution.steps) ? execution.steps.map((step) =>
|
|
28356
|
+
const steps = Array.isArray(execution.steps) ? execution.steps.map((step) => isRecord10(step) ? step : {}) : [];
|
|
27607
28357
|
const startIndex = steps.findIndex((step) => String(step.step_id || "") === currentStepId);
|
|
27608
28358
|
if (startIndex < 0) return [];
|
|
27609
28359
|
const runDir = path16.dirname(path16.resolve(manifestFile));
|
|
@@ -27709,7 +28459,7 @@ async function writeRunnerEvidenceFileManifest(evidenceDir, evidenceFiles) {
|
|
|
27709
28459
|
const content = await readFile15(absolutePath);
|
|
27710
28460
|
const extension = path16.extname(file).toLowerCase();
|
|
27711
28461
|
const mimeType = extension === ".png" ? "image/png" : "application/json";
|
|
27712
|
-
return { file, mime_type: mimeType, sha256:
|
|
28462
|
+
return { file, mime_type: mimeType, sha256: createHash10("sha256").update(content).digest("hex"), size: content.length };
|
|
27713
28463
|
}))
|
|
27714
28464
|
}, null, 2)}
|
|
27715
28465
|
`, "utf8");
|
|
@@ -27735,12 +28485,12 @@ async function runOneBrowserStep(options, session) {
|
|
|
27735
28485
|
if (state.complete === true) {
|
|
27736
28486
|
throw new Error("test_suite.run.completed_manifest: completed cases are never skipped or reused; start a new full_rerun manifest to execute the case again");
|
|
27737
28487
|
}
|
|
27738
|
-
const currentStep =
|
|
27739
|
-
const execution =
|
|
28488
|
+
const currentStep = isRecord10(state.current_step) ? state.current_step : {};
|
|
28489
|
+
const execution = isRecord10(state.execution) ? state.execution : {};
|
|
27740
28490
|
const requestedCase = options.caseId || String(execution.case_id || "");
|
|
27741
28491
|
const requestedStep = options.caseStepId || String(currentStep.step_id || "");
|
|
27742
28492
|
if (!requestedCase || !requestedStep) throw new Error("browser-run cannot resolve the current case/step from the execution manifest");
|
|
27743
|
-
const priorPassCount = Array.isArray(execution.steps) ? execution.steps.filter((step) =>
|
|
28493
|
+
const priorPassCount = Array.isArray(execution.steps) ? execution.steps.filter((step) => isRecord10(step) && step.status === "pass").length : 0;
|
|
27744
28494
|
if (priorPassCount > 0 && !options.resume) {
|
|
27745
28495
|
throw new Error("test_suite.run.resume_required: this current run already has recorded steps; use --resume to continue this same unfinished manifest");
|
|
27746
28496
|
}
|
|
@@ -28054,7 +28804,7 @@ async function runOneBrowserStep(options, session) {
|
|
|
28054
28804
|
await options.onMutationConfirmed?.({ ...event, evidence });
|
|
28055
28805
|
}
|
|
28056
28806
|
if (mutationEvents.length > 0) await refreshRunnerEvidenceFileManifest(evidenceDir);
|
|
28057
|
-
const reportSync =
|
|
28807
|
+
const reportSync = isRecord10(recorded.report_sync) ? recorded.report_sync : {};
|
|
28058
28808
|
if (reportSync.ok === false) {
|
|
28059
28809
|
return {
|
|
28060
28810
|
ok: false,
|
|
@@ -28156,12 +28906,12 @@ async function runBrowserAutomation(options) {
|
|
|
28156
28906
|
if (initialState.complete === true) {
|
|
28157
28907
|
throw new Error("test_suite.run.completed_manifest: completed cases are never skipped or reused; start a new full_rerun manifest to execute the case again");
|
|
28158
28908
|
}
|
|
28159
|
-
const initialStep =
|
|
28909
|
+
const initialStep = isRecord10(initialState.current_step) ? initialState.current_step : {};
|
|
28160
28910
|
if (initialStep.runner !== "browser_action") {
|
|
28161
28911
|
throw new Error(`test_suite.run.runner_mismatch: current step runner is ${String(initialStep.runner || "<missing>")}, not browser_action`);
|
|
28162
28912
|
}
|
|
28163
|
-
const initialExecution =
|
|
28164
|
-
const priorPassCount = Array.isArray(initialExecution.steps) ? initialExecution.steps.filter((step) =>
|
|
28913
|
+
const initialExecution = isRecord10(initialState.execution) ? initialState.execution : {};
|
|
28914
|
+
const priorPassCount = Array.isArray(initialExecution.steps) ? initialExecution.steps.filter((step) => isRecord10(step) && step.status === "pass").length : 0;
|
|
28165
28915
|
if (priorPassCount > 0 && !options.resume) {
|
|
28166
28916
|
throw new Error("test_suite.run.resume_required: this current run already has recorded steps; use --resume to continue this same unfinished manifest");
|
|
28167
28917
|
}
|
|
@@ -28211,7 +28961,7 @@ async function runBrowserAutomation(options) {
|
|
|
28211
28961
|
let remoteSubmitted = result.remote_submitted;
|
|
28212
28962
|
let mutationAttempted = result.mutation_attempted === true;
|
|
28213
28963
|
let mutationRequestObserved = result.mutation_request_observed === true;
|
|
28214
|
-
while (options.untilBlocked && result.ok &&
|
|
28964
|
+
while (options.untilBlocked && result.ok && isRecord10(result.next_step) && result.next_step.runner === "browser_action") {
|
|
28215
28965
|
currentOptions = {
|
|
28216
28966
|
...options,
|
|
28217
28967
|
resume: true,
|
|
@@ -28265,21 +29015,21 @@ function selectMutationResolutionOutcome(branchResults, expectedOutcome, trusted
|
|
|
28265
29015
|
return selected;
|
|
28266
29016
|
}
|
|
28267
29017
|
function mutationResolutionCommittedProbeUrl(options) {
|
|
28268
|
-
if (options.outcome !== "committed" || !
|
|
29018
|
+
if (options.outcome !== "committed" || !isRecord10(options.attemptEvidence)) return void 0;
|
|
28269
29019
|
const evidence = options.attemptEvidence;
|
|
28270
29020
|
if (String(evidence.run_id || "") !== options.runId || String(evidence.evidence_nonce || "") !== options.evidenceNonce || String(evidence.case_id || "") !== options.caseId || String(evidence.case_step_id || "") !== options.stepId || String(evidence.automation_step_sha256 || "") !== options.automationStepSha256 || evidence.remote_submitted !== true || evidence.readback_confirmed !== true) return void 0;
|
|
28271
29021
|
const runtimeUrl = String(evidence.runtime_url || "").trim();
|
|
28272
29022
|
return /^https?:\/\//i.test(runtimeUrl) ? runtimeUrl : void 0;
|
|
28273
29023
|
}
|
|
28274
29024
|
function mutationResolutionAttemptProbeUrl(options) {
|
|
28275
|
-
if (!
|
|
29025
|
+
if (!isRecord10(options.attemptEvidence)) return void 0;
|
|
28276
29026
|
const evidence = options.attemptEvidence;
|
|
28277
29027
|
if (String(evidence.run_id || "") !== options.runId || String(evidence.evidence_nonce || "") !== options.evidenceNonce || String(evidence.case_id || "") !== options.caseId || String(evidence.case_step_id || "") !== options.stepId || String(evidence.automation_step_sha256 || "") !== options.automationStepSha256) return void 0;
|
|
28278
29028
|
const runtimeUrl = String(evidence.runtime_url || "").trim();
|
|
28279
29029
|
return /^https?:\/\//i.test(runtimeUrl) ? runtimeUrl : void 0;
|
|
28280
29030
|
}
|
|
28281
29031
|
function mutationResolutionNoRequestEvidenceMatches(options) {
|
|
28282
|
-
if (!
|
|
29032
|
+
if (!isRecord10(options.attemptEvidence) || !options.urlPattern) return false;
|
|
28283
29033
|
const evidence = options.attemptEvidence;
|
|
28284
29034
|
if (String(evidence.run_id || "") !== options.runId || String(evidence.evidence_nonce || "") !== options.evidenceNonce || String(evidence.case_id || "") !== options.caseId || String(evidence.case_step_id || "") !== options.stepId || String(evidence.automation_step_sha256 || "") !== options.automationStepSha256 || evidence.mutation_attempted !== true || evidence.mutation_request_observed !== false || evidence.remote_submitted !== false) return false;
|
|
28285
29035
|
const patterns = Array.isArray(evidence.mutation_url_patterns) ? evidence.mutation_url_patterns.map((value) => String(value || "")) : [];
|
|
@@ -28312,8 +29062,8 @@ async function captureMutationResolutionReadback(options) {
|
|
|
28312
29062
|
automation: options.automation
|
|
28313
29063
|
});
|
|
28314
29064
|
const state = await nextTestSuiteRunStep(options.executionManifest, options.profile);
|
|
28315
|
-
const execution =
|
|
28316
|
-
const guard =
|
|
29065
|
+
const execution = isRecord10(state.execution) ? state.execution : {};
|
|
29066
|
+
const guard = isRecord10(execution.mutation_attempt_guard) ? execution.mutation_attempt_guard : {};
|
|
28317
29067
|
const caseId = String(guard.case_id || "");
|
|
28318
29068
|
const stepId = String(guard.case_step_id || "");
|
|
28319
29069
|
const mutationAttemptId = String(guard.mutation_attempt_id || "");
|
|
@@ -28585,7 +29335,7 @@ async function captureMutationResolutionReadback(options) {
|
|
|
28585
29335
|
urlPattern: mutationPattern
|
|
28586
29336
|
});
|
|
28587
29337
|
const message = error instanceof Error ? error.message : String(error);
|
|
28588
|
-
throw new Error(noRequestProvable ? `${message}; target_request_observed=false; recovery=review resolution_checks.not_committed to include mutation.assert_no_request for ${mutationPattern} plus a live wait.route, page.assert_step, or list.assert_record check` : `${message}; target_request_observed=${
|
|
29338
|
+
throw new Error(noRequestProvable ? `${message}; target_request_observed=false; recovery=review resolution_checks.not_committed to include mutation.assert_no_request for ${mutationPattern} plus a live wait.route, page.assert_step, or list.assert_record check` : `${message}; target_request_observed=${isRecord10(attemptEvidence) ? String(attemptEvidence.mutation_request_observed) : "unknown"}; recovery=review the branch diagnostics and current-run page/network evidence before changing the reviewed resolution checks`);
|
|
28589
29339
|
}
|
|
28590
29340
|
const selected = branchResults.find((branch) => branch.outcome === selectedOutcome);
|
|
28591
29341
|
const suffix = `-resolution-${mutationAttemptId.slice(0, 12)}-${selected.outcome}`;
|
|
@@ -28678,11 +29428,11 @@ var DEFAULT_DEPENDENCIES = {
|
|
|
28678
29428
|
recordExecutionMutationAttempt,
|
|
28679
29429
|
captureMutationResolutionReadback
|
|
28680
29430
|
};
|
|
28681
|
-
function
|
|
29431
|
+
function isRecord11(value) {
|
|
28682
29432
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28683
29433
|
}
|
|
28684
29434
|
function sha2562(value) {
|
|
28685
|
-
return
|
|
29435
|
+
return createHash11("sha256").update(value).digest("hex");
|
|
28686
29436
|
}
|
|
28687
29437
|
async function fileSha256(file) {
|
|
28688
29438
|
return sha2562(await readFile16(file));
|
|
@@ -28718,17 +29468,17 @@ async function readJsonFile2(file) {
|
|
|
28718
29468
|
} catch (error) {
|
|
28719
29469
|
throw new Error(`e2e.scenario.invalid_json: ${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
28720
29470
|
}
|
|
28721
|
-
if (!
|
|
29471
|
+
if (!isRecord11(value)) throw new Error(`e2e.scenario.invalid_json: ${file} must contain a JSON object`);
|
|
28722
29472
|
return value;
|
|
28723
29473
|
}
|
|
28724
29474
|
function executionRecord(state) {
|
|
28725
|
-
return
|
|
29475
|
+
return isRecord11(state.execution) ? state.execution : {};
|
|
28726
29476
|
}
|
|
28727
29477
|
function currentStepRecord(state) {
|
|
28728
|
-
return
|
|
29478
|
+
return isRecord11(state.current_step) ? state.current_step : null;
|
|
28729
29479
|
}
|
|
28730
29480
|
function executionSteps(execution) {
|
|
28731
|
-
return Array.isArray(execution.steps) ? execution.steps.filter(
|
|
29481
|
+
return Array.isArray(execution.steps) ? execution.steps.filter(isRecord11) : [];
|
|
28732
29482
|
}
|
|
28733
29483
|
function currentStepKey(state) {
|
|
28734
29484
|
const execution = executionRecord(state);
|
|
@@ -28807,7 +29557,7 @@ async function assertCheckpointRealScope(manifest, checkpoint) {
|
|
|
28807
29557
|
}
|
|
28808
29558
|
}
|
|
28809
29559
|
}
|
|
28810
|
-
function externalActionForStep(manifest, step
|
|
29560
|
+
function externalActionForStep(manifest, step) {
|
|
28811
29561
|
const runDir = path17.dirname(path17.resolve(manifest));
|
|
28812
29562
|
const caseId = String(step.case_id || "");
|
|
28813
29563
|
const stepId = String(step.step_id || "");
|
|
@@ -28825,28 +29575,13 @@ function externalActionForStep(manifest, step, profile) {
|
|
|
28825
29575
|
instruction: "Fix and review the identity case step before execution. Do not guess a user or fall back to Cookie/API impersonation."
|
|
28826
29576
|
};
|
|
28827
29577
|
}
|
|
28828
|
-
const prepare = [
|
|
28829
|
-
"bpmax-cli e2e identity browser",
|
|
28830
|
-
operation,
|
|
28831
|
-
...operation === "mock" && userId ? ["--user-id", userId] : [],
|
|
28832
|
-
"--evidence-dir",
|
|
28833
|
-
evidenceDir,
|
|
28834
|
-
"--execution-manifest",
|
|
28835
|
-
path17.resolve(manifest),
|
|
28836
|
-
"--case-id",
|
|
28837
|
-
caseId,
|
|
28838
|
-
"--case-step-id",
|
|
28839
|
-
stepId,
|
|
28840
|
-
...profile ? ["--profile", profile] : [],
|
|
28841
|
-
"--format json"
|
|
28842
|
-
].join(" ");
|
|
28843
29578
|
return {
|
|
28844
|
-
kind: "
|
|
28845
|
-
browser_tool: "
|
|
29579
|
+
kind: "playwright_identity_resume",
|
|
29580
|
+
browser_tool: "playwright",
|
|
28846
29581
|
operation,
|
|
28847
|
-
|
|
28848
|
-
|
|
28849
|
-
|
|
29582
|
+
target_user_id: operation === "mock" ? Number(userId) : void 0,
|
|
29583
|
+
evidence_dir: evidenceDir,
|
|
29584
|
+
instruction: "Resume `e2e scenario execute` with the same run-scoped Playwright profile. The scenario runner performs identity readback, mock/unmock, route refresh, evidence recording, and lease validation; do not invoke the Chrome recording bridge for a formal run."
|
|
28850
29585
|
};
|
|
28851
29586
|
}
|
|
28852
29587
|
return {
|
|
@@ -28868,7 +29603,7 @@ function reportSyncRecoveryAction(manifest) {
|
|
|
28868
29603
|
};
|
|
28869
29604
|
}
|
|
28870
29605
|
function reportSyncFailure(recorded) {
|
|
28871
|
-
if (!
|
|
29606
|
+
if (!isRecord11(recorded) || !isRecord11(recorded.report_sync) || recorded.report_sync.ok !== false) return void 0;
|
|
28872
29607
|
return String(recorded.report_sync.error || "execution report sync failed");
|
|
28873
29608
|
}
|
|
28874
29609
|
function repairRequestPath(checkpoint, stepKey, revision) {
|
|
@@ -28963,7 +29698,7 @@ async function finalizeExternalEvidence(state, manifest, profile, dependencies)
|
|
|
28963
29698
|
evidence,
|
|
28964
29699
|
profile
|
|
28965
29700
|
});
|
|
28966
|
-
return
|
|
29701
|
+
return isRecord11(recorded) ? recorded : {};
|
|
28967
29702
|
}
|
|
28968
29703
|
async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPENDENCIES) {
|
|
28969
29704
|
const manifest = path17.resolve(options.executionManifest);
|
|
@@ -28999,7 +29734,7 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
28999
29734
|
const automationHash = await fileSha256(automationFile);
|
|
29000
29735
|
let runState = await dependencies.nextTestSuiteRunStep(manifest, options.profile);
|
|
29001
29736
|
let execution = executionRecord(runState);
|
|
29002
|
-
const initialMutationGuard =
|
|
29737
|
+
const initialMutationGuard = isRecord11(execution.mutation_attempt_guard) ? execution.mutation_attempt_guard : void 0;
|
|
29003
29738
|
if (!hasCheckpoint && options.resume && !initialMutationGuard) {
|
|
29004
29739
|
throw new Error(`e2e.scenario.checkpoint_missing: cannot resume without ${checkpoint}`);
|
|
29005
29740
|
}
|
|
@@ -29047,7 +29782,7 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
29047
29782
|
let reportSyncError;
|
|
29048
29783
|
try {
|
|
29049
29784
|
const reportSync = await dependencies.syncTestSuiteRunReport(manifest);
|
|
29050
|
-
if (
|
|
29785
|
+
if (isRecord11(reportSync) && reportSync.ok === false) reportSyncError = String(reportSync.error || "execution report sync failed");
|
|
29051
29786
|
} catch (error) {
|
|
29052
29787
|
reportSyncError = error instanceof Error ? error.message : String(error);
|
|
29053
29788
|
}
|
|
@@ -29061,7 +29796,7 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
29061
29796
|
repair_scope: path17.join(path17.dirname(manifest), `${scenario}.md`),
|
|
29062
29797
|
script_change_required: false,
|
|
29063
29798
|
external_action: reportSyncRecoveryAction(manifest),
|
|
29064
|
-
evidence:
|
|
29799
|
+
evidence: isRecord11(mutationGuard.resolution_receipt) ? String(mutationGuard.resolution_receipt.evidence || "") : void 0
|
|
29065
29800
|
} : void 0;
|
|
29066
29801
|
await saveOperationState(checkpoint, operation);
|
|
29067
29802
|
await dependencies.clearExecutionMutationAttempt({
|
|
@@ -29071,7 +29806,7 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
29071
29806
|
runState = await dependencies.nextTestSuiteRunStep(manifest, options.profile);
|
|
29072
29807
|
execution = executionRecord(runState);
|
|
29073
29808
|
recoveredMutationGuard = true;
|
|
29074
|
-
} else if (guardedStep.status === "planned" &&
|
|
29809
|
+
} else if (guardedStep.status === "planned" && isRecord11(mutationGuard.resolution_receipt) && mutationGuard.resolution_receipt.outcome === "not_committed") {
|
|
29075
29810
|
await dependencies.validateExecutionMutationResolutionEvidence({
|
|
29076
29811
|
manifest,
|
|
29077
29812
|
caseId: String(mutationGuard.case_id || ""),
|
|
@@ -29149,7 +29884,7 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
29149
29884
|
}
|
|
29150
29885
|
const resumeFromRepair = Boolean(options.resume && operation.status === "paused_repairable");
|
|
29151
29886
|
const automationChanged = operation.automation_sha256 !== automationHash;
|
|
29152
|
-
const pendingRepairGuard =
|
|
29887
|
+
const pendingRepairGuard = isRecord11(execution.automation_repair_guard);
|
|
29153
29888
|
if (pendingRepairGuard && !resumeFromRepair) {
|
|
29154
29889
|
throw new Error("e2e.scenario.repair_transaction_pending: a reviewed automation repair is anchored but not consumed; resume the paused repair checkpoint only after the repair command completes");
|
|
29155
29890
|
}
|
|
@@ -29266,7 +30001,7 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
29266
30001
|
message: error instanceof Error ? error.message : String(error),
|
|
29267
30002
|
repair_scope: stepKey,
|
|
29268
30003
|
script_change_required: false,
|
|
29269
|
-
external_action: externalActionForStep(manifest, step
|
|
30004
|
+
external_action: externalActionForStep(manifest, step)
|
|
29270
30005
|
};
|
|
29271
30006
|
await saveOperationState(checkpoint, operation);
|
|
29272
30007
|
return pausedResult(operation, checkpoint);
|
|
@@ -29354,7 +30089,7 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
29354
30089
|
message: error instanceof Error ? error.message : String(error),
|
|
29355
30090
|
repair_scope: stepKey,
|
|
29356
30091
|
script_change_required: false,
|
|
29357
|
-
external_action: externalActionForStep(manifest, step
|
|
30092
|
+
external_action: externalActionForStep(manifest, step)
|
|
29358
30093
|
};
|
|
29359
30094
|
await saveOperationState(checkpoint, operation);
|
|
29360
30095
|
return pausedResult(operation, checkpoint);
|
|
@@ -29366,7 +30101,7 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
29366
30101
|
message: `Current step ${stepKey} uses ${String(step.runner || "<missing>")} and must be completed by its registered deterministic runner.`,
|
|
29367
30102
|
repair_scope: stepKey,
|
|
29368
30103
|
script_change_required: false,
|
|
29369
|
-
external_action: externalActionForStep(manifest, step
|
|
30104
|
+
external_action: externalActionForStep(manifest, step)
|
|
29370
30105
|
};
|
|
29371
30106
|
await saveOperationState(checkpoint, operation);
|
|
29372
30107
|
return pausedResult(operation, checkpoint);
|
|
@@ -29420,7 +30155,7 @@ async function executeE2eScenarioUnlocked(options, dependencies = DEFAULT_DEPEND
|
|
|
29420
30155
|
mutationAttemptId
|
|
29421
30156
|
});
|
|
29422
30157
|
await saveOperationState(checkpoint, operation);
|
|
29423
|
-
const recordedGuard =
|
|
30158
|
+
const recordedGuard = isRecord11(recorded.mutation_attempt_guard) ? recorded.mutation_attempt_guard : {};
|
|
29424
30159
|
return String(recordedGuard.mutation_attempt_id || mutationAttemptId);
|
|
29425
30160
|
},
|
|
29426
30161
|
onMutationConfirmed: async (confirmed) => {
|
|
@@ -29620,7 +30355,7 @@ async function validateResolutionEvidence(options, state, execution, dependencie
|
|
|
29620
30355
|
if (value.resolution !== options.outcome || value.readback_confirmed !== true || value.run_id !== execution.run_id || value.evidence_nonce !== execution.evidence_nonce || String(value.case_id || "") !== state.current_step?.split("/")[0] || String(value.case_step_id || "") !== state.current_step?.split("/")[1] || !state.pause?.failed_step_hash || String(value.automation_step_sha256 || "") !== state.pause.failed_step_hash || value.checkpoint_revision !== state.pause.checkpoint_revision || value.mutation_attempt_id !== state.pause.mutation_attempt_id) {
|
|
29621
30356
|
throw new Error("e2e.scenario.resolution_evidence_invalid: evidence must match the current run nonce, case/step, checkpoint revision, mutation attempt, attempted automation_step_sha256, requested resolution, and readback_confirmed=true");
|
|
29622
30357
|
}
|
|
29623
|
-
const assertions = Array.isArray(value.assertions) ? value.assertions.filter(
|
|
30358
|
+
const assertions = Array.isArray(value.assertions) ? value.assertions.filter(isRecord11) : [];
|
|
29624
30359
|
if (assertions.length === 0 || assertions.some((assertion) => assertion.passed !== true)) {
|
|
29625
30360
|
throw new Error("e2e.scenario.resolution_evidence_invalid: resolution evidence requires non-empty passed assertions");
|
|
29626
30361
|
}
|
|
@@ -29705,7 +30440,7 @@ async function resolveE2eScenarioWriteStateUnlocked(options, dependencies = DEFA
|
|
|
29705
30440
|
profile: options.profile,
|
|
29706
30441
|
mutationAttemptId
|
|
29707
30442
|
});
|
|
29708
|
-
recorded =
|
|
30443
|
+
recorded = isRecord11(result) ? result : {};
|
|
29709
30444
|
} else {
|
|
29710
30445
|
await dependencies.appendExecutionManifestEvidence({
|
|
29711
30446
|
manifest: state.manifest,
|
|
@@ -29805,7 +30540,7 @@ async function resolveE2eScenarioWriteState(options, dependencies = DEFAULT_DEPE
|
|
|
29805
30540
|
}
|
|
29806
30541
|
|
|
29807
30542
|
// src/core/e2e-identity-bridge.ts
|
|
29808
|
-
import { createHash as
|
|
30543
|
+
import { createHash as createHash12, randomUUID as randomUUID4 } from "crypto";
|
|
29809
30544
|
import { chmod as chmod3, lstat as lstat4, mkdir as mkdir13, readFile as readFile17, realpath as realpath7, rename as rename5, stat as stat12, unlink as unlink2, writeFile as writeFile13 } from "fs/promises";
|
|
29810
30545
|
import path18 from "path";
|
|
29811
30546
|
var REQUEST_TTL_SECONDS = 180;
|
|
@@ -29814,7 +30549,8 @@ var COMPLETION_CLAIM_TTL_MS = 5 * 60 * 1e3;
|
|
|
29814
30549
|
var DEFAULT_LEASE_TTL_SECONDS = 900;
|
|
29815
30550
|
var MIN_LEASE_TTL_SECONDS = 60;
|
|
29816
30551
|
var MAX_LEASE_TTL_SECONDS = 3600;
|
|
29817
|
-
|
|
30552
|
+
var LEASE_LOCK_ATTEMPTS = 100;
|
|
30553
|
+
function isRecord12(value) {
|
|
29818
30554
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29819
30555
|
}
|
|
29820
30556
|
function stringValue3(value) {
|
|
@@ -29861,7 +30597,7 @@ function normalizeLeaseTtl(value) {
|
|
|
29861
30597
|
return ttl;
|
|
29862
30598
|
}
|
|
29863
30599
|
function safeIdentity(value) {
|
|
29864
|
-
if (!
|
|
30600
|
+
if (!isRecord12(value)) return null;
|
|
29865
30601
|
const sourceValue = stringValue3(value.source);
|
|
29866
30602
|
const source = sourceValue === "vuex" || sourceValue === "profile_route" || sourceValue === "dom" ? sourceValue : "unknown";
|
|
29867
30603
|
return {
|
|
@@ -29869,11 +30605,40 @@ function safeIdentity(value) {
|
|
|
29869
30605
|
name: stringValue3(value.name) ?? null,
|
|
29870
30606
|
organization_id: integerValue(value.organization_id),
|
|
29871
30607
|
mock: booleanValue(value.mock) === true,
|
|
29872
|
-
mock_by_user: integerValue(
|
|
30608
|
+
mock_by_user: integerValue(isRecord12(value.mock_by_user) ? value.mock_by_user.id : value.mock_by_user),
|
|
29873
30609
|
can_mock: booleanValue(value.can_mock),
|
|
29874
30610
|
source
|
|
29875
30611
|
};
|
|
29876
30612
|
}
|
|
30613
|
+
function trustedOriginalIdentity(value) {
|
|
30614
|
+
if (!isRecord12(value) || value.mock !== false) return null;
|
|
30615
|
+
const identity = safeIdentity(value);
|
|
30616
|
+
return identity?.id ? identity : null;
|
|
30617
|
+
}
|
|
30618
|
+
function recoveredOriginalIdentity(lease) {
|
|
30619
|
+
const original = trustedOriginalIdentity(lease.original_user);
|
|
30620
|
+
if (original) return { identity: original, source: "lease_original" };
|
|
30621
|
+
const candidates = [
|
|
30622
|
+
{ identity: safeIdentity(lease.target_user), source: "target_mock_by_user" },
|
|
30623
|
+
{ identity: safeIdentity(lease.original_user), source: "original_mock_by_user" }
|
|
30624
|
+
];
|
|
30625
|
+
for (const candidate of candidates) {
|
|
30626
|
+
if (!candidate.identity?.mock_by_user) continue;
|
|
30627
|
+
return {
|
|
30628
|
+
identity: {
|
|
30629
|
+
id: candidate.identity.mock_by_user,
|
|
30630
|
+
name: null,
|
|
30631
|
+
organization_id: candidate.identity.organization_id,
|
|
30632
|
+
mock: false,
|
|
30633
|
+
mock_by_user: null,
|
|
30634
|
+
can_mock: null,
|
|
30635
|
+
source: candidate.identity.source
|
|
30636
|
+
},
|
|
30637
|
+
source: candidate.source
|
|
30638
|
+
};
|
|
30639
|
+
}
|
|
30640
|
+
return null;
|
|
30641
|
+
}
|
|
29877
30642
|
async function readJson(file) {
|
|
29878
30643
|
return JSON.parse(await readFile17(file, "utf8"));
|
|
29879
30644
|
}
|
|
@@ -29896,7 +30661,7 @@ async function readOptionalLease(file) {
|
|
|
29896
30661
|
try {
|
|
29897
30662
|
await assertSafeExistingFile(file, "lease");
|
|
29898
30663
|
const value = await readJson(file);
|
|
29899
|
-
if (!
|
|
30664
|
+
if (!isRecord12(value) || value.kind !== "bpmax_identity_lease" || value.schema_version !== 1) {
|
|
29900
30665
|
throw new Error("invalid identity lease state");
|
|
29901
30666
|
}
|
|
29902
30667
|
const state = stringValue3(value.state);
|
|
@@ -29904,7 +30669,7 @@ async function readOptionalLease(file) {
|
|
|
29904
30669
|
throw new Error("invalid identity lease state");
|
|
29905
30670
|
}
|
|
29906
30671
|
const lease = value;
|
|
29907
|
-
if (!stringValue3(lease.lease_id) || lease.browser_tool !== "chrome:control-chrome" || typeof lease.recovery_required !== "boolean" || !
|
|
30672
|
+
if (!stringValue3(lease.lease_id) || lease.browser_tool !== "chrome:control-chrome" || typeof lease.recovery_required !== "boolean" || !isRecord12(lease.binding)) {
|
|
29908
30673
|
throw new Error("invalid identity lease binding");
|
|
29909
30674
|
}
|
|
29910
30675
|
return lease;
|
|
@@ -29927,6 +30692,65 @@ async function atomicJson(file, value, exclusive = false) {
|
|
|
29927
30692
|
await chmod3(temp, 384);
|
|
29928
30693
|
await rename5(temp, file);
|
|
29929
30694
|
}
|
|
30695
|
+
async function withLeaseLock(leaseFile, action) {
|
|
30696
|
+
const lockFile = `${leaseFile}.lock`;
|
|
30697
|
+
const owner = randomUUID4();
|
|
30698
|
+
for (let attempt = 0; attempt < LEASE_LOCK_ATTEMPTS; attempt += 1) {
|
|
30699
|
+
try {
|
|
30700
|
+
await writeFile13(lockFile, `${JSON.stringify({ owner, created_at: (/* @__PURE__ */ new Date()).toISOString() })}
|
|
30701
|
+
`, {
|
|
30702
|
+
encoding: "utf8",
|
|
30703
|
+
flag: "wx",
|
|
30704
|
+
mode: 384
|
|
30705
|
+
});
|
|
30706
|
+
try {
|
|
30707
|
+
return await action();
|
|
30708
|
+
} finally {
|
|
30709
|
+
try {
|
|
30710
|
+
const lock = await readJson(lockFile);
|
|
30711
|
+
if (isRecord12(lock) && lock.owner === owner) await unlink2(lockFile);
|
|
30712
|
+
} catch {
|
|
30713
|
+
}
|
|
30714
|
+
}
|
|
30715
|
+
} catch (error) {
|
|
30716
|
+
if (error.code !== "EEXIST") throw error;
|
|
30717
|
+
const info = await lstatOptional(lockFile);
|
|
30718
|
+
if (!info?.isFile() || info.isSymbolicLink()) {
|
|
30719
|
+
throw new Error("e2e.identity.browser.lease_lock_unsafe: identity lease lock \u5FC5\u987B\u662F\u666E\u901A\u6587\u4EF6\u3002");
|
|
30720
|
+
}
|
|
30721
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
30722
|
+
}
|
|
30723
|
+
}
|
|
30724
|
+
throw new Error("e2e.identity.browser.lease_lock_timeout: identity lease \u6B63\u5728\u88AB\u53E6\u4E00\u4E2A\u6062\u590D\u8BF7\u6C42\u66F4\u65B0\u3002");
|
|
30725
|
+
}
|
|
30726
|
+
async function transitionIdentityLease(leaseFile, expectedLeaseId, expectedReleaseRequestId, update) {
|
|
30727
|
+
return withLeaseLock(leaseFile, async () => {
|
|
30728
|
+
const current = await readOptionalLease(leaseFile);
|
|
30729
|
+
if (!current || current.lease_id !== expectedLeaseId) {
|
|
30730
|
+
throw new Error("e2e.identity.browser.lease_changed: identity lease \u5DF2\u88AB\u5176\u4ED6\u8BF7\u6C42\u91CA\u653E\u6216\u66FF\u6362\uFF0C\u5F53\u524D\u8BF7\u6C42\u4E0D\u5F97\u8986\u76D6\u3002");
|
|
30731
|
+
}
|
|
30732
|
+
if (current.state === "released") return current;
|
|
30733
|
+
if (!["active", "uncertain"].includes(current.state)) {
|
|
30734
|
+
throw new Error("e2e.identity.browser.lease_changed: identity lease \u5DF2\u88AB\u5176\u4ED6\u8BF7\u6C42\u91CA\u653E\u6216\u66FF\u6362\uFF0C\u5F53\u524D\u8BF7\u6C42\u4E0D\u5F97\u8986\u76D6\u3002");
|
|
30735
|
+
}
|
|
30736
|
+
if (current.release_operation_request_id !== expectedReleaseRequestId) {
|
|
30737
|
+
throw new Error("e2e.identity.browser.lease_claim_changed: identity lease recovery claim \u5DF2\u88AB\u5176\u4ED6\u8BF7\u6C42\u63A5\u7BA1\u3002");
|
|
30738
|
+
}
|
|
30739
|
+
const next = update(current);
|
|
30740
|
+
await atomicJson(leaseFile, next);
|
|
30741
|
+
return next;
|
|
30742
|
+
});
|
|
30743
|
+
}
|
|
30744
|
+
async function persistMockIdentityLease(leaseFile, expectedLeaseId, expectedRequestId, next) {
|
|
30745
|
+
return withLeaseLock(leaseFile, async () => {
|
|
30746
|
+
const current = await readOptionalLease(leaseFile);
|
|
30747
|
+
if (current && (current.lease_id !== expectedLeaseId || current.operation_request_id !== expectedRequestId || !["active", "uncertain"].includes(current.state))) {
|
|
30748
|
+
throw new Error("e2e.identity.browser.lease_changed: identity lease \u5DF2\u88AB\u5176\u4ED6\u8BF7\u6C42\u91CA\u653E\u6216\u66FF\u6362\uFF0C\u5F53\u524D mock \u7ED3\u679C\u4E0D\u5F97\u8986\u76D6\u3002");
|
|
30749
|
+
}
|
|
30750
|
+
await atomicJson(leaseFile, next);
|
|
30751
|
+
return next;
|
|
30752
|
+
});
|
|
30753
|
+
}
|
|
29930
30754
|
function identityBrowserRequestModeIsSafe(mode, platform = process.platform) {
|
|
29931
30755
|
return platform === "win32" || (mode & 63) === 0;
|
|
29932
30756
|
}
|
|
@@ -29962,7 +30786,7 @@ async function prepareIdentityBrowserBridge(options) {
|
|
|
29962
30786
|
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");
|
|
29963
30787
|
}
|
|
29964
30788
|
const evidenceDir = path18.resolve(options.evidenceDir);
|
|
29965
|
-
const runDir = options.binding.execution_manifest ? path18.dirname(path18.resolve(options.binding.execution_manifest)) : evidenceDir;
|
|
30789
|
+
const runDir = options.binding.execution_manifest ? path18.dirname(path18.resolve(options.binding.execution_manifest)) : options.binding.recording_session ? path18.resolve(options.binding.recording_session) : evidenceDir;
|
|
29966
30790
|
const leaseFile = path18.resolve(options.leaseFile);
|
|
29967
30791
|
if (!pathInside4(runDir, evidenceDir)) {
|
|
29968
30792
|
throw new Error("e2e.identity.browser.evidence_scope: identity evidence \u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D run \u76EE\u5F55\u5185\u3002");
|
|
@@ -29986,8 +30810,12 @@ async function prepareIdentityBrowserBridge(options) {
|
|
|
29986
30810
|
const expired = activeLease.expires_at ? Date.parse(activeLease.expires_at) <= Date.now() : false;
|
|
29987
30811
|
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`);
|
|
29988
30812
|
}
|
|
29989
|
-
if (options.operation === "unmock" &&
|
|
29990
|
-
throw new Error("e2e.identity.browser.unmock_without_lease:
|
|
30813
|
+
if (options.operation === "unmock" && (!activeLease || !["active", "uncertain"].includes(activeLease.state))) {
|
|
30814
|
+
throw new Error("e2e.identity.browser.unmock_without_lease: unmock \u5FC5\u987B\u5BF9\u5E94\u540C\u4E00\u6B63\u5F0F run \u6216 recording session \u7684 active/uncertain identity lease\u3002");
|
|
30815
|
+
}
|
|
30816
|
+
const originalRecovery = options.operation === "unmock" && activeLease ? recoveredOriginalIdentity(activeLease) : null;
|
|
30817
|
+
if (options.operation === "unmock" && !originalRecovery) {
|
|
30818
|
+
throw new Error("e2e.identity.browser.original_identity_unrecoverable: lease \u65E0\u6CD5\u8BC1\u660E\u7CBE\u786E\u539F\u59CB\u8EAB\u4EFD\uFF0C\u7981\u6B62\u5C1D\u8BD5 unmock \u6216\u91CA\u653E\u79DF\u7EA6\u3002");
|
|
29991
30819
|
}
|
|
29992
30820
|
const ttlSeconds = normalizeLeaseTtl(options.leaseTtlSeconds);
|
|
29993
30821
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -29996,7 +30824,7 @@ async function prepareIdentityBrowserBridge(options) {
|
|
|
29996
30824
|
const stem = `identity-browser-${options.operation}-${now.toISOString().replace(/[:.]/g, "-")}-${requestId2.slice(0, 8)}`;
|
|
29997
30825
|
const requestPath = path18.join(evidenceDir, `${stem}.request.json`);
|
|
29998
30826
|
const resultPath = path18.join(evidenceDir, `${stem}.result.json`);
|
|
29999
|
-
const screenshotDir = options.binding.execution_manifest ? path18.join(runDir, "screenshots") : evidenceDir;
|
|
30827
|
+
const screenshotDir = options.binding.execution_manifest || options.binding.recording_session ? path18.join(runDir, "screenshots") : evidenceDir;
|
|
30000
30828
|
await mkdir13(screenshotDir, { recursive: true });
|
|
30001
30829
|
const realScreenshotDir = await realpath7(screenshotDir);
|
|
30002
30830
|
if (!pathInside4(realRunDir, realScreenshotDir)) {
|
|
@@ -30036,7 +30864,10 @@ async function prepareIdentityBrowserBridge(options) {
|
|
|
30036
30864
|
...leaseExpiresAt ? { expires_at: leaseExpiresAt } : {},
|
|
30037
30865
|
requires_dedicated_tab: true,
|
|
30038
30866
|
recovery_required: true,
|
|
30039
|
-
...
|
|
30867
|
+
...originalRecovery ? {
|
|
30868
|
+
expected_original_user: originalRecovery.identity,
|
|
30869
|
+
expected_original_user_source: originalRecovery.source
|
|
30870
|
+
} : {}
|
|
30040
30871
|
},
|
|
30041
30872
|
allowed_ui_actions: requestAllowedActions(options.operation)
|
|
30042
30873
|
};
|
|
@@ -30053,15 +30884,19 @@ async function prepareIdentityBrowserBridge(options) {
|
|
|
30053
30884
|
async function readIdentityBrowserRequest(file, options = {}) {
|
|
30054
30885
|
const requestPath = path18.resolve(file);
|
|
30055
30886
|
const value = await readJson(requestPath);
|
|
30056
|
-
if (!
|
|
30887
|
+
if (!isRecord12(value) || value.schema_version !== 1 || value.kind !== "bpmax_identity_browser_request" || value.transport !== "chrome_control_ui") {
|
|
30057
30888
|
throw new Error("e2e.identity.browser.request_invalid: \u4E0D\u652F\u6301\u7684 identity browser request\u3002");
|
|
30058
30889
|
}
|
|
30059
30890
|
const request = value;
|
|
30060
|
-
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))) {
|
|
30891
|
+
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)) || request.operation === "unmock" && !trustedOriginalIdentity(request.lease.expected_original_user)) {
|
|
30061
30892
|
throw new Error("e2e.identity.browser.request_invalid: request \u7F3A\u5C11\u8EAB\u4EFD\u6865\u7ED1\u5B9A\u5B57\u6BB5\u3002");
|
|
30062
30893
|
}
|
|
30063
30894
|
const runDir = path18.resolve(request.run_dir);
|
|
30064
30895
|
const evidenceDir = path18.resolve(request.evidence_dir);
|
|
30896
|
+
const recordingSession = request.binding.recording_session ? path18.resolve(request.binding.recording_session) : void 0;
|
|
30897
|
+
if (recordingSession && (request.binding.diagnostic || request.binding.execution_manifest || recordingSession !== runDir)) {
|
|
30898
|
+
throw new Error("e2e.identity.browser.recording_binding_invalid: recording request \u5FC5\u987B\u53EA\u7ED1\u5B9A\u552F\u4E00 recording session \u6839\u76EE\u5F55\u3002");
|
|
30899
|
+
}
|
|
30065
30900
|
const realRunDir = await realpath7(runDir);
|
|
30066
30901
|
const realEvidenceDir = await realpath7(evidenceDir);
|
|
30067
30902
|
const realRequestPath = await realpath7(requestPath);
|
|
@@ -30105,7 +30940,7 @@ function identityAssertion(name, passed, actual, expected) {
|
|
|
30105
30940
|
return { name, passed, actual, expected };
|
|
30106
30941
|
}
|
|
30107
30942
|
function resultError(value) {
|
|
30108
|
-
const error =
|
|
30943
|
+
const error = isRecord12(value.error) ? value.error : {};
|
|
30109
30944
|
return {
|
|
30110
30945
|
kind: stringValue3(error.kind) ?? "browser_identity_failed",
|
|
30111
30946
|
message: (stringValue3(error.message) ?? "Chrome identity bridge failed").slice(0, 500)
|
|
@@ -30142,7 +30977,7 @@ async function validateScreenshot(request, result) {
|
|
|
30142
30977
|
return {
|
|
30143
30978
|
path: realScreenshot,
|
|
30144
30979
|
mime: "image/jpeg",
|
|
30145
|
-
sha256:
|
|
30980
|
+
sha256: createHash12("sha256").update(content).digest("hex")
|
|
30146
30981
|
};
|
|
30147
30982
|
}
|
|
30148
30983
|
function validateResultEnvelope(request, value) {
|
|
@@ -30162,7 +30997,8 @@ function validateResultEnvelope(request, value) {
|
|
|
30162
30997
|
}
|
|
30163
30998
|
}
|
|
30164
30999
|
function expectedOriginalIdentityId(request, before) {
|
|
30165
|
-
|
|
31000
|
+
const expected = trustedOriginalIdentity(request.lease.expected_original_user);
|
|
31001
|
+
return expected?.id ?? before?.mock_by_user ?? null;
|
|
30166
31002
|
}
|
|
30167
31003
|
function restoredIdentityMatches(request, before, after) {
|
|
30168
31004
|
const expectedOriginalId = expectedOriginalIdentityId(request, before);
|
|
@@ -30174,9 +31010,9 @@ function operationSucceeded(request, value, before, after) {
|
|
|
30174
31010
|
return value.operation_executed === false && value.remote_submitted === false && after.id !== null && Boolean(after.name);
|
|
30175
31011
|
}
|
|
30176
31012
|
if (request.operation === "mock") {
|
|
30177
|
-
const permission =
|
|
31013
|
+
const permission = isRecord12(value.permission_preflight) ? booleanValue(value.permission_preflight.granted) : null;
|
|
30178
31014
|
const originalIdentityBound = after.mock_by_user === before?.id || after.mock_by_user === null && after.source === "profile_route" && before?.id !== null;
|
|
30179
|
-
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 &&
|
|
31015
|
+
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 && isRecord12(value.lease) && value.lease.lease_id === request.lease.lease_id && value.lease.recovery_required === true;
|
|
30180
31016
|
}
|
|
30181
31017
|
const expectedOriginalId = expectedOriginalIdentityId(request, before);
|
|
30182
31018
|
if (value.already_restored === true) {
|
|
@@ -30201,16 +31037,17 @@ async function completeIdentityBrowserBridge(requestFile) {
|
|
|
30201
31037
|
throw new Error("e2e.identity.browser.result_scope: Chrome identity result \u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D evidence \u76EE\u5F55\u5185\u3002");
|
|
30202
31038
|
}
|
|
30203
31039
|
const value = await readJson(realResultPath);
|
|
30204
|
-
if (!
|
|
31040
|
+
if (!isRecord12(value)) throw new Error("e2e.identity.browser.result_invalid: Chrome identity result \u5FC5\u987B\u662F JSON object\u3002");
|
|
30205
31041
|
validateResultEnvelope(request, value);
|
|
30206
31042
|
const screenshot = await validateScreenshot(request, value);
|
|
30207
31043
|
const before = safeIdentity(value.before);
|
|
30208
31044
|
const after = safeIdentity(value.after ?? value.current_user);
|
|
30209
31045
|
const ok = operationSucceeded(request, value, before, after);
|
|
30210
31046
|
const failure = ok ? void 0 : resultError(value);
|
|
30211
|
-
const cleanup =
|
|
31047
|
+
const cleanup = isRecord12(value.cleanup) ? value.cleanup : {};
|
|
30212
31048
|
let lease = await readOptionalLease(request.lease.lease_file);
|
|
30213
31049
|
if (request.operation === "mock" && ok) {
|
|
31050
|
+
const original = trustedOriginalIdentity(before) ?? recoveredOriginalIdentity({ original_user: before, target_user: after })?.identity ?? null;
|
|
30214
31051
|
lease = {
|
|
30215
31052
|
schema_version: 1,
|
|
30216
31053
|
kind: "bpmax_identity_lease",
|
|
@@ -30220,13 +31057,19 @@ async function completeIdentityBrowserBridge(requestFile) {
|
|
|
30220
31057
|
created_at: request.created_at,
|
|
30221
31058
|
...request.lease.expires_at ? { expires_at: request.lease.expires_at } : {},
|
|
30222
31059
|
target_user: after,
|
|
30223
|
-
original_user:
|
|
31060
|
+
original_user: original,
|
|
30224
31061
|
browser_tool: "chrome:control-chrome",
|
|
30225
31062
|
recovery_required: true,
|
|
30226
31063
|
binding: request.binding
|
|
30227
31064
|
};
|
|
30228
|
-
await
|
|
31065
|
+
lease = await persistMockIdentityLease(
|
|
31066
|
+
request.lease.lease_file,
|
|
31067
|
+
request.lease.lease_id,
|
|
31068
|
+
request.request_id,
|
|
31069
|
+
lease
|
|
31070
|
+
);
|
|
30229
31071
|
} else if (request.operation === "mock" && (value.remote_submitted === true || value.mutation_attempted === true) && cleanup.readback_confirmed !== true) {
|
|
31072
|
+
const original = trustedOriginalIdentity(before) ?? recoveredOriginalIdentity({ original_user: before, target_user: after })?.identity ?? null;
|
|
30230
31073
|
lease = {
|
|
30231
31074
|
schema_version: 1,
|
|
30232
31075
|
kind: "bpmax_identity_lease",
|
|
@@ -30236,36 +31079,40 @@ async function completeIdentityBrowserBridge(requestFile) {
|
|
|
30236
31079
|
created_at: request.created_at,
|
|
30237
31080
|
...request.lease.expires_at ? { expires_at: request.lease.expires_at } : {},
|
|
30238
31081
|
target_user: after,
|
|
30239
|
-
original_user:
|
|
31082
|
+
original_user: original,
|
|
30240
31083
|
browser_tool: "chrome:control-chrome",
|
|
30241
31084
|
recovery_required: true,
|
|
30242
31085
|
binding: request.binding
|
|
30243
31086
|
};
|
|
30244
|
-
await
|
|
31087
|
+
lease = await persistMockIdentityLease(
|
|
31088
|
+
request.lease.lease_file,
|
|
31089
|
+
request.lease.lease_id,
|
|
31090
|
+
request.request_id,
|
|
31091
|
+
lease
|
|
31092
|
+
);
|
|
30245
31093
|
} else if (request.operation === "unmock" && ok && lease) {
|
|
30246
|
-
lease = {
|
|
30247
|
-
...
|
|
31094
|
+
lease = await transitionIdentityLease(request.lease.lease_file, request.lease.lease_id, request.request_id, (current) => ({
|
|
31095
|
+
...current,
|
|
31096
|
+
original_user: trustedOriginalIdentity(request.lease.expected_original_user),
|
|
30248
31097
|
state: "released",
|
|
30249
31098
|
released_at: stringValue3(value.finished_at) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
30250
31099
|
recovery_required: false,
|
|
30251
31100
|
release_operation_request_id: request.request_id,
|
|
30252
31101
|
release_binding: request.binding
|
|
30253
|
-
};
|
|
30254
|
-
await atomicJson(request.lease.lease_file, lease);
|
|
31102
|
+
}));
|
|
30255
31103
|
} else if (request.operation === "unmock" && !ok && lease && (value.remote_submitted === true || value.mutation_attempted === true)) {
|
|
30256
|
-
lease = {
|
|
30257
|
-
...
|
|
31104
|
+
lease = await transitionIdentityLease(request.lease.lease_file, request.lease.lease_id, request.request_id, (current) => ({
|
|
31105
|
+
...current,
|
|
30258
31106
|
state: "uncertain",
|
|
30259
31107
|
recovery_required: true,
|
|
30260
31108
|
release_operation_request_id: request.request_id,
|
|
30261
31109
|
release_binding: request.binding
|
|
30262
|
-
};
|
|
30263
|
-
await atomicJson(request.lease.lease_file, lease);
|
|
31110
|
+
}));
|
|
30264
31111
|
}
|
|
30265
31112
|
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" ? [
|
|
30266
|
-
identityAssertion("\u539F\u8D26\u53F7\u5177\u5907\u6A21\u62DF\u8EAB\u4EFD\u6743\u9650",
|
|
31113
|
+
identityAssertion("\u539F\u8D26\u53F7\u5177\u5907\u6A21\u62DF\u8EAB\u4EFD\u6743\u9650", isRecord12(value.permission_preflight) && value.permission_preflight.granted === true, isRecord12(value.permission_preflight) ? value.permission_preflight.granted : null, true),
|
|
30267
31114
|
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),
|
|
30268
|
-
identityAssertion("\u539F\u8EAB\u4EFD\u6062\u590D\u95E8\u7981\u5DF2\u542F\u7528",
|
|
31115
|
+
identityAssertion("\u539F\u8EAB\u4EFD\u6062\u590D\u95E8\u7981\u5DF2\u542F\u7528", isRecord12(value.lease) && value.lease.recovery_required === true, isRecord12(value.lease) ? value.lease.recovery_required : null, true)
|
|
30269
31116
|
] : [identityAssertion(
|
|
30270
31117
|
"\u6D4F\u89C8\u5668\u5DF2\u6062\u590D\u539F\u59CB\u8EAB\u4EFD",
|
|
30271
31118
|
restoredIdentityMatches(request, before, after),
|
|
@@ -30288,8 +31135,16 @@ async function completeIdentityBrowserBridge(requestFile) {
|
|
|
30288
31135
|
current_user: after,
|
|
30289
31136
|
before,
|
|
30290
31137
|
after,
|
|
30291
|
-
...
|
|
30292
|
-
...
|
|
31138
|
+
...isRecord12(value.permission_preflight) ? { permission_preflight: value.permission_preflight } : {},
|
|
31139
|
+
...isRecord12(value.lease) ? { lease: value.lease } : {},
|
|
31140
|
+
...request.operation === "unmock" ? {
|
|
31141
|
+
identity_recovery: {
|
|
31142
|
+
lease_id: request.lease.lease_id,
|
|
31143
|
+
expected_original_user: request.lease.expected_original_user,
|
|
31144
|
+
source: request.lease.expected_original_user_source ?? "lease_original",
|
|
31145
|
+
released: lease?.state === "released"
|
|
31146
|
+
}
|
|
31147
|
+
} : {},
|
|
30293
31148
|
...failure ? { failure } : {},
|
|
30294
31149
|
runtime_scope: "page",
|
|
30295
31150
|
runtime_environment: "profile",
|
|
@@ -30329,7 +31184,7 @@ async function claimIdentityBrowserRequestCompletion(requestFile) {
|
|
|
30329
31184
|
if (error.code !== "EEXIST") throw error;
|
|
30330
31185
|
await assertSafeExistingFile(claimPath, "completion_claim");
|
|
30331
31186
|
const existing = await readJson(claimPath).catch(() => null);
|
|
30332
|
-
const expiresAt =
|
|
31187
|
+
const expiresAt = isRecord12(existing) ? Date.parse(stringValue3(existing.expires_at) ?? "") : Number.NaN;
|
|
30333
31188
|
if (Number.isFinite(expiresAt) && expiresAt > Date.now()) {
|
|
30334
31189
|
throw new Error("e2e.identity.browser.completion_in_progress: identity browser request \u6B63\u5728\u9A8C\u6536\uFF0C\u7981\u6B62\u5E76\u53D1 complete\u3002");
|
|
30335
31190
|
}
|
|
@@ -30343,7 +31198,7 @@ async function claimIdentityBrowserRequestCompletion(requestFile) {
|
|
|
30343
31198
|
async function releaseIdentityBrowserRequestCompletionClaim(claim) {
|
|
30344
31199
|
await assertSafeExistingFile(claim.claim_path, "completion_claim");
|
|
30345
31200
|
const current = await readJson(claim.claim_path).catch(() => null);
|
|
30346
|
-
if (
|
|
31201
|
+
if (isRecord12(current) && current.claim_id === claim.claim_id && current.request_id === claim.request_id) {
|
|
30347
31202
|
await unlink2(claim.claim_path).catch((error) => {
|
|
30348
31203
|
if (error.code !== "ENOENT") throw error;
|
|
30349
31204
|
});
|
|
@@ -30383,7 +31238,7 @@ var OPTION_NAMES = ["options", "items", "choices", "values"];
|
|
|
30383
31238
|
var REQUIRED_NAMES = ["required", "is_required", "isRequired", "require", "must", "validateRequired"];
|
|
30384
31239
|
var HIDDEN_NAMES = ["hidden", "is_hidden", "isHidden", "hide", "hideInForm"];
|
|
30385
31240
|
var VISIBLE_NAMES = ["visible", "display", "show"];
|
|
30386
|
-
function
|
|
31241
|
+
function isRecord13(value) {
|
|
30387
31242
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30388
31243
|
}
|
|
30389
31244
|
function pickString(source, keys) {
|
|
@@ -30410,10 +31265,10 @@ function pickBoolean(source, keys) {
|
|
|
30410
31265
|
}
|
|
30411
31266
|
const rules = source.rules;
|
|
30412
31267
|
if (Array.isArray(rules)) {
|
|
30413
|
-
return rules.some((rule) =>
|
|
31268
|
+
return rules.some((rule) => isRecord13(rule) && pickBoolean(rule, REQUIRED_NAMES));
|
|
30414
31269
|
}
|
|
30415
31270
|
const validateMap = source.validateMap;
|
|
30416
|
-
if (
|
|
31271
|
+
if (isRecord13(validateMap) && pickBoolean(validateMap, REQUIRED_NAMES)) {
|
|
30417
31272
|
return true;
|
|
30418
31273
|
}
|
|
30419
31274
|
return false;
|
|
@@ -30437,7 +31292,7 @@ function optionValue(option) {
|
|
|
30437
31292
|
if (typeof option === "string" || typeof option === "number") {
|
|
30438
31293
|
return String(option);
|
|
30439
31294
|
}
|
|
30440
|
-
if (!
|
|
31295
|
+
if (!isRecord13(option)) {
|
|
30441
31296
|
return null;
|
|
30442
31297
|
}
|
|
30443
31298
|
return pickString(option, ["value", "key", "id", "name", "label", "title"]) ?? null;
|
|
@@ -30455,7 +31310,7 @@ function pickOptions(source) {
|
|
|
30455
31310
|
}
|
|
30456
31311
|
for (const containerKey of ["props", "config", "setting", "value"]) {
|
|
30457
31312
|
const container = source[containerKey];
|
|
30458
|
-
if (
|
|
31313
|
+
if (isRecord13(container)) {
|
|
30459
31314
|
const nested = pickOptions(container);
|
|
30460
31315
|
if (nested?.length) {
|
|
30461
31316
|
return nested;
|
|
@@ -30511,7 +31366,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
30511
31366
|
}
|
|
30512
31367
|
return;
|
|
30513
31368
|
}
|
|
30514
|
-
if (!
|
|
31369
|
+
if (!isRecord13(value)) {
|
|
30515
31370
|
return;
|
|
30516
31371
|
}
|
|
30517
31372
|
const field = fieldFromRecord(value);
|
|
@@ -30519,7 +31374,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
30519
31374
|
if (isSubFormField(field)) {
|
|
30520
31375
|
const childFields = /* @__PURE__ */ new Map();
|
|
30521
31376
|
for (const child of Object.values(value)) {
|
|
30522
|
-
if (
|
|
31377
|
+
if (isRecord13(child) || Array.isArray(child)) {
|
|
30523
31378
|
collectFieldCandidates(child, childFields, depth + 1);
|
|
30524
31379
|
}
|
|
30525
31380
|
}
|
|
@@ -30533,7 +31388,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
30533
31388
|
fields.set(field.key, mergeField(fields.get(field.key), field));
|
|
30534
31389
|
}
|
|
30535
31390
|
for (const child of Object.values(value)) {
|
|
30536
|
-
if (
|
|
31391
|
+
if (isRecord13(child) || Array.isArray(child)) {
|
|
30537
31392
|
collectFieldCandidates(child, fields, depth + 1);
|
|
30538
31393
|
}
|
|
30539
31394
|
}
|
|
@@ -30552,7 +31407,7 @@ function validateComplexSelector(field, value) {
|
|
|
30552
31407
|
return null;
|
|
30553
31408
|
}
|
|
30554
31409
|
const validObject = (item) => {
|
|
30555
|
-
if (!
|
|
31410
|
+
if (!isRecord13(item)) return false;
|
|
30556
31411
|
if (type === "user_select") {
|
|
30557
31412
|
const id = Number(item.id);
|
|
30558
31413
|
return Number.isSafeInteger(id) && id > 0 && typeof item.name === "string" && item.name.trim().length > 0 && item._type === "user";
|
|
@@ -30567,7 +31422,7 @@ function validateComplexSelector(field, value) {
|
|
|
30567
31422
|
if (validObject(value)) {
|
|
30568
31423
|
return null;
|
|
30569
31424
|
}
|
|
30570
|
-
if (type === "user_select" &&
|
|
31425
|
+
if (type === "user_select" && isRecord13(value)) {
|
|
30571
31426
|
return `${field.key} must be a BPMAX user selector object with positive id, non-empty name, and _type="user".`;
|
|
30572
31427
|
}
|
|
30573
31428
|
return `${field.key} must be a selector option object or array of option objects, not a scalar value. ${hint}`;
|
|
@@ -30579,7 +31434,7 @@ function isEnumSelectType(type) {
|
|
|
30579
31434
|
return /enum_select/.test(type);
|
|
30580
31435
|
}
|
|
30581
31436
|
function optionComparableValue(value) {
|
|
30582
|
-
if (
|
|
31437
|
+
if (isRecord13(value) && ("value" in value || "label" in value)) {
|
|
30583
31438
|
return value.value ?? value.label;
|
|
30584
31439
|
}
|
|
30585
31440
|
return value;
|
|
@@ -30593,7 +31448,7 @@ function validateType(field, value) {
|
|
|
30593
31448
|
if (!Array.isArray(value)) {
|
|
30594
31449
|
return `${field.key} must be a JSON array of row objects`;
|
|
30595
31450
|
}
|
|
30596
|
-
const invalidRowIndex = value.findIndex((row) => !
|
|
31451
|
+
const invalidRowIndex = value.findIndex((row) => !isRecord13(row));
|
|
30597
31452
|
return invalidRowIndex >= 0 ? `${field.key}[${invalidRowIndex}] must be a row object` : null;
|
|
30598
31453
|
}
|
|
30599
31454
|
const selectorError = validateComplexSelector(field, value);
|
|
@@ -30619,7 +31474,7 @@ function validateType(field, value) {
|
|
|
30619
31474
|
if (/(array|multi|multiple)/.test(type) && !Array.isArray(value)) {
|
|
30620
31475
|
return `${field.key} must be an array`;
|
|
30621
31476
|
}
|
|
30622
|
-
if (isEnumSelectType(type) &&
|
|
31477
|
+
if (isEnumSelectType(type) && isRecord13(value)) {
|
|
30623
31478
|
const optionValue2 = value.value ?? value.label;
|
|
30624
31479
|
return typeof optionValue2 === "string" || typeof optionValue2 === "number" ? null : `${field.key} must be an enum option object with a scalar value`;
|
|
30625
31480
|
}
|
|
@@ -30649,7 +31504,7 @@ function validateFormEntries(form, fields, prefix = "") {
|
|
|
30649
31504
|
}
|
|
30650
31505
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
30651
31506
|
for (const [index, row] of value.entries()) {
|
|
30652
|
-
if (
|
|
31507
|
+
if (isRecord13(row)) {
|
|
30653
31508
|
errors.push(...validateFormEntries(row, field.children, `${prefix}${field.key}[${index}].`));
|
|
30654
31509
|
}
|
|
30655
31510
|
}
|
|
@@ -30727,7 +31582,7 @@ function explainFormValidationSchema(fields) {
|
|
|
30727
31582
|
}
|
|
30728
31583
|
|
|
30729
31584
|
// src/commands/step.ts
|
|
30730
|
-
function
|
|
31585
|
+
function isRecord14(value) {
|
|
30731
31586
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30732
31587
|
}
|
|
30733
31588
|
function stringValue4(value) {
|
|
@@ -30754,7 +31609,7 @@ function hasMeaningfulValue(value) {
|
|
|
30754
31609
|
if (Array.isArray(value)) {
|
|
30755
31610
|
return value.some(hasMeaningfulValue);
|
|
30756
31611
|
}
|
|
30757
|
-
if (
|
|
31612
|
+
if (isRecord14(value)) {
|
|
30758
31613
|
return Object.values(value).some(hasMeaningfulValue);
|
|
30759
31614
|
}
|
|
30760
31615
|
return false;
|
|
@@ -30763,7 +31618,7 @@ function isEmptyValue(value) {
|
|
|
30763
31618
|
return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
30764
31619
|
}
|
|
30765
31620
|
function projectIdOfStep(step) {
|
|
30766
|
-
const nestedProjectId =
|
|
31621
|
+
const nestedProjectId = isRecord14(step.project) ? step.project.id : void 0;
|
|
30767
31622
|
return idValue(step.project_id ?? step.projectId ?? nestedProjectId);
|
|
30768
31623
|
}
|
|
30769
31624
|
function stepFlowNodeId(step) {
|
|
@@ -30791,12 +31646,12 @@ function collectRecords(value, output = [], seen = /* @__PURE__ */ new Set()) {
|
|
|
30791
31646
|
value.forEach((item) => collectRecords(item, output, seen));
|
|
30792
31647
|
return output;
|
|
30793
31648
|
}
|
|
30794
|
-
if (!
|
|
31649
|
+
if (!isRecord14(value)) {
|
|
30795
31650
|
return output;
|
|
30796
31651
|
}
|
|
30797
31652
|
output.push(value);
|
|
30798
31653
|
for (const child of Object.values(value)) {
|
|
30799
|
-
if (Array.isArray(child) ||
|
|
31654
|
+
if (Array.isArray(child) || isRecord14(child)) {
|
|
30800
31655
|
collectRecords(child, output, seen);
|
|
30801
31656
|
}
|
|
30802
31657
|
}
|
|
@@ -30880,7 +31735,7 @@ function formListOfStep(step) {
|
|
|
30880
31735
|
return values.filter(hasMeaningfulValue);
|
|
30881
31736
|
}
|
|
30882
31737
|
function unwrapFormValue(value) {
|
|
30883
|
-
if (!
|
|
31738
|
+
if (!isRecord14(value)) {
|
|
30884
31739
|
return value;
|
|
30885
31740
|
}
|
|
30886
31741
|
if ("value" in value && Object.keys(value).length <= 3) {
|
|
@@ -30897,7 +31752,7 @@ function collectFormValues(value, output = {}, seen = /* @__PURE__ */ new Set())
|
|
|
30897
31752
|
value.forEach((item) => collectFormValues(item, output, seen));
|
|
30898
31753
|
return output;
|
|
30899
31754
|
}
|
|
30900
|
-
if (!
|
|
31755
|
+
if (!isRecord14(value)) {
|
|
30901
31756
|
return output;
|
|
30902
31757
|
}
|
|
30903
31758
|
const key = stringValue4(value.key ?? value.field_key ?? value.fieldKey ?? value.name);
|
|
@@ -30908,7 +31763,7 @@ function collectFormValues(value, output = {}, seen = /* @__PURE__ */ new Set())
|
|
|
30908
31763
|
}
|
|
30909
31764
|
}
|
|
30910
31765
|
for (const child of Object.values(value)) {
|
|
30911
|
-
if (Array.isArray(child) ||
|
|
31766
|
+
if (Array.isArray(child) || isRecord14(child)) {
|
|
30912
31767
|
collectFormValues(child, output, seen);
|
|
30913
31768
|
}
|
|
30914
31769
|
}
|
|
@@ -30955,7 +31810,7 @@ function collectMissingRequiredInputs(fields, values) {
|
|
|
30955
31810
|
continue;
|
|
30956
31811
|
}
|
|
30957
31812
|
value.forEach((row, index) => {
|
|
30958
|
-
if (!
|
|
31813
|
+
if (!isRecord14(row)) {
|
|
30959
31814
|
return;
|
|
30960
31815
|
}
|
|
30961
31816
|
for (const child of field.children ?? []) {
|
|
@@ -31009,7 +31864,7 @@ function ownerIdsFromStep(step) {
|
|
|
31009
31864
|
];
|
|
31010
31865
|
const ids = /* @__PURE__ */ new Set();
|
|
31011
31866
|
for (const owner of owners) {
|
|
31012
|
-
if (
|
|
31867
|
+
if (isRecord14(owner)) {
|
|
31013
31868
|
const id = idValue(owner.owner_id ?? owner.user_id ?? owner.id);
|
|
31014
31869
|
if (id) {
|
|
31015
31870
|
ids.add(id);
|
|
@@ -31048,7 +31903,7 @@ function ownerDiagnosticsFromStep(step, currentUser) {
|
|
|
31048
31903
|
const values = Array.isArray(value) ? value : [value];
|
|
31049
31904
|
for (const item of values) {
|
|
31050
31905
|
let id;
|
|
31051
|
-
if (
|
|
31906
|
+
if (isRecord14(item)) {
|
|
31052
31907
|
id = idValue(item.owner_id ?? item.user_id ?? item.id);
|
|
31053
31908
|
} else {
|
|
31054
31909
|
id = idValue(item);
|
|
@@ -31171,12 +32026,12 @@ function extractSubmitInputValues(data) {
|
|
|
31171
32026
|
const candidates = [data.form, data.form_data, data.formData, data.fields, data.values];
|
|
31172
32027
|
const values = {};
|
|
31173
32028
|
for (const candidate of candidates) {
|
|
31174
|
-
if (
|
|
32029
|
+
if (isRecord14(candidate)) {
|
|
31175
32030
|
Object.assign(values, candidate);
|
|
31176
32031
|
}
|
|
31177
32032
|
}
|
|
31178
32033
|
for (const [key, value] of Object.entries(data)) {
|
|
31179
|
-
if (!SUBMIT_NON_FORM_KEYS.has(key) && !
|
|
32034
|
+
if (!SUBMIT_NON_FORM_KEYS.has(key) && !isRecord14(value) && !Array.isArray(value)) {
|
|
31180
32035
|
values[key] = value;
|
|
31181
32036
|
}
|
|
31182
32037
|
}
|
|
@@ -31335,8 +32190,30 @@ async function requireE2eExecutionBinding(options, runners, evidenceDir) {
|
|
|
31335
32190
|
case_step_id: options.caseStepId
|
|
31336
32191
|
};
|
|
31337
32192
|
}
|
|
32193
|
+
function pathInside5(parent, child) {
|
|
32194
|
+
const relative = path19.relative(parent, child);
|
|
32195
|
+
return relative === "" || !relative.startsWith("..") && !path19.isAbsolute(relative);
|
|
32196
|
+
}
|
|
32197
|
+
async function requireIdentityBrowserBinding(options, evidenceDir) {
|
|
32198
|
+
if (!options.recordingSession) {
|
|
32199
|
+
return requireE2eExecutionBinding(options, ["identity"], evidenceDir);
|
|
32200
|
+
}
|
|
32201
|
+
if (options.diagnostic || options.executionManifest || options.caseId || options.caseStepId) {
|
|
32202
|
+
throw new Error("e2e.identity.browser.recording_binding_conflict: --recording-session \u4E0D\u80FD\u4E0E --diagnostic \u6216\u6B63\u5F0F execution manifest/case/step \u540C\u65F6\u4F7F\u7528\u3002");
|
|
32203
|
+
}
|
|
32204
|
+
const sessionDir = await ensureDir(options.recordingSession);
|
|
32205
|
+
const resolvedEvidenceDir = await ensureDir(evidenceDir);
|
|
32206
|
+
const [realSessionDir, realEvidenceDir] = await Promise.all([
|
|
32207
|
+
realpath8(sessionDir),
|
|
32208
|
+
realpath8(resolvedEvidenceDir)
|
|
32209
|
+
]);
|
|
32210
|
+
if (!pathInside5(realSessionDir, realEvidenceDir)) {
|
|
32211
|
+
throw new Error("e2e.identity.browser.recording_evidence_scope: identity evidence \u5FC5\u987B\u4F4D\u4E8E --recording-session \u76EE\u5F55\u5185\u3002");
|
|
32212
|
+
}
|
|
32213
|
+
return void 0;
|
|
32214
|
+
}
|
|
31338
32215
|
async function appendE2eExecutionEvidence(options, evidence, runners) {
|
|
31339
|
-
if (options.diagnostic || !options.executionManifest || !options.caseId || !options.caseStepId) return;
|
|
32216
|
+
if (options.diagnostic || options.recordingSession || !options.executionManifest || !options.caseId || !options.caseStepId) return;
|
|
31340
32217
|
const validated = await validateExecutionManifestStep({
|
|
31341
32218
|
manifest: options.executionManifest,
|
|
31342
32219
|
caseId: options.caseId,
|
|
@@ -31355,7 +32232,7 @@ async function appendE2eExecutionEvidence(options, evidence, runners) {
|
|
|
31355
32232
|
} catch {
|
|
31356
32233
|
continue;
|
|
31357
32234
|
}
|
|
31358
|
-
if (!
|
|
32235
|
+
if (!isRecord15(value)) continue;
|
|
31359
32236
|
if (value.run_id === validated.manifest.run_id && value.evidence_nonce === validated.manifest.evidence_nonce && value.case_id === options.caseId && value.case_step_id === options.caseStepId) {
|
|
31360
32237
|
matchedBinding = true;
|
|
31361
32238
|
}
|
|
@@ -31371,7 +32248,7 @@ async function appendE2eExecutionEvidence(options, evidence, runners) {
|
|
|
31371
32248
|
runners
|
|
31372
32249
|
});
|
|
31373
32250
|
}
|
|
31374
|
-
function
|
|
32251
|
+
function isRecord15(value) {
|
|
31375
32252
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31376
32253
|
}
|
|
31377
32254
|
function stringValue5(value) {
|
|
@@ -31403,7 +32280,7 @@ async function writeEvidence(dir, name, value) {
|
|
|
31403
32280
|
return file;
|
|
31404
32281
|
}
|
|
31405
32282
|
function summarizeRemoteResult(value) {
|
|
31406
|
-
if (!
|
|
32283
|
+
if (!isRecord15(value)) return value;
|
|
31407
32284
|
const summary = {};
|
|
31408
32285
|
for (const key of ["id", "project_id", "step_id", "status", "state", "code", "msg", "message", "next", "action"]) {
|
|
31409
32286
|
if (value[key] !== void 0) summary[key] = value[key];
|
|
@@ -31411,10 +32288,10 @@ function summarizeRemoteResult(value) {
|
|
|
31411
32288
|
return Object.keys(summary).length > 0 ? redactAuditValue(summary) : { received: true };
|
|
31412
32289
|
}
|
|
31413
32290
|
function stepReadbackConfirmed(before, after) {
|
|
31414
|
-
const beforeStatus =
|
|
31415
|
-
const afterStatus =
|
|
31416
|
-
const beforeProjectStep =
|
|
31417
|
-
const afterProjectStep =
|
|
32291
|
+
const beforeStatus = isRecord15(before.step) ? before.step.status : void 0;
|
|
32292
|
+
const afterStatus = isRecord15(after.step) ? after.step.status : void 0;
|
|
32293
|
+
const beforeProjectStep = isRecord15(before.project) ? before.project.current_flow_step_id : void 0;
|
|
32294
|
+
const afterProjectStep = isRecord15(after.project) ? after.project.current_flow_step_id : void 0;
|
|
31418
32295
|
return after.step_finished === true || beforeStatus !== afterStatus || beforeProjectStep !== afterProjectStep;
|
|
31419
32296
|
}
|
|
31420
32297
|
function evidenceMime(buffer, file) {
|
|
@@ -31441,7 +32318,7 @@ async function writeEvidenceManifest(evidenceDir, details, extraFiles = []) {
|
|
|
31441
32318
|
artifacts.push({
|
|
31442
32319
|
path: relativePath,
|
|
31443
32320
|
size: buffer.length,
|
|
31444
|
-
sha256:
|
|
32321
|
+
sha256: createHash13("sha256").update(buffer).digest("hex"),
|
|
31445
32322
|
mime_type: mimeType,
|
|
31446
32323
|
...expectedMime && expectedMime !== mimeType ? { extension_mismatch: true, expected_mime: expectedMime } : {}
|
|
31447
32324
|
});
|
|
@@ -31461,7 +32338,7 @@ function safeSegment(value) {
|
|
|
31461
32338
|
return value.trim().replace(/[^a-zA-Z0-9._:-]+/g, "_") || "default";
|
|
31462
32339
|
}
|
|
31463
32340
|
function safeIdentity2(value) {
|
|
31464
|
-
if (!
|
|
32341
|
+
if (!isRecord15(value)) return null;
|
|
31465
32342
|
const id = Number(value.id);
|
|
31466
32343
|
if (!Number.isSafeInteger(id) || id <= 0) return null;
|
|
31467
32344
|
return {
|
|
@@ -31513,14 +32390,14 @@ async function browserSessionRequest(profile, cookie, method, apiPath2, data, hr
|
|
|
31513
32390
|
response.status
|
|
31514
32391
|
);
|
|
31515
32392
|
}
|
|
31516
|
-
if (
|
|
32393
|
+
if (isRecord15(body) && typeof body.code === "number" && body.code !== 0) {
|
|
31517
32394
|
throw new BrowserSessionRejectedError(
|
|
31518
32395
|
`e2e.identity.api_error: ${String(body.msg ?? body.message ?? body.code)}`,
|
|
31519
32396
|
response.status,
|
|
31520
32397
|
body.code
|
|
31521
32398
|
);
|
|
31522
32399
|
}
|
|
31523
|
-
return
|
|
32400
|
+
return isRecord15(body) && Object.prototype.hasOwnProperty.call(body, "data") ? body.data : body;
|
|
31524
32401
|
}
|
|
31525
32402
|
function identityCookie(cookieEnv) {
|
|
31526
32403
|
const cookie = process.env[cookieEnv]?.trim();
|
|
@@ -31562,7 +32439,7 @@ function assertRestoredIdentity(before, after, errorCode) {
|
|
|
31562
32439
|
function requireLegacyIdentityDiagnostic(options) {
|
|
31563
32440
|
if (!options.diagnostic) {
|
|
31564
32441
|
throw new Error(
|
|
31565
|
-
"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\
|
|
32442
|
+
"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\u7531 `e2e scenario execute` \u5728\u5F53\u524D Playwright session \u4E2D\u6267\u884C identity step\u3002"
|
|
31566
32443
|
);
|
|
31567
32444
|
}
|
|
31568
32445
|
if (options.executionManifest || options.caseId || options.caseStepId) {
|
|
@@ -31574,6 +32451,7 @@ function requireLegacyIdentityDiagnostic(options) {
|
|
|
31574
32451
|
function identityBridgeBinding(options) {
|
|
31575
32452
|
return {
|
|
31576
32453
|
diagnostic: options.diagnostic === true,
|
|
32454
|
+
...options.recordingSession ? { recording_session: path19.resolve(options.recordingSession) } : {},
|
|
31577
32455
|
...options.executionManifest ? { execution_manifest: path19.resolve(options.executionManifest) } : {},
|
|
31578
32456
|
...options.caseId ? { case_id: options.caseId } : {},
|
|
31579
32457
|
...options.caseStepId ? { case_step_id: options.caseStepId } : {}
|
|
@@ -31581,7 +32459,7 @@ function identityBridgeBinding(options) {
|
|
|
31581
32459
|
}
|
|
31582
32460
|
function identityLeaseFile(options, evidenceDir) {
|
|
31583
32461
|
return path19.join(
|
|
31584
|
-
options.executionManifest ? path19.dirname(path19.resolve(options.executionManifest)) : path19.resolve(evidenceDir),
|
|
32462
|
+
options.executionManifest ? path19.dirname(path19.resolve(options.executionManifest)) : options.recordingSession ? path19.resolve(options.recordingSession) : path19.resolve(evidenceDir),
|
|
31585
32463
|
"identity-lease.json"
|
|
31586
32464
|
);
|
|
31587
32465
|
}
|
|
@@ -31594,7 +32472,7 @@ async function identityBridgeTargetUser(profile, userId) {
|
|
|
31594
32472
|
},
|
|
31595
32473
|
capability: "user.readback"
|
|
31596
32474
|
});
|
|
31597
|
-
const rows2 = Array.isArray(result) ? result.filter(
|
|
32475
|
+
const rows2 = Array.isArray(result) ? result.filter(isRecord15) : isRecord15(result) && Array.isArray(result.data) ? result.data.filter(isRecord15) : isRecord15(result) && result.id !== void 0 ? [result] : [];
|
|
31598
32476
|
const matched = rows2.find((item) => Number(item.id) === userId);
|
|
31599
32477
|
if (!matched) throw new Error(`e2e.identity.browser.target_not_found: typed user readback \u672A\u627E\u5230\u7528\u6237 ${userId}\u3002`);
|
|
31600
32478
|
const name = stringValue5(matched.name);
|
|
@@ -31635,7 +32513,7 @@ function valuesEqual(left, right) {
|
|
|
31635
32513
|
}
|
|
31636
32514
|
function pathValue(source, dottedPath) {
|
|
31637
32515
|
return dottedPath.split(".").reduce((current, segment) => {
|
|
31638
|
-
if (!
|
|
32516
|
+
if (!isRecord15(current)) {
|
|
31639
32517
|
return void 0;
|
|
31640
32518
|
}
|
|
31641
32519
|
return current[segment];
|
|
@@ -31645,7 +32523,7 @@ function normalizeExpectedChecks(value) {
|
|
|
31645
32523
|
if (!Array.isArray(value)) {
|
|
31646
32524
|
return [];
|
|
31647
32525
|
}
|
|
31648
|
-
return value.filter(
|
|
32526
|
+
return value.filter(isRecord15).map((item) => ({
|
|
31649
32527
|
...stringValue5(item.name) ? { name: stringValue5(item.name) } : {},
|
|
31650
32528
|
path: stringValue5(item.path) ?? "",
|
|
31651
32529
|
op: stringValue5(item.op) ?? "equals",
|
|
@@ -31726,7 +32604,7 @@ async function readOptionalJson(file) {
|
|
|
31726
32604
|
try {
|
|
31727
32605
|
const raw = await readFile18(file, "utf8");
|
|
31728
32606
|
const parsed = JSON.parse(raw);
|
|
31729
|
-
return
|
|
32607
|
+
return isRecord15(parsed) ? parsed : null;
|
|
31730
32608
|
} catch (error) {
|
|
31731
32609
|
if (error.code === "ENOENT") {
|
|
31732
32610
|
return null;
|
|
@@ -31753,11 +32631,11 @@ function stepsFromProfile(profile) {
|
|
|
31753
32631
|
}
|
|
31754
32632
|
const steps = profile.steps;
|
|
31755
32633
|
if (Array.isArray(steps)) {
|
|
31756
|
-
return steps.filter(
|
|
32634
|
+
return steps.filter(isRecord15);
|
|
31757
32635
|
}
|
|
31758
|
-
if (
|
|
32636
|
+
if (isRecord15(steps)) {
|
|
31759
32637
|
return Object.entries(steps).map(([stepId, value]) => ({
|
|
31760
|
-
...
|
|
32638
|
+
...isRecord15(value) ? value : { data: value },
|
|
31761
32639
|
step_id: stepId
|
|
31762
32640
|
}));
|
|
31763
32641
|
}
|
|
@@ -31769,7 +32647,7 @@ function normalizeStepPlan(input, defaults) {
|
|
|
31769
32647
|
throw new Error("e2e step-run requires --step-id or data-profile steps[].step_id.");
|
|
31770
32648
|
}
|
|
31771
32649
|
const rawData = input.data ?? input.payload_template ?? input.payloadTemplate ?? input.form ?? input.values ?? {};
|
|
31772
|
-
const data =
|
|
32650
|
+
const data = isRecord15(rawData) ? rawData : {};
|
|
31773
32651
|
return {
|
|
31774
32652
|
step_id: stepId,
|
|
31775
32653
|
action: stringValue5(input.action) ?? defaults.action,
|
|
@@ -31935,10 +32813,10 @@ async function writeBrowserRecordingReport(options) {
|
|
|
31935
32813
|
const evidenceDir = path19.resolve(options.evidenceDir);
|
|
31936
32814
|
const tracePath = path19.join(evidenceDir, "browser-action-trace.json");
|
|
31937
32815
|
const trace = await readOptionalJson(tracePath);
|
|
31938
|
-
if (!trace || !
|
|
32816
|
+
if (!trace || !isRecord15(trace) || !Array.isArray(trace.actions) || !Array.isArray(trace.expected_checks) || !isRecord15(trace.page_fingerprint)) {
|
|
31939
32817
|
throw new Error("browser-action-trace.json must contain page_fingerprint, actions, and expected_checks before a recording report can be generated");
|
|
31940
32818
|
}
|
|
31941
|
-
const traceSha256 =
|
|
32819
|
+
const traceSha256 = createHash13("sha256").update(await readFile18(tracePath)).digest("hex");
|
|
31942
32820
|
const files = (await readdir6(evidenceDir).catch(() => [])).filter((file) => file !== "browser-recording-report.json").sort();
|
|
31943
32821
|
const report = {
|
|
31944
32822
|
version: 1,
|
|
@@ -31956,7 +32834,7 @@ async function writeBrowserRecordingReport(options) {
|
|
|
31956
32834
|
page_fingerprint: trace.page_fingerprint,
|
|
31957
32835
|
action_count: trace.actions.length,
|
|
31958
32836
|
expected_check_count: trace.expected_checks.length,
|
|
31959
|
-
contains_mutation: trace.actions.some((action) =>
|
|
32837
|
+
contains_mutation: trace.actions.some((action) => isRecord15(action) && action.mutation === true),
|
|
31960
32838
|
artifacts: {
|
|
31961
32839
|
screenshots: files.filter((file) => /\.(?:png|jpe?g|webp)$/i.test(file)),
|
|
31962
32840
|
dom: files.filter((file) => /(?:dom|snapshot).*(?:\.json|\.txt|\.html)$/i.test(file)),
|
|
@@ -31968,7 +32846,7 @@ async function writeBrowserRecordingReport(options) {
|
|
|
31968
32846
|
const reportPath = path19.join(evidenceDir, "browser-recording-report.json");
|
|
31969
32847
|
await writeFile14(reportPath, `${JSON.stringify(report, null, 2)}
|
|
31970
32848
|
`, "utf8");
|
|
31971
|
-
const reportSha256 =
|
|
32849
|
+
const reportSha256 = createHash13("sha256").update(await readFile18(reportPath)).digest("hex");
|
|
31972
32850
|
return { path: reportPath, sha256: reportSha256, tracePath, traceSha256, report };
|
|
31973
32851
|
}
|
|
31974
32852
|
async function updateAutomationFromRecordedTrace(options) {
|
|
@@ -31977,7 +32855,7 @@ async function updateAutomationFromRecordedTrace(options) {
|
|
|
31977
32855
|
}
|
|
31978
32856
|
const recording = options.recording ?? await writeBrowserRecordingReport(options);
|
|
31979
32857
|
const trace = await readOptionalJson(recording.tracePath);
|
|
31980
|
-
if (!trace || !
|
|
32858
|
+
if (!trace || !isRecord15(trace) || !Array.isArray(trace.actions) || !Array.isArray(trace.expected_checks) || !isRecord15(trace.page_fingerprint)) {
|
|
31981
32859
|
throw new Error("browser recording report source trace is missing or invalid");
|
|
31982
32860
|
}
|
|
31983
32861
|
const out = path19.resolve(options.automationOut);
|
|
@@ -31985,7 +32863,7 @@ async function updateAutomationFromRecordedTrace(options) {
|
|
|
31985
32863
|
throw new Error("--automation-out writes a review candidate only; write it under .codex/tmp and merge it into an automation compile input before compile/review/promote");
|
|
31986
32864
|
}
|
|
31987
32865
|
const existing = await readOptionalJson(out);
|
|
31988
|
-
const document2 = existing &&
|
|
32866
|
+
const document2 = existing && isRecord15(existing) ? existing.kind === "bpmax_e2e_recorded_automation_candidate" ? existing : (() => {
|
|
31989
32867
|
throw new Error("existing --automation-out file is not a bpmax_e2e_recorded_automation_candidate");
|
|
31990
32868
|
})() : {
|
|
31991
32869
|
version: 1,
|
|
@@ -31995,12 +32873,36 @@ async function updateAutomationFromRecordedTrace(options) {
|
|
|
31995
32873
|
source_basis: [],
|
|
31996
32874
|
steps: {}
|
|
31997
32875
|
};
|
|
31998
|
-
|
|
32876
|
+
const provenance = options.profile ? {
|
|
32877
|
+
profile: options.profile.name,
|
|
32878
|
+
origin: options.profile.config.origin,
|
|
32879
|
+
workspace: normalizeWorkspaceForApi(options.profile.config.workspace) || "default"
|
|
32880
|
+
} : void 0;
|
|
32881
|
+
if (document2.provenance !== void 0 && !isRecord15(document2.provenance)) {
|
|
32882
|
+
throw new Error("existing --automation-out provenance must be an object");
|
|
32883
|
+
}
|
|
32884
|
+
if (isRecord15(document2.provenance)) {
|
|
32885
|
+
const existingProvenance = {
|
|
32886
|
+
profile: stringValue5(document2.provenance.profile),
|
|
32887
|
+
origin: stringValue5(document2.provenance.origin),
|
|
32888
|
+
workspace: stringValue5(document2.provenance.workspace)
|
|
32889
|
+
};
|
|
32890
|
+
if (!provenance) {
|
|
32891
|
+
throw new Error(`existing --automation-out is bound to profile ${existingProvenance.profile || "(unknown)"}; pass a matching --profile`);
|
|
32892
|
+
}
|
|
32893
|
+
if (existingProvenance.profile !== provenance.profile || existingProvenance.origin !== provenance.origin || existingProvenance.workspace !== provenance.workspace) {
|
|
32894
|
+
throw new Error(`existing --automation-out provenance does not match --profile ${provenance.profile}`);
|
|
32895
|
+
}
|
|
32896
|
+
}
|
|
32897
|
+
if (provenance) {
|
|
32898
|
+
document2.provenance = provenance;
|
|
32899
|
+
}
|
|
32900
|
+
if (!isRecord15(document2.steps)) document2.steps = {};
|
|
31999
32901
|
const sourceBasis = `browser_recording_report:${recording.path}#sha256=${recording.sha256}`;
|
|
32000
32902
|
document2.steps[automationStepKey(options.caseId, options.caseStepId)] = {
|
|
32001
32903
|
recording_report: recording.path,
|
|
32002
32904
|
recording_report_sha256: recording.sha256,
|
|
32003
|
-
...
|
|
32905
|
+
...isRecord15(recording.report.recording_job) ? { recording_job: recording.report.recording_job } : {},
|
|
32004
32906
|
source_trace: recording.tracePath,
|
|
32005
32907
|
source_trace_sha256: recording.traceSha256,
|
|
32006
32908
|
review_status: "review_required",
|
|
@@ -32048,7 +32950,7 @@ function scenarioRecords(plan) {
|
|
|
32048
32950
|
if (!Array.isArray(records)) {
|
|
32049
32951
|
return [];
|
|
32050
32952
|
}
|
|
32051
|
-
return records.filter(
|
|
32953
|
+
return records.filter(isRecord15);
|
|
32052
32954
|
}
|
|
32053
32955
|
function recordKey(record, index) {
|
|
32054
32956
|
return stringValue5(record.demo_no ?? record.id ?? record.case_id ?? record.subject) ?? `record-${index + 1}`;
|
|
@@ -32241,14 +33143,14 @@ function registerE2eCommands(program2) {
|
|
|
32241
33143
|
});
|
|
32242
33144
|
});
|
|
32243
33145
|
const identityBrowser = identity.command("browser").description("Prepare and verify Chrome Control identity switching without exporting browser Cookie");
|
|
32244
|
-
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");
|
|
33146
|
+
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("--recording-session <dir>", "Reviewed recording session root; recording-only and cannot become pass evidence").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");
|
|
32245
33147
|
const registerIdentityBrowserPrepare = (operation, command) => {
|
|
32246
33148
|
addIdentityBrowserPrepareOptions(command).action(async (options) => {
|
|
32247
33149
|
const targetUserId = options.userId === void 0 ? void 0 : Number(options.userId);
|
|
32248
33150
|
if (operation === "mock" && (!Number.isSafeInteger(targetUserId) || Number(targetUserId) <= 0)) {
|
|
32249
33151
|
throw new Error("e2e.identity.browser.invalid_user_id: --user-id \u5FC5\u987B\u662F\u6B63\u6574\u6570\u3002");
|
|
32250
33152
|
}
|
|
32251
|
-
await
|
|
33153
|
+
await requireIdentityBrowserBinding(options, options.evidenceDir);
|
|
32252
33154
|
const evidenceDir = await ensureDir(options.evidenceDir);
|
|
32253
33155
|
const config = await loadConfig();
|
|
32254
33156
|
const profile = resolveProfile(config, options.profile);
|
|
@@ -32282,6 +33184,8 @@ function registerE2eCommands(program2) {
|
|
|
32282
33184
|
lease_file: prepared.lease_file,
|
|
32283
33185
|
lease_expires_at: prepared.request.lease.expires_at ?? null,
|
|
32284
33186
|
...targetUser ? { target_user: targetUser } : {},
|
|
33187
|
+
recording_only: Boolean(options.recordingSession),
|
|
33188
|
+
formal_conclusion: false,
|
|
32285
33189
|
helper: "bpmax-user-mock-operator/scripts/chrome_identity_bridge.mjs",
|
|
32286
33190
|
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>`."
|
|
32287
33191
|
});
|
|
@@ -32306,9 +33210,11 @@ function registerE2eCommands(program2) {
|
|
|
32306
33210
|
profile: request.binding.profile,
|
|
32307
33211
|
executionManifest: request.binding.execution_manifest,
|
|
32308
33212
|
caseId: request.binding.case_id,
|
|
32309
|
-
caseStepId: request.binding.case_step_id
|
|
33213
|
+
caseStepId: request.binding.case_step_id,
|
|
33214
|
+
recordingSession: request.binding.recording_session
|
|
32310
33215
|
};
|
|
32311
|
-
const
|
|
33216
|
+
const formalBinding = await requireIdentityBrowserBinding(executionOptions, request.evidence_dir);
|
|
33217
|
+
const binding = formalBinding ?? (request.binding.recording_session ? { recording_only: true, recording_session: request.binding.recording_session } : void 0);
|
|
32312
33218
|
const config = await loadConfig();
|
|
32313
33219
|
const profile = resolveProfile(config, request.binding.profile);
|
|
32314
33220
|
const profileOrigin = new URL(profile.config.origin).origin;
|
|
@@ -32347,6 +33253,8 @@ function registerE2eCommands(program2) {
|
|
|
32347
33253
|
readback_confirmed: completed.evidence.readback_confirmed,
|
|
32348
33254
|
current_user: completed.evidence.current_user,
|
|
32349
33255
|
lease: completed.lease,
|
|
33256
|
+
recording_only: Boolean(request.binding.recording_session),
|
|
33257
|
+
formal_conclusion: false,
|
|
32350
33258
|
evidence,
|
|
32351
33259
|
evidence_manifest: evidenceManifest,
|
|
32352
33260
|
receipt
|
|
@@ -32355,8 +33263,8 @@ function registerE2eCommands(program2) {
|
|
|
32355
33263
|
await releaseIdentityBrowserRequestCompletionClaim(claim);
|
|
32356
33264
|
}
|
|
32357
33265
|
});
|
|
32358
|
-
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) => {
|
|
32359
|
-
const leaseFile = identityLeaseFile({ executionManifest: options.executionManifest }, options.evidenceDir);
|
|
33266
|
+
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("--recording-session <dir>", "Reviewed recording session root").option("--evidence-dir <dir>", "Diagnostic evidence directory", ".codex/tmp/e2e/identity").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
33267
|
+
const leaseFile = identityLeaseFile({ executionManifest: options.executionManifest, recordingSession: options.recordingSession }, options.evidenceDir);
|
|
32360
33268
|
const lease = await identityLeaseStatus(leaseFile);
|
|
32361
33269
|
printResult(options.format, {
|
|
32362
33270
|
ok: true,
|
|
@@ -32651,7 +33559,7 @@ function registerE2eCommands(program2) {
|
|
|
32651
33559
|
throw new Error(`Flow ${options.flowId} was not found.`);
|
|
32652
33560
|
}
|
|
32653
33561
|
const sourceUpdateTime = stringValue5(result.update_time ?? result.updateTime ?? result.updated_at ?? result.updatedAt);
|
|
32654
|
-
const cacheKey =
|
|
33562
|
+
const cacheKey = createHash13("sha256").update(JSON.stringify({
|
|
32655
33563
|
flow_id: options.flowId,
|
|
32656
33564
|
update_time: sourceUpdateTime,
|
|
32657
33565
|
template_id: result.template_id ?? result.templateId
|
|
@@ -32695,7 +33603,8 @@ function registerE2eCommands(program2) {
|
|
|
32695
33603
|
next_command: `npx playwright test ${generated.out}`
|
|
32696
33604
|
});
|
|
32697
33605
|
});
|
|
32698
|
-
e2e.command("record-from-evidence").description("Create a reusable E2E template from an evidence directory").option("--project-id <projectId>", "Project id for step evidence").option("--step-id <stepId>", "Step id for step evidence").requiredOption("--evidence-dir <dir>", "Evidence directory").requiredOption("--out <file>", "Template output JSON").option("--automation-out <file>", "Write a review-required automation candidate under .codex/tmp").option("--recording-job <file>", "Completed automation checkpoint receipt for the recorded case step").option("--scenario <id>", "Scenario id stored in a newly created automation.json").option("--name <name>", "Template 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("--format <format>", "Output format", "json").action(async (options) => {
|
|
33606
|
+
e2e.command("record-from-evidence").description("Create a reusable E2E template from an evidence directory").option("--profile <profile>", "Profile name recorded in generated asset provenance").option("--project-id <projectId>", "Project id for step evidence").option("--step-id <stepId>", "Step id for step evidence").requiredOption("--evidence-dir <dir>", "Evidence directory").requiredOption("--out <file>", "Template output JSON").option("--automation-out <file>", "Write a review-required automation candidate under .codex/tmp").option("--recording-job <file>", "Completed automation checkpoint receipt for the recorded case step").option("--scenario <id>", "Scenario id stored in a newly created automation.json").option("--name <name>", "Template 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("--format <format>", "Output format", "json").action(async (options) => {
|
|
33607
|
+
const resolvedProfile = options.profile ? resolveProfile(await loadConfig(), options.profile) : void 0;
|
|
32699
33608
|
const binding = await requireE2eExecutionBinding(options, ["browser", "browser_action", "e2e_create_page", "e2e_step_run", "observe"]);
|
|
32700
33609
|
let recordingJob;
|
|
32701
33610
|
if (options.recordingJob) {
|
|
@@ -32713,7 +33622,7 @@ function registerE2eCommands(program2) {
|
|
|
32713
33622
|
}
|
|
32714
33623
|
recordingJob = {
|
|
32715
33624
|
path: recordingJobPath,
|
|
32716
|
-
sha256:
|
|
33625
|
+
sha256: createHash13("sha256").update(raw).digest("hex"),
|
|
32717
33626
|
record
|
|
32718
33627
|
};
|
|
32719
33628
|
}
|
|
@@ -32726,10 +33635,10 @@ function registerE2eCommands(program2) {
|
|
|
32726
33635
|
}
|
|
32727
33636
|
const context2 = contextFile ? await readOptionalJson(path19.join(options.evidenceDir, contextFile)) : null;
|
|
32728
33637
|
const submit = submitFile ? await readOptionalJson(path19.join(options.evidenceDir, submitFile)) : null;
|
|
32729
|
-
const requirements =
|
|
32730
|
-
const requiredInputs = Array.isArray(requirements.required_inputs) ? requirements.required_inputs.filter(
|
|
32731
|
-
const missingInputs = Array.isArray(requirements.missing_required_inputs) ? requirements.missing_required_inputs.filter(
|
|
32732
|
-
const requestData =
|
|
33638
|
+
const requirements = isRecord15(context2?.requirements) ? context2.requirements : {};
|
|
33639
|
+
const requiredInputs = Array.isArray(requirements.required_inputs) ? requirements.required_inputs.filter(isRecord15) : [];
|
|
33640
|
+
const missingInputs = Array.isArray(requirements.missing_required_inputs) ? requirements.missing_required_inputs.filter(isRecord15) : [];
|
|
33641
|
+
const requestData = isRecord15(submit?.request) && isRecord15(submit.request.data) ? submit.request.data : {};
|
|
32733
33642
|
const recordedAction = stringValue5(requestData.action);
|
|
32734
33643
|
const expectedChecks = buildExpectedChecks({
|
|
32735
33644
|
context: context2,
|
|
@@ -32755,6 +33664,13 @@ function registerE2eCommands(program2) {
|
|
|
32755
33664
|
const template = hasStepEvidence ? {
|
|
32756
33665
|
...binding,
|
|
32757
33666
|
...recordingJob ? { recording_job: { path: recordingJob.path, sha256: recordingJob.sha256 } } : {},
|
|
33667
|
+
...resolvedProfile ? {
|
|
33668
|
+
provenance: {
|
|
33669
|
+
profile: resolvedProfile.name,
|
|
33670
|
+
origin: resolvedProfile.config.origin,
|
|
33671
|
+
workspace: normalizeWorkspaceForApi(resolvedProfile.config.workspace) || "default"
|
|
33672
|
+
}
|
|
33673
|
+
} : {},
|
|
32758
33674
|
name: options.name ?? `step-${inferredStepId}`,
|
|
32759
33675
|
...options.projectId ? { project_id: options.projectId } : {},
|
|
32760
33676
|
...inferredStepId ? { step_id: inferredStepId } : {},
|
|
@@ -32777,6 +33693,13 @@ function registerE2eCommands(program2) {
|
|
|
32777
33693
|
} : {
|
|
32778
33694
|
...binding,
|
|
32779
33695
|
...recordingJob ? { recording_job: { path: recordingJob.path, sha256: recordingJob.sha256 } } : {},
|
|
33696
|
+
...resolvedProfile ? {
|
|
33697
|
+
provenance: {
|
|
33698
|
+
profile: resolvedProfile.name,
|
|
33699
|
+
origin: resolvedProfile.config.origin,
|
|
33700
|
+
workspace: normalizeWorkspaceForApi(resolvedProfile.config.workspace) || "default"
|
|
33701
|
+
}
|
|
33702
|
+
} : {},
|
|
32780
33703
|
name: options.name ?? path19.basename(path19.resolve(options.evidenceDir)),
|
|
32781
33704
|
generated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
32782
33705
|
submit_mode: "browser_evidence_bootstrap",
|
|
@@ -32811,7 +33734,8 @@ function registerE2eCommands(program2) {
|
|
|
32811
33734
|
scenario: options.scenario,
|
|
32812
33735
|
caseId: options.caseId,
|
|
32813
33736
|
caseStepId: options.caseStepId,
|
|
32814
|
-
recording
|
|
33737
|
+
recording,
|
|
33738
|
+
profile: resolvedProfile
|
|
32815
33739
|
}) : void 0;
|
|
32816
33740
|
await appendE2eExecutionEvidence(options, out, ["browser", "browser_action", "e2e_create_page", "e2e_step_run", "observe"]);
|
|
32817
33741
|
printResult(options.format, {
|
|
@@ -32904,11 +33828,11 @@ function registerE2eCommands(program2) {
|
|
|
32904
33828
|
}
|
|
32905
33829
|
|
|
32906
33830
|
// src/core/project-search.ts
|
|
32907
|
-
function
|
|
33831
|
+
function isRecord16(value) {
|
|
32908
33832
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32909
33833
|
}
|
|
32910
33834
|
function hasRawProjectSearchBody(value) {
|
|
32911
|
-
return
|
|
33835
|
+
return isRecord16(value) && Object.prototype.hasOwnProperty.call(value, "body");
|
|
32912
33836
|
}
|
|
32913
33837
|
function assertProjectSearchBody(value) {
|
|
32914
33838
|
if (hasRawProjectSearchBody(value)) {
|
|
@@ -33717,20 +34641,20 @@ function isEmptyApproverValue(value) {
|
|
|
33717
34641
|
function shellQuote7(value) {
|
|
33718
34642
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
33719
34643
|
}
|
|
33720
|
-
var
|
|
34644
|
+
var isRecord17 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33721
34645
|
function dataArray(value) {
|
|
33722
34646
|
if (Array.isArray(value)) return value;
|
|
33723
|
-
if (
|
|
33724
|
-
if (
|
|
33725
|
-
if (
|
|
34647
|
+
if (isRecord17(value) && Array.isArray(value.data)) return value.data;
|
|
34648
|
+
if (isRecord17(value) && Array.isArray(value.list)) return value.list;
|
|
34649
|
+
if (isRecord17(value) && Array.isArray(value.rows)) return value.rows;
|
|
33726
34650
|
return [];
|
|
33727
34651
|
}
|
|
33728
34652
|
function predictedNodes(value) {
|
|
33729
|
-
if (!
|
|
33730
|
-
return dataArray(value.predicted_nodes).filter(
|
|
34653
|
+
if (!isRecord17(value)) return [];
|
|
34654
|
+
return dataArray(value.predicted_nodes).filter(isRecord17);
|
|
33731
34655
|
}
|
|
33732
34656
|
function safePredictedOwners(value) {
|
|
33733
|
-
return (Array.isArray(value) ? value : []).filter(
|
|
34657
|
+
return (Array.isArray(value) ? value : []).filter(isRecord17).map((owner) => ({
|
|
33734
34658
|
id: owner.id ?? owner.user_id ?? owner.owner_id,
|
|
33735
34659
|
name: owner.name ?? null
|
|
33736
34660
|
}));
|
|
@@ -33745,7 +34669,7 @@ async function fetchAllMatrixRuleRecords(client, flowType) {
|
|
|
33745
34669
|
data: { flow_type: flowType, page, page_size: pageSize },
|
|
33746
34670
|
capability: "project.list"
|
|
33747
34671
|
});
|
|
33748
|
-
const rows2 = dataArray(result).filter(
|
|
34672
|
+
const rows2 = dataArray(result).filter(isRecord17);
|
|
33749
34673
|
records.push(...rows2);
|
|
33750
34674
|
const total = Number(result.count ?? result.total ?? records.length);
|
|
33751
34675
|
if (rows2.length < pageSize || records.length >= total) break;
|
|
@@ -33764,7 +34688,7 @@ async function hydrateMatrixRuleRecords(client, records) {
|
|
|
33764
34688
|
for (let index = 0; index < records.length; index += 10) {
|
|
33765
34689
|
const chunk = records.slice(index, index + 10);
|
|
33766
34690
|
hydrated.push(...await Promise.all(chunk.map(async (record) => {
|
|
33767
|
-
if (
|
|
34691
|
+
if (isRecord17(record.metaForm) || Array.isArray(record.formList)) return record;
|
|
33768
34692
|
const id = Number(record.id ?? record.project_id);
|
|
33769
34693
|
return Number.isSafeInteger(id) && id > 0 ? apiRequest(client, "GET", `/project/${id}`) : record;
|
|
33770
34694
|
})));
|
|
@@ -33775,7 +34699,7 @@ function collectMatrixOwnerPaths(value, path25 = "$") {
|
|
|
33775
34699
|
if (Array.isArray(value)) {
|
|
33776
34700
|
return value.flatMap((item, index) => collectMatrixOwnerPaths(item, `${path25}[${index}]`));
|
|
33777
34701
|
}
|
|
33778
|
-
if (!
|
|
34702
|
+
if (!isRecord17(value)) {
|
|
33779
34703
|
return [];
|
|
33780
34704
|
}
|
|
33781
34705
|
const matches = [];
|
|
@@ -33789,25 +34713,25 @@ function collectMatrixOwnerPaths(value, path25 = "$") {
|
|
|
33789
34713
|
return matches;
|
|
33790
34714
|
}
|
|
33791
34715
|
function projectFormKeys(project) {
|
|
33792
|
-
const metaForm =
|
|
34716
|
+
const metaForm = isRecord17(project.metaForm) ? project.metaForm : {};
|
|
33793
34717
|
const values = dataArray(metaForm.value ?? project.formList);
|
|
33794
|
-
return values.filter(
|
|
34718
|
+
return values.filter(isRecord17).map((item) => String(item.key ?? item.field_key ?? "")).filter(Boolean);
|
|
33795
34719
|
}
|
|
33796
34720
|
function findFlowNode2(flow, nodeId) {
|
|
33797
|
-
const data =
|
|
33798
|
-
return dataArray(data.nodes).filter(
|
|
34721
|
+
const data = isRecord17(flow.data) ? flow.data : {};
|
|
34722
|
+
return dataArray(data.nodes).filter(isRecord17).find((node) => String(node.id ?? node.key ?? node.flow_step_id ?? "") === nodeId);
|
|
33799
34723
|
}
|
|
33800
34724
|
function flowCategory(flow) {
|
|
33801
|
-
const data =
|
|
33802
|
-
const meta =
|
|
34725
|
+
const data = isRecord17(flow.data) ? flow.data : {};
|
|
34726
|
+
const meta = isRecord17(data.meta) ? data.meta : {};
|
|
33803
34727
|
return String(flow.category ?? data.category ?? meta.category ?? "");
|
|
33804
34728
|
}
|
|
33805
34729
|
function hasIdentifier(value) {
|
|
33806
34730
|
return value !== void 0 && value !== null && String(value).trim() !== "" && String(value) !== "0";
|
|
33807
34731
|
}
|
|
33808
34732
|
function matrixAppSummary(flow, listTemplates = [], filterTemplates = [], datasets = [], workspaceBound = false) {
|
|
33809
|
-
const data =
|
|
33810
|
-
const meta =
|
|
34733
|
+
const data = isRecord17(flow.data) ? flow.data : {};
|
|
34734
|
+
const meta = isRecord17(data.meta) ? data.meta : {};
|
|
33811
34735
|
const refs = {
|
|
33812
34736
|
form_template_id: meta.form_template ?? flow.form_template_id,
|
|
33813
34737
|
list_template_ids: listTemplates.map((item) => item.id ?? item.flow_page_template_id).filter(hasIdentifier),
|
|
@@ -33848,7 +34772,7 @@ function matrixAppSummary(flow, listTemplates = [], filterTemplates = [], datase
|
|
|
33848
34772
|
suggestion: "\u4ECE\u6700\u65B0 workspace-flow \u56DE\u8BFB merge \u540E\u901A\u8FC7 typed CLI \u63D0\u4EA4\u7ED1\u5B9A\u3002"
|
|
33849
34773
|
});
|
|
33850
34774
|
}
|
|
33851
|
-
const nodes = dataArray(data.nodes).filter(
|
|
34775
|
+
const nodes = dataArray(data.nodes).filter(isRecord17);
|
|
33852
34776
|
const activeNodes = nodes.filter((node) => {
|
|
33853
34777
|
const name = String(node.name ?? "").trim();
|
|
33854
34778
|
return name === "\u751F\u6548\u4E2D" || name === "\u8FDB\u884C\u4E2D" || Number(node.status) === 1;
|
|
@@ -33897,10 +34821,10 @@ async function inspectMatrixAppDefinition(profile, flowType, workspace, includeR
|
|
|
33897
34821
|
apiRequest(client, "GET", "/flow_page_template", { params: { type: 3, flow_type: flowType, flow_key: "", skip_i18n: true }, capability: "config.filter_template.export" }),
|
|
33898
34822
|
apiRequest(client, "GET", "/workspace/by_key", { params: { key: workspace }, capability: "config.workspace_flow.export" })
|
|
33899
34823
|
]);
|
|
33900
|
-
const flowData =
|
|
33901
|
-
const meta =
|
|
33902
|
-
const listRows = dataArray(listResult).filter(
|
|
33903
|
-
const filterRows = dataArray(filterResult).filter(
|
|
34824
|
+
const flowData = isRecord17(flow.data) ? flow.data : {};
|
|
34825
|
+
const meta = isRecord17(flowData.meta) ? flowData.meta : {};
|
|
34826
|
+
const listRows = dataArray(listResult).filter(isRecord17);
|
|
34827
|
+
const filterRows = dataArray(filterResult).filter(isRecord17);
|
|
33904
34828
|
const listIds = uniqueIds([meta.table_list_template, ...listRows.map((item) => item.id ?? item.flow_page_template_id)]);
|
|
33905
34829
|
const filterIds = uniqueIds([meta.table_filter_template, ...filterRows.map((item) => item.id ?? item.flow_page_template_id)]);
|
|
33906
34830
|
const formId = String(meta.form_template ?? flow.form_template_id ?? "");
|
|
@@ -33918,7 +34842,7 @@ async function inspectMatrixAppDefinition(profile, flowType, workspace, includeR
|
|
|
33918
34842
|
if (strict) {
|
|
33919
34843
|
assertNoMatrixErrors(summary.errors);
|
|
33920
34844
|
}
|
|
33921
|
-
const formRecord =
|
|
34845
|
+
const formRecord = isRecord17(form) ? form : {};
|
|
33922
34846
|
const exactReadback = {
|
|
33923
34847
|
flow: { id: flowType, readback_hash: matrixHash(flow), ...includeRaw ? { readback: flow } : {} },
|
|
33924
34848
|
form_template: { id: formId, draft_id: formRecord.origin_template_id ?? formRecord.id ?? null, readback_hash: matrixHash(formRecord), ...includeRaw ? { readback: formRecord } : {} },
|
|
@@ -33930,8 +34854,8 @@ async function inspectMatrixAppDefinition(profile, flowType, workspace, includeR
|
|
|
33930
34854
|
return { ok: summary.errors.length === 0, domain: "approval-matrix", action: "app.inspect", flow_type: flowType, workspace, ...summary, exact_readback: exactReadback };
|
|
33931
34855
|
}
|
|
33932
34856
|
function workspaceHasFlow(value, flowType) {
|
|
33933
|
-
if (!
|
|
33934
|
-
const rows2 = Array.isArray(value.workspace_flow) ? value.workspace_flow.filter(
|
|
34857
|
+
if (!isRecord17(value)) return false;
|
|
34858
|
+
const rows2 = Array.isArray(value.workspace_flow) ? value.workspace_flow.filter(isRecord17) : isRecord17(value.data) && Array.isArray(value.data.workspace_flow) ? value.data.workspace_flow.filter(isRecord17) : [];
|
|
33935
34859
|
return rows2.some((item) => String(item.flow_type ?? "") === flowType && Number(item.is_del ?? 0) === 0);
|
|
33936
34860
|
}
|
|
33937
34861
|
function matrixConsumerSummary(node, expectedMatrixFlowType) {
|
|
@@ -33947,8 +34871,8 @@ function matrixConsumerSummary(node, expectedMatrixFlowType) {
|
|
|
33947
34871
|
});
|
|
33948
34872
|
return { errors, owner: null, cc: null };
|
|
33949
34873
|
}
|
|
33950
|
-
const owner =
|
|
33951
|
-
const cc =
|
|
34874
|
+
const owner = isRecord17(node.matrix_owner) ? node.matrix_owner : null;
|
|
34875
|
+
const cc = isRecord17(node.cc_matrix) ? node.cc_matrix : null;
|
|
33952
34876
|
const normalizeFlowRef = (value) => String(value ?? "").trim().replace(/:$/, "");
|
|
33953
34877
|
if (node.auto_range_type === "matrix") {
|
|
33954
34878
|
if (!owner || !String(owner.flow ?? owner.matrix_flow_type ?? "").trim()) {
|
|
@@ -33979,16 +34903,16 @@ function matrixConsumerSummary(node, expectedMatrixFlowType) {
|
|
|
33979
34903
|
return { errors, owner, cc };
|
|
33980
34904
|
}
|
|
33981
34905
|
function projectField(project, key) {
|
|
33982
|
-
const metaForm =
|
|
33983
|
-
const values = dataArray(metaForm.value ?? project.formList).filter(
|
|
34906
|
+
const metaForm = isRecord17(project.metaForm) ? project.metaForm : {};
|
|
34907
|
+
const values = dataArray(metaForm.value ?? project.formList).filter(isRecord17);
|
|
33984
34908
|
const row = values.find((item) => String(item.key ?? item.field_key ?? "") === key);
|
|
33985
34909
|
if (!row) return void 0;
|
|
33986
34910
|
const value = row.value;
|
|
33987
|
-
return
|
|
34911
|
+
return isRecord17(value) && Object.prototype.hasOwnProperty.call(value, "value") ? value.value : value;
|
|
33988
34912
|
}
|
|
33989
34913
|
function collectUserIds(value) {
|
|
33990
34914
|
if (Array.isArray(value)) return [...new Set(value.flatMap(collectUserIds))];
|
|
33991
|
-
if (
|
|
34915
|
+
if (isRecord17(value)) {
|
|
33992
34916
|
const direct2 = Number(value.id ?? value.user_id ?? value.value);
|
|
33993
34917
|
if (Number.isSafeInteger(direct2) && direct2 > 0) return [direct2];
|
|
33994
34918
|
return [...new Set(Object.values(value).flatMap(collectUserIds))];
|
|
@@ -34009,7 +34933,7 @@ async function readMatrixApprovers(client, ids) {
|
|
|
34009
34933
|
},
|
|
34010
34934
|
capability: "user.readback"
|
|
34011
34935
|
});
|
|
34012
|
-
users.push(...dataArray(result).filter(
|
|
34936
|
+
users.push(...dataArray(result).filter(isRecord17));
|
|
34013
34937
|
}
|
|
34014
34938
|
return users;
|
|
34015
34939
|
}
|
|
@@ -34093,7 +35017,7 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
34093
35017
|
const matrixOwnerConfig = node ? collectMatrixOwnerPaths(node) : [];
|
|
34094
35018
|
const predictedNode = predictedNodes(prediction).find((item) => String(item.node_id ?? item.id ?? "") === options.node);
|
|
34095
35019
|
const owners = safePredictedOwners(predictedNode?.owners);
|
|
34096
|
-
const ownerResolution = predictedNode &&
|
|
35020
|
+
const ownerResolution = predictedNode && isRecord17(predictedNode.owner_resolution) ? predictedNode.owner_resolution : { status: predictedNode ? "resolved" : "missing" };
|
|
34097
35021
|
const projectFlowType = String(project.flow_type ?? "");
|
|
34098
35022
|
const flowMatchesProject = !projectFlowType || projectFlowType === options.flowType;
|
|
34099
35023
|
printResult(options.format, {
|
|
@@ -34184,14 +35108,14 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
34184
35108
|
if (!workspace) throw new Error("matrix.app.workspace_required: \u8BF7\u63D0\u4F9B --workspace \u4EE5\u5220\u9664\u77E9\u9635\u5E94\u7528\u3002");
|
|
34185
35109
|
const definition = await inspectMatrixAppDefinition(profile, options.flowType, workspace, true, false);
|
|
34186
35110
|
const exact = definition.exact_readback;
|
|
34187
|
-
const listItems = Array.isArray(exact.list_templates) ? exact.list_templates.filter(
|
|
34188
|
-
const filterItems = Array.isArray(exact.filter_templates) ? exact.filter_templates.filter(
|
|
34189
|
-
const datasetItems = Array.isArray(exact.datasets) ? exact.datasets.filter(
|
|
35111
|
+
const listItems = Array.isArray(exact.list_templates) ? exact.list_templates.filter(isRecord17) : [];
|
|
35112
|
+
const filterItems = Array.isArray(exact.filter_templates) ? exact.filter_templates.filter(isRecord17) : [];
|
|
35113
|
+
const datasetItems = Array.isArray(exact.datasets) ? exact.datasets.filter(isRecord17) : [];
|
|
34190
35114
|
const datasetFieldIds = uniqueIds(datasetItems.flatMap((item) => {
|
|
34191
|
-
const readback =
|
|
34192
|
-
return Array.isArray(readback.dataSetFields) ? readback.dataSetFields.filter(
|
|
35115
|
+
const readback = isRecord17(item.readback) ? item.readback : {};
|
|
35116
|
+
return Array.isArray(readback.dataSetFields) ? readback.dataSetFields.filter(isRecord17).map((field) => field.id) : [];
|
|
34193
35117
|
}));
|
|
34194
|
-
const formItem =
|
|
35118
|
+
const formItem = isRecord17(exact.form_template) ? exact.form_template : {};
|
|
34195
35119
|
const formDraftId = String(formItem.draft_id ?? formItem.id ?? "");
|
|
34196
35120
|
const expectedConfirm = `delete matrix app ${options.flowType} from ${workspace}`;
|
|
34197
35121
|
const plan = [
|
|
@@ -34253,8 +35177,8 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
34253
35177
|
apiRequest(client, "GET", "/flow_page_template", { params: { type: 3, flow_type: options.matrixFlowType, flow_key: "", skip_i18n: true }, capability: "config.filter_template.export" }),
|
|
34254
35178
|
apiRequest(client, "GET", "/workspace/by_key", { params: { key: workspace }, capability: "config.workspace_flow.export" })
|
|
34255
35179
|
]);
|
|
34256
|
-
const listRows = dataArray(listResult).filter(
|
|
34257
|
-
const filterRows = dataArray(filterResult).filter(
|
|
35180
|
+
const listRows = dataArray(listResult).filter(isRecord17);
|
|
35181
|
+
const filterRows = dataArray(filterResult).filter(isRecord17);
|
|
34258
35182
|
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" })));
|
|
34259
35183
|
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" })));
|
|
34260
35184
|
const datasetIds = uniqueIds([...listTemplates.map((item) => item.data_set_id), ...filterTemplates.map((item) => item.data_set_id)]);
|
|
@@ -34288,7 +35212,7 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
34288
35212
|
}
|
|
34289
35213
|
const predictedNode = predictedNodes(prediction).find((item) => String(item.node_id ?? item.id ?? "") === options.node);
|
|
34290
35214
|
const predictedOwners = safePredictedOwners(predictedNode?.owners);
|
|
34291
|
-
const ownerResolution = predictedNode &&
|
|
35215
|
+
const ownerResolution = predictedNode && isRecord17(predictedNode.owner_resolution) ? predictedNode.owner_resolution : { status: predictedNode ? "resolved" : "missing" };
|
|
34292
35216
|
if (ownerResolution.status === "error") {
|
|
34293
35217
|
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" });
|
|
34294
35218
|
} else if (!predictedNode || predictedOwners.length === 0) {
|
|
@@ -34312,13 +35236,13 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
34312
35236
|
}
|
|
34313
35237
|
|
|
34314
35238
|
// src/commands/organization.ts
|
|
34315
|
-
function
|
|
35239
|
+
function isRecord18(value) {
|
|
34316
35240
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34317
35241
|
}
|
|
34318
35242
|
function rows(value) {
|
|
34319
|
-
if (Array.isArray(value)) return value.filter(
|
|
34320
|
-
if (!
|
|
34321
|
-
if (Array.isArray(value.data)) return value.data.filter(
|
|
35243
|
+
if (Array.isArray(value)) return value.filter(isRecord18);
|
|
35244
|
+
if (!isRecord18(value)) return [];
|
|
35245
|
+
if (Array.isArray(value.data)) return value.data.filter(isRecord18);
|
|
34322
35246
|
return value.id ? [value] : [];
|
|
34323
35247
|
}
|
|
34324
35248
|
function positiveId(value, errorCode) {
|
|
@@ -34342,7 +35266,7 @@ function safeDepartment(group) {
|
|
|
34342
35266
|
function departmentRows(value) {
|
|
34343
35267
|
const result = [];
|
|
34344
35268
|
const visit = (item) => {
|
|
34345
|
-
if (!
|
|
35269
|
+
if (!isRecord18(item)) return;
|
|
34346
35270
|
if (item.id !== void 0) result.push(safeDepartment(item));
|
|
34347
35271
|
if (Array.isArray(item.children)) item.children.forEach(visit);
|
|
34348
35272
|
};
|
|
@@ -34351,7 +35275,7 @@ function departmentRows(value) {
|
|
|
34351
35275
|
}
|
|
34352
35276
|
function relationDepartments(value) {
|
|
34353
35277
|
if (!Array.isArray(value)) return [];
|
|
34354
|
-
return value.filter(
|
|
35278
|
+
return value.filter(isRecord18).map(safeDepartment);
|
|
34355
35279
|
}
|
|
34356
35280
|
function safeUser(user) {
|
|
34357
35281
|
const status = user.status === void 0 ? null : Number(user.status);
|
|
@@ -34409,7 +35333,7 @@ function pathIds(departments) {
|
|
|
34409
35333
|
function mainDepartmentId(raw) {
|
|
34410
35334
|
for (const key of ["main_department_id", "main_group_id", "main_department"]) {
|
|
34411
35335
|
const value = raw[key];
|
|
34412
|
-
if (
|
|
35336
|
+
if (isRecord18(value)) {
|
|
34413
35337
|
const id2 = Number(value.id);
|
|
34414
35338
|
if (Number.isSafeInteger(id2) && id2 > 0) return id2;
|
|
34415
35339
|
}
|
|
@@ -34421,7 +35345,7 @@ function mainDepartmentId(raw) {
|
|
|
34421
35345
|
function branchId(raw) {
|
|
34422
35346
|
for (const key of ["branch_id", "branch_group_id", "branch"]) {
|
|
34423
35347
|
const value = raw[key];
|
|
34424
|
-
if (
|
|
35348
|
+
if (isRecord18(value)) {
|
|
34425
35349
|
const id2 = Number(value.id);
|
|
34426
35350
|
if (Number.isSafeInteger(id2) && id2 > 0) return id2;
|
|
34427
35351
|
}
|
|
@@ -34939,15 +35863,15 @@ async function promptProjectCreateForm(input) {
|
|
|
34939
35863
|
}
|
|
34940
35864
|
|
|
34941
35865
|
// src/core/project-form.ts
|
|
34942
|
-
function
|
|
35866
|
+
function isRecord19(value) {
|
|
34943
35867
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34944
35868
|
}
|
|
34945
35869
|
function clone(value) {
|
|
34946
35870
|
return JSON.parse(JSON.stringify(value));
|
|
34947
35871
|
}
|
|
34948
35872
|
function getFlowFormTemplateId(flowDetail) {
|
|
34949
|
-
const data =
|
|
34950
|
-
const meta =
|
|
35873
|
+
const data = isRecord19(flowDetail?.data) ? flowDetail.data : void 0;
|
|
35874
|
+
const meta = isRecord19(data?.meta) ? data.meta : void 0;
|
|
34951
35875
|
const templateId = meta?.form_template;
|
|
34952
35876
|
if (typeof templateId === "number" && Number.isFinite(templateId)) {
|
|
34953
35877
|
return templateId;
|
|
@@ -34972,7 +35896,7 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
34972
35896
|
if (Array.isArray(value)) {
|
|
34973
35897
|
return value.some((item) => hasAutoInitLambda(item, seen));
|
|
34974
35898
|
}
|
|
34975
|
-
if (!
|
|
35899
|
+
if (!isRecord19(value)) {
|
|
34976
35900
|
return false;
|
|
34977
35901
|
}
|
|
34978
35902
|
if (seen.has(value)) {
|
|
@@ -34987,14 +35911,14 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
34987
35911
|
function setControlValue(control, value) {
|
|
34988
35912
|
const next = clone(control);
|
|
34989
35913
|
next.value = {
|
|
34990
|
-
...
|
|
35914
|
+
...isRecord19(next.value) ? next.value : {},
|
|
34991
35915
|
type: next.value?.type ?? next.field_type,
|
|
34992
35916
|
value
|
|
34993
35917
|
};
|
|
34994
35918
|
return next;
|
|
34995
35919
|
}
|
|
34996
35920
|
function applyRowValues(rowTemplate, rowValue) {
|
|
34997
|
-
const source =
|
|
35921
|
+
const source = isRecord19(rowValue) ? rowValue : {};
|
|
34998
35922
|
return rowTemplate.map((control) => {
|
|
34999
35923
|
if (control.key && Object.prototype.hasOwnProperty.call(source, control.key)) {
|
|
35000
35924
|
return setControlValue(control, source[control.key]);
|
|
@@ -35033,6 +35957,67 @@ async function buildProjectFormPayload(client, flowDetail, form, knownTemplate)
|
|
|
35033
35957
|
}
|
|
35034
35958
|
|
|
35035
35959
|
// src/commands/project.ts
|
|
35960
|
+
async function createTypedProjectFixture(options) {
|
|
35961
|
+
if ("projectForm" in options.input || "project_form" in options.input || "user_id" in options.input || "owner_id" in options.input) {
|
|
35962
|
+
throw new Error(
|
|
35963
|
+
"test_fixture.payload_override_forbidden: typed fixture creation must build projectForm and actor fields from the reviewed fixture contract"
|
|
35964
|
+
);
|
|
35965
|
+
}
|
|
35966
|
+
if (options.actorUserId !== void 0 && (!Number.isSafeInteger(options.actorUserId) || options.actorUserId <= 0)) {
|
|
35967
|
+
throw new Error("test_fixture.actor_user_invalid: actorUserId must be a positive safe integer");
|
|
35968
|
+
}
|
|
35969
|
+
const flow = await resolveFlowIdentifiers(options.client, {
|
|
35970
|
+
flowType: options.flowType,
|
|
35971
|
+
flowKey: options.flowKey ?? ""
|
|
35972
|
+
}, { loadDetail: true });
|
|
35973
|
+
const { flowDetail, ...flowIdentifiers } = flow;
|
|
35974
|
+
const projectFormTemplate = await fetchProjectFormTemplate(options.client, flowDetail);
|
|
35975
|
+
const fields = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
35976
|
+
if (fields.length === 0) {
|
|
35977
|
+
throw new Error(
|
|
35978
|
+
"test_fixture.form_schema_unavailable: typed fixture creation requires a discoverable live create-form schema"
|
|
35979
|
+
);
|
|
35980
|
+
}
|
|
35981
|
+
const handoffReasons = collectHandoffReasons(fields, projectFormTemplate?.template);
|
|
35982
|
+
if (handoffReasons.length > 0) {
|
|
35983
|
+
throw new Error(
|
|
35984
|
+
`test_fixture.typed_create_unsupported: ${options.flowType}:${options.flowKey ?? ""} requires page-only initialization (${formatHandoffReasonsForMessage(handoffReasons)}). Add a domain typed adapter or a reviewed BBS that calls one; do not fall back to browser exploration or raw API creation.`
|
|
35985
|
+
);
|
|
35986
|
+
}
|
|
35987
|
+
const form = structuredClone(options.input.form);
|
|
35988
|
+
const validation = validateFormAgainstFields(form, fields);
|
|
35989
|
+
if (validation.errors.length > 0) {
|
|
35990
|
+
throw new Error(`Form validation failed:
|
|
35991
|
+
- ${validation.errors.join("\n- ")}`);
|
|
35992
|
+
}
|
|
35993
|
+
const usesTemplateProjectName = metaUsesTemplateProjectName(flowDetail);
|
|
35994
|
+
if (options.requireProjectNamePersistence && usesTemplateProjectName) {
|
|
35995
|
+
throw new Error(
|
|
35996
|
+
"test_fixture.project_name_marker_unsupported: this flow derives the project name from its form template; use an existing reviewed form field as marker_field"
|
|
35997
|
+
);
|
|
35998
|
+
}
|
|
35999
|
+
const name = String(options.name ?? "").trim();
|
|
36000
|
+
if (!name && !usesTemplateProjectName) {
|
|
36001
|
+
throw new Error("test_fixture.project_name_required: typed fixture creation requires a deterministic project name");
|
|
36002
|
+
}
|
|
36003
|
+
const { form: _form, ...projectExtra } = structuredClone(options.input);
|
|
36004
|
+
const { flow_key: flowKey, ...projectFlowIdentifiers } = flowIdentifiers;
|
|
36005
|
+
const payload = {
|
|
36006
|
+
...projectExtra,
|
|
36007
|
+
...projectFlowIdentifiers,
|
|
36008
|
+
key: flowKey,
|
|
36009
|
+
...name ? { name } : {},
|
|
36010
|
+
workspace: options.profile.config.workspace,
|
|
36011
|
+
...options.actorUserId ? { user_id: options.actorUserId, owner_id: options.actorUserId } : {},
|
|
36012
|
+
...await buildProjectFormPayload(options.client, flowDetail, form, projectFormTemplate)
|
|
36013
|
+
};
|
|
36014
|
+
await options.onMutationAttempt?.(payload);
|
|
36015
|
+
const result = await apiRequest(options.client, "POST", "/project", {
|
|
36016
|
+
data: payload,
|
|
36017
|
+
capability: "project.create"
|
|
36018
|
+
});
|
|
36019
|
+
return attachProjectDetailUrl(options.profile, result);
|
|
36020
|
+
}
|
|
35036
36021
|
function projectCreateErrorDiagnostic(error, context2) {
|
|
35037
36022
|
const baseMessage = error instanceof Error ? error.message : String(error || "");
|
|
35038
36023
|
const response = typeof error === "object" && error !== null && "response" in error ? error.response : void 0;
|
|
@@ -35552,8 +36537,8 @@ function fieldsForValidation(flowDetail, projectFormTemplate) {
|
|
|
35552
36537
|
}));
|
|
35553
36538
|
}
|
|
35554
36539
|
function metaUsesTemplateProjectName(flowDetail) {
|
|
35555
|
-
const data =
|
|
35556
|
-
const meta =
|
|
36540
|
+
const data = isRecord20(flowDetail?.data) ? flowDetail.data : void 0;
|
|
36541
|
+
const meta = isRecord20(data?.meta) ? data.meta : void 0;
|
|
35557
36542
|
const hideFields = Array.isArray(meta?.hide_fields) ? meta.hide_fields.map(String) : [];
|
|
35558
36543
|
return meta?.use_template_project_name === true || hideFields.includes("project.name");
|
|
35559
36544
|
}
|
|
@@ -35662,7 +36647,7 @@ function collectPrefillContextForFields(fields, form, result, options = {}) {
|
|
|
35662
36647
|
result.filled_fields.push(contextField(field, "prefilled", fieldOptions));
|
|
35663
36648
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
35664
36649
|
value.forEach((row, index) => {
|
|
35665
|
-
if (
|
|
36650
|
+
if (isRecord20(row)) {
|
|
35666
36651
|
collectPrefillContextForFields(field.children ?? [], row, result, {
|
|
35667
36652
|
prefix: `${field.key}[${index}]`,
|
|
35668
36653
|
rootKey: field.key,
|
|
@@ -35689,7 +36674,7 @@ function buildPrefillContext(fields, form) {
|
|
|
35689
36674
|
}
|
|
35690
36675
|
};
|
|
35691
36676
|
}
|
|
35692
|
-
function
|
|
36677
|
+
function isRecord20(value) {
|
|
35693
36678
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35694
36679
|
}
|
|
35695
36680
|
function isEndedStep(step) {
|
|
@@ -35712,7 +36697,7 @@ function stepIdOf(step) {
|
|
|
35712
36697
|
function pickStepFormPayload(step) {
|
|
35713
36698
|
const formList = Array.isArray(step.formList) ? step.formList : [];
|
|
35714
36699
|
const forms = Array.isArray(step.forms) ? step.forms : [];
|
|
35715
|
-
const metaForm =
|
|
36700
|
+
const metaForm = isRecord20(step.metaForm) ? step.metaForm : void 0;
|
|
35716
36701
|
return {
|
|
35717
36702
|
step_id: step.id,
|
|
35718
36703
|
flow_step_id: step.flow_step_id,
|
|
@@ -35729,7 +36714,7 @@ function pickStepFormPayload(step) {
|
|
|
35729
36714
|
}
|
|
35730
36715
|
async function buildApprovalContext(client, projectId, options) {
|
|
35731
36716
|
const projectDetail = await apiRequest(client, "GET", `/project/${projectId}`);
|
|
35732
|
-
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(
|
|
36717
|
+
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(isRecord20) : [];
|
|
35733
36718
|
const targetStepIds = /* @__PURE__ */ new Set();
|
|
35734
36719
|
for (const step of steps) {
|
|
35735
36720
|
const id = stepIdOf(step);
|
|
@@ -35755,7 +36740,7 @@ async function buildApprovalContext(client, projectId, options) {
|
|
|
35755
36740
|
}
|
|
35756
36741
|
return {
|
|
35757
36742
|
project: projectDetail,
|
|
35758
|
-
project_form:
|
|
36743
|
+
project_form: isRecord20(projectDetail.metaForm) ? projectDetail.metaForm : null,
|
|
35759
36744
|
inspected_step_count: stepForms.length,
|
|
35760
36745
|
step_forms: stepForms,
|
|
35761
36746
|
failed_steps: failedSteps
|
|
@@ -36125,7 +37110,7 @@ function getRecipesDir(options) {
|
|
|
36125
37110
|
const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
|
|
36126
37111
|
return path20.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
|
|
36127
37112
|
}
|
|
36128
|
-
function
|
|
37113
|
+
function isRecord21(value) {
|
|
36129
37114
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36130
37115
|
}
|
|
36131
37116
|
function asString(value, fieldName) {
|
|
@@ -36135,7 +37120,7 @@ function asString(value, fieldName) {
|
|
|
36135
37120
|
return value;
|
|
36136
37121
|
}
|
|
36137
37122
|
function parseRecipeDefinition(input) {
|
|
36138
|
-
if (!
|
|
37123
|
+
if (!isRecord21(input)) {
|
|
36139
37124
|
throw new Error("recipe.json must be a JSON object.");
|
|
36140
37125
|
}
|
|
36141
37126
|
if (input.version !== 1) {
|
|
@@ -36143,7 +37128,7 @@ function parseRecipeDefinition(input) {
|
|
|
36143
37128
|
}
|
|
36144
37129
|
const name = asString(input.name, "recipe.name");
|
|
36145
37130
|
assertSafeName("Recipe name", name);
|
|
36146
|
-
if (!
|
|
37131
|
+
if (!isRecord21(input.command)) {
|
|
36147
37132
|
throw new Error("recipe.command must be an object.");
|
|
36148
37133
|
}
|
|
36149
37134
|
const argv = input.command.argv;
|
|
@@ -36151,7 +37136,7 @@ function parseRecipeDefinition(input) {
|
|
|
36151
37136
|
throw new Error("recipe.command.argv must be a non-empty string array.");
|
|
36152
37137
|
}
|
|
36153
37138
|
const variables = Array.isArray(input.variables) ? input.variables.map((item, index) => {
|
|
36154
|
-
if (!
|
|
37139
|
+
if (!isRecord21(item)) {
|
|
36155
37140
|
throw new Error(`recipe.variables[${index}] must be an object.`);
|
|
36156
37141
|
}
|
|
36157
37142
|
const variableName = asString(item.name, `recipe.variables[${index}].name`);
|
|
@@ -36227,7 +37212,7 @@ function parseVarsJson(input) {
|
|
|
36227
37212
|
return {};
|
|
36228
37213
|
}
|
|
36229
37214
|
const parsed = JSON.parse(input);
|
|
36230
|
-
if (!
|
|
37215
|
+
if (!isRecord21(parsed)) {
|
|
36231
37216
|
throw new Error("--vars must be a JSON object.");
|
|
36232
37217
|
}
|
|
36233
37218
|
const variables = {};
|
|
@@ -38281,21 +39266,21 @@ function registerTestSuiteCommands(program2) {
|
|
|
38281
39266
|
}
|
|
38282
39267
|
|
|
38283
39268
|
// src/commands/test-fixture.ts
|
|
38284
|
-
import { randomUUID as randomUUID5 } from "crypto";
|
|
38285
|
-
import { readFile as readFile24, rename as rename6, writeFile as writeFile17 } from "fs/promises";
|
|
39269
|
+
import { createHash as createHash14, randomUUID as randomUUID5 } from "crypto";
|
|
39270
|
+
import { lstat as lstat5, readFile as readFile24, realpath as realpath9, rename as rename6, writeFile as writeFile17 } from "fs/promises";
|
|
38286
39271
|
import path23 from "path";
|
|
38287
|
-
function
|
|
39272
|
+
function isRecord22(value) {
|
|
38288
39273
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
38289
39274
|
}
|
|
38290
39275
|
async function parseJsonInput2(value, option) {
|
|
38291
39276
|
const raw = value.startsWith("@") ? await readFile24(value.slice(1), "utf8") : value;
|
|
38292
39277
|
const parsed = JSON.parse(raw);
|
|
38293
|
-
if (!
|
|
39278
|
+
if (!isRecord22(parsed)) throw new Error(`test_fixture.invalid_json: ${option} \u5FC5\u987B\u662F JSON \u5BF9\u8C61\u6216 @file\u3002`);
|
|
38294
39279
|
return parsed;
|
|
38295
39280
|
}
|
|
38296
39281
|
function safeToken(value, label) {
|
|
38297
39282
|
const normalized = value.trim();
|
|
38298
|
-
if (!/^[A-Za-z0-9._-]+$/.test(normalized)) {
|
|
39283
|
+
if (!/^[A-Za-z0-9._-]+$/.test(normalized) || ["__proto__", "prototype", "constructor"].includes(normalized)) {
|
|
38299
39284
|
throw new Error(`test_fixture.invalid_${label}: ${label} \u53EA\u80FD\u5305\u542B\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u70B9\u3001\u4E0B\u5212\u7EBF\u548C\u8FDE\u5B57\u7B26\u3002`);
|
|
38300
39285
|
}
|
|
38301
39286
|
return normalized;
|
|
@@ -38303,65 +39288,328 @@ function safeToken(value, label) {
|
|
|
38303
39288
|
function safeReadbackPath(value, label) {
|
|
38304
39289
|
const normalized = String(value ?? "").trim();
|
|
38305
39290
|
const segments = normalized.split(".");
|
|
38306
|
-
if (!normalized || segments.some((segment) =>
|
|
39291
|
+
if (!normalized || segments.some((segment, index) => !(/^[A-Za-z_][A-Za-z0-9_]*$/.test(segment) || index > 0 && /^\d+$/.test(segment)) || ["__proto__", "prototype", "constructor"].includes(segment))) {
|
|
38307
39292
|
throw new Error(`test_fixture.invalid_${label}: ${label} \u5FC5\u987B\u662F\u5B89\u5168\u7684\u70B9\u5206\u5BF9\u8C61\u8DEF\u5F84\u3002`);
|
|
38308
39293
|
}
|
|
38309
39294
|
return normalized;
|
|
38310
39295
|
}
|
|
39296
|
+
function fixtureActor(raw, label) {
|
|
39297
|
+
const actor = isRecord22(raw) ? raw : { mode: "profile" };
|
|
39298
|
+
const mode = String(actor.mode ?? "profile");
|
|
39299
|
+
const userId = Number(actor.user_id);
|
|
39300
|
+
const expectedName = String(actor.expected_name ?? "").trim();
|
|
39301
|
+
if (!["profile", "user"].includes(mode)) {
|
|
39302
|
+
throw new Error(`test_fixture.actor_mode_invalid: ${label} actor.mode \u53EA\u5141\u8BB8 profile \u6216 user\u3002`);
|
|
39303
|
+
}
|
|
39304
|
+
if (mode === "user" && (!Number.isSafeInteger(userId) || userId <= 0 || !expectedName)) {
|
|
39305
|
+
throw new Error(`test_fixture.actor_contract_required: ${label} \u4F7F\u7528\u76EE\u6807\u7528\u6237\u65F6\u5FC5\u987B\u58F0\u660E\u6B63\u6574\u6570 actor.user_id \u548C actor.expected_name\u3002`);
|
|
39306
|
+
}
|
|
39307
|
+
return {
|
|
39308
|
+
mode,
|
|
39309
|
+
...mode === "user" ? { user_id: userId, expected_name: expectedName } : {}
|
|
39310
|
+
};
|
|
39311
|
+
}
|
|
39312
|
+
function fixtureTransitions(raw, seedKey) {
|
|
39313
|
+
if (raw === void 0) return [];
|
|
39314
|
+
if (!Array.isArray(raw)) throw new Error(`test_fixture.invalid_transitions: ${seedKey} transitions \u5FC5\u987B\u662F\u6570\u7EC4\u3002`);
|
|
39315
|
+
const keys = /* @__PURE__ */ new Set();
|
|
39316
|
+
return raw.map((value, index) => {
|
|
39317
|
+
if (!isRecord22(value)) throw new Error(`test_fixture.invalid_transition: ${seedKey}.transitions[${index}] \u5FC5\u987B\u662F\u5BF9\u8C61\u3002`);
|
|
39318
|
+
const key = safeToken(String(value.key ?? ""), "transition_key");
|
|
39319
|
+
if (keys.has(key)) throw new Error(`test_fixture.invalid_transition: ${seedKey} transition key \u91CD\u590D: ${key}\u3002`);
|
|
39320
|
+
keys.add(key);
|
|
39321
|
+
const stepId = value.step_id;
|
|
39322
|
+
const action = String(value.action ?? "").trim();
|
|
39323
|
+
if (typeof stepId !== "string" && typeof stepId !== "number" || !String(stepId).trim() || !action) {
|
|
39324
|
+
throw new Error(`test_fixture.invalid_transition: ${seedKey}.${key} \u9700\u8981 step_id \u548C action\u3002`);
|
|
39325
|
+
}
|
|
39326
|
+
return {
|
|
39327
|
+
key,
|
|
39328
|
+
step_id: stepId,
|
|
39329
|
+
action,
|
|
39330
|
+
...String(value.target_step ?? "").trim() ? { target_step: String(value.target_step).trim() } : {},
|
|
39331
|
+
data: isRecord22(value.data) ? structuredClone(value.data) : {},
|
|
39332
|
+
actor: fixtureActor(value.actor, `${seedKey}.${key}`)
|
|
39333
|
+
};
|
|
39334
|
+
});
|
|
39335
|
+
}
|
|
39336
|
+
function fixtureOutputs(raw, seedKey) {
|
|
39337
|
+
if (raw === void 0) return {};
|
|
39338
|
+
if (!isRecord22(raw)) throw new Error(`test_fixture.invalid_outputs: ${seedKey} outputs \u5FC5\u987B\u662F\u5BF9\u8C61\u3002`);
|
|
39339
|
+
const outputs = {};
|
|
39340
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
39341
|
+
const outputKey = safeToken(key, "output_key");
|
|
39342
|
+
if (["project_id", "marker", "outputs"].includes(outputKey)) {
|
|
39343
|
+
throw new Error(`test_fixture.invalid_output_key: ${seedKey}.${outputKey} \u4F1A\u8986\u76D6 fixture runtime \u4FDD\u7559\u5B57\u6BB5\u3002`);
|
|
39344
|
+
}
|
|
39345
|
+
outputs[outputKey] = safeReadbackPath(value, `${seedKey}.${outputKey}`);
|
|
39346
|
+
}
|
|
39347
|
+
return outputs;
|
|
39348
|
+
}
|
|
39349
|
+
function referencedAssetKeys(value) {
|
|
39350
|
+
const refs = /* @__PURE__ */ new Set();
|
|
39351
|
+
const visit = (current) => {
|
|
39352
|
+
if (typeof current === "string") {
|
|
39353
|
+
for (const match of current.matchAll(/\{\{assets\.([A-Za-z0-9._-]+)\.url\}\}/g)) refs.add(match[1]);
|
|
39354
|
+
return;
|
|
39355
|
+
}
|
|
39356
|
+
if (Array.isArray(current)) current.forEach(visit);
|
|
39357
|
+
else if (isRecord22(current)) Object.values(current).forEach(visit);
|
|
39358
|
+
};
|
|
39359
|
+
visit(value);
|
|
39360
|
+
return [...refs];
|
|
39361
|
+
}
|
|
39362
|
+
function fixtureAssets(manifest, seeds) {
|
|
39363
|
+
if (manifest.assets === void 0) return [];
|
|
39364
|
+
if (!Array.isArray(manifest.assets)) throw new Error("test_fixture.invalid_assets: assets \u5FC5\u987B\u662F\u6570\u7EC4\u3002");
|
|
39365
|
+
const keys = /* @__PURE__ */ new Set();
|
|
39366
|
+
const assets = manifest.assets.map((raw, index) => {
|
|
39367
|
+
if (!isRecord22(raw)) throw new Error(`test_fixture.invalid_asset: assets[${index}] \u5FC5\u987B\u662F\u5BF9\u8C61\u3002`);
|
|
39368
|
+
const key = safeToken(String(raw.key ?? ""), "asset_key");
|
|
39369
|
+
if (keys.has(key)) throw new Error(`test_fixture.invalid_asset: asset key \u91CD\u590D: ${key}\u3002`);
|
|
39370
|
+
keys.add(key);
|
|
39371
|
+
const relativePath = String(raw.path ?? "").trim().replace(/\\/g, "/");
|
|
39372
|
+
const sha2563 = String(raw.sha256 ?? "").trim().toLowerCase();
|
|
39373
|
+
const mime = String(raw.mime ?? "").trim();
|
|
39374
|
+
const size = Number(raw.size);
|
|
39375
|
+
const purpose = String(raw.purpose ?? "").trim();
|
|
39376
|
+
if (!relativePath.startsWith("fixtures/") || path23.posix.isAbsolute(relativePath) || relativePath.split("/").includes("..")) {
|
|
39377
|
+
throw new Error(`test_fixture.invalid_asset_path: ${key} path \u5FC5\u987B\u4F4D\u4E8E\u573A\u666F fixtures/ \u76EE\u5F55\u5185\u3002`);
|
|
39378
|
+
}
|
|
39379
|
+
if (!/^[a-f0-9]{64}$/.test(sha2563) || !["image/png", "image/jpeg"].includes(mime) || !Number.isSafeInteger(size) || size <= 0 || size > 10 * 1024 * 1024 || !["project_create", "step_transition"].includes(purpose)) {
|
|
39380
|
+
throw new Error(`test_fixture.invalid_asset: ${key} \u9700\u8981 sha256\u3001\u53D7\u652F\u6301\u7684\u56FE\u7247 mime\u3001\u6B63\u6574\u6570 size \u548C purpose\u3002`);
|
|
39381
|
+
}
|
|
39382
|
+
return { key, path: relativePath, sha256: sha2563, mime, size, purpose };
|
|
39383
|
+
});
|
|
39384
|
+
const createRefs = new Set(referencedAssetKeys(seeds.map((seed) => ({ name: seed.name, create_payload: seed.create_payload }))));
|
|
39385
|
+
const transitionRefs = new Set(referencedAssetKeys(seeds.map((seed) => seed.transitions)));
|
|
39386
|
+
for (const reference of [...createRefs, ...transitionRefs]) {
|
|
39387
|
+
if (!keys.has(reference)) throw new Error(`test_fixture.unresolved_asset_reference: asset ${reference} \u672A\u58F0\u660E\u3002`);
|
|
39388
|
+
}
|
|
39389
|
+
for (const asset of assets) {
|
|
39390
|
+
const usedByCreate = createRefs.has(asset.key);
|
|
39391
|
+
const usedByTransition = transitionRefs.has(asset.key);
|
|
39392
|
+
if (!usedByCreate && !usedByTransition) throw new Error(`test_fixture.unused_asset: asset ${asset.key} \u672A\u88AB fixture graph \u5F15\u7528\u3002`);
|
|
39393
|
+
if (usedByCreate && asset.purpose !== "project_create" || usedByTransition && asset.purpose !== "step_transition" || usedByCreate && usedByTransition) {
|
|
39394
|
+
throw new Error(`test_fixture.asset_purpose_mismatch: asset ${asset.key} \u7684 purpose \u4E0E\u5F15\u7528\u4F4D\u7F6E\u4E0D\u4E00\u81F4\u3002`);
|
|
39395
|
+
}
|
|
39396
|
+
}
|
|
39397
|
+
return assets;
|
|
39398
|
+
}
|
|
39399
|
+
function referencedSeedKeys(value) {
|
|
39400
|
+
const refs = /* @__PURE__ */ new Set();
|
|
39401
|
+
const visit = (current) => {
|
|
39402
|
+
if (typeof current === "string") {
|
|
39403
|
+
for (const match of current.matchAll(/\{\{seeds\.([A-Za-z0-9._-]+)\.(?:project_id|marker|outputs\.[A-Za-z0-9._-]+)\}\}/g)) {
|
|
39404
|
+
refs.add(match[1]);
|
|
39405
|
+
}
|
|
39406
|
+
return;
|
|
39407
|
+
}
|
|
39408
|
+
if (Array.isArray(current)) current.forEach(visit);
|
|
39409
|
+
else if (isRecord22(current)) Object.values(current).forEach(visit);
|
|
39410
|
+
};
|
|
39411
|
+
visit(value);
|
|
39412
|
+
return [...refs];
|
|
39413
|
+
}
|
|
39414
|
+
function orderFixtureSeeds(seeds) {
|
|
39415
|
+
const byKey = new Map(seeds.map((seed) => [seed.key, seed]));
|
|
39416
|
+
for (const seed of seeds) {
|
|
39417
|
+
const createReferences = referencedSeedKeys({ name: seed.name, create_payload: seed.create_payload });
|
|
39418
|
+
if (createReferences.includes(seed.key)) {
|
|
39419
|
+
throw new Error(`test_fixture.invalid_dependency: ${seed.key} \u7684\u521B\u5EFA\u53C2\u6570\u4E0D\u80FD\u5F15\u7528\u81EA\u8EAB\u8FD0\u884C\u65F6\u6570\u636E\u3002`);
|
|
39420
|
+
}
|
|
39421
|
+
const transitionReferences = referencedSeedKeys(seed.transitions).filter((key) => key !== seed.key);
|
|
39422
|
+
const implicit = [.../* @__PURE__ */ new Set([...createReferences, ...transitionReferences])];
|
|
39423
|
+
seed.depends_on = [.../* @__PURE__ */ new Set([...seed.depends_on, ...implicit])];
|
|
39424
|
+
for (const dependency of seed.depends_on) {
|
|
39425
|
+
if (dependency === seed.key || !byKey.has(dependency)) {
|
|
39426
|
+
throw new Error(`test_fixture.invalid_dependency: ${seed.key} \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u6216\u81EA\u5F15\u7528\u7684 seed ${dependency}\u3002`);
|
|
39427
|
+
}
|
|
39428
|
+
}
|
|
39429
|
+
}
|
|
39430
|
+
const ordered = [];
|
|
39431
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
39432
|
+
const visited = /* @__PURE__ */ new Set();
|
|
39433
|
+
const visit = (seed) => {
|
|
39434
|
+
if (visited.has(seed.key)) return;
|
|
39435
|
+
if (visiting.has(seed.key)) throw new Error(`test_fixture.dependency_cycle: fixture seed \u4F9D\u8D56\u5F62\u6210\u73AF: ${seed.key}\u3002`);
|
|
39436
|
+
visiting.add(seed.key);
|
|
39437
|
+
seed.depends_on.forEach((key) => visit(byKey.get(key)));
|
|
39438
|
+
visiting.delete(seed.key);
|
|
39439
|
+
visited.add(seed.key);
|
|
39440
|
+
ordered.push(seed);
|
|
39441
|
+
};
|
|
39442
|
+
seeds.forEach(visit);
|
|
39443
|
+
return ordered;
|
|
39444
|
+
}
|
|
38311
39445
|
function fixtureSeeds(manifest) {
|
|
38312
|
-
if (Number(manifest.version)
|
|
38313
|
-
throw new Error("test_fixture.invalid_manifest: version=1 \u4E14 seeds \u975E\u7A7A\u662F\u5FC5\u9700\u7684\u3002");
|
|
39446
|
+
if (![1, 2].includes(Number(manifest.version)) || !Array.isArray(manifest.seeds) || manifest.seeds.length === 0) {
|
|
39447
|
+
throw new Error("test_fixture.invalid_manifest: version=1|2 \u4E14 seeds \u975E\u7A7A\u662F\u5FC5\u9700\u7684\u3002");
|
|
38314
39448
|
}
|
|
38315
39449
|
const seedKeys = /* @__PURE__ */ new Set();
|
|
38316
|
-
|
|
38317
|
-
if (!
|
|
39450
|
+
const seeds = manifest.seeds.map((raw, index) => {
|
|
39451
|
+
if (!isRecord22(raw)) throw new Error(`test_fixture.invalid_seed: seeds[${index}] \u5FC5\u987B\u662F\u5BF9\u8C61\u3002`);
|
|
38318
39452
|
const key = safeToken(String(raw.key ?? ""), "seed_key");
|
|
39453
|
+
if (key === "assets") throw new Error("test_fixture.invalid_seed_key: seed key assets \u662F fixture runtime \u4FDD\u7559\u5B57\u6BB5\u3002");
|
|
38319
39454
|
if (seedKeys.has(key)) throw new Error(`test_fixture.invalid_manifest: seed key \u91CD\u590D: ${key}\u3002`);
|
|
38320
39455
|
seedKeys.add(key);
|
|
38321
39456
|
const flowType = String(raw.flow_type ?? "").trim();
|
|
38322
|
-
const
|
|
38323
|
-
const
|
|
39457
|
+
const flowKey = String(raw.flow_key ?? "").trim();
|
|
39458
|
+
const name = String(raw.name ?? "").trim();
|
|
39459
|
+
const payload = isRecord22(raw.create_payload) ? structuredClone(raw.create_payload) : null;
|
|
39460
|
+
const form = payload && isRecord22(payload.form) ? payload.form : null;
|
|
38324
39461
|
const markerField = String(raw.marker_field ?? "").trim();
|
|
38325
39462
|
const markerReadbackPath = safeReadbackPath(raw.marker_readback_path, "marker_readback_path");
|
|
38326
|
-
const cleanup =
|
|
39463
|
+
const cleanup = isRecord22(raw.cleanup) ? raw.cleanup : null;
|
|
38327
39464
|
const cleanupMode = String(cleanup?.mode ?? "");
|
|
38328
39465
|
const cleanupInstructions = String(cleanup?.instructions ?? "").trim();
|
|
39466
|
+
const creator = isRecord22(raw.creator) ? raw.creator : { mode: "typed_cli" };
|
|
39467
|
+
const creatorMode = String(creator.mode ?? "typed_cli");
|
|
39468
|
+
const bbsKey = String(creator.bbs_key ?? "").trim();
|
|
39469
|
+
const bbsAction = String(creator.bbs_action ?? "").trim();
|
|
39470
|
+
const actor = fixtureActor(raw.actor, key);
|
|
38329
39471
|
if (!flowType || !form || !markerField) {
|
|
38330
39472
|
throw new Error(`test_fixture.invalid_seed: ${key} \u9700\u8981 flow_type\u3001create_payload.form \u548C marker_field\u3002`);
|
|
38331
39473
|
}
|
|
39474
|
+
const projectNameMarker = markerField === "$project.name";
|
|
39475
|
+
if (["__proto__", "prototype", "constructor"].includes(markerField)) {
|
|
39476
|
+
throw new Error(`test_fixture.invalid_marker_field: ${key} marker_field \u4E0D\u80FD\u4F7F\u7528\u5371\u9669\u5BF9\u8C61\u5B57\u6BB5\u540D\u3002`);
|
|
39477
|
+
}
|
|
39478
|
+
if (!projectNameMarker && !Object.hasOwn(form, markerField)) {
|
|
39479
|
+
throw new Error(`test_fixture.marker_field_missing: ${key} marker_field \u5FC5\u987B\u662F create_payload.form \u4E2D\u5DF2\u5BA1\u6838\u7684\u5B57\u6BB5\u3002`);
|
|
39480
|
+
}
|
|
39481
|
+
const expectedMarkerReadbackPath = projectNameMarker ? "name" : `metaForm.key_to_value.${markerField}`;
|
|
39482
|
+
if (markerReadbackPath !== expectedMarkerReadbackPath) {
|
|
39483
|
+
throw new Error(
|
|
39484
|
+
`test_fixture.marker_readback_mismatch: ${key} marker_readback_path \u5FC5\u987B\u662F ${expectedMarkerReadbackPath}\u3002`
|
|
39485
|
+
);
|
|
39486
|
+
}
|
|
39487
|
+
if (payload && ("projectForm" in payload || "project_form" in payload || "user_id" in payload || "owner_id" in payload)) {
|
|
39488
|
+
throw new Error(
|
|
39489
|
+
`test_fixture.payload_override_forbidden: ${key} \u4E0D\u5F97\u5728 create_payload \u4E2D\u76F4\u63A5\u63D0\u4F9B projectForm\u3001user_id \u6216 owner_id\uFF1B\u8BF7\u4F7F\u7528 form \u548C actor \u5951\u7EA6\u3002`
|
|
39490
|
+
);
|
|
39491
|
+
}
|
|
38332
39492
|
const expectedState = String(raw.expected_state ?? "").trim();
|
|
38333
39493
|
const stateReadbackPath = expectedState ? safeReadbackPath(raw.state_readback_path, "state_readback_path") : void 0;
|
|
38334
39494
|
if (!["none", "retain", "restore"].includes(cleanupMode) || !cleanupInstructions) {
|
|
38335
39495
|
throw new Error(`test_fixture.cleanup_contract_required: ${key} \u9700\u8981\u660E\u786E cleanup.mode \u548C instructions\u3002`);
|
|
38336
39496
|
}
|
|
39497
|
+
if (!["typed_cli", "bbs"].includes(creatorMode)) {
|
|
39498
|
+
throw new Error(`test_fixture.creator_mode_invalid: ${key} creator.mode \u53EA\u5141\u8BB8 typed_cli \u6216 bbs\u3002`);
|
|
39499
|
+
}
|
|
39500
|
+
if (creatorMode === "bbs" && (!bbsKey || !bbsAction)) {
|
|
39501
|
+
throw new Error(`test_fixture.bbs_contract_required: ${key} \u4F7F\u7528 BBS \u65F6\u5FC5\u987B\u58F0\u660E creator.bbs_key \u548C creator.bbs_action\u3002`);
|
|
39502
|
+
}
|
|
39503
|
+
const dependsOn = Array.isArray(raw.depends_on) ? raw.depends_on.map((value) => safeToken(String(value), "dependency_key")) : [];
|
|
38337
39504
|
return {
|
|
38338
39505
|
key,
|
|
38339
39506
|
flow_type: flowType,
|
|
39507
|
+
...flowKey ? { flow_key: flowKey } : {},
|
|
39508
|
+
...name ? { name } : {},
|
|
38340
39509
|
create_payload: payload,
|
|
38341
39510
|
marker_field: markerField,
|
|
38342
39511
|
marker_readback_path: markerReadbackPath,
|
|
38343
39512
|
...expectedState ? { expected_state: expectedState, state_readback_path: stateReadbackPath } : {},
|
|
38344
|
-
cleanup: { mode: cleanupMode, instructions: cleanupInstructions }
|
|
39513
|
+
cleanup: { mode: cleanupMode, instructions: cleanupInstructions },
|
|
39514
|
+
creator: {
|
|
39515
|
+
mode: creatorMode,
|
|
39516
|
+
...bbsKey ? { bbs_key: bbsKey } : {},
|
|
39517
|
+
...bbsAction ? { bbs_action: bbsAction } : {}
|
|
39518
|
+
},
|
|
39519
|
+
actor,
|
|
39520
|
+
depends_on: dependsOn,
|
|
39521
|
+
outputs: fixtureOutputs(raw.outputs, key),
|
|
39522
|
+
transitions: fixtureTransitions(raw.transitions, key)
|
|
38345
39523
|
};
|
|
38346
39524
|
});
|
|
39525
|
+
return orderFixtureSeeds(seeds);
|
|
38347
39526
|
}
|
|
38348
39527
|
function markerFor(runId, key) {
|
|
38349
39528
|
return `E2E-SEED-${runId}-${key}`;
|
|
38350
39529
|
}
|
|
38351
39530
|
function payloadWithMarker(seed, marker) {
|
|
38352
39531
|
const payload = structuredClone(seed.create_payload);
|
|
39532
|
+
if (seed.marker_field === "$project.name") return payload;
|
|
38353
39533
|
const current = String(payload.form[seed.marker_field] ?? "").trim();
|
|
38354
39534
|
payload.form[seed.marker_field] = current ? `${current} ${marker}` : marker;
|
|
38355
39535
|
return payload;
|
|
38356
39536
|
}
|
|
39537
|
+
function projectNameWithMarker(seed, marker) {
|
|
39538
|
+
const current = String(seed.name ?? "").trim();
|
|
39539
|
+
return current ? `${current} ${marker}` : marker;
|
|
39540
|
+
}
|
|
38357
39541
|
function readbackValueAtPath(readback, readbackPath) {
|
|
39542
|
+
const formValueMatch = /^metaForm\.key_to_value\.([^.]+)$/.exec(readbackPath);
|
|
39543
|
+
if (formValueMatch && isRecord22(readback)) {
|
|
39544
|
+
const metaForm = readback.metaForm;
|
|
39545
|
+
if (isRecord22(metaForm)) {
|
|
39546
|
+
const keyToValue = metaForm.key_to_value;
|
|
39547
|
+
if (isRecord22(keyToValue) && Object.hasOwn(keyToValue, formValueMatch[1])) {
|
|
39548
|
+
return keyToValue[formValueMatch[1]];
|
|
39549
|
+
}
|
|
39550
|
+
if (Array.isArray(metaForm.value)) {
|
|
39551
|
+
const item = metaForm.value.find((candidate) => isRecord22(candidate) && (candidate.key === formValueMatch[1] || candidate.field === formValueMatch[1]));
|
|
39552
|
+
if (isRecord22(item)) {
|
|
39553
|
+
const value = item.value;
|
|
39554
|
+
return isRecord22(value) && Object.hasOwn(value, "value") ? value.value : value;
|
|
39555
|
+
}
|
|
39556
|
+
}
|
|
39557
|
+
}
|
|
39558
|
+
return void 0;
|
|
39559
|
+
}
|
|
38358
39560
|
let current = readback;
|
|
38359
39561
|
for (const segment of readbackPath.split(".")) {
|
|
38360
|
-
if (
|
|
39562
|
+
if (Array.isArray(current) && /^\d+$/.test(segment)) {
|
|
39563
|
+
current = current[Number(segment)];
|
|
39564
|
+
continue;
|
|
39565
|
+
}
|
|
39566
|
+
if (!isRecord22(current) || !Object.hasOwn(current, segment)) return void 0;
|
|
38361
39567
|
current = current[segment];
|
|
38362
39568
|
}
|
|
38363
39569
|
return current;
|
|
38364
39570
|
}
|
|
39571
|
+
function runtimeReferenceValue(reference, runtime, assets) {
|
|
39572
|
+
const assetMatch = /^assets\.([A-Za-z0-9._-]+)\.url$/.exec(reference);
|
|
39573
|
+
if (assetMatch) {
|
|
39574
|
+
const asset = assets[assetMatch[1]];
|
|
39575
|
+
if (!asset) throw new Error(`test_fixture.unresolved_asset_reference: asset ${assetMatch[1]} \u5C1A\u672A\u5B8C\u6210\u4E0A\u4F20\u56DE\u8BFB\u3002`);
|
|
39576
|
+
return asset.url;
|
|
39577
|
+
}
|
|
39578
|
+
const match = /^seeds\.([A-Za-z0-9._-]+)\.(project_id|marker|outputs\.([A-Za-z0-9._-]+))$/.exec(reference);
|
|
39579
|
+
if (!match) throw new Error(`test_fixture.invalid_reference: \u4E0D\u652F\u6301\u7684 fixture \u5F15\u7528 {{${reference}}}\u3002`);
|
|
39580
|
+
const seed = runtime[match[1]];
|
|
39581
|
+
if (!seed) throw new Error(`test_fixture.unresolved_reference: fixture \u5F15\u7528 ${match[1]} \u5C1A\u672A\u4EA7\u751F\u8FD0\u884C\u65F6\u6570\u636E\u3002`);
|
|
39582
|
+
if (match[2] === "project_id") return seed.project_id;
|
|
39583
|
+
if (match[2] === "marker") return seed.marker;
|
|
39584
|
+
if (!Object.hasOwn(seed.outputs, match[3])) {
|
|
39585
|
+
throw new Error(`test_fixture.unresolved_reference: ${match[1]} \u672A\u5BFC\u51FA output ${match[3]}\u3002`);
|
|
39586
|
+
}
|
|
39587
|
+
return seed.outputs[match[3]];
|
|
39588
|
+
}
|
|
39589
|
+
function resolveRuntimeReferences(value, runtime, assets = {}) {
|
|
39590
|
+
if (typeof value === "string") {
|
|
39591
|
+
const exact = /^\{\{([^{}]+)\}\}$/.exec(value);
|
|
39592
|
+
if (exact) return runtimeReferenceValue(exact[1], runtime, assets);
|
|
39593
|
+
return value.replace(/\{\{([^{}]+)\}\}/g, (_match, reference) => String(runtimeReferenceValue(reference, runtime, assets)));
|
|
39594
|
+
}
|
|
39595
|
+
if (Array.isArray(value)) return value.map((item) => resolveRuntimeReferences(item, runtime, assets));
|
|
39596
|
+
if (isRecord22(value)) {
|
|
39597
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, resolveRuntimeReferences(item, runtime, assets)]));
|
|
39598
|
+
}
|
|
39599
|
+
return value;
|
|
39600
|
+
}
|
|
39601
|
+
function fixtureRuntimeOutputs(seed, readback, requireOutputs = true) {
|
|
39602
|
+
const outputs = {};
|
|
39603
|
+
for (const [key, readbackPath] of Object.entries(seed.outputs)) {
|
|
39604
|
+
const value = readbackValueAtPath(readback, readbackPath);
|
|
39605
|
+
if (value === void 0 || value === null || value === "") {
|
|
39606
|
+
if (!requireOutputs) continue;
|
|
39607
|
+
throw new Error(`test_fixture.output_readback_missing: ${seed.key}.${key} \u65E0\u6CD5\u4ECE\u7CBE\u786E\u8DEF\u5F84 ${readbackPath} \u56DE\u8BFB\u3002`);
|
|
39608
|
+
}
|
|
39609
|
+
outputs[key] = value;
|
|
39610
|
+
}
|
|
39611
|
+
return outputs;
|
|
39612
|
+
}
|
|
38365
39613
|
async function writeReceipt(output, receipt) {
|
|
38366
39614
|
if (!output) return void 0;
|
|
38367
39615
|
const resolved = path23.resolve(output);
|
|
@@ -38371,11 +39619,208 @@ async function writeReceipt(output, receipt) {
|
|
|
38371
39619
|
await rename6(temporary, resolved);
|
|
38372
39620
|
return resolved;
|
|
38373
39621
|
}
|
|
39622
|
+
async function readOptionalReceipt(input) {
|
|
39623
|
+
let raw;
|
|
39624
|
+
try {
|
|
39625
|
+
raw = await readFile24(input, "utf8");
|
|
39626
|
+
} catch (error) {
|
|
39627
|
+
if (error.code === "ENOENT") return void 0;
|
|
39628
|
+
throw error;
|
|
39629
|
+
}
|
|
39630
|
+
try {
|
|
39631
|
+
const parsed = JSON.parse(raw);
|
|
39632
|
+
if (!isRecord22(parsed)) throw new Error("receipt root must be an object");
|
|
39633
|
+
return parsed;
|
|
39634
|
+
} catch (error) {
|
|
39635
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
39636
|
+
throw new Error(`test_fixture.state_invalid: cannot parse existing fixture state ${input}: ${message}`);
|
|
39637
|
+
}
|
|
39638
|
+
}
|
|
39639
|
+
function fixtureAssetMime(content) {
|
|
39640
|
+
if (content.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) return "image/png";
|
|
39641
|
+
if (content.subarray(0, 3).equals(Buffer.from([255, 216, 255]))) return "image/jpeg";
|
|
39642
|
+
return void 0;
|
|
39643
|
+
}
|
|
39644
|
+
async function readReviewedFixtureAsset(asset, scenarioRoot) {
|
|
39645
|
+
const root = await realpath9(path23.join(scenarioRoot, "fixtures"));
|
|
39646
|
+
const candidate = path23.resolve(scenarioRoot, asset.path);
|
|
39647
|
+
const fileInfo = await lstat5(candidate);
|
|
39648
|
+
if (!fileInfo.isFile() || fileInfo.isSymbolicLink()) {
|
|
39649
|
+
throw new Error(`test_fixture.asset_file_invalid: ${asset.key} \u5FC5\u987B\u662F\u975E\u7B26\u53F7\u94FE\u63A5\u666E\u901A\u6587\u4EF6\u3002`);
|
|
39650
|
+
}
|
|
39651
|
+
const file = await realpath9(candidate);
|
|
39652
|
+
if (!file.startsWith(`${root}${path23.sep}`)) {
|
|
39653
|
+
throw new Error(`test_fixture.asset_path_escape: ${asset.key} \u5FC5\u987B\u4FDD\u7559\u5728\u573A\u666F fixtures/ \u76EE\u5F55\u5185\u3002`);
|
|
39654
|
+
}
|
|
39655
|
+
const content = await readFile24(file);
|
|
39656
|
+
const actualSha256 = createHash14("sha256").update(content).digest("hex");
|
|
39657
|
+
const actualMime = fixtureAssetMime(content);
|
|
39658
|
+
if (content.length !== asset.size || actualSha256 !== asset.sha256 || actualMime !== asset.mime) {
|
|
39659
|
+
throw new Error(`test_fixture.asset_metadata_mismatch: ${asset.key} \u7684 size/sha256/mime \u4E0E\u5DF2\u5BA1\u6838\u6E05\u5355\u4E0D\u4E00\u81F4\u3002`);
|
|
39660
|
+
}
|
|
39661
|
+
return { file, content };
|
|
39662
|
+
}
|
|
39663
|
+
async function readbackUploadedFixtureAsset(asset, url) {
|
|
39664
|
+
const response = await fetch(url);
|
|
39665
|
+
if (!response.ok) throw new Error(`test_fixture.asset_readback_failed: ${asset.key} upload URL \u8FD4\u56DE HTTP ${response.status}\u3002`);
|
|
39666
|
+
const content = Buffer.from(await response.arrayBuffer());
|
|
39667
|
+
const actualSha256 = createHash14("sha256").update(content).digest("hex");
|
|
39668
|
+
if (content.length !== asset.size || actualSha256 !== asset.sha256 || fixtureAssetMime(content) !== asset.mime) {
|
|
39669
|
+
throw new Error(`test_fixture.asset_readback_mismatch: ${asset.key} \u4E0A\u4F20\u540E\u5185\u5BB9\u4E0E\u5DF2\u5BA1\u6838\u6587\u4EF6\u4E0D\u4E00\u81F4\u3002`);
|
|
39670
|
+
}
|
|
39671
|
+
}
|
|
39672
|
+
async function uploadTypedFixtureAsset(options) {
|
|
39673
|
+
const reviewed = await readReviewedFixtureAsset(options.asset, options.scenarioRoot);
|
|
39674
|
+
const form = new FormData();
|
|
39675
|
+
const content = reviewed.content.buffer.slice(
|
|
39676
|
+
reviewed.content.byteOffset,
|
|
39677
|
+
reviewed.content.byteOffset + reviewed.content.byteLength
|
|
39678
|
+
);
|
|
39679
|
+
form.set("file", new Blob([content], { type: options.asset.mime }), path23.basename(reviewed.file));
|
|
39680
|
+
await options.onMutationAttempt();
|
|
39681
|
+
const uploaded = await apiRequest(options.client, "POST", "/upload", {
|
|
39682
|
+
data: form,
|
|
39683
|
+
capability: options.asset.purpose === "project_create" ? "project.create" : "step.submit"
|
|
39684
|
+
});
|
|
39685
|
+
const uploadedPath = String(uploaded.path ?? "").trim();
|
|
39686
|
+
if (!/^\/upload\/[^?#]+$/.test(uploadedPath) || uploadedPath.split("/").includes("..")) {
|
|
39687
|
+
throw new Error(`test_fixture.asset_upload_response_invalid: ${options.asset.key} upload response \u7F3A\u5C11\u5B89\u5168\u7684 /upload/ path\u3002`);
|
|
39688
|
+
}
|
|
39689
|
+
const url = new URL(uploadedPath, options.profile.config.origin).toString();
|
|
39690
|
+
await options.onRemoteSubmitted(url);
|
|
39691
|
+
await readbackUploadedFixtureAsset(options.asset, url);
|
|
39692
|
+
return { url, sha256: options.asset.sha256, mime: options.asset.mime, size: options.asset.size };
|
|
39693
|
+
}
|
|
39694
|
+
async function readbackFixtureSeed(client, seed, projectId, marker, options = {}) {
|
|
39695
|
+
const readback = await apiRequest(client, "GET", `/project/${projectId}`, { capability: "project.get" });
|
|
39696
|
+
const markerValue = readbackValueAtPath(readback, seed.marker_readback_path);
|
|
39697
|
+
const markerVerified = typeof markerValue === "string" && markerValue.split(/\s+/).includes(marker);
|
|
39698
|
+
const stateValue = seed.state_readback_path ? readbackValueAtPath(readback, seed.state_readback_path) : void 0;
|
|
39699
|
+
const stateVerified = options.verifyState === false || !seed.expected_state || stateValue === seed.expected_state;
|
|
39700
|
+
const ownerId2 = Number(readbackValueAtPath(readback, "owner_id"));
|
|
39701
|
+
const actorVerified = seed.actor.mode !== "user" || ownerId2 === seed.actor.user_id;
|
|
39702
|
+
return {
|
|
39703
|
+
key: seed.key,
|
|
39704
|
+
project_id: projectId,
|
|
39705
|
+
marker,
|
|
39706
|
+
marker_readback_path: seed.marker_readback_path,
|
|
39707
|
+
lifecycle_state: markerVerified && stateVerified && actorVerified ? "readback_verified" : "readback_mismatch",
|
|
39708
|
+
evidence_layer: "typed_project_readback",
|
|
39709
|
+
creation_transport: "typed_cli",
|
|
39710
|
+
creator: seed.creator,
|
|
39711
|
+
actor: seed.actor,
|
|
39712
|
+
actor_verified: actorVerified,
|
|
39713
|
+
owner_id: Number.isSafeInteger(ownerId2) && ownerId2 > 0 ? ownerId2 : null,
|
|
39714
|
+
marker_verified: markerVerified,
|
|
39715
|
+
state_verified: stateVerified,
|
|
39716
|
+
expected_state: seed.expected_state ?? null,
|
|
39717
|
+
state_readback_path: seed.state_readback_path ?? null,
|
|
39718
|
+
cleanup: seed.cleanup,
|
|
39719
|
+
outputs: fixtureRuntimeOutputs(seed, readback, options.requireOutputs !== false)
|
|
39720
|
+
};
|
|
39721
|
+
}
|
|
39722
|
+
async function resolveFixtureActor(client, contract, label, requireUserId = false) {
|
|
39723
|
+
if (contract.mode === "profile") {
|
|
39724
|
+
if (!requireUserId) return { mode: "profile" };
|
|
39725
|
+
const current = await apiRequest(client, "GET", "/user/current");
|
|
39726
|
+
const id = Number(current.id);
|
|
39727
|
+
if (!Number.isSafeInteger(id) || id <= 0) throw new Error(`test_fixture.actor_current_invalid: ${label} \u5F53\u524D profile \u7528\u6237\u65E0\u6709\u6548 ID\u3002`);
|
|
39728
|
+
return { mode: "profile", user_id: id, name: current.name ?? null, evidence_layer: "typed_user_readback" };
|
|
39729
|
+
}
|
|
39730
|
+
const operator = await apiRequest(client, "GET", "/user/current");
|
|
39731
|
+
const points = Array.isArray(operator.points) ? operator.points.map(String) : [];
|
|
39732
|
+
const canActAsUser = operator.can_mock === true || operator.role_key === "super" || points.includes("organization.admin") || points.includes("user.mock");
|
|
39733
|
+
if (!canActAsUser) {
|
|
39734
|
+
throw new Error("test_fixture.actor_permission_missing: target-user fixture creation requires user.mock, organization.admin, or super-user permission");
|
|
39735
|
+
}
|
|
39736
|
+
const userId = Number(contract.user_id);
|
|
39737
|
+
const response = await apiRequest(client, "GET", "/user", {
|
|
39738
|
+
params: {
|
|
39739
|
+
ids: String(userId),
|
|
39740
|
+
subRelations: "role",
|
|
39741
|
+
field_filter: "id,name,status,is_del,organization_id"
|
|
39742
|
+
},
|
|
39743
|
+
capability: "user.readback"
|
|
39744
|
+
});
|
|
39745
|
+
const rows2 = Array.isArray(response) ? response.filter(isRecord22) : isRecord22(response) && Array.isArray(response.data) ? response.data.filter(isRecord22) : [];
|
|
39746
|
+
const user = rows2.find((item) => Number(item.id) === userId);
|
|
39747
|
+
if (!user) throw new Error(`test_fixture.actor_not_found: target user ${userId} was not found`);
|
|
39748
|
+
if (String(user.name ?? "").trim() !== contract.expected_name) {
|
|
39749
|
+
throw new Error(`test_fixture.actor_name_mismatch: target user ${userId} is ${String(user.name ?? "")}, not ${contract.expected_name}`);
|
|
39750
|
+
}
|
|
39751
|
+
if (Number(user.status) !== 0 || Number(user.is_del) !== 0) {
|
|
39752
|
+
throw new Error(`test_fixture.actor_inactive: target user ${userId} is inactive or deleted`);
|
|
39753
|
+
}
|
|
39754
|
+
if (operator.organization_id !== void 0 && user.organization_id !== void 0 && Number(operator.organization_id) !== Number(user.organization_id)) {
|
|
39755
|
+
throw new Error(`test_fixture.actor_organization_mismatch: target user ${userId} is outside the operator organization`);
|
|
39756
|
+
}
|
|
39757
|
+
return {
|
|
39758
|
+
mode: "user",
|
|
39759
|
+
user_id: userId,
|
|
39760
|
+
name: String(user.name),
|
|
39761
|
+
organization_id: user.organization_id ?? null,
|
|
39762
|
+
active: true,
|
|
39763
|
+
authorized_by_user_id: operator.id ?? null,
|
|
39764
|
+
evidence_layer: "typed_user_readback"
|
|
39765
|
+
};
|
|
39766
|
+
}
|
|
39767
|
+
function stepOwnerIds2(step) {
|
|
39768
|
+
if (!isRecord22(step)) return [];
|
|
39769
|
+
const owners = [step.owners, step.owner].find(Array.isArray);
|
|
39770
|
+
return (owners ?? []).map((owner) => Number(isRecord22(owner) ? owner.id ?? owner.owner_id ?? owner.user_id : owner)).filter((id) => Number.isSafeInteger(id) && id > 0);
|
|
39771
|
+
}
|
|
39772
|
+
async function executeFixtureTransition(options) {
|
|
39773
|
+
const transition = resolveRuntimeReferences(options.transition, options.runtime, options.assets);
|
|
39774
|
+
const stepId = Number(transition.step_id);
|
|
39775
|
+
if (!Number.isSafeInteger(stepId) || stepId <= 0) {
|
|
39776
|
+
throw new Error(`test_fixture.transition_step_invalid: ${options.seed.key}.${transition.key} step_id \u5FC5\u987B\u89E3\u6790\u4E3A\u6B63\u6574\u6570\u3002`);
|
|
39777
|
+
}
|
|
39778
|
+
const actor = await resolveFixtureActor(options.client, transition.actor, `${options.seed.key}.${transition.key}`, true);
|
|
39779
|
+
const step = await apiRequest(options.client, "GET", `/step/${stepId}`, { capability: "step.get" });
|
|
39780
|
+
if (Number(readbackValueAtPath(step, "project_id")) !== options.projectId) {
|
|
39781
|
+
throw new Error(`test_fixture.transition_project_mismatch: step ${stepId} \u4E0D\u5C5E\u4E8E project ${options.projectId}\u3002`);
|
|
39782
|
+
}
|
|
39783
|
+
const ownerIds = stepOwnerIds2(step);
|
|
39784
|
+
if (!ownerIds.includes(Number(actor.user_id))) {
|
|
39785
|
+
throw new Error(`test_fixture.transition_actor_not_owner: ${options.seed.key}.${transition.key} actor ${String(actor.user_id)} \u4E0D\u662F step ${stepId} \u7684\u7CBE\u786E owner\u3002`);
|
|
39786
|
+
}
|
|
39787
|
+
const payload = {
|
|
39788
|
+
...transition.data,
|
|
39789
|
+
project_id: options.projectId,
|
|
39790
|
+
step_id: stepId,
|
|
39791
|
+
action: transition.action,
|
|
39792
|
+
user_id: Number(actor.user_id),
|
|
39793
|
+
...transition.target_step ? { target_step: transition.target_step } : {}
|
|
39794
|
+
};
|
|
39795
|
+
await options.onMutationAttempt({ step_id: stepId, actor_user_id: actor.user_id, action: transition.action });
|
|
39796
|
+
await apiRequest(options.client, "PUT", "/step/open-api/next", {
|
|
39797
|
+
data: payload,
|
|
39798
|
+
capability: "step.submit"
|
|
39799
|
+
});
|
|
39800
|
+
const afterStep = await apiRequest(options.client, "GET", `/step/${stepId}`, { capability: "step.get" });
|
|
39801
|
+
const status = Number(readbackValueAtPath(afterStep, "status"));
|
|
39802
|
+
if (![3, 5].includes(status)) {
|
|
39803
|
+
throw new Error(`test_fixture.transition_readback_unconfirmed: ${options.seed.key}.${transition.key} step ${stepId} status=${String(status)}\u3002`);
|
|
39804
|
+
}
|
|
39805
|
+
return {
|
|
39806
|
+
key: transition.key,
|
|
39807
|
+
step_id: stepId,
|
|
39808
|
+
project_id: options.projectId,
|
|
39809
|
+
action: transition.action,
|
|
39810
|
+
actor,
|
|
39811
|
+
status,
|
|
39812
|
+
lifecycle_state: "readback_verified",
|
|
39813
|
+
evidence_layer: "typed_step_readback"
|
|
39814
|
+
};
|
|
39815
|
+
}
|
|
38374
39816
|
function registerTestFixtureCommands(program2) {
|
|
38375
39817
|
const fixture = program2.command("test-fixture").description("Plan and verify deterministic BPMAX E2E business-data fixtures");
|
|
38376
|
-
fixture.command("plan").description("Generate unique markers, typed
|
|
39818
|
+
fixture.command("plan").description("Generate unique markers, typed direct-create commands, and cleanup contracts without writing business data").requiredOption("--json <json>", "Fixture manifest JSON or @file").requiredOption("--run-id <runId>", "Stable current-run identifier").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
38377
39819
|
const manifest = await parseJsonInput2(options.json, "--json");
|
|
38378
39820
|
const seeds = fixtureSeeds(manifest);
|
|
39821
|
+
const assets = fixtureAssets(manifest, seeds);
|
|
39822
|
+
const scenarioRoot = options.json.startsWith("@") ? path23.dirname(path23.resolve(options.json.slice(1))) : process.cwd();
|
|
39823
|
+
await Promise.all(assets.map((asset) => readReviewedFixtureAsset(asset, scenarioRoot)));
|
|
38379
39824
|
const runId = safeToken(options.runId, "run_id");
|
|
38380
39825
|
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
38381
39826
|
printResult(options.format, {
|
|
@@ -38385,6 +39830,24 @@ function registerTestFixtureCommands(program2) {
|
|
|
38385
39830
|
profile: profile.name,
|
|
38386
39831
|
run_id: runId,
|
|
38387
39832
|
evidence_layer: "fixture_plan",
|
|
39833
|
+
fixture_manifest_sha256: fixtureManifestSha256(manifest),
|
|
39834
|
+
assets: assets.map((asset) => ({ ...asset, lifecycle_state: "planned", next_evidence_required: ["upload_url", "content_sha256_readback"] })),
|
|
39835
|
+
create_command: {
|
|
39836
|
+
executable: "bpmax-cli",
|
|
39837
|
+
argv: [
|
|
39838
|
+
"test-fixture",
|
|
39839
|
+
"create",
|
|
39840
|
+
"--profile",
|
|
39841
|
+
profile.name,
|
|
39842
|
+
"--json",
|
|
39843
|
+
options.json,
|
|
39844
|
+
"--manifest",
|
|
39845
|
+
"<execution-manifest>",
|
|
39846
|
+
"--format",
|
|
39847
|
+
"json"
|
|
39848
|
+
],
|
|
39849
|
+
available_after: "confirmed_scoped_run_start"
|
|
39850
|
+
},
|
|
38388
39851
|
seeds: seeds.map((seed) => {
|
|
38389
39852
|
const marker = markerFor(runId, seed.key);
|
|
38390
39853
|
const payload = payloadWithMarker(seed, marker);
|
|
@@ -38398,35 +39861,377 @@ function registerTestFixtureCommands(program2) {
|
|
|
38398
39861
|
state_readback_path: seed.state_readback_path ?? null,
|
|
38399
39862
|
cleanup: seed.cleanup,
|
|
38400
39863
|
create_payload: payload,
|
|
38401
|
-
|
|
38402
|
-
|
|
38403
|
-
|
|
38404
|
-
|
|
38405
|
-
|
|
38406
|
-
|
|
38407
|
-
profile.name,
|
|
38408
|
-
"--flow-type",
|
|
38409
|
-
seed.flow_type,
|
|
38410
|
-
"--json",
|
|
38411
|
-
JSON.stringify(payload),
|
|
38412
|
-
"--handoff-only",
|
|
38413
|
-
"--format",
|
|
38414
|
-
"json"
|
|
38415
|
-
]
|
|
38416
|
-
},
|
|
39864
|
+
project_name: projectNameWithMarker(seed, marker),
|
|
39865
|
+
creator: seed.creator,
|
|
39866
|
+
actor: seed.actor,
|
|
39867
|
+
depends_on: seed.depends_on,
|
|
39868
|
+
outputs: seed.outputs,
|
|
39869
|
+
transitions: seed.transitions,
|
|
38417
39870
|
next_evidence_required: [
|
|
38418
|
-
"browser_prefill_verified",
|
|
38419
39871
|
"project_id",
|
|
38420
|
-
"project_readback_verified"
|
|
39872
|
+
"project_readback_verified",
|
|
39873
|
+
...seed.transitions.length > 0 ? ["transition_readback_verified", "fixture_runtime_data"] : []
|
|
38421
39874
|
]
|
|
38422
39875
|
};
|
|
38423
39876
|
})
|
|
38424
39877
|
});
|
|
38425
39878
|
});
|
|
39879
|
+
fixture.command("create").description("Create current-run BPMAX prerequisite data through typed CLI and record passed precondition evidence").requiredOption("--json <json>", "Fixture manifest JSON or @file").requiredOption("--manifest <file>", "Current scoped-run execution manifest").option("--profile <profile>", "Profile name; must match the execution manifest").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
39880
|
+
const fixtureManifest = await parseJsonInput2(options.json, "--json");
|
|
39881
|
+
const seeds = fixtureSeeds(fixtureManifest);
|
|
39882
|
+
const assets = fixtureAssets(fixtureManifest, seeds);
|
|
39883
|
+
const manifestPath = path23.resolve(options.manifest);
|
|
39884
|
+
const result = await withExecutionOperationLock(manifestPath, async () => {
|
|
39885
|
+
const execution = await inspectPendingTestSuiteRunPrecondition(manifestPath, options.profile);
|
|
39886
|
+
if (!execution.v2_confirmation_receipt || !execution.v2_confirmation_digest) {
|
|
39887
|
+
throw new Error(
|
|
39888
|
+
"test_fixture.confirmation_required: typed fixture creation requires a V2 scoped run bound to explicit user confirmation"
|
|
39889
|
+
);
|
|
39890
|
+
}
|
|
39891
|
+
const profile = resolveProfile(await loadConfig(), options.profile || execution.profile);
|
|
39892
|
+
if (profile.name !== execution.profile) {
|
|
39893
|
+
throw new Error(`test_fixture.profile_mismatch: execution manifest profile is ${execution.profile}, not ${profile.name}`);
|
|
39894
|
+
}
|
|
39895
|
+
const client = createApiClient(profile);
|
|
39896
|
+
const runDir = path23.dirname(manifestPath);
|
|
39897
|
+
const evidenceDir = path23.join(runDir, "precondition-evidence");
|
|
39898
|
+
await preflightExecutionEvidenceDirectory({ manifest: manifestPath, evidenceDir: runDir });
|
|
39899
|
+
await preflightExecutionEvidenceDirectory({ manifest: manifestPath, evidenceDir });
|
|
39900
|
+
const statePath = path23.join(runDir, "fixture-create-state.json");
|
|
39901
|
+
const evidencePath = path23.join(evidenceDir, "typed-fixture-create.json");
|
|
39902
|
+
const runtimeDataPath = path23.join(runDir, "fixture-runtime-data.json");
|
|
39903
|
+
const manifestHash = fixtureManifestSha256(fixtureManifest);
|
|
39904
|
+
if (!execution.fixture_manifest) {
|
|
39905
|
+
throw new Error(
|
|
39906
|
+
"test_fixture.unreviewed_manifest: the scoped run does not anchor a reviewed fixtures.json asset; update the draft, review/promote it, confirm the scope, and start a new run"
|
|
39907
|
+
);
|
|
39908
|
+
}
|
|
39909
|
+
if (execution.fixture_manifest.sha256 !== manifestHash) {
|
|
39910
|
+
throw new Error(
|
|
39911
|
+
"test_fixture.manifest_hash_mismatch: --json does not match the fixtures.json asset anchored by the confirmed scoped run"
|
|
39912
|
+
);
|
|
39913
|
+
}
|
|
39914
|
+
let state = await readOptionalReceipt(statePath);
|
|
39915
|
+
if (state && (state.kind !== "bpmax_test_fixture_create_state" || state.run_id !== execution.run_id || state.fixture_manifest_sha256 !== manifestHash)) {
|
|
39916
|
+
throw new Error("test_fixture.state_mismatch: existing fixture create state does not match this run and manifest");
|
|
39917
|
+
}
|
|
39918
|
+
if (!state) {
|
|
39919
|
+
state = {
|
|
39920
|
+
schema_version: 1,
|
|
39921
|
+
kind: "bpmax_test_fixture_create_state",
|
|
39922
|
+
run_id: execution.run_id,
|
|
39923
|
+
fixture_manifest_sha256: manifestHash,
|
|
39924
|
+
seeds: {},
|
|
39925
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
39926
|
+
};
|
|
39927
|
+
await writeReceipt(statePath, state);
|
|
39928
|
+
}
|
|
39929
|
+
const seedStates = isRecord22(state.seeds) ? state.seeds : {};
|
|
39930
|
+
const assetStates = isRecord22(state.assets) ? state.assets : {};
|
|
39931
|
+
const results = [];
|
|
39932
|
+
const runtime = {};
|
|
39933
|
+
const runtimeAssets = {};
|
|
39934
|
+
const scenarioRoot = String(execution.source_suite ?? "").trim();
|
|
39935
|
+
if (assets.length > 0 && !path23.isAbsolute(scenarioRoot)) {
|
|
39936
|
+
throw new Error("test_fixture.asset_source_suite_missing: execution manifest \u7F3A\u5C11\u7EDD\u5BF9 source_suite\uFF0C\u65E0\u6CD5\u9A8C\u8BC1 reviewed assets\u3002");
|
|
39937
|
+
}
|
|
39938
|
+
for (const asset of assets) {
|
|
39939
|
+
const existingAsset = isRecord22(assetStates[asset.key]) ? assetStates[asset.key] : void 0;
|
|
39940
|
+
if (existingAsset?.state === "mutation_attempted") {
|
|
39941
|
+
throw new Error(`test_fixture.asset_write_state_unknown: ${asset.key} \u4E0A\u4F20\u72B6\u6001\u672A\u77E5\u4E14\u6CA1\u6709\u53EF\u56DE\u8BFB URL\uFF0C\u7981\u6B62\u91CD\u8BD5\u3002`);
|
|
39942
|
+
}
|
|
39943
|
+
const existingUrl = String(existingAsset?.url ?? "").trim();
|
|
39944
|
+
if (existingAsset?.state === "remote_submitted" || existingAsset?.state === "readback_verified") {
|
|
39945
|
+
if (!existingUrl) throw new Error(`test_fixture.asset_state_invalid: ${asset.key} \u7F3A\u5C11 upload URL\u3002`);
|
|
39946
|
+
await readReviewedFixtureAsset(asset, scenarioRoot);
|
|
39947
|
+
await readbackUploadedFixtureAsset(asset, existingUrl);
|
|
39948
|
+
runtimeAssets[asset.key] = { url: existingUrl, sha256: asset.sha256, mime: asset.mime, size: asset.size };
|
|
39949
|
+
assetStates[asset.key] = { ...runtimeAssets[asset.key], state: "readback_verified", verified_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
39950
|
+
state.assets = assetStates;
|
|
39951
|
+
await writeReceipt(statePath, state);
|
|
39952
|
+
continue;
|
|
39953
|
+
}
|
|
39954
|
+
if (existingAsset) throw new Error(`test_fixture.asset_state_invalid: ${asset.key} state=${String(existingAsset.state ?? "")}\u3002`);
|
|
39955
|
+
runtimeAssets[asset.key] = await uploadTypedFixtureAsset({
|
|
39956
|
+
client,
|
|
39957
|
+
profile,
|
|
39958
|
+
asset,
|
|
39959
|
+
scenarioRoot,
|
|
39960
|
+
onMutationAttempt: async () => {
|
|
39961
|
+
assetStates[asset.key] = {
|
|
39962
|
+
state: "mutation_attempted",
|
|
39963
|
+
sha256: asset.sha256,
|
|
39964
|
+
attempted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
39965
|
+
};
|
|
39966
|
+
state.assets = assetStates;
|
|
39967
|
+
await writeReceipt(statePath, state);
|
|
39968
|
+
},
|
|
39969
|
+
onRemoteSubmitted: async (url) => {
|
|
39970
|
+
assetStates[asset.key] = {
|
|
39971
|
+
state: "remote_submitted",
|
|
39972
|
+
url,
|
|
39973
|
+
sha256: asset.sha256,
|
|
39974
|
+
submitted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
39975
|
+
};
|
|
39976
|
+
state.assets = assetStates;
|
|
39977
|
+
await writeReceipt(statePath, state);
|
|
39978
|
+
}
|
|
39979
|
+
});
|
|
39980
|
+
assetStates[asset.key] = {
|
|
39981
|
+
...runtimeAssets[asset.key],
|
|
39982
|
+
state: "readback_verified",
|
|
39983
|
+
verified_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
39984
|
+
};
|
|
39985
|
+
state.assets = assetStates;
|
|
39986
|
+
await writeReceipt(statePath, state);
|
|
39987
|
+
}
|
|
39988
|
+
for (const seed of seeds) {
|
|
39989
|
+
const marker = markerFor(execution.run_id, seed.key);
|
|
39990
|
+
const existing = isRecord22(seedStates[seed.key]) ? seedStates[seed.key] : void 0;
|
|
39991
|
+
if (existing?.state === "readback_verified" && Number.isSafeInteger(Number(existing.project_id))) {
|
|
39992
|
+
const verified2 = await readbackFixtureSeed(client, seed, Number(existing.project_id), marker);
|
|
39993
|
+
if (verified2.lifecycle_state !== "readback_verified") {
|
|
39994
|
+
throw new Error(`test_fixture.resume_readback_mismatch: existing fixture ${seed.key} no longer matches its anchored project`);
|
|
39995
|
+
}
|
|
39996
|
+
runtime[seed.key] = {
|
|
39997
|
+
marker,
|
|
39998
|
+
project_id: Number(existing.project_id),
|
|
39999
|
+
outputs: isRecord22(verified2.outputs) ? verified2.outputs : {}
|
|
40000
|
+
};
|
|
40001
|
+
results.push({ ...verified2, transitions: Array.isArray(existing.transitions) ? existing.transitions : [] });
|
|
40002
|
+
continue;
|
|
40003
|
+
}
|
|
40004
|
+
if (existing?.state === "mutation_attempted") {
|
|
40005
|
+
throw new Error(
|
|
40006
|
+
`test_fixture.write_state_unknown: ${seed.key} may already have been created. Resolve it by the unique marker ${marker}; do not retry direct creation.`
|
|
40007
|
+
);
|
|
40008
|
+
}
|
|
40009
|
+
const existingTransitions = Array.isArray(existing?.transitions) ? existing.transitions.filter(isRecord22) : [];
|
|
40010
|
+
for (let index = existingTransitions.length - 1; index >= 0; index -= 1) {
|
|
40011
|
+
const attempted = existingTransitions[index];
|
|
40012
|
+
if (attempted.state !== "mutation_attempted") continue;
|
|
40013
|
+
const declaredTransition = seed.transitions.find((item) => item.key === attempted.key);
|
|
40014
|
+
if (!declaredTransition || attempted.action !== declaredTransition.action) {
|
|
40015
|
+
throw new Error(`test_fixture.write_state_unknown: ${seed.key}.${String(attempted.key ?? "")} \u4E0E\u5DF2\u951A\u5B9A transition \u4E0D\u4E00\u81F4\uFF0C\u7981\u6B62\u91CD\u8BD5\u3002`);
|
|
40016
|
+
}
|
|
40017
|
+
const stepId = Number(attempted.step_id);
|
|
40018
|
+
if (!Number.isSafeInteger(stepId) || stepId <= 0) {
|
|
40019
|
+
throw new Error(`test_fixture.write_state_unknown: ${seed.key}.${String(attempted.key ?? "")} \u7F3A\u5C11\u53EF\u56DE\u8BFB step_id\uFF0C\u7981\u6B62\u91CD\u8BD5\u3002`);
|
|
40020
|
+
}
|
|
40021
|
+
const step = await apiRequest(client, "GET", `/step/${stepId}`, { capability: "step.get" });
|
|
40022
|
+
if (Number(readbackValueAtPath(step, "project_id")) !== Number(existing?.project_id)) {
|
|
40023
|
+
throw new Error(`test_fixture.write_state_unknown: ${seed.key}.${String(attempted.key ?? "")} step ${stepId} \u4E0D\u5C5E\u4E8E\u5DF2\u951A\u5B9A project\uFF0C\u7981\u6B62\u91CD\u8BD5\u3002`);
|
|
40024
|
+
}
|
|
40025
|
+
const status = Number(readbackValueAtPath(step, "status"));
|
|
40026
|
+
if ([3, 5].includes(status)) {
|
|
40027
|
+
existingTransitions[index] = {
|
|
40028
|
+
...attempted,
|
|
40029
|
+
state: "readback_verified",
|
|
40030
|
+
status,
|
|
40031
|
+
recovered_by_readback: true,
|
|
40032
|
+
verified_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
40033
|
+
};
|
|
40034
|
+
continue;
|
|
40035
|
+
}
|
|
40036
|
+
throw new Error(
|
|
40037
|
+
`test_fixture.write_state_unknown: ${seed.key}.${String(attempted.key ?? "")} step ${stepId} status=${String(status)} \u4E0D\u80FD\u8BC1\u660E mutation \u672A\u63D0\u4EA4\uFF0C\u7981\u6B62\u91CD\u8BD5\u3002`
|
|
40038
|
+
);
|
|
40039
|
+
}
|
|
40040
|
+
if (existing && existing.state !== "remote_submitted" && existing.state !== "project_readback_verified") {
|
|
40041
|
+
throw new Error(`test_fixture.state_invalid: ${seed.key} has unsupported fixture state ${String(existing.state ?? "")}`);
|
|
40042
|
+
}
|
|
40043
|
+
let projectId = Number(existing?.project_id);
|
|
40044
|
+
if (!Number.isSafeInteger(projectId) || projectId <= 0) {
|
|
40045
|
+
if (seed.creator.mode === "bbs") {
|
|
40046
|
+
throw new Error(
|
|
40047
|
+
`test_fixture.bbs_wrapper_only: ${seed.key} \u7684 BBS \u53EA\u80FD\u751F\u6210/\u5BA1\u67E5 fixtures.json \u5E76\u8C03\u7528 test-fixture create\uFF1B\u5B9E\u9645 mutation \u5FC5\u987B\u7531 manifest \u4E2D\u7684 typed_cli \u56FE\u6267\u884C\uFF0C\u4E0D\u80FD\u5728 create \u5185\u9012\u5F52\u8C03\u7528 BBS\u3002`
|
|
40048
|
+
);
|
|
40049
|
+
}
|
|
40050
|
+
const resolvedSeed = {
|
|
40051
|
+
...seed,
|
|
40052
|
+
name: seed.name ? resolveRuntimeReferences(seed.name, runtime, runtimeAssets) : void 0,
|
|
40053
|
+
create_payload: resolveRuntimeReferences(seed.create_payload, runtime, runtimeAssets)
|
|
40054
|
+
};
|
|
40055
|
+
const actor = await resolveFixtureActor(client, resolvedSeed.actor, resolvedSeed.key);
|
|
40056
|
+
const createPayload = payloadWithMarker(resolvedSeed, marker);
|
|
40057
|
+
const created = await createTypedProjectFixture({
|
|
40058
|
+
client,
|
|
40059
|
+
profile,
|
|
40060
|
+
flowType: resolvedSeed.flow_type,
|
|
40061
|
+
flowKey: resolvedSeed.flow_key,
|
|
40062
|
+
name: projectNameWithMarker(resolvedSeed, marker),
|
|
40063
|
+
requireProjectNamePersistence: resolvedSeed.marker_field === "$project.name",
|
|
40064
|
+
input: createPayload,
|
|
40065
|
+
...actor.mode === "user" ? { actorUserId: Number(actor.user_id) } : {},
|
|
40066
|
+
onMutationAttempt: async () => {
|
|
40067
|
+
seedStates[seed.key] = {
|
|
40068
|
+
state: "mutation_attempted",
|
|
40069
|
+
marker,
|
|
40070
|
+
attempted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
40071
|
+
};
|
|
40072
|
+
state.seeds = seedStates;
|
|
40073
|
+
await writeReceipt(statePath, state);
|
|
40074
|
+
}
|
|
40075
|
+
});
|
|
40076
|
+
projectId = Number(created.id ?? created.project_id);
|
|
40077
|
+
if (!Number.isSafeInteger(projectId) || projectId <= 0) {
|
|
40078
|
+
throw new Error(`test_fixture.create_response_invalid: ${seed.key} create response is missing a positive project id`);
|
|
40079
|
+
}
|
|
40080
|
+
seedStates[seed.key] = {
|
|
40081
|
+
state: "remote_submitted",
|
|
40082
|
+
marker,
|
|
40083
|
+
project_id: projectId,
|
|
40084
|
+
transitions: [],
|
|
40085
|
+
submitted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
40086
|
+
};
|
|
40087
|
+
state.seeds = seedStates;
|
|
40088
|
+
await writeReceipt(statePath, state);
|
|
40089
|
+
}
|
|
40090
|
+
const createdReadback = await readbackFixtureSeed(client, seed, projectId, marker, {
|
|
40091
|
+
verifyState: seed.transitions.length === 0,
|
|
40092
|
+
requireOutputs: seed.transitions.length === 0
|
|
40093
|
+
});
|
|
40094
|
+
if (createdReadback.lifecycle_state !== "readback_verified") {
|
|
40095
|
+
throw new Error(`test_fixture.readback_mismatch: ${seed.key} project ${projectId} exact marker/owner readback failed`);
|
|
40096
|
+
}
|
|
40097
|
+
runtime[seed.key] = {
|
|
40098
|
+
marker,
|
|
40099
|
+
project_id: projectId,
|
|
40100
|
+
outputs: isRecord22(createdReadback.outputs) ? createdReadback.outputs : {}
|
|
40101
|
+
};
|
|
40102
|
+
const transitionResults = [...existingTransitions];
|
|
40103
|
+
for (const transition of seed.transitions) {
|
|
40104
|
+
const prior = transitionResults.find((item) => item.key === transition.key);
|
|
40105
|
+
if (prior?.state === "readback_verified") continue;
|
|
40106
|
+
const result2 = await executeFixtureTransition({
|
|
40107
|
+
client,
|
|
40108
|
+
seed,
|
|
40109
|
+
transition,
|
|
40110
|
+
projectId,
|
|
40111
|
+
runtime,
|
|
40112
|
+
assets: runtimeAssets,
|
|
40113
|
+
onMutationAttempt: async (details) => {
|
|
40114
|
+
const attempted = { key: transition.key, state: "mutation_attempted", ...details, attempted_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
40115
|
+
const index2 = transitionResults.findIndex((item) => item.key === transition.key);
|
|
40116
|
+
if (index2 >= 0) transitionResults[index2] = attempted;
|
|
40117
|
+
else transitionResults.push(attempted);
|
|
40118
|
+
seedStates[seed.key] = { state: "project_readback_verified", marker, project_id: projectId, transitions: transitionResults };
|
|
40119
|
+
state.seeds = seedStates;
|
|
40120
|
+
await writeReceipt(statePath, state);
|
|
40121
|
+
}
|
|
40122
|
+
});
|
|
40123
|
+
const completed = { ...result2, state: "readback_verified", verified_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
40124
|
+
const index = transitionResults.findIndex((item) => item.key === transition.key);
|
|
40125
|
+
if (index >= 0) transitionResults[index] = completed;
|
|
40126
|
+
else transitionResults.push(completed);
|
|
40127
|
+
const transitionReadback = await readbackFixtureSeed(client, seed, projectId, marker, {
|
|
40128
|
+
verifyState: false,
|
|
40129
|
+
requireOutputs: false
|
|
40130
|
+
});
|
|
40131
|
+
if (transitionReadback.lifecycle_state !== "readback_verified") {
|
|
40132
|
+
throw new Error(`test_fixture.transition_project_readback_mismatch: ${seed.key}.${transition.key} \u540E\u9879\u76EE\u56DE\u8BFB\u5931\u8D25\u3002`);
|
|
40133
|
+
}
|
|
40134
|
+
runtime[seed.key] = {
|
|
40135
|
+
marker,
|
|
40136
|
+
project_id: projectId,
|
|
40137
|
+
outputs: isRecord22(transitionReadback.outputs) ? transitionReadback.outputs : {}
|
|
40138
|
+
};
|
|
40139
|
+
seedStates[seed.key] = { state: "project_readback_verified", marker, project_id: projectId, transitions: transitionResults };
|
|
40140
|
+
state.seeds = seedStates;
|
|
40141
|
+
await writeReceipt(statePath, state);
|
|
40142
|
+
}
|
|
40143
|
+
const verified = await readbackFixtureSeed(client, seed, projectId, marker);
|
|
40144
|
+
if (verified.lifecycle_state !== "readback_verified") {
|
|
40145
|
+
throw new Error(`test_fixture.readback_mismatch: ${seed.key} project ${projectId} final marker/state/owner readback failed`);
|
|
40146
|
+
}
|
|
40147
|
+
runtime[seed.key] = { marker, project_id: projectId, outputs: isRecord22(verified.outputs) ? verified.outputs : {} };
|
|
40148
|
+
seedStates[seed.key] = {
|
|
40149
|
+
state: "readback_verified",
|
|
40150
|
+
marker,
|
|
40151
|
+
project_id: projectId,
|
|
40152
|
+
outputs: runtime[seed.key].outputs,
|
|
40153
|
+
transitions: transitionResults,
|
|
40154
|
+
verified_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
40155
|
+
};
|
|
40156
|
+
state.seeds = seedStates;
|
|
40157
|
+
await writeReceipt(statePath, state);
|
|
40158
|
+
results.push({ ...verified, transitions: transitionResults });
|
|
40159
|
+
}
|
|
40160
|
+
await writeReceipt(runtimeDataPath, {
|
|
40161
|
+
schema_version: 1,
|
|
40162
|
+
kind: "bpmax_fixture_runtime_data",
|
|
40163
|
+
run_id: execution.run_id,
|
|
40164
|
+
fixture_manifest_sha256: manifestHash,
|
|
40165
|
+
seeds: runtime,
|
|
40166
|
+
assets: runtimeAssets,
|
|
40167
|
+
data: {
|
|
40168
|
+
assets: runtimeAssets,
|
|
40169
|
+
...Object.fromEntries(Object.entries(runtime).map(([key, value]) => [key, {
|
|
40170
|
+
project_id: value.project_id,
|
|
40171
|
+
marker: value.marker,
|
|
40172
|
+
...value.outputs
|
|
40173
|
+
}]))
|
|
40174
|
+
},
|
|
40175
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
40176
|
+
});
|
|
40177
|
+
const checks = results.map((item) => ({
|
|
40178
|
+
name: `typed fixture ${String(item.key)} created and read back`,
|
|
40179
|
+
passed: true,
|
|
40180
|
+
detail: `project_id=${String(item.project_id)}; transport=typed_cli`
|
|
40181
|
+
}));
|
|
40182
|
+
const evidence = {
|
|
40183
|
+
schema_version: 1,
|
|
40184
|
+
kind: "bpmax_e2e_precondition_evidence",
|
|
40185
|
+
run_id: execution.run_id,
|
|
40186
|
+
evidence_nonce: execution.evidence_nonce,
|
|
40187
|
+
scenario_id: execution.scenario_id,
|
|
40188
|
+
case_id: execution.case_id,
|
|
40189
|
+
selected_case_ids: execution.selected_case_ids ?? [execution.case_id],
|
|
40190
|
+
profile: execution.profile,
|
|
40191
|
+
precondition_verified: true,
|
|
40192
|
+
creation_transport: "typed_cli",
|
|
40193
|
+
fixture_manifest_sha256: manifestHash,
|
|
40194
|
+
fixtures: results,
|
|
40195
|
+
assets: runtimeAssets,
|
|
40196
|
+
runtime_data: runtimeDataPath,
|
|
40197
|
+
checks,
|
|
40198
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
40199
|
+
};
|
|
40200
|
+
const anchoredEvidence = execution.precondition?.state === "passed" ? String(execution.precondition.evidence ?? "").trim() : "";
|
|
40201
|
+
const evidenceForRecord = anchoredEvidence || evidencePath;
|
|
40202
|
+
if (anchoredEvidence) {
|
|
40203
|
+
if (path23.resolve(anchoredEvidence) !== path23.resolve(evidencePath)) {
|
|
40204
|
+
throw new Error("test_fixture.precondition_evidence_mismatch: passed fixture precondition is anchored to an unexpected evidence file");
|
|
40205
|
+
}
|
|
40206
|
+
} else {
|
|
40207
|
+
await writeReceipt(evidencePath, evidence);
|
|
40208
|
+
}
|
|
40209
|
+
const recorded = await recordTestSuiteRunPrecondition({
|
|
40210
|
+
manifest: manifestPath,
|
|
40211
|
+
evidence: evidenceForRecord,
|
|
40212
|
+
profile: execution.profile
|
|
40213
|
+
});
|
|
40214
|
+
return {
|
|
40215
|
+
ok: true,
|
|
40216
|
+
domain: "test_fixture",
|
|
40217
|
+
action: "create",
|
|
40218
|
+
creation_transport: "typed_cli",
|
|
40219
|
+
manifest: manifestPath,
|
|
40220
|
+
state: statePath,
|
|
40221
|
+
evidence: evidenceForRecord,
|
|
40222
|
+
runtime_data: runtimeDataPath,
|
|
40223
|
+
fixtures: results,
|
|
40224
|
+
assets: runtimeAssets,
|
|
40225
|
+
precondition: recorded
|
|
40226
|
+
};
|
|
40227
|
+
});
|
|
40228
|
+
printResult(options.format, result);
|
|
40229
|
+
});
|
|
38426
40230
|
fixture.command("verify").description("Verify created fixture project IDs through typed project.get and emit a reusable receipt").requiredOption("--json <json>", "Fixture manifest JSON or @file").requiredOption("--projects <json>", "Map of seed key to project id, inline JSON or @file").requiredOption("--run-id <runId>", "Stable current-run identifier").option("--profile <profile>", "Profile name").option("--out <file>", "Write the verified receipt to a file").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
38427
40231
|
const manifest = await parseJsonInput2(options.json, "--json");
|
|
38428
40232
|
const projects = await parseJsonInput2(options.projects, "--projects");
|
|
38429
40233
|
const seeds = fixtureSeeds(manifest);
|
|
40234
|
+
fixtureAssets(manifest, seeds);
|
|
38430
40235
|
const runId = safeToken(options.runId, "run_id");
|
|
38431
40236
|
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
38432
40237
|
const client = createApiClient(profile);
|
|
@@ -38439,24 +40244,7 @@ function registerTestFixtureCommands(program2) {
|
|
|
38439
40244
|
continue;
|
|
38440
40245
|
}
|
|
38441
40246
|
try {
|
|
38442
|
-
|
|
38443
|
-
const markerValue = readbackValueAtPath(readback, seed.marker_readback_path);
|
|
38444
|
-
const markerVerified = typeof markerValue === "string" && markerValue.split(/\s+/).includes(marker);
|
|
38445
|
-
const stateValue = seed.state_readback_path ? readbackValueAtPath(readback, seed.state_readback_path) : void 0;
|
|
38446
|
-
const stateVerified = !seed.expected_state || stateValue === seed.expected_state;
|
|
38447
|
-
results.push({
|
|
38448
|
-
key: seed.key,
|
|
38449
|
-
project_id: projectId,
|
|
38450
|
-
marker,
|
|
38451
|
-
marker_readback_path: seed.marker_readback_path,
|
|
38452
|
-
lifecycle_state: markerVerified && stateVerified ? "readback_verified" : "readback_mismatch",
|
|
38453
|
-
evidence_layer: "typed_project_readback",
|
|
38454
|
-
marker_verified: markerVerified,
|
|
38455
|
-
state_verified: stateVerified,
|
|
38456
|
-
expected_state: seed.expected_state ?? null,
|
|
38457
|
-
state_readback_path: seed.state_readback_path ?? null,
|
|
38458
|
-
cleanup: seed.cleanup
|
|
38459
|
-
});
|
|
40247
|
+
results.push(await readbackFixtureSeed(client, seed, projectId, marker));
|
|
38460
40248
|
} catch (error) {
|
|
38461
40249
|
const message = error instanceof Error ? error.message : String(error);
|
|
38462
40250
|
const capabilityBlocked = message.includes('capability "project.get"') || message.includes("capability 'project.get'");
|
|
@@ -38490,7 +40278,7 @@ function registerTestFixtureCommands(program2) {
|
|
|
38490
40278
|
}
|
|
38491
40279
|
|
|
38492
40280
|
// src/core/update.ts
|
|
38493
|
-
import { access as access2, mkdir as mkdir17, readFile as readFile25, realpath as
|
|
40281
|
+
import { access as access2, mkdir as mkdir17, readFile as readFile25, realpath as realpath10, writeFile as writeFile18 } from "fs/promises";
|
|
38494
40282
|
import path24 from "path";
|
|
38495
40283
|
var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/";
|
|
38496
40284
|
var UPDATE_STATE_FILE = "update-state.json";
|
|
@@ -38673,7 +40461,7 @@ async function executablePath() {
|
|
|
38673
40461
|
return "";
|
|
38674
40462
|
}
|
|
38675
40463
|
try {
|
|
38676
|
-
return await
|
|
40464
|
+
return await realpath10(candidate);
|
|
38677
40465
|
} catch {
|
|
38678
40466
|
return candidate;
|
|
38679
40467
|
}
|
|
@@ -38933,7 +40721,7 @@ import { readFile as readFile26 } from "fs/promises";
|
|
|
38933
40721
|
async function parseJsonInput3(value) {
|
|
38934
40722
|
const raw = value.startsWith("@") ? await readFile26(value.slice(1), "utf8") : value;
|
|
38935
40723
|
const parsed = JSON.parse(raw);
|
|
38936
|
-
if (!
|
|
40724
|
+
if (!isRecord23(parsed)) throw new Error("user.pool.invalid_manifest: --json \u5FC5\u987B\u662F JSON \u5BF9\u8C61\u6216 @file\u3002");
|
|
38937
40725
|
return parsed;
|
|
38938
40726
|
}
|
|
38939
40727
|
function positiveUserId(value) {
|
|
@@ -38942,17 +40730,17 @@ function positiveUserId(value) {
|
|
|
38942
40730
|
function sortedStrings(value) {
|
|
38943
40731
|
return Array.isArray(value) ? [...new Set(value.map((item) => String(item).trim()).filter(Boolean))].sort() : [];
|
|
38944
40732
|
}
|
|
38945
|
-
function
|
|
40733
|
+
function isRecord23(value) {
|
|
38946
40734
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
38947
40735
|
}
|
|
38948
40736
|
function userRows(value) {
|
|
38949
|
-
if (Array.isArray(value)) return value.filter(
|
|
38950
|
-
if (!
|
|
38951
|
-
if (Array.isArray(value.data)) return value.data.filter(
|
|
40737
|
+
if (Array.isArray(value)) return value.filter(isRecord23);
|
|
40738
|
+
if (!isRecord23(value)) return [];
|
|
40739
|
+
if (Array.isArray(value.data)) return value.data.filter(isRecord23);
|
|
38952
40740
|
return value.id ? [value] : [];
|
|
38953
40741
|
}
|
|
38954
40742
|
function safeUser2(user) {
|
|
38955
|
-
const roles = Array.isArray(user.role) ? user.role.filter(
|
|
40743
|
+
const roles = Array.isArray(user.role) ? user.role.filter(isRecord23).map((role) => ({
|
|
38956
40744
|
id: role.id,
|
|
38957
40745
|
key: role.key,
|
|
38958
40746
|
name: role.name
|
|
@@ -38991,7 +40779,7 @@ function registerUserCommands(program2) {
|
|
|
38991
40779
|
throw new Error("user.pool.invalid_manifest: version=1 \u4E14 identities \u975E\u7A7A\u662F\u5FC5\u9700\u7684\u3002");
|
|
38992
40780
|
}
|
|
38993
40781
|
const identities = rawIdentities.map((identity, index) => {
|
|
38994
|
-
if (!
|
|
40782
|
+
if (!isRecord23(identity)) {
|
|
38995
40783
|
throw new Error(`user.pool.invalid_manifest: identities[${index}] \u5FC5\u987B\u662F\u5BF9\u8C61\u3002`);
|
|
38996
40784
|
}
|
|
38997
40785
|
if (!Array.isArray(identity.expected_roles)) {
|