fix(cli): site/data-connection/api-method update are preserve-if-null partial updates (CLI-2, WP2 task 2.8)

Decision 2.8: preserve-if-null on the server. UpdateSiteCommand,
UpdateDataConnectionCommand and UpdateApiMethodCommand fields (except the id)
are now nullable; the ManagementActor handlers apply only non-null values and
treat an empty string as 'clear this optional field'. The CLI update commands
no longer require --name/--protocol/--script and drop the --failover-retry-count
(3) and --timeout (30) defaults, so an omitted option travels as null instead of
overwriting the stored value (site update --name used to null both gRPC
addresses). The site gRPC-address validation now runs on the merged values.

Additive/compatible: the fields only became nullable, so an older CLI that
always sends every field still deserializes (pinned by a test) and now simply
updates every field as before. The Central UI full-entity forms send "" for a
field the operator cleared (description/addresses, removed backup endpoint,
cleared parameter/return definitions) so clearing keeps working.
This commit is contained in:
Joseph Doherty
2026-12-03 09:48:00 -05:00
parent c207809ef3
commit 61c6278bd0
17 changed files with 533 additions and 93 deletions
@@ -4,7 +4,9 @@ using ZB.MOM.WW.ScadaBridge.CLI.Commands;
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests;
/// <summary>
/// Regression tests for the update commands. The <c>Update*Command</c> records in Commons carry
/// Regression tests for the update commands. Site, data-connection and api-method updates are
/// preserve-if-null partial updates (CLI-2, see <see cref="PartialUpdateCommandTests"/>); the
/// remaining <c>Update*Command</c> records in Commons carry
/// non-nullable "core" fields (e.g. <c>string Name</c>, <c>string Protocol</c>,
/// <c>string Script</c>) — an update is a <em>whole-entity replace</em>, not a sparse
/// patch. The CLI must therefore mark those core flags as <c>Required</c>: making them
@@ -57,15 +59,24 @@ public class UpdateCommandContractTests
public void TemplateScriptUpdate_CoreFieldsRequired()
=> AssertRequired(UpdateCommand(TemplateCommands.Build(Url, Format, Username, Password), "script", "update"), "--name", "--code");
/// <summary>Verifies that the site update command marks its core fields as required.</summary>
/// <summary>CLI-2: site update is a preserve-if-null partial update, so only <c>--id</c> is required.</summary>
[Fact]
public void SiteUpdate_CoreFieldsRequired()
=> AssertRequired(UpdateCommand(SiteCommands.Build(Url, Format, Username, Password), "update"), "--name");
public void SiteUpdate_IsPartial_OnlyIdRequired()
{
var update = UpdateCommand(SiteCommands.Build(Url, Format, Username, Password), "update");
AssertRequired(update, "--id");
AssertOptional(update, "--name", "--description", "--node-a-address", "--node-b-address",
"--grpc-node-a-address", "--grpc-node-b-address");
}
/// <summary>Verifies that the data connection update command marks its core fields as required.</summary>
/// <summary>CLI-2: data-connection update is a preserve-if-null partial update, so only <c>--id</c> is required.</summary>
[Fact]
public void DataConnectionUpdate_CoreFieldsRequired()
=> AssertRequired(UpdateCommand(DataConnectionCommands.Build(Url, Format, Username, Password), "update"), "--name", "--protocol");
public void DataConnectionUpdate_IsPartial_OnlyIdRequired()
{
var update = UpdateCommand(DataConnectionCommands.Build(Url, Format, Username, Password), "update");
AssertRequired(update, "--id");
AssertOptional(update, "--name", "--protocol", "--primary-config", "--backup-config", "--failover-retry-count");
}
/// <summary>Verifies that the external system update command marks its core fields as required.</summary>
[Fact]
@@ -110,10 +121,25 @@ public class UpdateCommandContractTests
}
}
/// <summary>Verifies that the API method update command marks its script as required.</summary>
/// <summary>CLI-2: api-method update is a preserve-if-null partial update, so only <c>--id</c> is required.</summary>
[Fact]
public void ApiMethodUpdate_CoreFieldsRequired()
=> AssertRequired(UpdateCommand(ApiMethodCommands.Build(Url, Format, Username, Password), "update"), "--script");
public void ApiMethodUpdate_IsPartial_OnlyIdRequired()
{
var update = UpdateCommand(ApiMethodCommands.Build(Url, Format, Username, Password), "update");
AssertRequired(update, "--id");
AssertOptional(update, "--script", "--timeout", "--parameters", "--return-def", "--trace-all-calls");
}
private static void AssertOptional(Command command, params string[] optionNames)
{
foreach (var name in optionNames)
{
var option = command.Options.SingleOrDefault(o => o.Name == name);
Assert.True(option != null, $"'{command.Name}' is missing expected option '{name}'.");
Assert.False(option!.Required, $"'{command.Name}' option '{name}' must be optional (partial update).");
Assert.False(option.HasDefaultValue, $"'{command.Name}' option '{name}' must have no default — an omitted option must travel as null.");
}
}
/// <summary>Verifies that the external system method update command keeps all of its fields optional because it is a sparse update.</summary>
[Fact]