merge: integrate review-15-snapshot-config-diff
This commit is contained in:
commit
1197b5b985
4 files changed
+245
-225
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);
|
||||
});
|
||||
@@ -141,3 +141,5 @@ hose-use workflow eval-script --code="return a + b;" --input='{"a":1,"b":2}'
|
||||
草稿补丁路径仅遍历对象自身属性,禁止 `__proto__`、`constructor`、`prototype` 路径段;非法路径在写入前拒绝。CLI 选项仅识别自身属性,继承的确认标记无效。
|
||||
|
||||
脚本静态校验和离线仿真的本地、远端节点路径均支持 `--json/-j` 与 `--output-file`:stdout 返回 JSON 报告或导出摘要,失败时保留结构化错误并返回非零退出码。
|
||||
|
||||
快照 Diff 对比节点的全部配置字段(脚本和过滤器沿用专用输出),覆盖 `mapping/inputs/fields` 及自定义配置。节点顺序或父容器变化通过 `configChanges` 中的 `$path` 表达,不依赖服务端是否重算索引。
|
||||
Reference in new issue
Block a user