feat(workflow & platform): optimize complex workflow orchestration, code node debug summary, MVEL simulation and entity/feetype helpers

- feat(feetype): add --subtree and --ids-only flags to listFeeTypes for direct array export
- feat(platform): add platform gen-props command to generate MVEL/JS entity field constants and templates
- feat(workflow): show code node return value summaries in workflow test and job first screen
- feat(workflow): add workflow node map sub-command and --mapping-file for deep declarative field mutations
- feat(workflow): add executeMvelSandbox for local offline simulation of MVEL code nodes
- test: add comprehensive test cases across feetype, platform gen-props, node map, and MVEL sandbox

Closes #140
This commit is contained in:
gitea committed 2026-10-23 13:06:32 +08:00
1 parent 1739daacf2
commit ad771e92e0
18 files changed
+591 -29

No files matched your search

@@ -5,6 +5,7 @@ import {
lintMvelCode,
lintWorkflowScripts,
executeJavaScriptSandbox,
executeMvelSandbox,
} from "./index.js";
import type { WorkflowDetail } from "../../types.js";
@@ -275,4 +276,30 @@ describe("isolated script runtime boundaries", () => {
expect((await executeJavaScriptSandbox('return Promise.resolve(1);')).success).toBe(false);
expect((await executeJavaScriptSandbox('return 1;')).returnValue).toBe(1);
});
describe("executeMvelSandbox", () => {
it("executes basic MVEL variable assignments, collections and return statements", async () => {
const mvel = [
'String planCode = "AMORT-001";',
'int periods = 3;',
'Map row = new HashMap();',
'row.put("code", planCode);',
'row.put("periods", periods);',
'return row;',
].join("\n");
const result = await executeMvelSandbox(mvel);
expect(result.success).toBe(true);
expect(result.returnValue).toEqual({ code: "AMORT-001", periods: 3 });
});
it("accesses inputs in MVEL code", async () => {
const mvel = [
'int total = amount * 2;',
'return total;',
].join("\n");
const result = await executeMvelSandbox(mvel, { amount: 50 });
expect(result.success).toBe(true);
expect(result.returnValue).toBe(100);
});
});
});
@@ -122,3 +122,54 @@ export async function executeJavaScriptSandbox(
runtime?.dispose();
}
}
/**
* 转换 MVEL 常用语法为 QuickJS 可执行的 JavaScript,实现轻量仿真
*/
export function transpileMvelToJs(mvelCode: string): string {
let js = mvelCode;
// 1. 移除 Java 类型声明:如 String x =, int y =, List z =, Map m =, boolean b =, double d =, long l =
js = js.replace(/\b(String|int|Integer|long|Long|double|Double|float|Float|boolean|Boolean|List|Map|HashMap|ArrayList|Object)\s+([a-zA-Z_$][a-zA-Z0-9_$]*\s*=)/g, "var $2");
js = js.replace(/\b(String|int|Integer|long|Long|double|Double|float|Float|boolean|Boolean|List|Map|HashMap|ArrayList|Object)\s+([a-zA-Z_$][a-zA-Z0-9_$]*\s*;)/g, "var $2");
// 2. 转换 new HashMap() / new ArrayList()
js = js.replace(/new\s+(?:HashMap|Map)\s*(?:\([^)]*\)|<[^>]*>\s*\([^)]*\))/g, "({})");
js = js.replace(/new\s+(?:ArrayList|List)\s*(?:\([^)]*\)|<[^>]*>\s*\([^)]*\))/g, "([])");
// 3. 常见 Map/List 方法调用模拟:
// .put(k, v) -> [k] = v (包装为安全赋值辅助)
// 注入轻量 helper
const preamble = [
"function _mvel_put(obj, key, val) { if (obj && typeof obj === 'object') { obj[key] = val; } return val; }",
"function _mvel_get(obj, key) { return obj ? obj[key] : undefined; }",
"function _mvel_size(obj) { if (!obj) return 0; if (Array.isArray(obj)) return obj.length; if (typeof obj === 'object') return Object.keys(obj).length; return 0; }",
"function _mvel_add(arr, item) { if (Array.isArray(arr)) arr.push(item); return arr; }",
"",
].join("\n");
js = js.replace(/\.put\s*\(\s*([^,]+)\s*,\s*([^)]+)\s*\)/g, ""); // 避免直接正则冲突,使用下面逐行或更精确替换
// 恢复并使用 helper
js = mvelCode;
js = js.replace(/\b(String|int|Integer|long|Long|double|Double|float|Float|boolean|Boolean|List|Map|HashMap|ArrayList|Object)\s+([a-zA-Z_$][a-zA-Z0-9_$]*\s*=)/g, "var $2");
js = js.replace(/\b(String|int|Integer|long|Long|double|Double|float|Float|boolean|Boolean|List|Map|HashMap|ArrayList|Object)\s+([a-zA-Z_$][a-zA-Z0-9_$]*\s*;)/g, "var $2");
js = js.replace(/new\s+(?:HashMap|Map)\s*(?:\([^)]*\)|<[^>]*>\s*\([^)]*\))/g, "({})");
js = js.replace(/new\s+(?:ArrayList|List)\s*(?:\([^)]*\)|<[^>]*>\s*\([^)]*\))/g, "([])");
js = js.replace(/\.put\s*\(\s*([^,]+)\s*,\s*([^)]+)\s*\)/g, "[$1] = $2");
js = js.replace(/\.size\s*\(\s*\)/g, ".length");
return `${preamble}${js}`;
}
/**
* 轻量仿真执行 MVEL 节点
*/
export async function executeMvelSandbox(
code: string,
inputs: Record<string, unknown> = {},
options: { timeoutMs?: number } = {}
): Promise<ScriptEvalResult> {
const transpiled = transpileMvelToJs(code);
const result = await executeJavaScriptSandbox(transpiled, inputs, options);
return result;
}