feat(workflow): 支持节点只读透视与样本固化,规范企业切换上下文持久化
- skill: 补充终止节点物理断点与样本固化 (Stop Barrier & Sample Pinning) 最佳实践 - config: 修复 switchCorp / enter --switch 持久化写入 defaultCorpId 与激活 stateful 模式 - workflow node: 新增 inspect (探针透视配置/样本/执行) 与 sample-save (一键固化出参至 sampleData 并刷新选择树) - workflow test: 新增 --save-sample 选项,调测通过后自动将产生出参的节点固化为 sampleData - parser/metadata: 注册 save-sample 选项词汇表,补充单测 workflow-node-sample-inspect.test.ts
This commit is contained in:
1 parent
5e59c835f1
commit
86a02b82b7
7 files changed
+949
-11
No files matched your search
@@ -6,6 +6,9 @@ import {
|
||||
getWorkflowDetail,
|
||||
getWorkflowSampleData,
|
||||
runWorkflowDebugTest,
|
||||
updateWorkflow,
|
||||
refreshWorkflowChooses,
|
||||
flattenWorkflowTaskTree,
|
||||
type WorkflowTriggerCategory,
|
||||
} from "../../../domains/platform/workflow/services.js";
|
||||
import { stringOption, booleanOption, numberOption } from "../../parser.js";
|
||||
@@ -46,6 +49,7 @@ export async function handleWorkflowTest(
|
||||
" 4. 外部调用 (webhook): --body='{...}' 或 --file=<path.json> 传入事件请求体",
|
||||
"",
|
||||
"通用选项:",
|
||||
" --save-sample 调试通过后自动将执行节点的真实出参保存为样本数据 (sampleData)",
|
||||
" --timeout=<ms> 设置轮询超时时间 (默认 15000ms)",
|
||||
" --auto-publish 是否自动发布测试快照 (默认 false)",
|
||||
" --allow-prod 确认在正式生产环境 (env: prod) 下执行调试(--force 为兼容别名)",
|
||||
@@ -59,6 +63,7 @@ export async function handleWorkflowTest(
|
||||
}
|
||||
|
||||
const autoPublish = booleanOption(parsed.options, ["auto-publish", "autoPublish", "publish"]);
|
||||
const saveSample = booleanOption(parsed.options, ["save-sample", "saveSample", "save-samples", "saveSamples"]);
|
||||
const timeoutMs = numberOption(parsed.options, ["timeout", "timeout-ms", "timeoutMs"]) ?? 15000;
|
||||
const rawBody = stringOption(parsed.options, ["body", "data", "payload"]);
|
||||
const filePath = stringOption(parsed.options, ["file", "path"]);
|
||||
@@ -109,7 +114,7 @@ export async function handleWorkflowTest(
|
||||
});
|
||||
if (blocked) return blocked;
|
||||
if (flowCodeOrId || rawBody || filePath || isEmpty) confirmExecution();
|
||||
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
|
||||
const { client, platformId } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
|
||||
|
||||
// 1. 获取工作流详情与触发器元数据
|
||||
const detail = await getWorkflowDetail(client, pipelineId).catch(() => {
|
||||
@@ -414,9 +419,48 @@ export async function handleWorkflowTest(
|
||||
autoPublish,
|
||||
timeoutMs,
|
||||
});
|
||||
|
||||
const savedSampleNodes: Array<{ name: string; label: string; fieldCount: number }> = [];
|
||||
if (saveSample && execution.outcome === "completed" && execution.executionTree?.length > 0) {
|
||||
try {
|
||||
const latestDetail = await getWorkflowDetail(client, pipelineId);
|
||||
const flattened = flattenWorkflowTaskTree(latestDetail.tasks || []);
|
||||
let updatedCount = 0;
|
||||
|
||||
for (const execNode of execution.executionTree) {
|
||||
if (!execNode.name || execNode.output === undefined || execNode.output === null) continue;
|
||||
if (typeof execNode.output !== "object" || Object.keys(execNode.output).length === 0) continue;
|
||||
|
||||
const matched = flattened.find((f) => f.task.name === execNode.name);
|
||||
if (matched) {
|
||||
(matched.task as any).sampleData = execNode.output;
|
||||
savedSampleNodes.push({
|
||||
name: matched.task.name,
|
||||
label: (matched.task as any).displayName || matched.task.label || matched.task.type,
|
||||
fieldCount: Object.keys(execNode.output).length,
|
||||
});
|
||||
updatedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (updatedCount > 0) {
|
||||
await updateWorkflow(client, latestDetail, {
|
||||
platformId,
|
||||
expectedVersion: { version: latestDetail.version, tasksVersion: latestDetail.tasksVersion },
|
||||
});
|
||||
try {
|
||||
await refreshWorkflowChooses(client, pipelineId);
|
||||
} catch {}
|
||||
}
|
||||
} catch (sampleErr: any) {
|
||||
warnings.push(`自动固化样本数据警告: ${sampleErr.message || String(sampleErr)}`);
|
||||
}
|
||||
}
|
||||
|
||||
const report = {
|
||||
...execution,
|
||||
productionEnabled: detail ? isEnabled : null,
|
||||
savedSampleNodes: savedSampleNodes.length > 0 ? savedSampleNodes : undefined,
|
||||
warnings,
|
||||
...productionOverrideMeta(
|
||||
parsed,
|
||||
@@ -514,6 +558,15 @@ export async function handleWorkflowTest(
|
||||
outLines.push(...formatCodeNodeSummariesCard(codeSummaries, report.jobId));
|
||||
}
|
||||
|
||||
if (savedSampleNodes.length > 0) {
|
||||
outLines.push("");
|
||||
outLines.push("── ✨ 样本数据自动固化 (Sample Data Saved) ──");
|
||||
outLines.push(`已自动将 ${savedSampleNodes.length} 个节点的真实调试出参固化为 sampleData 并刷新设计器选择树:`);
|
||||
for (const sn of savedSampleNodes) {
|
||||
outLines.push(` • [${sn.name}] (${sn.label}): 固化 ${sn.fieldCount} 个属性`);
|
||||
}
|
||||
}
|
||||
|
||||
if (category === "WEBHOOK" && report.outcome !== "completed") {
|
||||
outLines.push("");
|
||||
outLines.push("💡 [Webhook 流程调试提示]");
|
||||
|
||||
Reference in new issue
Block a user