v3(b1-modbus): RawPath identity seam — RawTagEntry-driven Modbus driver

Wave-B EXEMPLAR. Retire the pre-declared/blob-parse tag model; the driver now
builds its RawPath -> definition table from the artifact's RawTagEntry set via a
pure mapper.

- Contracts: rename ModbusEquipmentTagParser -> ModbusTagDefinitionFactory;
  TryParse(reference) -> FromTagConfig(tagConfig, rawPath) (def.Name = rawPath,
  no leading-brace heuristic); add inverse ToTagConfig(def) serializer; keep all
  strict-enum reads + guards; also read stringByteOrder/deadband/coalesceProhibited
  so a RawTagEntry round-trips the full authored def. Inspect() unchanged.
- Options: Tags(IReadOnlyList<ModbusTagDefinition>) -> RawTags(IReadOnlyList<RawTagEntry>).
- Driver: _tagsByName -> _tagsByRawPath (Ordinal); resolver byRawPath-only; build
  the table from RawTags at Initialize threading entry.WriteIdempotent onto each def;
  Discover/Teardown updated.
- Factory: remove ModbusTagDto/BuildTag/ValidateStringLength + ConfigDto.Tags; bind
  RawTags from driver-config JSON.
- CLI ModbusCommandBase.BuildOptions: serialise typed defs -> RawTagEntry via ToTagConfig.
- Tests: migrate Tags= -> RawTags via ModbusRawTags.Entries helper; parser tests ->
  FromTagConfig(rawPath); factory String-length/enum tests re-seated on the mapper seam.
- Propagated rename to ControlPlane EquipmentTagConfigInspector (outside Modbus projects).

Modbus.Tests 315/315, Addressing.Tests 161/161, Cli.Tests 72/72 green.
Docker-gated Driver.Modbus.IntegrationTests left untouched (won't compile against
the new API; expected).
This commit is contained in:
Joseph Doherty
2026-07-15 19:50:10 -04:00
parent 906800abc0
commit aafb9d4929
27 changed files with 362 additions and 362 deletions
@@ -6,44 +6,49 @@ using Xunit;
namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.Tests;
/// <summary>
/// Regression guard for the 2026-06-19 enum-serialization bug (the FB-9 Modbus-Int64 authoring
/// case). The AdminUI Modbus page now serialises tag enums (<see cref="ModbusRegion"/>,
/// <see cref="ModbusDataType"/>, byte-order) as STRINGS. This proves the factory parses that
/// AdminUI-shaped Int64-tag blob, and documents that the pre-fix NUMERIC form threw because the
/// <c>ModbusTagDto</c> enum fields are <c>string?</c>.
/// v3 factory RawTags binding. Under v3 tags are delivered as authored raw tags
/// (<c>{rawPath, tagConfig, writeIdempotent}</c>) — the tag's address enums live INSIDE the opaque
/// <c>tagConfig</c> blob (authored by the AdminUI <c>ModbusTagConfigModel</c>), not in the driver
/// config DTO. This proves the factory binds a <c>rawTags</c> array and documents that the legacy
/// structured/AddressString <c>tags</c> path (and the FB-9 numeric-vs-string tag-enum bug class it
/// carried) is retired.
/// </summary>
public sealed class ModbusDriverConfigEnumSerializationTests
{
// Mirrors the (now fixed) AdminUI ModbusDriverPage._jsonOpts: camelCase + string enums.
// Mirrors the AdminUI ModbusDriverPage._jsonOpts: camelCase + string enums.
private static readonly JsonSerializerOptions _adminPageOpts = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters = { new JsonStringEnumConverter() },
};
/// <summary>Verifies the factory parses an AdminUI-authored Modbus config carrying an Int64
/// holding-register tag (string enums) without throwing.</summary>
/// <summary>Verifies the factory binds an AdminUI-authored Modbus config carrying an Int64
/// holding-register raw tag (string enums inside the tagConfig blob) without throwing.</summary>
[Fact]
public void Factory_parses_admin_authored_int64_string_enum_config()
public void Factory_binds_admin_authored_rawTags_config()
{
var tag = new ModbusTagDefinition("Int64Tag", ModbusRegion.HoldingRegisters, (ushort)100, ModbusDataType.Int64);
var opts = new ModbusDriverOptions { Host = "10.0.0.5", Port = 502, UnitId = 1, Tags = new[] { tag } };
var tag = new ModbusTagDefinition("cell/modbus/dev1/Int64Tag", ModbusRegion.HoldingRegisters, (ushort)100, ModbusDataType.Int64);
var opts = new ModbusDriverOptions { Host = "10.0.0.5", Port = 502, UnitId = 1, RawTags = ModbusRawTags.Entries(new[] { tag }) };
var blob = JsonSerializer.Serialize(opts, _adminPageOpts);
// The fixed AdminUI page must emit tag enums as strings, not numbers.
blob.ShouldContain("\"dataType\":\"Int64\"");
// The raw tag serialises as {rawPath, tagConfig, writeIdempotent}; the address enums live
// inside the (string-encoded) tagConfig blob.
blob.ShouldContain("\"rawPath\":\"cell/modbus/dev1/Int64Tag\"");
blob.ShouldContain("Int64");
using var driver = ModbusDriverFactoryExtensions.CreateInstance("mb-test", blob);
driver.DriverType.ShouldBe("Modbus");
}
/// <summary>Documents the original bug: the pre-fix AdminUI page emitted numeric tag enums
/// (<c>"dataType":5,"region":3</c>) which the string-typed tag DTO cannot bind, so the factory throws.</summary>
/// <summary>Documents the retirement of the legacy structured <c>tags</c> path: a legacy tag array
/// (including the pre-fix numeric-enum shape) is no longer a recognised property, so it binds nothing
/// and the factory succeeds rather than throwing on its enum shape.</summary>
[Fact]
public void Factory_throws_on_the_numeric_enum_form_the_pre_fix_page_emitted()
public void Factory_ignores_the_retired_structured_tags_array()
{
const string numericBlob =
const string legacyBlob =
"{\"host\":\"10.0.0.5\",\"port\":502,\"unitId\":1,\"tags\":[" +
"{\"name\":\"Int64Tag\",\"region\":3,\"address\":100,\"dataType\":5}]}";
Should.Throw<Exception>(() => ModbusDriverFactoryExtensions.CreateInstance("mb-test", numericBlob));
using var driver = ModbusDriverFactoryExtensions.CreateInstance("mb-test", legacyBlob);
driver.DriverType.ShouldBe("Modbus");
}
}