fix(drivers): ResolveHost resolves equipment-tag refs via EquipmentTagRefResolver — per-host breaker isolation (CONV-4)

This commit is contained in:
Joseph Doherty
2026-07-13 12:26:42 -04:00
parent 8a7701db3f
commit 9262dd25b7
6 changed files with 67 additions and 22 deletions
@@ -16,37 +16,45 @@ public sealed class FocasResolveHostTests
private const string DeviceA = "focas://10.0.0.5:8193";
private const string DeviceB = "focas://10.0.0.6:8193";
private static FocasDriver NewDriver() => new(
new FocasDriverOptions
{
Devices = [new FocasDeviceOptions(DeviceA), new FocasDeviceOptions(DeviceB)],
Probe = new FocasProbeOptions { Enabled = false },
},
"focas-1", new FakeFocasClientFactory());
// FOCAS's equipment-ref resolver validates against the initialized Devices map, so — unlike
// the other drivers — the driver must be initialized (as it always is when ResolveHost runs at
// runtime) before an equipment ref resolves. Probe off / no connect: init just parses devices.
private static async Task<FocasDriver> NewDriverAsync()
{
var drv = new FocasDriver(
new FocasDriverOptions
{
Devices = [new FocasDeviceOptions(DeviceA), new FocasDeviceOptions(DeviceB)],
Probe = new FocasProbeOptions { Enabled = false },
},
"focas-1", new FakeFocasClientFactory());
await drv.InitializeAsync("{}", CancellationToken.None);
return drv;
}
/// <summary>An equipment-tag ref naming device B resolves to device B's host, not the first device.</summary>
[Fact]
public void ResolveHost_EquipmentTagRef_ReturnsItsOwnDeviceHost()
public async Task ResolveHost_EquipmentTagRef_ReturnsItsOwnDeviceHost()
{
var drv = NewDriver();
var drv = await NewDriverAsync();
var json = $$"""{"deviceHostAddress":"{{DeviceB}}","address":"R100","dataType":"Byte"}""";
drv.ResolveHost(json).ShouldBe(DeviceB);
}
/// <summary>An equipment ref with no deviceHostAddress falls back to the first device, not an empty host.</summary>
[Fact]
public void ResolveHost_EquipmentTagRef_WithoutDeviceHost_FallsBack()
public async Task ResolveHost_EquipmentTagRef_WithoutDeviceHost_FallsBack()
{
var drv = NewDriver();
var drv = await NewDriverAsync();
var json = """{"address":"R100","dataType":"Byte"}""";
drv.ResolveHost(json).ShouldBe(DeviceA);
}
/// <summary>An unresolvable ref keeps the current first-device fallback.</summary>
[Fact]
public void ResolveHost_UnknownRef_KeepsCurrentFallback()
public async Task ResolveHost_UnknownRef_KeepsCurrentFallback()
{
var drv = NewDriver();
var drv = await NewDriverAsync();
drv.ResolveHost("totally-unknown").ShouldBe(DeviceA);
}
}