fix(workflow): 扩展字段引用扫描并收紧 choose 描述符门禁
- 字段引用检查覆盖 combineFilters、filters、conditions、flowCode、list、details 及嵌套结构 - choose 描述符 JSON 损坏或缺少有效 key 时新增 INVALID_CHOOSE_DESCRIPTOR 硬门禁 - DataLink 使用 gte/lte 时新增 DATALINK_FILTER_COMPARISON_COMPATIBILITY 软提示,不自动改写边界 - 重新生成 dist/mcp/server.js 并同步领域测试与 README 说明
This commit is contained in:
1 parent
89dc650464
commit
71d1a59934
4 files changed
+318
-250
No files matched your search
Vendored
+243
-243
File diff suppressed because it is too large.
Load diff
@@ -165,7 +165,9 @@ MVEL 本地仿真支持的是转译子集:零参 `HashMap` / `ArrayList` 及 `
|
||||
|
||||
## 工具链静态门禁与防御性保障 (Toolchain Defense & Linting)
|
||||
|
||||
字段引用检查覆盖 `inputs`、`fields`、`mapping`、直接 `form` 及其嵌套对象/数组,不扫描脚本和说明文本。`choose` 支持 JSON 描述符、引号路径和裸路径:明确节点键或标准节点前缀缺失时产生 `BROKEN_CHOOSE_REFERENCE`,旧循环 `$item` 路径产生 `BROKEN_LOOP_ITEM_REFERENCE`;`trigger_1` 也必须实际存在。`body` 等上下文根不按节点处理,来源无法静态确定或无法解析的表达式给出软提示,不据此声称已验证可用。此检查不等同于完整的上游作用域或字段类型校验。
|
||||
字段引用检查覆盖 `inputs`、`fields`、`mapping`、直接 `form`、`combineFilters`、`filters`、`conditions`、`flowCode`、`list`、`details` 及其嵌套对象/数组,不扫描脚本和说明文本。`choose` 支持 JSON 描述符、引号路径和裸路径:明确节点键或标准节点前缀缺失时产生 `BROKEN_CHOOSE_REFERENCE`,旧循环 `$item` 路径产生 `BROKEN_LOOP_ITEM_REFERENCE`;`trigger_1` 也必须实际存在。明确为 JSON 描述符但 JSON 损坏(例如多余 `}`)或缺少有效节点 key 时产生 `INVALID_CHOOSE_DESCRIPTOR` 硬门禁。`body` 等上下文根不按节点处理,来源无法静态确定或使用不支持的表达式时仍给出软提示,不据此声称已验证可用。此检查不等同于完整的上游作用域或字段类型校验。
|
||||
|
||||
业务对象查询的 `gte/lte` 会产生 `DATALINK_FILTER_COMPARISON_COMPATIBILITY` 软提示:本地条件解释器支持通用比较符,不代表真实设计器的日期字段支持同一枚举。分析器不会自动改为 `gt/lt`,因为这会改变端点是否包含的业务语义;采用严格比较时需同时核对月初、下月月初等毫秒边界。保存成功及静态门禁通过均不等于前端配置校验或租户实际运行通过。
|
||||
|
||||
1. **文档站点域名拦截 (`DOCS_DOMAIN_USED`)**:静态分析会阻断在 HTTP 任务节点配置 `docs.ekuaibao.com` 的行为(错误复制开放平台文档地址),指导修正为 `app.ekuaibao.com`;
|
||||
2. **应用权限代码交叉核验 (`UNLICENSED_POWER_CODE`)**:扫描 HTTP 任务 URL 中的 `powerCode` 参数(如 `TICKET_AUDIT_switch`),与当前企业已开通应用交叉核验,未开通时产生硬门禁阻断;参数包含无效 URL 百分号转义时产生 `INVALID_POWER_CODE_ENCODING` 硬门禁诊断,避免权限探测异常中断其他节点分析;
|
||||
|
||||
@@ -58,6 +58,7 @@ interface ChooseReference {
|
||||
key?: string;
|
||||
descriptor?: boolean;
|
||||
problem?: string;
|
||||
invalidDescriptor?: boolean;
|
||||
}
|
||||
|
||||
/** 只解析 choose 参数,不执行表达式;引号内的括号不参与标签边界匹配。 */
|
||||
@@ -90,6 +91,7 @@ function extractChooseTags(val: unknown): ChooseReference[] {
|
||||
marker.lastIndex = end + 1 + close[0].length;
|
||||
const raw = val.slice(match.index, marker.lastIndex);
|
||||
const argument = val.slice(from, end).trim();
|
||||
let isDescriptor = false;
|
||||
try {
|
||||
let value = argument;
|
||||
if (argument.startsWith('"')) value = JSON.parse(argument);
|
||||
@@ -100,6 +102,7 @@ function extractChooseTags(val: unknown): ChooseReference[] {
|
||||
}
|
||||
if (typeof value !== "string") throw new Error("参数应为节点描述或路径");
|
||||
if (value.trim().startsWith("{")) {
|
||||
isDescriptor = true;
|
||||
const descriptor: unknown = JSON.parse(value);
|
||||
if (!descriptor || typeof descriptor !== "object" || Array.isArray(descriptor) || typeof (descriptor as Record<string, unknown>).key !== "string" || !(descriptor as { key: string }).key.trim()) throw new Error("节点描述缺少 key");
|
||||
results.push({ raw, key: (descriptor as { key: string }).key.trim(), descriptor: true });
|
||||
@@ -107,7 +110,8 @@ function extractChooseTags(val: unknown): ChooseReference[] {
|
||||
results.push({ raw, key: value.trim(), descriptor: false });
|
||||
} else throw new Error("参数不是可静态识别的节点路径");
|
||||
} catch {
|
||||
results.push({ raw, problem: "choose 参数不是可静态识别的节点描述或路径" });
|
||||
results.push({ raw, invalidDescriptor: isDescriptor,
|
||||
problem: isDescriptor ? "choose 节点描述不是有效 JSON 对象或缺少有效 key" : "choose 参数不是可静态识别的节点描述或路径" });
|
||||
}
|
||||
}
|
||||
return results;
|
||||
@@ -245,6 +249,7 @@ interface LeafFilterItem {
|
||||
}
|
||||
|
||||
function extractLeafFilters(filterGroup: unknown): LeafFilterItem[] {
|
||||
if (Array.isArray(filterGroup)) return filterGroup.flatMap(extractLeafFilters);
|
||||
if (!filterGroup || typeof filterGroup !== "object") return [];
|
||||
const items: LeafFilterItem[] = [];
|
||||
const rec = filterGroup as Record<string, unknown>;
|
||||
@@ -496,6 +501,19 @@ export function analyzeWorkflow(
|
||||
// 诊断:DataLink 字段误填表单公式硬校验
|
||||
checkMisplacedFormulasInDatalink(task, path, diagnostics);
|
||||
|
||||
// 本地条件解释器支持的通用比较符,不等于真实设计器对应字段的枚举。
|
||||
if (task.type === "ekuaibao-datalink-filter") {
|
||||
const raw = task as Record<string, unknown>;
|
||||
for (const filter of extractLeafFilters(raw.combineFilters ?? raw.filters)) {
|
||||
if (filter.compare === "gte" || filter.compare === "lte") {
|
||||
addDiagnostic(diagnostics, {
|
||||
severity: "warning", code: "DATALINK_FILTER_COMPARISON_COMPATIBILITY", path,
|
||||
message: `业务对象筛选字段 [${String(filter.key || "未知")}] 使用通用比较符 '${filter.compare}'。合思前端日期字段可能不识别该枚举,请在设计器核对支持的比较符;直接替换为 gt/lt 会改变等号边界,月份范围需同时核对月初及下月月初时间戳。`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 诊断 2: every 循环内 flow-create-task (SKIP) 后跟无状态守卫的 ekuaibao-datalink-edit
|
||||
if (insideEvery && task.type === "flow-create-task") {
|
||||
const onError = (task as Record<string, unknown>).onError as
|
||||
@@ -753,7 +771,7 @@ export function analyzeWorkflow(
|
||||
// 诊断 5: 字段变量引用失效校验 (BROKEN_CHOOSE_REFERENCE / BROKEN_LOOP_ITEM_REFERENCE)
|
||||
const inspectFields: Array<{ key: string; value: string }> = [];
|
||||
const rawTask = task as Record<string, unknown>;
|
||||
for (const key of ["inputs", "fields", "mapping", "form"]) collectExpressionValues(rawTask[key], key, inspectFields);
|
||||
for (const key of ["inputs", "fields", "mapping", "form", "combineFilters", "filters", "conditions", "flowCode", "list", "details"]) collectExpressionValues(rawTask[key], key, inspectFields);
|
||||
|
||||
for (const field of inspectFields) {
|
||||
if (typeof field.value === "string") {
|
||||
@@ -762,8 +780,11 @@ export function analyzeWorkflow(
|
||||
const chooseKey = item.key;
|
||||
if (!chooseKey) {
|
||||
addDiagnostic(diagnostics, {
|
||||
severity: "warning", category: "soft_advice", code: "UNRESOLVED_CHOOSE_REFERENCE", path,
|
||||
message: `字段 [${field.key}] 的引用无法静态检查:${item.problem}。请在真实流程设计器中确认。`,
|
||||
severity: item.invalidDescriptor ? "error" : "warning",
|
||||
code: item.invalidDescriptor ? "INVALID_CHOOSE_DESCRIPTOR" : "UNRESOLVED_CHOOSE_REFERENCE", path,
|
||||
message: item.invalidDescriptor
|
||||
? `字段 [${field.key}] 的 choose 节点描述损坏:${item.problem}。请检查多余括号、JSON 转义和节点 key。`
|
||||
: `字段 [${field.key}] 的引用无法静态检查:${item.problem}。请在真实流程设计器中确认。`,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -70,8 +70,8 @@ describe("choose reference containers and source classification", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("warns for unknown bare roots and unsupported or malformed expressions without blocking", () => {
|
||||
for (const tag of ["@{choose(missing_node.data)}", "@{choose('missing_node.data')}", "@{choose(action_x.data + 1)}", "@{choose('action_missing.data')", "@{choose('{bad json}')}"]) {
|
||||
test("warns for unknown bare roots and unsupported or incomplete expressions without blocking", () => {
|
||||
for (const tag of ["@{choose(missing_node.data)}", "@{choose('missing_node.data')}", "@{choose(action_x.data + 1)}", "@{choose('action_missing.data')"]) {
|
||||
const result = analyze({ form: { title: tag } });
|
||||
expect(result.summary.passed).toBe(true);
|
||||
expect(result.diagnostics.map(item => item.code)).toContain("UNRESOLVED_CHOOSE_REFERENCE");
|
||||
@@ -79,6 +79,51 @@ describe("choose reference containers and source classification", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test.each([
|
||||
"@{choose('{bad json}')}",
|
||||
`@{choose('${JSON.stringify({ key: "trigger_actual", properties: [{ key: "startTime", type: "NUMBER" }] })}}')}`,
|
||||
`@{choose('${JSON.stringify({ properties: [] })}')}`,
|
||||
])("blocks an explicitly damaged JSON descriptor in %s", tag => {
|
||||
const result = analyze({ combineFilters: { condition: "and", filters: [{ key: "日期", compare: "gt", value: tag }] } });
|
||||
expect(result.summary.passed).toBe(false);
|
||||
expect(result.diagnostics).toMatchObject([{ code: "INVALID_CHOOSE_DESCRIPTOR", category: "hard_block", severity: "error" }]);
|
||||
expect(result.diagnostics[0].message).toContain("日期");
|
||||
});
|
||||
|
||||
test("checks runtime expressions in filters, lookup codes, loops and nested details", () => {
|
||||
const missing = descriptor("action_missing");
|
||||
for (const config of [
|
||||
{ combineFilters: { filters: [{ filters: [{ key: "日期", value: missing, compare: "gt" }], condition: "and" }], condition: "or" } },
|
||||
{ filters: [{ key: "日期", value: missing }] },
|
||||
{ conditions: { value: missing } },
|
||||
{ flowCode: missing },
|
||||
{ list: missing },
|
||||
{ details: { fixed: [{ amount: missing }] } },
|
||||
]) {
|
||||
const result = analyze(config);
|
||||
expect(result.diagnostics.map(item => item.code)).toContain("BROKEN_CHOOSE_REFERENCE");
|
||||
expect(result.summary.passed).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
test("warns about DataLink inclusive comparison compatibility without rewriting boundaries", () => {
|
||||
const config = { type: "ekuaibao-datalink-filter", combineFilters: { filters: [
|
||||
{ key: "日期", compare: "gte", value: descriptor("trigger_actual") },
|
||||
{ key: "日期", compare: "lte", value: descriptor("trigger_actual") },
|
||||
] } };
|
||||
const original = JSON.stringify(config);
|
||||
const result = analyze(config);
|
||||
expect(result.diagnostics).toHaveLength(2);
|
||||
expect(result.diagnostics.every(item => item.code === "DATALINK_FILTER_COMPARISON_COMPATIBILITY" && item.category === "soft_advice")).toBe(true);
|
||||
expect(result.diagnostics[0].message).toContain("边界");
|
||||
expect(JSON.stringify(config)).toBe(original);
|
||||
expect(analyze({ type: "ekuaibao-datalink-filter", filters: config.combineFilters.filters }).diagnostics).toHaveLength(2);
|
||||
for (const compare of ["gt", "lt"]) {
|
||||
expect(analyze({ ...config, combineFilters: { filters: [{ key: "日期", compare, value: descriptor("trigger_actual") }] } }).diagnostics).toEqual([]);
|
||||
}
|
||||
expect(analyze({ ...config, type: "condition", tasks: [{ name: "child", type: "http" }] }).diagnostics).toEqual([]);
|
||||
});
|
||||
|
||||
test.each(["@{choose(control_loop.$item)}", "@{choose('control_loop.$item.data')}", descriptor("control_loop.$item")])("blocks old loop item paths in %s", tag => {
|
||||
const result = analyze({ fields: [{ key: "value", value: tag }] });
|
||||
expect(result.summary.passed).toBe(false);
|
||||
|
||||
Reference in new issue
Block a user