fix(historian): read-only historian bindings + ProvisionTags policy; provision OPC UA type names (#899, #898)
v2-ci / unit-tests (push) Has been cancelled
v2-ci / unit-tests (push) Has been cancelled
#899 — EnsureTags is an upsert, so binding a node to an existing AVEVA tag via historianTagname re-typed/re-described it on every add and host start. - TagConfig `historianReadOnly: true` (TagConfigIntent -> RawTagPlan.HistorianReadOnly): HistoryRead from an existing historian tag that OtOpcUa never provisions and never records into (AddressSpaceApplier.IsOwnedHistorizedValue gates both the EnsureTags hook and the recorder feed). Node-inert: surgical, not mirrored on UNS refs, in the RawTagPlan equality/hash. A non-bool value is the deploy error HistorianReadOnlyInvalid. AdminUI: CSV column HistorianReadOnly (strict), TagHistorizeConfig reads via the runtime parse. - ServerHistorian:ProvisionTags = CreateOrUpdate (default, unchanged) | CreateOnly (Gateway only: TagExistsAsync first, existing tags left alone, failed lookup not sent) | Off. Unknown value / CreateOnly on a SQL backend fail host start. - Default for an explicit historianTagname stays OWNED: overrides pin owned history across renames, a read-only default would silently stop provisioning + recording. #898 — the hook parsed Tag.DataType (an OPC UA name) as DriverDataType, so historized Float/Double/Byte/SByte tags were never provisioned. New shared HistorianDataTypeNames.TryResolve: Float->Float32, Double->Float64, Byte/SByte->Int16 (lossless, provisioned as Int2); unmapped names logged at Information. Gateway now skips Int64/UInt64 (HistorianGateway cannot create Int8/UInt8: lossless-cast-or-reject). UPGRADE: the first host start after this provisions (upserts) every existing historized Float/Double/Byte/SByte tag. Mark foreign-tag bindings historianReadOnly, or set ServerHistorian:ProvisionTags=CreateOnly/Off, before upgrading (docs/Historian.md). Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -68,6 +68,43 @@ public sealed class RawTagCsvRoundTripTests
|
||||
AssertRoundTrip(DriverTypeNames.Galaxy, new[] { galaxy });
|
||||
}
|
||||
|
||||
/// <summary>lmxopcua#899: the HistorianReadOnly column round-trips a read-only binding, and an exported row carries
|
||||
/// it in its own column, never in the TagConfigJson residual.</summary>
|
||||
[Fact]
|
||||
public void Historian_read_only_binding_round_trips_through_its_own_column()
|
||||
{
|
||||
var ro = new RawCsvExportTag(
|
||||
null, "systime", "Int32", TagAccessLevel.Read, false, null,
|
||||
"""{"FullName":"Reactor_001.Temp","isHistorized":true,"historianTagname":"SysTimeSec","historianReadOnly":true}""");
|
||||
|
||||
AssertRoundTrip(DriverTypeNames.Galaxy, new[] { ro });
|
||||
|
||||
var csv = RawTagCsvMapper.Export(DriverTypeNames.Galaxy, new[] { ro });
|
||||
var rows = CsvParser.Parse(csv);
|
||||
var header = rows[0].ToList();
|
||||
var row = rows[1];
|
||||
row[header.IndexOf("HistorianReadOnly")].ShouldBe("true");
|
||||
row[header.IndexOf(CsvColumnMap.TagConfigJsonColumn)].ShouldNotContain("historianReadOnly");
|
||||
}
|
||||
|
||||
/// <summary>lmxopcua#899: the column imports strictly — "true" sets the key, blank leaves an owned tag, and a
|
||||
/// non-boolean cell is a row error rather than a silently owned tag.</summary>
|
||||
[Theory]
|
||||
[InlineData("true", true, true)]
|
||||
[InlineData("", true, false)]
|
||||
[InlineData("maybe", false, false)]
|
||||
public void HistorianReadOnly_column_imports_strictly(string cell, bool valid, bool readOnly)
|
||||
{
|
||||
var csv = "Name,DataType,AccessLevel,IsHistorized,HistorianTagname,HistorianReadOnly,TagConfigJson\n"
|
||||
+ $"t1,Int32,Read,true,SysTimeSec,{cell},\"{{\"\"FullName\"\":\"\"A.B\"\"}}\"\n";
|
||||
|
||||
var result = RawTagCsvMapper.Parse(DriverTypeNames.Galaxy, csv);
|
||||
|
||||
var reviewRow = result.Rows.ShouldHaveSingleItem();
|
||||
reviewRow.Ok.ShouldBe(valid);
|
||||
if (valid) TagHistorizeConfig.Read(reviewRow.ImportRow!.Tag.TagConfig).HistorianReadOnly.ShouldBe(readOnly);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Variable_length_array_round_trips_lmxopcua_770()
|
||||
{
|
||||
|
||||
@@ -143,4 +143,30 @@ public sealed class TagHistorizeConfigTests
|
||||
h.HistorianTagname.ShouldBe("TN");
|
||||
OpcUaClientTagConfigModel.FromJson(afterEditor).NodeId.ShouldBe("ns=2;s=X");
|
||||
}
|
||||
|
||||
// ---- lmxopcua#899: historianReadOnly ----
|
||||
|
||||
[Fact]
|
||||
public void Set_writes_and_clears_historianReadOnly_and_Read_uses_the_runtime_parse()
|
||||
{
|
||||
var on = TagHistorizeConfig.Set("""{"a":1}""", isHistorized: true, historianTagname: "SysTimeSec", historianReadOnly: true);
|
||||
on.ShouldContain("\"historianReadOnly\":true");
|
||||
TagHistorizeConfig.Read(on).ShouldBe(new TagHistorizeConfig.HistorizeState(true, "SysTimeSec", true));
|
||||
|
||||
var off = TagHistorizeConfig.Set(on, isHistorized: true, historianTagname: "SysTimeSec", historianReadOnly: false);
|
||||
off.ShouldNotContain("historianReadOnly");
|
||||
off.ShouldContain("\"a\":1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Set_without_a_read_only_argument_preserves_the_existing_key()
|
||||
{
|
||||
var json = TagHistorizeConfig.Set("""{"historianReadOnly":true}""", isHistorized: true, historianTagname: null);
|
||||
TagHistorizeConfig.Read(json).HistorianReadOnly.ShouldBeTrue();
|
||||
}
|
||||
|
||||
/// <summary>A string "true" is what the runtime treats as NOT read-only; the AdminUI must say the same.</summary>
|
||||
[Fact]
|
||||
public void Read_reports_a_string_true_as_not_read_only_like_the_runtime()
|
||||
=> TagHistorizeConfig.Read("""{"isHistorized":true,"historianReadOnly":"true"}""").HistorianReadOnly.ShouldBeFalse();
|
||||
}
|
||||
|
||||
+37
@@ -460,4 +460,41 @@ public sealed class ServerHistorianOptionsValidatorTests
|
||||
result.Failed.ShouldBeTrue();
|
||||
result.Failures.ShouldContain(f => f.Contains("ServerHistorian:QuestDb:TablePrefix"));
|
||||
}
|
||||
|
||||
// ---- lmxopcua#899: ServerHistorian:ProvisionTags ----
|
||||
|
||||
/// <summary>An unknown policy fails, even when nothing consumes the section (like an unknown backend).</summary>
|
||||
[Fact]
|
||||
public void Unknown_ProvisionTags_policy_fails()
|
||||
{
|
||||
var result = Sut().Validate(null, new ServerHistorianOptions { ProvisionTags = "UpdateOnly" });
|
||||
|
||||
result.Failed.ShouldBeTrue();
|
||||
result.Failures.ShouldContain(f => f.Contains("ServerHistorian:ProvisionTags") && f.Contains("CreateOnly"));
|
||||
}
|
||||
|
||||
/// <summary>CreateOnly needs the Gateway's existence lookup; on an enabled SQL backend it fails host start.</summary>
|
||||
[Theory]
|
||||
[InlineData("SqlServer", true)]
|
||||
[InlineData("QuestDb", true)]
|
||||
[InlineData("Gateway", false)]
|
||||
public void CreateOnly_is_gateway_only(string backend, bool fails)
|
||||
{
|
||||
var result = Sut().Validate(null, new ServerHistorianOptions
|
||||
{
|
||||
Backend = backend, Enabled = true, ProvisionTags = "createonly",
|
||||
Endpoint = "https://host:5222", ApiKey = "histgw_x_y", UseTls = true,
|
||||
});
|
||||
|
||||
result.Failures?.Any(f => f.Contains("ProvisionTags=CreateOnly")).ShouldBe(fails);
|
||||
}
|
||||
|
||||
/// <summary>The policies parse case-insensitively; blank is the default.</summary>
|
||||
[Theory]
|
||||
[InlineData("CreateOrUpdate", HistorianProvisionPolicy.CreateOrUpdate)]
|
||||
[InlineData(" off ", HistorianProvisionPolicy.Off)]
|
||||
[InlineData("CREATEONLY", HistorianProvisionPolicy.CreateOnly)]
|
||||
[InlineData("", HistorianProvisionPolicy.CreateOrUpdate)]
|
||||
public void ProvisionTags_parses(string value, HistorianProvisionPolicy expected)
|
||||
=> new ServerHistorianOptions { ProvisionTags = value }.ProvisionPolicy.ShouldBe(expected);
|
||||
}
|
||||
|
||||
+108
-8
@@ -126,24 +126,88 @@ public sealed class AddressSpaceApplierProvisioningTests
|
||||
outcome.AddedNodes.ShouldBeGreaterThan(0);
|
||||
}
|
||||
|
||||
/// <summary>An added historized tag whose DataType string is not a <see cref="DriverDataType"/> is
|
||||
/// skipped (no request) — the hook never throws on an unparseable type.</summary>
|
||||
/// <summary>lmxopcua#898: Tag.DataType holds OPC UA built-in names (what the AdminUI writes). Float, Double, Byte and
|
||||
/// SByte used to fail <c>Enum.TryParse<DriverDataType></c> and were silently never provisioned; they now resolve
|
||||
/// (Float→Float32, Double→Float64, Byte/SByte→Int16, a lossless widening). The DriverDataType spelling still works,
|
||||
/// and a name with no historian mapping (Guid) is skipped without faulting the hook.</summary>
|
||||
[Fact]
|
||||
public async Task Apply_skips_added_tag_with_unparseable_datatype()
|
||||
public async Task Apply_provisions_opc_ua_type_names_and_skips_unmapped_ones()
|
||||
{
|
||||
var prov = new CapturingProvisioner();
|
||||
var applier = new AddressSpaceApplier(NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance, prov);
|
||||
|
||||
// "Float" is NOT a DriverDataType member (the members are Float32/Float64); it must be skipped.
|
||||
var plan = PlanWithAddedTags(
|
||||
HistorizedTag(displayName: "Bad", historianName: "Pump1.Bad", dataType: "Float"),
|
||||
HistorizedTag(displayName: "Good", historianName: "Pump1.Good", dataType: "Float32"));
|
||||
HistorizedTag(displayName: "F", historianName: "P.F", dataType: "Float"),
|
||||
HistorizedTag(displayName: "D", historianName: "P.D", dataType: "Double"),
|
||||
HistorizedTag(displayName: "B", historianName: "P.B", dataType: "Byte"),
|
||||
HistorizedTag(displayName: "S", historianName: "P.S", dataType: "SByte"),
|
||||
HistorizedTag(displayName: "F32", historianName: "P.F32", dataType: "Float32"),
|
||||
HistorizedTag(displayName: "G", historianName: "P.G", dataType: "Guid"));
|
||||
|
||||
applier.Apply(plan);
|
||||
|
||||
await prov.Called.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
||||
prov.Seen.Count.ShouldBe(1);
|
||||
prov.Seen[0].TagName.ShouldBe("Pump1.Good");
|
||||
prov.Seen.Select(r => (r.TagName, r.DataType)).ShouldBe(new[]
|
||||
{
|
||||
("P.F", DriverDataType.Float32),
|
||||
("P.D", DriverDataType.Float64),
|
||||
("P.B", DriverDataType.Int16),
|
||||
("P.S", DriverDataType.Int16),
|
||||
("P.F32", DriverDataType.Float32),
|
||||
}, ignoreOrder: true);
|
||||
}
|
||||
|
||||
/// <summary>lmxopcua#899: a read-only binding (<c>historianReadOnly: true</c>) never reaches EnsureTags — neither
|
||||
/// as an add nor as a change. The owned "Control" tag is the positive control, so the absence is not a vacuous
|
||||
/// no-dispatch; the override-without-the-flag tag shows the chosen default is unchanged (an override alone still
|
||||
/// provisions).</summary>
|
||||
[Fact]
|
||||
public async Task Apply_never_provisions_a_read_only_binding()
|
||||
{
|
||||
var prov = new CapturingProvisioner();
|
||||
var applier = new AddressSpaceApplier(NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance, prov);
|
||||
|
||||
var readOnlyAdded = HistorizedTag("SysTime", "SysTimeSec", "Int32", fullName: "Plant/SysTime") with { HistorianReadOnly = true };
|
||||
var flipToReadOnlyOld = HistorizedTag("Pulse", "SysPulse", "Boolean", fullName: "Plant/Pulse");
|
||||
var flipToReadOnlyNew = flipToReadOnlyOld with { HistorianReadOnly = true, DataType = "Int32" };
|
||||
var readOnlyRenamedOld = HistorizedTag("Ro", "Other.A", "Float", fullName: "Plant/Ro") with { HistorianReadOnly = true };
|
||||
var readOnlyRenamedNew = readOnlyRenamedOld with { HistorianTagname = "Other.B" };
|
||||
|
||||
var plan = PlanWithAddedTags(
|
||||
HistorizedTag("Control", "Control.Name", "Float"),
|
||||
HistorizedTag("Override", "Someones.Tag", "Double", fullName: "Plant/Override"),
|
||||
readOnlyAdded) with
|
||||
{
|
||||
ChangedRawTags = new[]
|
||||
{
|
||||
new AddressSpacePlan.RawTagDelta(flipToReadOnlyOld, flipToReadOnlyNew),
|
||||
new AddressSpacePlan.RawTagDelta(readOnlyRenamedOld, readOnlyRenamedNew),
|
||||
},
|
||||
};
|
||||
|
||||
applier.Apply(plan);
|
||||
|
||||
await prov.Called.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
||||
prov.Seen.Select(r => r.TagName).ShouldBe(new[] { "Control.Name", "Someones.Tag" }, ignoreOrder: true);
|
||||
}
|
||||
|
||||
/// <summary>lmxopcua#899: turning read-only OFF makes the tag owned, so it provisions like a historization flip.</summary>
|
||||
[Fact]
|
||||
public async Task Apply_provisions_a_tag_whose_read_only_flag_is_cleared()
|
||||
{
|
||||
var prov = new CapturingProvisioner();
|
||||
var applier = new AddressSpaceApplier(NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance, prov);
|
||||
|
||||
var before = HistorizedTag("Own", "Mine.Tag", "Float", fullName: "Plant/Own") with { HistorianReadOnly = true };
|
||||
var plan = PlanWithAddedTags() with
|
||||
{
|
||||
ChangedRawTags = new[] { new AddressSpacePlan.RawTagDelta(before, before with { HistorianReadOnly = false }) },
|
||||
};
|
||||
|
||||
applier.Apply(plan);
|
||||
|
||||
await prov.Called.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
||||
prov.Seen.Select(r => r.TagName).ShouldBe(new[] { "Mine.Tag" });
|
||||
}
|
||||
|
||||
/// <summary>#600.1: a CHANGED raw tag that flips to historized, or whose historian name / data type
|
||||
@@ -348,6 +412,42 @@ public sealed class AddressSpaceApplierProvisioningTests
|
||||
}, ignoreOrder: true);
|
||||
}
|
||||
|
||||
/// <summary>lmxopcua#899: a read-only binding is never fed to the recorder (its WriteLiveValues would write into a
|
||||
/// historian tag OtOpcUa does not own); flipping the flag on removes the ref, flipping it off adds it.</summary>
|
||||
[Fact]
|
||||
public void Apply_never_feeds_a_read_only_binding_to_the_recorder()
|
||||
{
|
||||
var sink = new CapturingSubscriptionSink();
|
||||
var applier = new AddressSpaceApplier(
|
||||
NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance,
|
||||
historizedSubscriptions: sink);
|
||||
|
||||
var owned = HistorizedTag("Own", "Mine.Tag", "Float", fullName: "Plant/Own");
|
||||
var readOnly = HistorizedTag("Ro", "SysTimeSec", "Int32", fullName: "Plant/Ro") with { HistorianReadOnly = true };
|
||||
var goingRo = HistorizedTag("ToRo", "X.Tag", "Float", fullName: "Plant/ToRo");
|
||||
var goingOwned = HistorizedTag("ToOwn", "Y.Tag", "Float", fullName: "Plant/ToOwn") with { HistorianReadOnly = true };
|
||||
var removedRo = HistorizedTag("Gone", "Z.Tag", "Float", fullName: "Plant/Gone") with { HistorianReadOnly = true };
|
||||
|
||||
var plan = PlanWithAddedTags(owned, readOnly) with
|
||||
{
|
||||
RemovedRawTags = new[] { removedRo },
|
||||
ChangedRawTags = new[]
|
||||
{
|
||||
new AddressSpacePlan.RawTagDelta(goingRo, goingRo with { HistorianReadOnly = true }),
|
||||
new AddressSpacePlan.RawTagDelta(goingOwned, goingOwned with { HistorianReadOnly = false }),
|
||||
},
|
||||
};
|
||||
|
||||
applier.Apply(plan);
|
||||
|
||||
sink.Added.ShouldBe(new[]
|
||||
{
|
||||
new HistorizedTagRef("Plant/Own", "Mine.Tag"),
|
||||
new HistorizedTagRef("Plant/ToOwn", "Y.Tag"),
|
||||
}, ignoreOrder: true);
|
||||
sink.Removed.ShouldBe(new[] { new HistorizedTagRef("Plant/ToRo", "X.Tag") });
|
||||
}
|
||||
|
||||
/// <summary>A synchronously-throwing subscription sink must NOT block or break the publish — the
|
||||
/// address-space work still completes and <see cref="AddressSpaceApplier.Apply"/> returns its outcome.</summary>
|
||||
[Fact]
|
||||
|
||||
+2
@@ -102,6 +102,7 @@ public sealed class AddressSpaceChangeClassifierDualNamespaceTests
|
||||
[InlineData("writable")]
|
||||
[InlineData("historized")]
|
||||
[InlineData("historianTagname")]
|
||||
[InlineData("historianReadOnly")]
|
||||
[InlineData("dataType")]
|
||||
[InlineData("array")]
|
||||
[InlineData("arrayLength")]
|
||||
@@ -118,6 +119,7 @@ public sealed class AddressSpaceChangeClassifierDualNamespaceTests
|
||||
"writable" => prev with { Writable = true },
|
||||
"historized" => prev with { IsHistorized = true },
|
||||
"historianTagname" => prev with { IsHistorized = true, HistorianTagname = "Plant.PLC_A.Speed" },
|
||||
"historianReadOnly" => prev with { HistorianReadOnly = true }, // lmxopcua#899: node-inert
|
||||
"dataType" => prev with { DataType = "Double" },
|
||||
"array" => prev with { IsArray = true, ArrayLength = 8 },
|
||||
"arrayLength" => prev with { ArrayLength = 16 },
|
||||
|
||||
+36
@@ -219,6 +219,42 @@ public sealed class AddressSpacePlannerDualNamespaceTests
|
||||
_ = prev;
|
||||
}
|
||||
|
||||
/// <summary>lmxopcua#899: a redeploy whose ONLY change is <c>historianReadOnly</c> must reach the applier as a
|
||||
/// ChangedRawTags delta — otherwise (the field missing from RawTagPlan's hand-written equality) the flip would diff
|
||||
/// empty and a tag marked read-only would keep being provisioned and recorded until something else about it changed.</summary>
|
||||
[Theory]
|
||||
[InlineData(false, true)]
|
||||
[InlineData(true, false)]
|
||||
public void Historian_read_only_flip_alone_routes_to_ChangedRawTags(bool before, bool after)
|
||||
{
|
||||
var folder = new RawFolder { RawFolderId = "raw-plant", ClusterId = "c1", Name = RawFolderName };
|
||||
var driver = new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "drv-modbus", ClusterId = "c1", RawFolderId = "raw-plant",
|
||||
Name = DriverName, DriverType = "Modbus", DriverConfig = "{}",
|
||||
};
|
||||
var device = new Device { DeviceId = "dev-1", DriverInstanceId = "drv-modbus", Name = DeviceName, DeviceConfig = "{}" };
|
||||
AddressSpaceComposition ComposeWith(bool readOnly) => AddressSpaceComposer.Compose(
|
||||
Array.Empty<UnsArea>(), Array.Empty<UnsLine>(), Array.Empty<Equipment>(),
|
||||
new[] { driver }, Array.Empty<ScriptedAlarm>(),
|
||||
tags: new[]
|
||||
{
|
||||
new Tag
|
||||
{
|
||||
TagId = "t-speed", DeviceId = "dev-1", Name = "Speed", DataType = "Int32", AccessLevel = TagAccessLevel.Read,
|
||||
TagConfig = $"{{\"isHistorized\":true,\"historianTagname\":\"SysTimeSec\",\"historianReadOnly\":{(readOnly ? "true" : "false")}}}",
|
||||
},
|
||||
},
|
||||
rawFolders: new[] { folder }, devices: new[] { device });
|
||||
|
||||
var plan = AddressSpacePlanner.Compute(ComposeWith(before), ComposeWith(after));
|
||||
|
||||
var changed = plan.ChangedRawTags.ShouldHaveSingleItem();
|
||||
changed.Previous.HistorianReadOnly.ShouldBe(before);
|
||||
changed.Current.HistorianReadOnly.ShouldBe(after);
|
||||
AddressSpaceChangeClassifier.Classify(plan).ShouldBe(AddressSpaceChangeKind.AttributeOnly); // in place, no rebuild
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <b>THE PIN (2026-08-15 surgical-deploys review):</b> a RAW-side edit to the backing tag's historian
|
||||
/// intent or array shape must produce a <c>ChangedRawTags</c> delta AND a <b>coincident</b>
|
||||
|
||||
@@ -36,6 +36,9 @@ public sealed class UnsReferenceBackingParityTests
|
||||
// Node-inert for a value tag: it only drives native-alarm notifier wiring, and an alarm-bearing delta
|
||||
// never takes the surgical path. The mirror is the referencing side, so it has nothing to inherit.
|
||||
[nameof(RawTagPlan.ReferencingEquipmentPaths)] = "notifier wiring only; the mirror is the referencing side",
|
||||
// lmxopcua#899: node-inert — it only steers the raw-tag provisioning hook and recorder feed; a UNS mirror
|
||||
// serves the same HistoryRead either way and neither provisions nor records.
|
||||
[nameof(RawTagPlan.HistorianReadOnly)] = "provisioning/recorder only; node-inert and never applied to a UNS mirror",
|
||||
};
|
||||
|
||||
private static RawTagPlan Baseline() => new(
|
||||
@@ -86,7 +89,7 @@ public sealed class UnsReferenceBackingParityTests
|
||||
{
|
||||
nameof(RawTagPlan.DataType), nameof(RawTagPlan.Writable), nameof(RawTagPlan.ReferencingEquipmentPaths),
|
||||
nameof(RawTagPlan.IsHistorized), nameof(RawTagPlan.HistorianTagname), nameof(RawTagPlan.IsArray),
|
||||
nameof(RawTagPlan.ArrayLength), nameof(RawTagPlan.ArrayWritable),
|
||||
nameof(RawTagPlan.ArrayLength), nameof(RawTagPlan.ArrayWritable), nameof(RawTagPlan.HistorianReadOnly),
|
||||
},
|
||||
ignoreOrder: true);
|
||||
|
||||
|
||||
+9
-2
@@ -20,6 +20,8 @@ namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Drivers;
|
||||
/// </summary>
|
||||
public sealed class DeploymentArtifactRawUnsParityTests
|
||||
{
|
||||
private const string RunTagConfig = "{\"isHistorized\":true,\"historianTagname\":\"SysPulse\",\"historianReadOnly\":true}";
|
||||
|
||||
[Fact]
|
||||
public void Raw_and_uns_node_sets_are_byte_parity_between_compose_and_artifact_decode()
|
||||
{
|
||||
@@ -44,7 +46,8 @@ public sealed class DeploymentArtifactRawUnsParityTests
|
||||
var run = new Tag
|
||||
{
|
||||
TagId = "tag-run", DeviceId = "dev-1", TagGroupId = null, Name = "Run", DataType = "Boolean",
|
||||
AccessLevel = TagAccessLevel.Read, TagConfig = "{}",
|
||||
// lmxopcua#899: a read-only historian binding — the flag must survive the artifact round-trip.
|
||||
AccessLevel = TagAccessLevel.Read, TagConfig = RunTagConfig,
|
||||
};
|
||||
var profile = new Tag
|
||||
{
|
||||
@@ -81,7 +84,7 @@ public sealed class DeploymentArtifactRawUnsParityTests
|
||||
Tags = new object[]
|
||||
{
|
||||
new { TagId = "tag-speed", DeviceId = "dev-1", TagGroupId = "grp-1", Name = "Speed", DataType = "Float", AccessLevel = 1, TagConfig = "{\"isHistorized\":true,\"historianTagname\":\"WW.Speed\"}" },
|
||||
new { TagId = "tag-run", DeviceId = "dev-1", TagGroupId = (string?)null, Name = "Run", DataType = "Boolean", AccessLevel = 0, TagConfig = "{}" },
|
||||
new { TagId = "tag-run", DeviceId = "dev-1", TagGroupId = (string?)null, Name = "Run", DataType = "Boolean", AccessLevel = 0, TagConfig = RunTagConfig },
|
||||
new { TagId = "tag-profile", DeviceId = "dev-1", TagGroupId = "grp-1", Name = "Profile", DataType = "Float", AccessLevel = 0, TagConfig = "{\"region\":\"HoldingRegisters\",\"address\":100,\"dataType\":\"Float32\",\"isArray\":true,\"arrayLength\":16}" },
|
||||
new { TagId = "tag-temphi", DeviceId = "dev-1", TagGroupId = (string?)null, Name = "TempHi", DataType = "Boolean", AccessLevel = 1, TagConfig = "{\"alarm\":{\"alarmType\":\"OffNormalAlarm\",\"severity\":700}}" },
|
||||
},
|
||||
@@ -111,6 +114,10 @@ public sealed class DeploymentArtifactRawUnsParityTests
|
||||
composedAlarm.Alarm.ShouldNotBeNull();
|
||||
composedAlarm.Alarm!.AlarmType.ShouldBe("OffNormalAlarm");
|
||||
composedAlarm.Writable.ShouldBeTrue();
|
||||
var composedRun = composed.RawTags.Single(t => t.Name == "Run");
|
||||
composedRun.IsHistorized.ShouldBeTrue();
|
||||
composedRun.HistorianReadOnly.ShouldBeTrue();
|
||||
composed.RawTags.Single(t => t.Name == "Speed").HistorianReadOnly.ShouldBeFalse();
|
||||
composed.UnsReferenceVariables.Count.ShouldBe(2);
|
||||
var composedSpeedRef = composed.UnsReferenceVariables.Single(v => v.UnsTagReferenceId == "ref-1");
|
||||
composedSpeedRef.NodeId.ShouldBe("filling/line1/station1/MotorSpeed");
|
||||
|
||||
@@ -81,5 +81,9 @@ public static class TagConfigGoldenCorpus
|
||||
"{\"address\":5,\"region\":\"Coils\",\"dataType\":\"Int16\",\"isHistorized\":true,\"alarm\":{\"severity\":250},\"foo\":\"bar\"}",
|
||||
// 29 all intents combined
|
||||
"{\"address\":\"C.D\",\"isArray\":true,\"arrayLength\":4,\"isHistorized\":true,\"historianTagname\":\"H\",\"alarm\":{\"alarmType\":\"DiscreteAlarm\",\"severity\":900,\"historizeToAveva\":false}}",
|
||||
// 30 lmxopcua#899 read-only historian binding
|
||||
"{\"address\":\"A\",\"isHistorized\":true,\"historianTagname\":\"SysTimeSec\",\"historianReadOnly\":true}",
|
||||
// 31 historianReadOnly non-bool → false (the deploy gate refuses it: HistorianReadOnlyInvalid)
|
||||
"{\"address\":\"A\",\"isHistorized\":true,\"historianReadOnly\":\"true\"}",
|
||||
};
|
||||
}
|
||||
|
||||
+32
@@ -113,6 +113,38 @@ public sealed class AddHistorianProvisioningTests
|
||||
resolved.ShouldNotBeSameAs(NullHistorianProvisioning.Instance);
|
||||
}
|
||||
|
||||
/// <summary>lmxopcua#899: ServerHistorian:ProvisionTags=Off keeps the no-op even with the section enabled; the
|
||||
/// other policies register the backend's provisioner (control).</summary>
|
||||
[Theory]
|
||||
[InlineData("Off", false)]
|
||||
[InlineData("off", false)]
|
||||
[InlineData("CreateOnly", true)]
|
||||
[InlineData("CreateOrUpdate", true)]
|
||||
public void ProvisionTags_Off_keeps_null_provisioning(string policy, bool registered)
|
||||
{
|
||||
var factoryInvoked = false;
|
||||
var services = new ServiceCollection();
|
||||
services.AddOtOpcUaRuntime();
|
||||
var config = ConfigFrom(new Dictionary<string, string?>
|
||||
{
|
||||
["ServerHistorian:Enabled"] = "true",
|
||||
["ServerHistorian:Endpoint"] = "https://historian.example.com:5222",
|
||||
["ServerHistorian:ApiKey"] = "histgw_x_y",
|
||||
["ServerHistorian:ProvisionTags"] = policy,
|
||||
});
|
||||
|
||||
services.AddHistorianProvisioning(config, (_, _) =>
|
||||
{
|
||||
factoryInvoked = true;
|
||||
return new CapturingProvisioner();
|
||||
});
|
||||
|
||||
using var provider = services.BuildServiceProvider();
|
||||
var resolved = provider.GetRequiredService<IHistorianProvisioning>();
|
||||
(resolved is NullHistorianProvisioning).ShouldBe(!registered);
|
||||
factoryInvoked.ShouldBe(registered);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Section_enabled_passes_bound_options_to_factory()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user