fix(driver-opcuaclient): resolve Medium code-review finding (Driver.OpcUaClient-010)

Map DataTypeIds.Byte to DriverDataType.UInt16 (unsigned family) rather than Int16
(signed family). Update attribute mapping test to assert the correct unsigned mapping
and add Byte/UInt16 to the standard-types theory.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-05-22 10:35:37 -04:00
parent 412c4bbd40
commit 2df614c79e

View File

@@ -10,6 +10,8 @@ public sealed class OpcUaClientAttributeMappingTests
{
[Theory]
[InlineData((uint)DataTypes.Boolean, DriverDataType.Boolean)]
[InlineData((uint)DataTypes.SByte, DriverDataType.Int16)]
[InlineData((uint)DataTypes.Byte, DriverDataType.UInt16)]
[InlineData((uint)DataTypes.Int16, DriverDataType.Int16)]
[InlineData((uint)DataTypes.UInt16, DriverDataType.UInt16)]
[InlineData((uint)DataTypes.Int32, DriverDataType.Int32)]
@@ -27,12 +29,19 @@ public sealed class OpcUaClientAttributeMappingTests
}
[Fact]
public void MapUpstreamDataType_maps_SByte_and_Byte_to_Int16_since_DriverDataType_lacks_8bit()
public void MapUpstreamDataType_maps_SByte_to_Int16_since_DriverDataType_lacks_8bit_signed()
{
// DriverDataType has no 8-bit type; conservative widen to Int16. Documented so a
// future Core.Abstractions PR that adds Int8/Byte can find this call site.
// SByte (signed 8-bit) has no narrower signed type in DriverDataType; widen to Int16.
OpcUaClientDriver.MapUpstreamDataType(new NodeId((uint)DataTypes.SByte)).ShouldBe(DriverDataType.Int16);
OpcUaClientDriver.MapUpstreamDataType(new NodeId((uint)DataTypes.Byte)).ShouldBe(DriverDataType.Int16);
}
[Fact]
public void MapUpstreamDataType_maps_Byte_to_UInt16_not_Int16()
{
// Driver.OpcUaClient-010: Byte is unsigned 0-255 and must map to the unsigned family
// (UInt16), NOT Int16. The old mapping misrepresented type metadata for downstream
// clients and range/validation logic keyed off DriverDataType.
OpcUaClientDriver.MapUpstreamDataType(new NodeId((uint)DataTypes.Byte)).ShouldBe(DriverDataType.UInt16);
}
[Fact]