From ca90c9a19efdee17920986d6849df9460bfae23b Mon Sep 17 00:00:00 2001 From: Matthew Ball Date: Fri, 20 Nov 2026 13:57:28 -0800 Subject: [PATCH] refactor(frontend): deep-compare operator properties in the version diff getOperatorsDifference compared each operator property with !=, so object- and array-valued properties were compared by reference and always reported as changed in the workflow version diff, and the loop iterated only the first operator's keys, so a property present only in the second version was never reported. It now compares with lodash isEqual over the union of both operators' property keys, so only genuinely changed properties are highlighted and added properties are detected. workflow-version.service.spec adds cases that deeply-equal object and array properties are not flagged, that a changed nested value is flagged, and that a property present only in the second operator is flagged. --- .../workflow-version.service.spec.ts | 23 +++++++++++++++++++ .../workflow-version.service.ts | 13 +++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.spec.ts b/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.spec.ts index aa29f455903..2f1cb167203 100644 --- a/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.spec.ts +++ b/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.spec.ts @@ -566,4 +566,27 @@ describe("WorkflowVersionService", () => { expect(await pending).toBe(99); }); }); + + describe("getOperatorsDifference", () => { + const op = (operatorProperties: Record, operatorVersion = "1") => + buildOperator({ operatorProperties, operatorVersion }); + + it("does not flag object or array properties that are deeply equal", () => { + const diff = service.getOperatorsDifference( + op({ list: [1, 2], cfg: { x: 1 } }), + op({ list: [1, 2], cfg: { x: 1 } }) + ); + expect(diff.size).toBe(0); + }); + + it("flags a property whose nested value changed", () => { + const diff = service.getOperatorsDifference(op({ cfg: { x: 1 } }), op({ cfg: { x: 2 } })); + expect(diff.has("cfg")).toBe(true); + }); + + it("flags a property present only in the second operator", () => { + const diff = service.getOperatorsDifference(op({}), op({ extra: 5 })); + expect(diff.has("extra")).toBe(true); + }); + }); }); diff --git a/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.ts b/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.ts index cf2db135ee2..c44c3430719 100644 --- a/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.ts +++ b/frontend/src/app/dashboard/service/user/workflow-version/workflow-version.service.ts @@ -218,13 +218,18 @@ export class WorkflowVersionService { public getOperatorsDifference(operator1: OperatorPredicate, operator2: OperatorPredicate) { const difference: Map = new Map(); - for (const property of Object.keys(operator1.operatorProperties)) { - if (operator1.operatorProperties[property] != operator2.operatorProperties[property]) { - difference.set(property, "outline: 3px solid rgb(255, 118, 20); transition: 0.3s ease-in-out outline;"); + const highlight = "outline: 3px solid rgb(255, 118, 20); transition: 0.3s ease-in-out outline;"; + const properties = new Set([ + ...Object.keys(operator1.operatorProperties), + ...Object.keys(operator2.operatorProperties), + ]); + for (const property of properties) { + if (!isEqual(operator1.operatorProperties[property], operator2.operatorProperties[property])) { + difference.set(property, highlight); } } if (operator1.operatorVersion != operator2.operatorVersion) { - difference.set("operatorVersion", "outline: 3px solid rgb(255, 118, 20); transition: 0.3s ease-in-out outline;"); + difference.set("operatorVersion", highlight); } return difference; }