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:
1 parent
1739daacf2
commit
ad771e92e0
18 files changed
+591
-29
No files matched your search
@@ -17,7 +17,7 @@ import { stringOption, numberOption, booleanOption } from "../../parser.js";
|
||||
import { createClientsForCorp, createPiperClientForCorp } from "../../helpers.js";
|
||||
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { PLATFORM_ID_OPTION_KEYS } from "./shared.js";
|
||||
import { PLATFORM_ID_OPTION_KEYS, extractCodeNodeSummaries, formatCodeNodeSummariesCard } from "./shared.js";
|
||||
|
||||
async function createJobPiperClient(
|
||||
parsed: CliParsedArgs,
|
||||
@@ -629,6 +629,11 @@ export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Pro
|
||||
}
|
||||
}
|
||||
|
||||
const codeSummaries = extractCodeNodeSummaries(tree, flattenExecutionTree);
|
||||
if (codeSummaries.length > 0) {
|
||||
outLines.push(...formatCodeNodeSummariesCard(codeSummaries, job.id));
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: `${outLines.join("\n")}\n`,
|
||||
stderr: "",
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
addWorkflowTask,
|
||||
editWorkflowTask,
|
||||
removeWorkflowTask,
|
||||
applyNodeMapping,
|
||||
getWorkflowAvailableNodes,
|
||||
grantWorkflowNodes,
|
||||
} from "../../../domains/platform/services.js";
|
||||
@@ -20,7 +21,7 @@ import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { createPiperClientForCorp } from "../../helpers.js";
|
||||
import { createWorkflowDetailClient } from "./shared.js";
|
||||
|
||||
const SUB_ACTIONS = new Set(["list", "ls", "get", "show", "info", "add", "append", "insert", "edit", "update", "set", "rm", "remove", "delete", "del"]);
|
||||
const SUB_ACTIONS = new Set(["list", "ls", "get", "show", "info", "add", "append", "insert", "edit", "update", "set", "map", "rm", "remove", "delete", "del"]);
|
||||
const CORP_LEVEL_ACTIONS = new Set(["available", "list-available", "catalog", "probe", "grant", "open"]);
|
||||
|
||||
export async function handleNodeCommand(
|
||||
@@ -78,6 +79,7 @@ export async function handleNodeCommand(
|
||||
" get <pipelineId> <节点标识> 查看指定节点的完整配置 (别名: show, info)",
|
||||
" add <pipelineId> [选项] 声明式追加或插入新任务节点 (别名: append, insert)",
|
||||
" edit <pipelineId> <节点标识> 定向修改指定节点配置 (别名: update, set)",
|
||||
" map <pipelineId> <节点标识> 从映射文件批量更新深层字段 (别名: node map --mapping-file)",
|
||||
" rm <pipelineId> <节点标识> 安全移除指定任务节点 (别名: remove, delete)",
|
||||
"",
|
||||
"子命令 (企业灰度节点级别):",
|
||||
@@ -110,6 +112,8 @@ export async function handleNodeCommand(
|
||||
case "update":
|
||||
case "set":
|
||||
return handleEditNode(pipelineId, nodeTarget, parsed, runtime);
|
||||
case "map":
|
||||
return handleMapNode(pipelineId, nodeTarget, parsed, runtime);
|
||||
case "rm":
|
||||
case "remove":
|
||||
case "delete":
|
||||
@@ -383,6 +387,14 @@ async function handleEditNode(
|
||||
}
|
||||
}
|
||||
|
||||
const mappingFile = stringOption(parsed.options, ["mapping-file", "mapping", "file", "json-file"]);
|
||||
if (mappingFile) {
|
||||
const fs = await import("fs/promises");
|
||||
const rawContent = await fs.readFile(mappingFile, "utf-8");
|
||||
const mappingData = JSON.parse(rawContent);
|
||||
return handleMapNode(pipelineId, nodeTarget, parsed, runtime, mappingData);
|
||||
}
|
||||
|
||||
requireMutationConfirmation(
|
||||
parsed,
|
||||
runtime,
|
||||
@@ -436,6 +448,96 @@ async function handleEditNode(
|
||||
};
|
||||
}
|
||||
|
||||
async function handleMapNode(
|
||||
pipelineId: string,
|
||||
nodeTarget: string,
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime,
|
||||
injectedMappingData?: any
|
||||
): Promise<CliResult> {
|
||||
if (!nodeTarget) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: [
|
||||
"请提供目标节点标识 (name 或层级序号): hose-use workflow node map <pipelineId> <nodeNameOrIndex> --mapping-file=<path> [选项]",
|
||||
"",
|
||||
"常用选项:",
|
||||
" --mapping-file=<路径> 包含字段映射的本地 JSON 文件 (可为字段数组或属性对象)",
|
||||
" --dry-run 只预览变更",
|
||||
" --yes 确认保存修改",
|
||||
"",
|
||||
"示例:",
|
||||
" hose-use workflow node map 900682164608835609 action_datalink_create --mapping-file=./fields.json --yes",
|
||||
].join("\n") + "\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
let mappingData = injectedMappingData;
|
||||
if (!mappingData) {
|
||||
const mappingFile = stringOption(parsed.options, ["mapping-file", "mapping", "file", "json-file"]);
|
||||
if (!mappingFile) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "错误: 请通过 --mapping-file=<路径> 指定本地字段映射 JSON 文件\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
const fs = await import("fs/promises");
|
||||
try {
|
||||
const content = await fs.readFile(mappingFile, "utf-8");
|
||||
mappingData = JSON.parse(content);
|
||||
} catch (e: any) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `错误: 读取或解析映射文件失败: ${e.message}\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
requireMutationConfirmation(
|
||||
parsed,
|
||||
runtime,
|
||||
"批量映射工作流节点配置",
|
||||
`hose-use workflow node map ${pipelineId} ${nodeTarget} --yes`
|
||||
);
|
||||
|
||||
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
|
||||
const detail = await getWorkflowDetail(client, pipelineId);
|
||||
|
||||
const { workflow: updatedWorkflow, editedTask, changedKeys } = applyNodeMapping(detail, nodeTarget, mappingData);
|
||||
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, "批量映射工作流节点配置", `${pipelineId}:${editedTask.name}`, {
|
||||
pipelineId,
|
||||
nodeName: editedTask.name,
|
||||
label: editedTask.label,
|
||||
nodeType: editedTask.type,
|
||||
changedKeys,
|
||||
mappingSummary: Array.isArray(mappingData)
|
||||
? `数组格式更新 (${mappingData.length} 项)`
|
||||
: `对象属性更新 (${Object.keys(mappingData).join(", ")})`,
|
||||
});
|
||||
}
|
||||
|
||||
const saveResult = await updateWorkflow(client, updatedWorkflow);
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({ success: true, pipelineId, editedTask, changedKeys, workflow: saveResult }, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.label}) 已批量应用映射: ${changedKeys.join(", ")},并已保存至工作流 [${pipelineId}]。\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
async function handleRemoveNode(
|
||||
pipelineId: string,
|
||||
nodeTarget: string,
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
lintJavaScriptCode,
|
||||
lintMvelCode,
|
||||
executeJavaScriptSandbox,
|
||||
executeMvelSandbox,
|
||||
} from "../../../domains/platform/services.js";
|
||||
import { stringOption, booleanOption } from "../../parser.js";
|
||||
import { printJson, printKeyValue } from "../../printer.js";
|
||||
@@ -196,6 +197,8 @@ export async function handleWorkflowEvalScript(
|
||||
const codeInline = stringOption(parsed.options, ["code"]);
|
||||
const timeoutStr = stringOption(parsed.options, ["timeout"]);
|
||||
const timeoutMs = timeoutStr ? parseInt(timeoutStr, 10) : 3000;
|
||||
const explicitType = (stringOption(parsed.options, ["type"]) || "").toLowerCase();
|
||||
const isMvel = explicitType === "code" || explicitType === "mvel" || (filePath ? filePath.endsWith(".mvel") : false);
|
||||
|
||||
// 1. 获取输入参数 inputs
|
||||
let inputs: Record<string, unknown> = {};
|
||||
@@ -245,7 +248,9 @@ export async function handleWorkflowEvalScript(
|
||||
code = fs.readFileSync(filePath, "utf-8");
|
||||
}
|
||||
|
||||
const evalResult = await executeJavaScriptSandbox(code, inputs, { timeoutMs });
|
||||
const evalResult = isMvel
|
||||
? await executeMvelSandbox(code, inputs, { timeoutMs })
|
||||
: await executeJavaScriptSandbox(code, inputs, { timeoutMs });
|
||||
|
||||
if (isJson) {
|
||||
return { stdout: printJson(evalResult, runtime.outputOptions), stderr: "", exitCode: evalResult.success ? 0 : 1 };
|
||||
@@ -296,18 +301,7 @@ export async function handleWorkflowEvalScript(
|
||||
}
|
||||
|
||||
const task = located.task;
|
||||
if (task.type !== "code-js2") {
|
||||
if (task.type === "code") {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: [
|
||||
`节点 [${task.name}] 是 MVEL (code) 节点。`,
|
||||
"当前本地离线沙箱仅支持 JavaScript (code-js2) 运行时仿真。",
|
||||
"提示: 您可以使用 hose-use workflow lint-script 检查其括号与上游引用,或使用 hose-use workflow test 进行全链路调试。",
|
||||
].join("\n") + "\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
if (task.type !== "code-js2" && task.type !== "code") {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `节点 [${task.name}] 不是代码节点,类型为: ${task.type}\n`,
|
||||
@@ -316,6 +310,7 @@ export async function handleWorkflowEvalScript(
|
||||
}
|
||||
|
||||
const code: string = (task as any).code || "";
|
||||
const isNodeMvel = task.type === "code";
|
||||
|
||||
// 如果没有显式传 input,尝试提取工作流样本数据
|
||||
if (Object.keys(inputs).length === 0) {
|
||||
@@ -352,7 +347,9 @@ export async function handleWorkflowEvalScript(
|
||||
}
|
||||
}
|
||||
|
||||
const evalResult = await executeJavaScriptSandbox(code, inputs, { timeoutMs });
|
||||
const evalResult = isNodeMvel
|
||||
? await executeMvelSandbox(code, inputs, { timeoutMs })
|
||||
: await executeJavaScriptSandbox(code, inputs, { timeoutMs });
|
||||
|
||||
if (isJson) {
|
||||
return { stdout: printJson(evalResult, runtime.outputOptions), stderr: "", exitCode: evalResult.success ? 0 : 1 };
|
||||
|
||||
@@ -56,3 +56,105 @@ export async function createJobPiperClient(
|
||||
}
|
||||
return clients.easoClient;
|
||||
}
|
||||
|
||||
export interface CodeNodeSummary {
|
||||
id: string;
|
||||
name: string;
|
||||
label: string;
|
||||
type: string;
|
||||
status: string;
|
||||
rawOutput: unknown;
|
||||
summaryLines: string[];
|
||||
}
|
||||
|
||||
export function extractCodeNodeSummaries(
|
||||
nodes: Array<any>,
|
||||
flattenExecutionTreeFn?: (nodes: any[]) => any[]
|
||||
): CodeNodeSummary[] {
|
||||
const flattened = flattenExecutionTreeFn ? flattenExecutionTreeFn(nodes) : nodes;
|
||||
const summaries: CodeNodeSummary[] = [];
|
||||
|
||||
for (const node of flattened) {
|
||||
if (!node) continue;
|
||||
const type = String(node.type || "");
|
||||
if (type !== "code" && type !== "code-js2") continue;
|
||||
|
||||
const rawOutput = node.output ?? node.outputs ?? node.details;
|
||||
const summaryLines: string[] = [];
|
||||
|
||||
if (rawOutput === undefined || rawOutput === null) {
|
||||
summaryLines.push(" 出参: (无返回值或 null)");
|
||||
} else if (Array.isArray(rawOutput)) {
|
||||
summaryLines.push(` 出参类型: Array (${rawOutput.length} 项)`);
|
||||
if (rawOutput.length > 0) {
|
||||
const first = rawOutput[0];
|
||||
if (first && typeof first === "object") {
|
||||
const keys = ["planCode", "code", "id", "name", "title", "totalAmount", "amount"];
|
||||
const matchedKey = keys.find((k) => (first as Record<string, unknown>)[k] !== undefined);
|
||||
if (matchedKey) {
|
||||
summaryLines.push(` 首项 ${matchedKey}: ${String((first as Record<string, unknown>)[matchedKey])}`);
|
||||
}
|
||||
if ((first as any).amount !== undefined && matchedKey !== "amount") {
|
||||
summaryLines.push(` 首项金额: ${String((first as any).amount)}`);
|
||||
}
|
||||
} else {
|
||||
summaryLines.push(` 首项值: ${String(first)}`);
|
||||
}
|
||||
}
|
||||
} else if (typeof rawOutput === "object") {
|
||||
const obj = rawOutput as Record<string, unknown>;
|
||||
summaryLines.push(" 出参类型: Object");
|
||||
if (Array.isArray(obj.items)) {
|
||||
summaryLines.push(` items.length: ${obj.items.length}`);
|
||||
}
|
||||
for (const k of ["planCode", "totalAmount", "count", "code", "total", "amount", "success"]) {
|
||||
if (obj[k] !== undefined) {
|
||||
summaryLines.push(` ${k}: ${String(obj[k])}`);
|
||||
}
|
||||
}
|
||||
const allKeys = Object.keys(obj);
|
||||
if (summaryLines.length === 1 && allKeys.length > 0) {
|
||||
summaryLines.push(` 字段列表 (${allKeys.length} 个): ${allKeys.slice(0, 5).join(", ")}${allKeys.length > 5 ? "..." : ""}`);
|
||||
}
|
||||
} else {
|
||||
summaryLines.push(` 出参值: ${String(rawOutput)}`);
|
||||
}
|
||||
|
||||
summaries.push({
|
||||
id: node.id || "-",
|
||||
name: node.name || "-",
|
||||
label: node.label || node.displayName || (type === "code" ? "MVEL代码节点" : "JS代码节点"),
|
||||
type,
|
||||
status: node.status || "UNKNOWN",
|
||||
rawOutput,
|
||||
summaryLines,
|
||||
});
|
||||
}
|
||||
|
||||
return summaries;
|
||||
}
|
||||
|
||||
export function formatCodeNodeSummariesCard(
|
||||
summaries: CodeNodeSummary[],
|
||||
jobId?: string
|
||||
): string[] {
|
||||
if (summaries.length === 0) return [];
|
||||
|
||||
const lines: string[] = [
|
||||
"",
|
||||
"── 🧮 核心代码节点出参即时摘要 (Code Return Values) ──",
|
||||
];
|
||||
|
||||
for (const s of summaries) {
|
||||
const statusIcon = s.status === "COMPLETED" || s.status === "SUCCESS" ? "✅" : s.status === "FAILED" ? "❌" : "⏳";
|
||||
lines.push(` ${statusIcon} [${s.name}] ${s.label} (${s.type}, 状态: ${s.status})`);
|
||||
for (const l of s.summaryLines) {
|
||||
lines.push(` ${l}`);
|
||||
}
|
||||
if (jobId) {
|
||||
lines.push(` ↳ 完整出参查看: hose-use workflow job ${jobId} --node=${s.name} --full`);
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { stringOption, booleanOption, numberOption } from "../../parser.js";
|
||||
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { createWorkflowDetailClient } from "./shared.js";
|
||||
import { createWorkflowDetailClient, extractCodeNodeSummaries, formatCodeNodeSummariesCard } from "./shared.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
|
||||
export async function handleWorkflowTest(
|
||||
@@ -484,6 +484,11 @@ export async function handleWorkflowTest(
|
||||
}
|
||||
}
|
||||
|
||||
const codeSummaries = extractCodeNodeSummaries(report.executionTree);
|
||||
if (codeSummaries.length > 0) {
|
||||
outLines.push(...formatCodeNodeSummariesCard(codeSummaries, report.jobId));
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: `${outLines.join("\n")}\n`,
|
||||
stderr: "",
|
||||
|
||||
Reference in new issue
Block a user