feat(workflow): 增强 MVEL 脚本条件块变量首次赋值与 break 静态拦截
- 在 `lintMvelCode` 中新增 `mvel-unscoped-block-assignment` 规则,检测在 if/else/switch/catch 等条件分支块内首次赋值但未在外部预先初始化的变量,提前防范 MVEL2 优化编译模式下的 `unresolvable property or identifier` 运行时反射异常 - 新增 `mvel-unsupported-break` 规则,拦截 MVEL2 循环中不支持的 `break` 控制流关键字,引导改用条件标志位控制终止 - 在 `workflow save` 草稿保存前自动注入工作流全节点脚本静态健康度扫描,及时透出代码告警 - 补充对应的单元测试用例,覆盖块内未声明赋值、预声明/三元表达式放行及 break 拦截场景
This commit is contained in:
1 parent
75a0611f0e
commit
e00adbe5a8
3 files changed
+158
-1
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { EkbError } from "../../../core/errors.js";
|
||||
import { getWorkflowDetail, listAllWorkflows, refreshWorkflowChooses, updateWorkflow } from "../../../domains/platform/workflow/services.js";
|
||||
import { getWorkflowDetail, listAllWorkflows, refreshWorkflowChooses, updateWorkflow, lintWorkflowScripts } from "../../../domains/platform/workflow/services.js";
|
||||
import { WorkflowSavePartialError } from "../../../domains/platform/workflow/management/save-error.js";
|
||||
import { WorkflowDetailSchema } from "../../../domains/platform/workflow/types.js";
|
||||
import {
|
||||
@@ -99,6 +99,22 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
|
||||
const forceWrite = booleanOption(parsed.options, ["force-write", "forceWrite"]);
|
||||
const syncFile = booleanOption(parsed.options, ["in-place", "inPlace"]);
|
||||
|
||||
// 保存前静态代码健康度检查
|
||||
const scriptLintReport = lintWorkflowScripts(parsedWorkflow as any);
|
||||
const scriptWarnings: string[] = [];
|
||||
if (scriptLintReport.totalCodeNodes > 0) {
|
||||
for (const node of scriptLintReport.reports) {
|
||||
if (node.issues.length > 0) {
|
||||
for (const iss of node.issues) {
|
||||
const icon = iss.level === "error" ? "❌" : "⚠️";
|
||||
const loc = iss.line ? `(L${iss.line})` : "";
|
||||
scriptWarnings.push(`${icon} 节点 [${node.nodeName}] ${loc}: [${iss.rule}] ${iss.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
requireMutationConfirmation(
|
||||
parsed,
|
||||
runtime,
|
||||
@@ -112,6 +128,7 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
tasksVersion: parsedWorkflow.tasksVersion,
|
||||
forceWrite,
|
||||
syncFile,
|
||||
...(scriptWarnings.length > 0 ? { scriptWarnings } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user