fix(scripteditor): complete + hover absolute RawPaths (#490)
The issue reports a missing feature. The cause is a stale projection, and the
consequence was worse than the gap described.
`ScriptTagCatalog` still emitted `Tag.TagConfig.FullName` — the pre-v3 driver wire
address. Since v3 the mux key is the **RawPath**: `AddressSpaceComposer` harvests the
`ctx.GetTag("…")` literals into `DependencyRefs`, those become `VirtualTagActor`
dependency refs registered with `DependencyMuxActor`, whose `_byRef` is keyed Ordinal
by `AttributeValuePublished.FullReference` — and a driver's wire ref IS the RawPath
(`DriverHostActor._nodeIdByDriverRef` is keyed `(DriverInstanceId, RawPath)`). The
`{{equip}}/<RefName>` form already substitutes to RawPaths at both compose seams.
So the catalog was wrong in BOTH directions, not merely incomplete: completion
offered paths that could never resolve at runtime, while a CORRECT absolute RawPath
got no completion and hovered as "not a known configured tag path". The file's own
comment admitted the raw/UNS catalog was left for "Batch 2/3" and it never came.
Now projected through the shared `RawPathResolver` — the same byte-parity authority
`DraftValidator` and `AddressSpaceComposer` use — so a suggested path is identical to
the one the deploy gate and the runtime compute. A tag with a broken ancestry chain
resolves to null and is omitted: the runtime could not route it either, so offering
it would be a lie. Hover additionally gains the owning `DriverInstanceId`, which the
topology now makes available (it was always null before).
Editor-accepts <=> publish-accepts is preserved: no diagnostic keys off this catalog
(`OTSCRIPT_EQUIPREF` only marks `{{equip}}` paths), so this changes completion and
hover only — it cannot newly reject a script.
The existing tests pinned the v2 contract and were re-authored: a RawPath only exists
if the RawFolder -> DriverInstance -> Device -> TagGroup -> Tag chain does, so the
seed now builds one. Added coverage for group-nested paths, a driver at the cluster
root (no folder segment), a broken chain being omitted rather than guessed, and the
pre-v3 FullName no longer resolving.
Live-gated on docker-dev (rig rebuilt, both central nodes):
- completion, empty literal -> every RawPath incl. group-nested
`opcua1/plc/OpcPlc/Telemetry/Basic/AlternatingBoolean`
- completion, prefix `pymod` -> `pymodbus/plc/HR200X`, `pymodbus/plc/ImportedTag`
- hover `pymodbus/plc/HR200X` -> "Tag · Type UInt16 · Driver MAIN-modbus"
- hover an unknown path -> "Not a known configured tag path"
AdminUI 742/742; script-analysis 55/55; solution builds 0 errors.
This commit is contained in:
+128
-77
@@ -13,14 +13,21 @@ namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.ScriptAnalysis;
|
||||
/// pass to <c>ctx.GetTag("…")</c> / <c>ctx.SetVirtualTag("…")</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Fidelity finding (see <see cref="ScriptTagCatalog"/> doc comment): the runtime Akka path resolves
|
||||
/// a <c>ctx.GetTag</c> literal against the driver <b>FullName</b> (the wire reference in
|
||||
/// <c>Tag.TagConfig.FullName</c>), NOT the UNS browse path — the UNS-path engine is dormant. v3: Tag is
|
||||
/// Raw-only (no <c>EquipmentId</c>/<c>FolderPath</c>/<c>DriverInstanceId</c>), so the catalog projects
|
||||
/// the surviving <c>Name</c>/<c>DataType</c>/<c>TagConfig</c> columns: the resolvable path derives from
|
||||
/// the <c>TagConfig.FullName</c> field when present, else the tag <c>Name</c>; the projected
|
||||
/// <c>DriverInstanceId</c> is always <see langword="null"/>. Virtual tags emit their leaf Name. These
|
||||
/// assertions check the resolvable key is present AND that the UNS browse paths are absent.
|
||||
/// <para>
|
||||
/// Fidelity finding (see the <see cref="ScriptTagCatalog"/> doc comment): the runtime resolves a
|
||||
/// <c>ctx.GetTag</c> literal through <c>DependencyMuxActor._byRef</c>, keyed Ordinal by the driver's
|
||||
/// wire reference — and in v3 that wire reference <b>is the RawPath</b>
|
||||
/// (<c>Folder/…/Driver/Device/[TagGroup/…]/Tag</c>). So the catalog projects RawPaths for raw tags and
|
||||
/// the leaf <c>Name</c> for virtual tags.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// These assertions were rewritten for #490. They previously pinned the pre-v3 projection —
|
||||
/// <c>Tag.TagConfig.FullName</c> — which since v3 is not the mux key at all, so they were encoding a
|
||||
/// contract the runtime had stopped honouring: completion offered paths that could never resolve, and a
|
||||
/// correct absolute RawPath resolved to nothing. The seed now builds a real raw topology
|
||||
/// (RawFolder → DriverInstance → Device → TagGroup → Tag) because a RawPath only exists if that chain
|
||||
/// does.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class ScriptTagCatalogTests
|
||||
@@ -43,8 +50,9 @@ public sealed class ScriptTagCatalogTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seeds an Area → Line → Equipment path with: one equipment driver tag (FullName "Motor.Speed"),
|
||||
/// one virtual tag, and one FolderPath-scoped tag (EquipmentId null, FolderPath set).
|
||||
/// Seeds the UNS path (Area → Line → Equipment) AND the raw topology a RawPath is built from:
|
||||
/// RawFolder "Plant" → DriverInstance "Modbus" → Device "dev1", with one tag directly under the
|
||||
/// device and one under a nested TagGroup. A virtual tag is added for the leaf-Name projection.
|
||||
/// </summary>
|
||||
private static void Seed(DbContextOptions<OtOpcUaConfigDbContext> opts)
|
||||
{
|
||||
@@ -61,26 +69,38 @@ public sealed class ScriptTagCatalogTests
|
||||
MachineCode = "machine_001",
|
||||
});
|
||||
|
||||
// Raw tag — the GetTag key is the driver FullName from TagConfig.
|
||||
// Raw topology — the ancestry a RawPath is composed from.
|
||||
db.RawFolders.Add(new RawFolder { RawFolderId = "RF-1", ClusterId = "MAIN", ParentRawFolderId = null, Name = "Plant" });
|
||||
db.DriverInstances.Add(new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "DRV-1", ClusterId = "MAIN", RawFolderId = "RF-1",
|
||||
Name = "Modbus", DriverType = "Modbus", DriverConfig = "{}",
|
||||
});
|
||||
db.Devices.Add(new Device { DeviceId = "DEV-1", DriverInstanceId = "DRV-1", Name = "dev1", DeviceConfig = "{}" });
|
||||
db.TagGroups.Add(new TagGroup { TagGroupId = "TG-1", DeviceId = "DEV-1", ParentTagGroupId = null, Name = "Motors" });
|
||||
|
||||
// Directly under the device -> Plant/Modbus/dev1/Speed
|
||||
db.Tags.Add(new Tag
|
||||
{
|
||||
TagId = "TAG-EQ",
|
||||
DeviceId = "DEV-1",
|
||||
TagGroupId = null,
|
||||
Name = "Speed",
|
||||
DataType = "Float",
|
||||
AccessLevel = TagAccessLevel.Read,
|
||||
TagConfig = "{\"FullName\":\"Motor.Speed\"}",
|
||||
});
|
||||
|
||||
// Raw tag whose FullName is an MXAccess dot-ref; resolves by that FullName.
|
||||
// Under a tag group -> Plant/Modbus/dev1/Motors/Torque
|
||||
db.Tags.Add(new Tag
|
||||
{
|
||||
TagId = "TAG-SP",
|
||||
TagId = "TAG-GRP",
|
||||
DeviceId = "DEV-1",
|
||||
Name = "DownloadPath",
|
||||
DataType = "String",
|
||||
TagGroupId = "TG-1",
|
||||
Name = "Torque",
|
||||
DataType = "Double",
|
||||
AccessLevel = TagAccessLevel.Read,
|
||||
TagConfig = "{\"FullName\":\"DelmiaReceiver_001.DownloadPath\"}",
|
||||
TagConfig = "{\"FullName\":\"Motor.Torque\"}",
|
||||
});
|
||||
|
||||
db.VirtualTags.Add(new VirtualTag
|
||||
@@ -95,30 +115,27 @@ public sealed class ScriptTagCatalogTests
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>A null filter returns only the resolvable keys: the driver FullName for the equipment
|
||||
/// tag, the MXAccess dot-ref for the FolderPath-scoped tag, and the virtual tag's leaf Name — and
|
||||
/// NONE of the UNS browse paths.</summary>
|
||||
/// <summary>The v3 resolvable keys: a RawPath per raw tag (device-level and group-nested), plus the
|
||||
/// virtual tag's leaf Name — and NOT the pre-v3 <c>TagConfig.FullName</c>, which is no longer the mux
|
||||
/// key and would suggest a path that cannot resolve at runtime (#490).</summary>
|
||||
[Fact]
|
||||
public async Task GetPaths_no_filter_returns_resolvable_keys_only()
|
||||
public async Task GetPaths_no_filter_returns_rawpaths_only()
|
||||
{
|
||||
var (catalog, opts) = Fresh();
|
||||
Seed(opts);
|
||||
|
||||
var paths = await catalog.GetPathsAsync(null, default);
|
||||
|
||||
// Equipment driver tag: the authoritative GetTag key (driver FullName).
|
||||
paths.ShouldContain("Motor.Speed");
|
||||
paths.ShouldContain("Plant/Modbus/dev1/Speed"); // directly under the device
|
||||
paths.ShouldContain("Plant/Modbus/dev1/Motors/Torque"); // nested under a tag group
|
||||
paths.ShouldContain("Computed"); // virtual tag: leaf Name
|
||||
|
||||
// FolderPath-scoped tag: MXAccess dot-ref.
|
||||
paths.ShouldContain("DelmiaReceiver_001.DownloadPath");
|
||||
// The pre-v3 wire address is NOT a resolvable key in v3.
|
||||
paths.ShouldNotContain("Motor.Speed");
|
||||
paths.ShouldNotContain("Motor.Torque");
|
||||
|
||||
// Virtual tag: leaf Name only.
|
||||
paths.ShouldContain("Computed");
|
||||
|
||||
// The UNS browse paths are intentionally NOT suggested (the UNS-path engine is dormant).
|
||||
// UNS browse paths are intentionally NOT suggested (that engine is dormant).
|
||||
paths.ShouldNotContain("Assembly/LineA/Machine1/Speed");
|
||||
paths.ShouldNotContain("DelmiaReceiver_001/DownloadPath");
|
||||
paths.ShouldNotContain("Assembly/LineA/Machine1/Computed");
|
||||
}
|
||||
|
||||
/// <summary>The result is distinct.</summary>
|
||||
@@ -133,37 +150,66 @@ public sealed class ScriptTagCatalogTests
|
||||
paths.Distinct(StringComparer.OrdinalIgnoreCase).Count().ShouldBe(paths.Count);
|
||||
}
|
||||
|
||||
/// <summary>A literal prefix narrows the result (case-insensitive StartsWith) to matching keys.</summary>
|
||||
/// <summary>A literal prefix narrows the result (case-insensitive StartsWith). This is the completion
|
||||
/// path an author actually hits: typing a partial absolute RawPath inside ctx.GetTag("…").</summary>
|
||||
[Fact]
|
||||
public async Task GetPaths_prefix_filter_narrows()
|
||||
public async Task GetPaths_prefix_filter_narrows_on_a_partial_rawpath()
|
||||
{
|
||||
var (catalog, opts) = Fresh();
|
||||
Seed(opts);
|
||||
|
||||
var paths = await catalog.GetPathsAsync("Motor", default);
|
||||
var paths = await catalog.GetPathsAsync("Plant/Modbus/dev1/", default);
|
||||
|
||||
paths.ShouldContain("Motor.Speed");
|
||||
paths.ShouldNotContain("DelmiaReceiver_001.DownloadPath");
|
||||
paths.ShouldContain("Plant/Modbus/dev1/Speed");
|
||||
paths.ShouldContain("Plant/Modbus/dev1/Motors/Torque");
|
||||
paths.ShouldNotContain("Computed");
|
||||
paths.ShouldAllBe(p => p.StartsWith("Motor", StringComparison.OrdinalIgnoreCase));
|
||||
paths.ShouldAllBe(p => p.StartsWith("Plant/Modbus/dev1/", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>The prefix match is case-insensitive.</summary>
|
||||
/// <summary>The prefix match is case-insensitive (completion is forgiving; the exact lookup is not).</summary>
|
||||
[Fact]
|
||||
public async Task GetPaths_prefix_filter_is_case_insensitive()
|
||||
{
|
||||
var (catalog, opts) = Fresh();
|
||||
Seed(opts);
|
||||
|
||||
var paths = await catalog.GetPathsAsync("motor", default);
|
||||
|
||||
paths.ShouldContain("Motor.Speed");
|
||||
(await catalog.GetPathsAsync("plant/modbus", default)).ShouldContain("Plant/Modbus/dev1/Speed");
|
||||
}
|
||||
|
||||
/// <summary>A tag whose <c>TagConfig</c> is malformed JSON must not throw — the catalog falls back
|
||||
/// to the raw blob and still returns every other tag.</summary>
|
||||
/// <summary>A tag whose ancestry chain is broken (device row missing) has no RawPath. The runtime could
|
||||
/// not route it either, so it is omitted rather than guessed — and it must not throw or suppress the
|
||||
/// tags that DO resolve.</summary>
|
||||
[Fact]
|
||||
public async Task GetPaths_malformed_tagconfig_does_not_throw()
|
||||
public async Task GetPaths_tag_with_a_broken_ancestry_chain_is_omitted()
|
||||
{
|
||||
var (catalog, opts) = Fresh();
|
||||
Seed(opts);
|
||||
|
||||
using (var db = new OtOpcUaConfigDbContext(opts))
|
||||
{
|
||||
db.Tags.Add(new Tag
|
||||
{
|
||||
TagId = "TAG-ORPHAN",
|
||||
DeviceId = "DEV-DOES-NOT-EXIST",
|
||||
Name = "Orphan",
|
||||
DataType = "Float",
|
||||
AccessLevel = TagAccessLevel.Read,
|
||||
TagConfig = "{}",
|
||||
});
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
IReadOnlyList<string> paths = [];
|
||||
await Should.NotThrowAsync(async () => paths = await catalog.GetPathsAsync(null, default));
|
||||
|
||||
paths.ShouldNotContain("Orphan");
|
||||
paths.ShouldContain("Plant/Modbus/dev1/Speed");
|
||||
}
|
||||
|
||||
/// <summary>A malformed <c>TagConfig</c> is irrelevant to the RawPath (which comes from the topology,
|
||||
/// not the blob) — it must neither throw nor drop the tag.</summary>
|
||||
[Fact]
|
||||
public async Task GetPaths_malformed_tagconfig_does_not_affect_the_rawpath()
|
||||
{
|
||||
var (catalog, opts) = Fresh();
|
||||
Seed(opts);
|
||||
@@ -185,37 +231,33 @@ public sealed class ScriptTagCatalogTests
|
||||
IReadOnlyList<string> paths = [];
|
||||
await Should.NotThrowAsync(async () => paths = await catalog.GetPathsAsync(null, default));
|
||||
|
||||
// The malformed tag falls through to the raw blob (acceptable), and the other tags still appear.
|
||||
paths.ShouldContain("Motor.Speed");
|
||||
paths.ShouldContain("DelmiaReceiver_001.DownloadPath");
|
||||
paths.ShouldContain("Computed");
|
||||
paths.ShouldContain("Plant/Modbus/dev1/Broken");
|
||||
paths.ShouldContain("Plant/Modbus/dev1/Speed");
|
||||
}
|
||||
|
||||
/// <summary>A FolderPath-scoped tag with a null/empty <c>FolderPath</c> yields just its <c>Name</c>
|
||||
/// (no leading dot).</summary>
|
||||
/// <summary>A driver at the cluster root (no RawFolder) contributes no folder segment.</summary>
|
||||
[Fact]
|
||||
public async Task GetPaths_unbound_tag_without_folder_yields_name_only()
|
||||
public async Task GetPaths_driver_at_cluster_root_has_no_folder_segment()
|
||||
{
|
||||
var (catalog, opts) = Fresh();
|
||||
|
||||
using (var db = new OtOpcUaConfigDbContext(opts))
|
||||
{
|
||||
db.DriverInstances.Add(new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "DRV-ROOT", ClusterId = "MAIN", RawFolderId = null,
|
||||
Name = "RootDrv", DriverType = "Modbus", DriverConfig = "{}",
|
||||
});
|
||||
db.Devices.Add(new Device { DeviceId = "DEV-ROOT", DriverInstanceId = "DRV-ROOT", Name = "d0", DeviceConfig = "{}" });
|
||||
db.Tags.Add(new Tag
|
||||
{
|
||||
TagId = "TAG-SP-ROOT",
|
||||
DeviceId = "DEV-1",
|
||||
Name = "RootScalar",
|
||||
DataType = "String",
|
||||
AccessLevel = TagAccessLevel.Read,
|
||||
TagConfig = "{\"FullName\":\"RootScalar\"}",
|
||||
TagId = "TAG-ROOT", DeviceId = "DEV-ROOT", Name = "Scalar",
|
||||
DataType = "String", AccessLevel = TagAccessLevel.Read, TagConfig = "{}",
|
||||
});
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
var paths = await catalog.GetPathsAsync(null, default);
|
||||
|
||||
paths.ShouldContain("RootScalar");
|
||||
paths.ShouldNotContain(".RootScalar");
|
||||
(await catalog.GetPathsAsync(null, default)).ShouldContain("RootDrv/d0/Scalar");
|
||||
}
|
||||
|
||||
/// <summary>An empty database yields an empty list rather than throwing.</summary>
|
||||
@@ -224,26 +266,24 @@ public sealed class ScriptTagCatalogTests
|
||||
{
|
||||
var (catalog, _) = Fresh();
|
||||
|
||||
var paths = await catalog.GetPathsAsync(null, default);
|
||||
|
||||
paths.ShouldBeEmpty();
|
||||
(await catalog.GetPathsAsync(null, default)).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>A raw tag whose FullName is a dot-ref resolves by that FullName to a Tag-kind info with
|
||||
/// the configured DataType. v3: Tag no longer binds a driver, so the projected DriverInstanceId is null.</summary>
|
||||
/// <summary>Hover: an absolute RawPath resolves to Tag-kind info carrying the configured DataType and —
|
||||
/// new in #490 — the owning driver instance, which the topology now makes available.</summary>
|
||||
[Fact]
|
||||
public async Task GetTagInfo_unbound_tag_returns_tag_info()
|
||||
public async Task GetTagInfo_absolute_rawpath_returns_tag_info_with_driver()
|
||||
{
|
||||
var (catalog, opts) = Fresh();
|
||||
Seed(opts);
|
||||
|
||||
var info = await catalog.GetTagInfoAsync("DelmiaReceiver_001.DownloadPath", default);
|
||||
var info = await catalog.GetTagInfoAsync("Plant/Modbus/dev1/Motors/Torque", default);
|
||||
|
||||
info.ShouldNotBeNull();
|
||||
info!.Path.ShouldBe("DelmiaReceiver_001.DownloadPath");
|
||||
info!.Path.ShouldBe("Plant/Modbus/dev1/Motors/Torque");
|
||||
info.Kind.ShouldBe("Tag");
|
||||
info.DataType.ShouldBe("String");
|
||||
info.DriverInstanceId.ShouldBeNull();
|
||||
info.DataType.ShouldBe("Double");
|
||||
info.DriverInstanceId.ShouldBe("DRV-1");
|
||||
}
|
||||
|
||||
/// <summary>A virtual tag resolves by its leaf Name to a "Virtual tag"-kind info with no driver.</summary>
|
||||
@@ -256,12 +296,22 @@ public sealed class ScriptTagCatalogTests
|
||||
var info = await catalog.GetTagInfoAsync("Computed", default);
|
||||
|
||||
info.ShouldNotBeNull();
|
||||
info!.Path.ShouldBe("Computed");
|
||||
info.Kind.ShouldBe("Virtual tag");
|
||||
info!.Kind.ShouldBe("Virtual tag");
|
||||
info.DataType.ShouldBe("Double");
|
||||
info.DriverInstanceId.ShouldBeNull();
|
||||
}
|
||||
|
||||
/// <summary>The pre-v3 wire address no longer resolves — the regression #490 is really about. Hovering
|
||||
/// one must report "not a known path" rather than validating a string the runtime would drop.</summary>
|
||||
[Fact]
|
||||
public async Task GetTagInfo_pre_v3_fullname_no_longer_resolves()
|
||||
{
|
||||
var (catalog, opts) = Fresh();
|
||||
Seed(opts);
|
||||
|
||||
(await catalog.GetTagInfoAsync("Motor.Speed", default)).ShouldBeNull();
|
||||
}
|
||||
|
||||
/// <summary>An unknown path resolves to null.</summary>
|
||||
[Fact]
|
||||
public async Task GetTagInfo_unknown_path_returns_null()
|
||||
@@ -269,19 +319,20 @@ public sealed class ScriptTagCatalogTests
|
||||
var (catalog, opts) = Fresh();
|
||||
Seed(opts);
|
||||
|
||||
(await catalog.GetTagInfoAsync("NoSuchPath", default)).ShouldBeNull();
|
||||
(await catalog.GetTagInfoAsync("Plant/Modbus/dev1/NoSuchTag", default)).ShouldBeNull();
|
||||
}
|
||||
|
||||
/// <summary>The lookup is case-SENSITIVE (Ordinal): a path that differs only in case does NOT
|
||||
/// resolve, mirroring the runtime DependencyMuxActor's StringComparer.Ordinal keying.</summary>
|
||||
/// <summary>The lookup is case-SENSITIVE (Ordinal), mirroring the runtime DependencyMuxActor's
|
||||
/// StringComparer.Ordinal keying — a case-mismatched path would not resolve live, so hover must not
|
||||
/// claim it does.</summary>
|
||||
[Fact]
|
||||
public async Task GetTagInfo_case_mismatch_returns_null_ordinal()
|
||||
{
|
||||
var (catalog, opts) = Fresh();
|
||||
Seed(opts);
|
||||
|
||||
(await catalog.GetTagInfoAsync("motor.speed", default)).ShouldBeNull();
|
||||
(await catalog.GetTagInfoAsync("Motor.Speed", default)).ShouldNotBeNull();
|
||||
(await catalog.GetTagInfoAsync("plant/modbus/dev1/speed", default)).ShouldBeNull();
|
||||
(await catalog.GetTagInfoAsync("Plant/Modbus/dev1/Speed", default)).ShouldNotBeNull();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user