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); });