fix(workflow): include mappings and structural movement in snapshot diffs
This commit is contained in:
1 parent
fac81b08e8
commit
2aea435116
4 files changed
+125
-105
No files matched your search
@@ -556,6 +556,16 @@ export function diffWorkflowSnapshots(
|
||||
): WorkflowSnapshotDiff {
|
||||
const tasksA = flattenWorkflowTasks(snapshotA.tasks);
|
||||
const tasksB = flattenWorkflowTasks(snapshotB.tasks);
|
||||
const indexPaths = (tasks: WorkflowTask[] = [], prefix = "tasks", paths = new Map<string, string>()): Map<string, string> => {
|
||||
tasks.forEach((task, i) => {
|
||||
const path = `${prefix}.${i}`;
|
||||
if (task.name) paths.set(task.name, path);
|
||||
if (task.tasks) indexPaths(task.tasks, `${path}.tasks`, paths);
|
||||
});
|
||||
return paths;
|
||||
};
|
||||
const pathsA = indexPaths(snapshotA.tasks || []);
|
||||
const pathsB = indexPaths(snapshotB.tasks || []);
|
||||
|
||||
const mapA = new Map<string, WorkflowTask>();
|
||||
for (const t of tasksA) {
|
||||
@@ -629,22 +639,11 @@ export function diffWorkflowSnapshots(
|
||||
}
|
||||
|
||||
// 关键字段变动比较
|
||||
const checkFields = [
|
||||
"type",
|
||||
"url",
|
||||
"method",
|
||||
"entityId",
|
||||
"specificationId",
|
||||
"flowCode",
|
||||
"formState",
|
||||
"subType",
|
||||
"itemType",
|
||||
"targetType",
|
||||
"orderMode",
|
||||
"orderKey",
|
||||
"batch",
|
||||
"batchSize",
|
||||
];
|
||||
const checkFields = [...new Set([...Object.keys(tA), ...Object.keys(tB)])]
|
||||
.filter(field => !["name", "tasks", "code", "combineFilters", "filters"].includes(field));
|
||||
if (pathsA.get(name) !== pathsB.get(name)) {
|
||||
configChanges.push({ field: "$path", from: pathsA.get(name), to: pathsB.get(name) });
|
||||
}
|
||||
for (const f of checkFields) {
|
||||
const valA = (tA as any)[f];
|
||||
const valB = (tB as any)[f];
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { diffWorkflowSnapshots } from "./services.js";
|
||||
for (const field of ["mapping", "inputs", "fields", "form", "header", "params", "onError", "customConfig"]) {
|
||||
test(`snapshot diff includes ${field} changes`, () => {
|
||||
const before = { id: "a", tasks: [{ name: "node", type: "http", [field]: { target: "old" } }] } as any;
|
||||
const after = structuredClone(before); after.id = "b"; after.tasks[0][field] = { target: "new" };
|
||||
const result = diffWorkflowSnapshots(before, after);
|
||||
expect(result.summary.changedCount).toBe(1);
|
||||
expect(result.modifiedTasks[0].configChanges).toContainEqual({ field, from: { target: "old" }, to: { target: "new" } });
|
||||
});
|
||||
}
|
||||
test("snapshot diff detects reordered and reparented nodes without relying on saved index metadata", () => {
|
||||
const a = { id: "a", tasks: [{ name: "first", type: "http" }, { name: "branch", type: "condition", tasks: [{ name: "child", type: "http" }] }] } as any;
|
||||
const b = { id: "b", tasks: [{ name: "branch", type: "condition", tasks: [] }, { name: "first", type: "http" }, { name: "child", type: "http" }] } as any;
|
||||
const diff = diffWorkflowSnapshots(a, b);
|
||||
expect(diff.summary.changedCount).toBe(3);
|
||||
expect(diff.modifiedTasks.find(t => t.taskName === "child")?.configChanges).toContainEqual({ field: "$path", from: "tasks.1.tasks.0", to: "tasks.2" });
|
||||
expect(diffWorkflowSnapshots(a, structuredClone(a)).summary.changedCount).toBe(0);
|
||||
});
|
||||
@@ -128,3 +128,5 @@ hose-use workflow eval-script --code="return a + b;" --input='{"a":1,"b":2}'
|
||||
- 借助 Kimi 网桥(`kimi-webbridge`)建立真实微前端会话,自动探测并解析不同应用类型下的非费用类表单元数据;
|
||||
- 提取出动态列、关联实体 ID 与系统字段字典,在 CLI 层面提供对非费用类业务对象的只读探针与结构化校验能力。
|
||||
|
||||
|
||||
快照 Diff 对比节点的全部配置字段(脚本和过滤器沿用专用输出),覆盖 `mapping/inputs/fields` 及自定义配置。节点顺序或父容器变化通过 `configChanges` 中的 `$path` 表达,不依赖服务端是否重算索引。
|
||||
Reference in new issue
Block a user