From 198770f578744ae1c68b0fccbb637447d9ec4eaf Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Mon, 15 Jun 2026 13:41:39 -0400 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20address=20M2.2=20review=20nits?= =?UTF-8?q?=20=E2=80=94=20backup=20endpoint=20in=20diff=20summary=20+=20nu?= =?UTF-8?q?ll-oldConfig=20test=20(#10)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FormatConnection now includes BackupConfigurationJson so a backup-only change no longer renders identical Before/After cells (covers all 4 ConnectionsEqual fields) - add ComputeConnectionsDiff(null, newConfig) first-deploy unit test --- .../Pages/Deployment/Topology.razor | 13 ++++++-- .../Flattening/DiffServiceTests.cs | 30 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/Topology.razor b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/Topology.razor index 6a0fb025..326a80eb 100644 --- a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/Topology.razor +++ b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/Topology.razor @@ -892,13 +892,20 @@ } // Compact summary of a connection's deployment-relevant fields for the diff - // table's Before/After cells: protocol, primary endpoint config, and the - // failover retry count. Mirrors the fields ConnectionsEqual compares. + // table's Before/After cells. Surfaces all four fields ConnectionsEqual + // compares — protocol, primary endpoint config, failover retry count, and + // the backup endpoint — so a backup-only change doesn't show identical + // Before/After cells. The backup segment is omitted when there is no backup. private static string FormatConnection( ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening.ConnectionConfig c) { var endpoint = string.IsNullOrWhiteSpace(c.ConfigurationJson) ? "—" : c.ConfigurationJson; - return $"{c.Protocol} · {endpoint} · failover ×{c.FailoverRetryCount}"; + var summary = $"{c.Protocol} · {endpoint} · failover ×{c.FailoverRetryCount}"; + if (!string.IsNullOrWhiteSpace(c.BackupConfigurationJson)) + { + summary += $" · backup {c.BackupConfigurationJson}"; + } + return summary; } // Renders one change section (a heading plus a Bootstrap change-table) for a diff --git a/tests/ZB.MOM.WW.ScadaBridge.TemplateEngine.Tests/Flattening/DiffServiceTests.cs b/tests/ZB.MOM.WW.ScadaBridge.TemplateEngine.Tests/Flattening/DiffServiceTests.cs index e405a109..fb5fa89f 100644 --- a/tests/ZB.MOM.WW.ScadaBridge.TemplateEngine.Tests/Flattening/DiffServiceTests.cs +++ b/tests/ZB.MOM.WW.ScadaBridge.TemplateEngine.Tests/Flattening/DiffServiceTests.cs @@ -286,6 +286,36 @@ public class DiffServiceTests Assert.Equal("OpcUa", diff[0].NewValue!.Protocol); } + [Fact] + public void ComputeConnectionsDiff_NullOldConfig_AllReportedAsAdded() + { + // First deploy: there is no prior flattened config at all (null), so + // every connection in the new config is Added. Exercises the public + // method's null-oldConfig tolerance explicitly (the ComputeDiff path + // covers it end-to-end, but the isolated API contract is asserted here). + var newConfig = new FlattenedConfiguration + { + InstanceUniqueName = "Instance1", + Connections = new Dictionary + { + ["plc1"] = new ConnectionConfig + { + Protocol = "OpcUa", + ConfigurationJson = "{\"endpoint\":\"opc.tcp://host\"}", + FailoverRetryCount = 3, + } + } + }; + + var diff = _sut.ComputeConnectionsDiff(null, newConfig); + + Assert.Single(diff); + Assert.Equal("plc1", diff[0].CanonicalName); + Assert.Equal(DiffChangeType.Added, diff[0].ChangeType); + Assert.Null(diff[0].OldValue); + Assert.Equal("OpcUa", diff[0].NewValue!.Protocol); + } + [Fact] public void ComputeConnectionsDiff_BindingCleared_ReportedAsRemoved() {