v3 Batch 3 WP1: UNS Equipment Tags tab → reference list + raw-tag picker
Replace the Batch-1-stubbed authored-tag flow with a UnsTagReference list on the equipment page's Tags tab (v3 reference-only equipment): columns are effective name, computed raw path, inherited datatype/access (read-only), display-name override (editable), and remove. The retired equipment-authored-tag editor (TagModal.razor) is deleted; the VirtualTag and ScriptedAlarm flows are untouched. - "+ Add reference" opens a new AddReferenceModal that reuses RawTree in a new opt-in PickerMode (Tag-leaf checkboxes + Device/TagGroup "select all tags below"), scoped structurally to the equipment's cluster via LoadReferencePickerRootAsync (a single cluster root — cross-cluster tags are unreachable, not merely hidden). Default /raw usage is byte-unchanged (PickerMode defaults false). - UnsTreeService (+ IUnsTreeService) gain the reference mutations: LoadReferencesForEquipmentAsync (computes each RawPath via the shared RawPathResolver), AddReferencesAsync (cluster-checked, all-or-nothing), RemoveReferenceAsync, SetReferenceOverrideAsync, plus the picker helpers LoadReferencePickerRootAsync / LoadDescendantTagIdsAsync. - Consume IEffectiveNameGuard (constructor-injected, no-op fallback when unregistered): AddReferences, SetReferenceOverride, and the VirtualTag + ScriptedAlarm create/update mutations now call CheckAsync before persisting and surface a collision as the failure. WP2 supplies the implementation + DI registration. - Drop the retired equipment↔driver binding: remove DriverInstanceId from EquipmentInput, the ImportEquipmentModal CSV column, the EquipmentPage Details driver select, and the dead decision-#122 driver-cluster guard. Tests: new UnsTreeServiceReferenceTests (add/remove/override, cross-cluster + duplicate rejection, guard-consumed rejection via a fake guard, RawPath projection, picker helpers); Equipment/Import test suites rewritten to drop the retired driver-guard cases. AdminUI suite green (639 passed, 3 skipped); full solution builds 0 errors. Claude-Session: https://claude.ai/code/session_01LVneM3eh1UtJxEisFXgmox
This commit is contained in:
@@ -6,10 +6,10 @@ using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the bulk <see cref="UnsTreeService.ImportEquipmentAsync"/> path: valid rows insert,
|
||||
/// rows whose MachineCode already exists (in the DB or earlier in the same batch) are skipped,
|
||||
/// rows referencing an unknown UNS line or unknown driver are reported as errors, and the
|
||||
/// decision-#122 driver-cluster guard rejects a driver in a different cluster than the line.
|
||||
/// Verifies the bulk <see cref="UnsTreeService.ImportEquipmentAsync"/> path: valid rows insert, rows
|
||||
/// whose MachineCode already exists (in the DB or earlier in the same batch) are skipped, and rows
|
||||
/// referencing an unknown UNS line are reported as errors. (v3: equipment no longer binds a driver, so
|
||||
/// the old DriverInstanceId column and its decision-#122 cluster guard — and their tests — are gone.)
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class UnsTreeServiceImportTests
|
||||
@@ -20,32 +20,17 @@ public sealed class UnsTreeServiceImportTests
|
||||
return (new UnsTreeService(UnsTreeTestDb.Factory(dbName)), dbName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seeds a line under an area in <paramref name="lineCluster"/>, plus an optional driver in
|
||||
/// <paramref name="driverCluster"/>. The line id is always <c>LINE-1</c>; the driver (when
|
||||
/// requested) is always <c>DRV-1</c>.
|
||||
/// </summary>
|
||||
private static void SeedLineAndDriver(string dbName, string lineCluster, string? driverCluster)
|
||||
/// <summary>Seeds an area → line (id <c>LINE-1</c>) under <paramref name="cluster"/>.</summary>
|
||||
private static void SeedLine(string dbName, string cluster)
|
||||
{
|
||||
using var db = UnsTreeTestDb.CreateNamed(dbName);
|
||||
db.UnsAreas.Add(new UnsArea { UnsAreaId = "AREA-1", ClusterId = lineCluster, Name = "a" });
|
||||
db.UnsAreas.Add(new UnsArea { UnsAreaId = "AREA-1", ClusterId = cluster, Name = "a" });
|
||||
db.UnsLines.Add(new UnsLine { UnsLineId = "LINE-1", UnsAreaId = "AREA-1", Name = "l" });
|
||||
if (driverCluster is not null)
|
||||
{
|
||||
db.DriverInstances.Add(new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "DRV-1",
|
||||
ClusterId = driverCluster,
|
||||
Name = "drv",
|
||||
DriverType = "Modbus",
|
||||
DriverConfig = "{}",
|
||||
});
|
||||
}
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
private static EquipmentInput Input(string name, string machineCode, string unsLineId, string? driverInstanceId) =>
|
||||
new(name, machineCode, unsLineId, driverInstanceId,
|
||||
private static EquipmentInput Input(string name, string machineCode, string unsLineId) =>
|
||||
new(name, machineCode, unsLineId,
|
||||
ZTag: null, SAPID: null, Manufacturer: null, Model: null, SerialNumber: null,
|
||||
HardwareRevision: null, SoftwareRevision: null, YearOfConstruction: null,
|
||||
AssetLocation: null, ManufacturerUri: null, DeviceManualUri: null, Enabled: true);
|
||||
@@ -55,12 +40,12 @@ public sealed class UnsTreeServiceImportTests
|
||||
public async Task Import_inserts_valid_rows()
|
||||
{
|
||||
var (service, dbName) = Fresh();
|
||||
SeedLineAndDriver(dbName, lineCluster: "MAIN", driverCluster: null);
|
||||
SeedLine(dbName, "MAIN");
|
||||
|
||||
var result = await service.ImportEquipmentAsync(
|
||||
[
|
||||
Input("machine-1", "mc_1", "LINE-1", null),
|
||||
Input("machine-2", "mc_2", "LINE-1", null),
|
||||
Input("machine-1", "mc_1", "LINE-1"),
|
||||
Input("machine-2", "mc_2", "LINE-1"),
|
||||
]);
|
||||
|
||||
result.Inserted.ShouldBe(2);
|
||||
@@ -85,15 +70,15 @@ public sealed class UnsTreeServiceImportTests
|
||||
public async Task Import_skips_duplicate_machinecode()
|
||||
{
|
||||
var (service, dbName) = Fresh();
|
||||
SeedLineAndDriver(dbName, lineCluster: "MAIN", driverCluster: null);
|
||||
SeedLine(dbName, "MAIN");
|
||||
// Pre-existing equipment with MachineCode "mc_existing".
|
||||
await service.CreateEquipmentAsync(Input("machine-x", "mc_existing", "LINE-1", null));
|
||||
await service.CreateEquipmentAsync(Input("machine-x", "mc_existing", "LINE-1"));
|
||||
|
||||
var result = await service.ImportEquipmentAsync(
|
||||
[
|
||||
Input("machine-1", "mc_existing", "LINE-1", null), // dup of DB row → skip
|
||||
Input("machine-2", "mc_new", "LINE-1", null), // inserts
|
||||
Input("machine-3", "mc_new", "LINE-1", null), // dup of in-batch row → skip
|
||||
Input("machine-1", "mc_existing", "LINE-1"), // dup of DB row → skip
|
||||
Input("machine-2", "mc_new", "LINE-1"), // inserts
|
||||
Input("machine-3", "mc_new", "LINE-1"), // dup of in-batch row → skip
|
||||
]);
|
||||
|
||||
result.Inserted.ShouldBe(1);
|
||||
@@ -110,12 +95,12 @@ public sealed class UnsTreeServiceImportTests
|
||||
public async Task Import_reports_unknown_line()
|
||||
{
|
||||
var (service, dbName) = Fresh();
|
||||
SeedLineAndDriver(dbName, lineCluster: "MAIN", driverCluster: null);
|
||||
SeedLine(dbName, "MAIN");
|
||||
|
||||
var result = await service.ImportEquipmentAsync(
|
||||
[
|
||||
Input("machine-1", "mc_1", "LINE-BOGUS", null),
|
||||
Input("machine-2", "mc_2", "LINE-1", null),
|
||||
Input("machine-1", "mc_1", "LINE-BOGUS"),
|
||||
Input("machine-2", "mc_2", "LINE-1"),
|
||||
]);
|
||||
|
||||
result.Inserted.ShouldBe(1);
|
||||
@@ -128,73 +113,4 @@ public sealed class UnsTreeServiceImportTests
|
||||
db.Equipment.Any(e => e.MachineCode == "mc_1").ShouldBeFalse();
|
||||
db.Equipment.Any(e => e.MachineCode == "mc_2").ShouldBeTrue();
|
||||
}
|
||||
|
||||
/// <summary>A driver-bound row whose DriverInstanceId does not resolve is reported as an error.</summary>
|
||||
[Fact]
|
||||
public async Task Import_reports_unknown_driver()
|
||||
{
|
||||
var (service, dbName) = Fresh();
|
||||
SeedLineAndDriver(dbName, lineCluster: "MAIN", driverCluster: null); // no driver seeded
|
||||
|
||||
var result = await service.ImportEquipmentAsync(
|
||||
[
|
||||
Input("machine-1", "mc_1", "LINE-1", "DRV-GHOST"),
|
||||
]);
|
||||
|
||||
result.Inserted.ShouldBe(0);
|
||||
result.Skipped.ShouldBe(0);
|
||||
result.Errors.Count.ShouldBe(1);
|
||||
result.Errors[0].ShouldContain("mc_1");
|
||||
result.Errors[0].ShouldContain("DRV-GHOST");
|
||||
result.Errors[0].ShouldContain("not found");
|
||||
|
||||
using var db = UnsTreeTestDb.CreateNamed(dbName);
|
||||
db.Equipment.Any(e => e.MachineCode == "mc_1").ShouldBeFalse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The decision-#122 guard rejects a row that binds a driver living in a different cluster than
|
||||
/// the row's UNS line.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Import_enforces_122_cluster()
|
||||
{
|
||||
var (service, dbName) = Fresh();
|
||||
SeedLineAndDriver(dbName, lineCluster: "MAIN", driverCluster: "SITE-A");
|
||||
|
||||
var result = await service.ImportEquipmentAsync(
|
||||
[
|
||||
Input("machine-1", "mc_1", "LINE-1", "DRV-1"),
|
||||
]);
|
||||
|
||||
result.Inserted.ShouldBe(0);
|
||||
result.Skipped.ShouldBe(0);
|
||||
result.Errors.Count.ShouldBe(1);
|
||||
result.Errors[0].ShouldContain("mc_1");
|
||||
result.Errors[0].ShouldContain("decision #122");
|
||||
|
||||
using var db = UnsTreeTestDb.CreateNamed(dbName);
|
||||
db.Equipment.Any(e => e.MachineCode == "mc_1").ShouldBeFalse();
|
||||
}
|
||||
|
||||
/// <summary>A driver in the same cluster as the line imports cleanly.</summary>
|
||||
[Fact]
|
||||
public async Task Import_allows_driver_in_same_cluster()
|
||||
{
|
||||
var (service, dbName) = Fresh();
|
||||
SeedLineAndDriver(dbName, lineCluster: "MAIN", driverCluster: "MAIN");
|
||||
|
||||
var result = await service.ImportEquipmentAsync(
|
||||
[
|
||||
Input("machine-1", "mc_1", "LINE-1", "DRV-1"),
|
||||
]);
|
||||
|
||||
result.Inserted.ShouldBe(1);
|
||||
result.Skipped.ShouldBe(0);
|
||||
result.Errors.ShouldBeEmpty();
|
||||
|
||||
// v3: the driver passes the #122 guard but is not persisted (binding column retired).
|
||||
using var db = UnsTreeTestDb.CreateNamed(dbName);
|
||||
db.Equipment.Single(e => e.MachineCode == "mc_1").UnsLineId.ShouldBe("LINE-1");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user