test: preserve server SDK 2.0 value security and history contracts
This commit is contained in:
@@ -323,20 +323,15 @@ public sealed class SdkAddressSpaceSinkTests : IDisposable
|
||||
condition.Parent!.NodeId.ShouldBe(new NodeId("eq-1", unsNs));
|
||||
|
||||
// Initial state set by MaterialiseAlarmCondition: enabled, inactive, acked, retain=false.
|
||||
condition.EnabledState.Id.Value.ShouldBeTrue();
|
||||
condition.ActiveState.Id.Value.ShouldBeFalse();
|
||||
condition.Retain.Value.ShouldBeFalse();
|
||||
condition.EnabledState!.Id!.Value.ShouldBeTrue();
|
||||
condition.ActiveState!.Id!.Value.ShouldBeFalse();
|
||||
condition.Retain!.Value.ShouldBeFalse();
|
||||
|
||||
// --- T13 optional-children finding (RESOLVED by THIS real-server test) ---
|
||||
// AckedState is mandatory on AcknowledgeableConditionState so it is always present.
|
||||
condition.AckedState.ShouldNotBeNull();
|
||||
// FINDING (1.5.378.106): Create auto-builds the FULL optional Part 9 child set from the
|
||||
// embedded type definition WITHOUT us pre-setting any property — both ConfirmedState (Confirm
|
||||
// sub-state machine) AND ShelvingState (Shelve state machine) come back non-null. This is
|
||||
// RICHER than the SDK-notes' [SAMPLE-ONLY] caveat predicted (it suggested we'd have to
|
||||
// instantiate optional children ourselves). Net: T15/T16 can drive SetConfirmedState /
|
||||
// SetShelvingState directly — no manual child materialisation needed. Asserting both non-null
|
||||
// so a future SDK bump that changes auto-build behaviour fails loudly.
|
||||
// SDK 2.0 only builds the optional children explicitly requested by the application.
|
||||
// The existing confirm/shelve workflow remains part of the served condition contract.
|
||||
condition.ConfirmedState.ShouldNotBeNull();
|
||||
condition.ShelvingState.ShouldNotBeNull();
|
||||
|
||||
@@ -345,9 +340,9 @@ public sealed class SdkAddressSpaceSinkTests : IDisposable
|
||||
sink.WriteAlarmCondition("alm-1", Snapshot(active: true, acknowledged: false), DateTime.UtcNow, AddressSpaceRealm.Uns);
|
||||
nm.VariableCount.ShouldBe(0); // fallback bool[2] path NOT taken
|
||||
|
||||
condition.ActiveState.Id.Value.ShouldBeTrue();
|
||||
condition.AckedState.Id.Value.ShouldBeFalse();
|
||||
condition.Retain.Value.ShouldBeTrue(); // active || !acked ⇒ retain
|
||||
condition.ActiveState!.Id!.Value.ShouldBeTrue();
|
||||
condition.AckedState!.Id!.Value.ShouldBeFalse();
|
||||
condition.Retain!.Value.ShouldBeTrue(); // active || !acked ⇒ retain
|
||||
|
||||
// Idempotent re-materialise (e.g. redeploy): still exactly one condition node for the id.
|
||||
sink.MaterialiseAlarmCondition("alm-1", "eq-1", "HighTemp", "OffNormalAlarm", severity: 700, realm: AddressSpaceRealm.Uns);
|
||||
@@ -410,17 +405,17 @@ public sealed class SdkAddressSpaceSinkTests : IDisposable
|
||||
Message: "Pressure above limit"),
|
||||
DateTime.UtcNow, AddressSpaceRealm.Uns);
|
||||
|
||||
condition.ActiveState.Id.Value.ShouldBeTrue();
|
||||
condition.AckedState.Id.Value.ShouldBeFalse();
|
||||
condition.EnabledState.Id.Value.ShouldBeFalse(); // disabled
|
||||
condition.ConfirmedState!.Id.Value.ShouldBeFalse(); // unconfirmed
|
||||
condition.ActiveState!.Id!.Value.ShouldBeTrue();
|
||||
condition.AckedState!.Id!.Value.ShouldBeFalse();
|
||||
condition.EnabledState!.Id!.Value.ShouldBeFalse(); // disabled
|
||||
condition.ConfirmedState!.Id!.Value.ShouldBeFalse(); // unconfirmed
|
||||
// SetShelvingState(shelved:true, oneShot:false) drives the shelving sub-state machine into a
|
||||
// shelved state; CurrentState is populated (TimedShelved).
|
||||
condition.ShelvingState!.CurrentState.Id.Value.ShouldNotBeNull();
|
||||
condition.ShelvingState!.CurrentState!.Id!.Value.IsNull.ShouldBeFalse();
|
||||
// Severity 850 is carried verbatim — not re-bucketed onto EventSeverity.High (900).
|
||||
condition.Severity.Value.ShouldBe((ushort)850);
|
||||
condition.Message.Value.Text.ShouldBe("Pressure above limit");
|
||||
condition.Retain.Value.ShouldBeTrue(); // active || !acked ⇒ retain
|
||||
condition.Severity!.Value.ShouldBe((ushort)850);
|
||||
condition.Message!.Value.Text.ShouldBe("Pressure above limit");
|
||||
condition.Retain!.Value.ShouldBeTrue(); // active || !acked ⇒ retain
|
||||
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
@@ -462,9 +457,9 @@ public sealed class SdkAddressSpaceSinkTests : IDisposable
|
||||
DateTime.UtcNow, AddressSpaceRealm.Uns));
|
||||
|
||||
// Mandatory state still projected despite the missing optional child.
|
||||
condition.ActiveState.Id.Value.ShouldBeTrue();
|
||||
condition.AckedState.Id.Value.ShouldBeFalse();
|
||||
condition.Message.Value.Text.ShouldBe("still works");
|
||||
condition.ActiveState!.Id!.Value.ShouldBeTrue();
|
||||
condition.AckedState!.Id!.Value.ShouldBeFalse();
|
||||
condition.Message!.Value.Text.ShouldBe("still works");
|
||||
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
@@ -495,12 +490,12 @@ public sealed class SdkAddressSpaceSinkTests : IDisposable
|
||||
|
||||
// EventId at materialise time (Create stamps an initial one). Capture a COPY — the live byte[]
|
||||
// reference is reused, so we compare snapshots, not the same array instance.
|
||||
var materialiseEventId = (byte[]?)condition!.EventId.Value?.Clone();
|
||||
var materialiseEventId = (byte[]?)condition!.EventId!.Value.ToArray();
|
||||
|
||||
// First engine-driven transition → fires an event with a fresh EventId.
|
||||
sink.WriteAlarmCondition("alm-evt", Snapshot(active: true, acknowledged: false), DateTime.UtcNow, AddressSpaceRealm.Uns);
|
||||
|
||||
var firstEventId = (byte[]?)condition.EventId.Value?.Clone();
|
||||
var firstEventId = (byte[]?)condition.EventId!.Value.ToArray();
|
||||
firstEventId.ShouldNotBeNull();
|
||||
firstEventId!.Length.ShouldBe(16); // GUID bytes
|
||||
// Changed from the materialise-time value (a real event fired, not the create-time stamp).
|
||||
@@ -512,7 +507,7 @@ public sealed class SdkAddressSpaceSinkTests : IDisposable
|
||||
// Second transition → DIFFERENT EventId (fresh per event, so T17 ack-correlation is unambiguous).
|
||||
sink.WriteAlarmCondition("alm-evt", Snapshot(active: true, acknowledged: true), DateTime.UtcNow, AddressSpaceRealm.Uns);
|
||||
|
||||
var secondEventId = (byte[]?)condition.EventId.Value?.Clone();
|
||||
var secondEventId = (byte[]?)condition.EventId!.Value.ToArray();
|
||||
secondEventId.ShouldNotBeNull();
|
||||
secondEventId!.ShouldNotBe(firstEventId);
|
||||
|
||||
@@ -551,10 +546,10 @@ public sealed class SdkAddressSpaceSinkTests : IDisposable
|
||||
});
|
||||
|
||||
// Final projected state is intact after the last firing.
|
||||
condition!.ActiveState.Id.Value.ShouldBeFalse();
|
||||
condition.AckedState.Id.Value.ShouldBeTrue();
|
||||
condition.Message.Value.Text.ShouldBe("cleared");
|
||||
condition.Retain.Value.ShouldBeFalse(); // inactive && acked ⇒ no retain
|
||||
condition!.ActiveState!.Id!.Value.ShouldBeFalse();
|
||||
condition.AckedState!.Id!.Value.ShouldBeTrue();
|
||||
condition.Message!.Value.Text.ShouldBe("cleared");
|
||||
condition.Retain!.Value.ShouldBeFalse(); // inactive && acked ⇒ no retain
|
||||
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
@@ -583,8 +578,8 @@ public sealed class SdkAddressSpaceSinkTests : IDisposable
|
||||
|
||||
// Drive the alarm active+unacked through the engine path (a genuine transition → fires).
|
||||
sink.WriteAlarmCondition("alm-ack", Snapshot(active: true, acknowledged: false, message: "active"), DateTime.UtcNow, AddressSpaceRealm.Uns);
|
||||
condition!.ActiveState.Id.Value.ShouldBeTrue();
|
||||
condition.AckedState.Id.Value.ShouldBeFalse();
|
||||
condition!.ActiveState!.Id!.Value.ShouldBeTrue();
|
||||
condition.AckedState!.Id!.Value.ShouldBeFalse();
|
||||
|
||||
// === Simulate the SDK-applied inbound Acknowledge (E2) ===
|
||||
// After T18's gate returns Good, the SDK applies the acked state to the node and auto-fires its
|
||||
@@ -592,26 +587,26 @@ public sealed class SdkAddressSpaceSinkTests : IDisposable
|
||||
lock (nm.Lock)
|
||||
{
|
||||
condition.SetAcknowledgedState(nm.SystemContext, true);
|
||||
condition.Message.Value = new LocalizedText("active");
|
||||
condition.Message!.Value = new LocalizedText("active");
|
||||
condition.ClearChangeMasks(nm.SystemContext, includeChildren: true);
|
||||
}
|
||||
condition.AckedState.Id.Value.ShouldBeTrue();
|
||||
condition.AckedState!.Id!.Value.ShouldBeTrue();
|
||||
|
||||
// Capture the EventId AFTER the SDK-applied ack but BEFORE the engine re-projection.
|
||||
var beforeReProject = (byte[]?)condition.EventId.Value?.Clone();
|
||||
var beforeReProject = (byte[]?)condition.EventId!.Value.ToArray();
|
||||
|
||||
// === Engine re-projects the SAME acked transition through WriteAlarmCondition (would-be E3) ===
|
||||
// Snapshot equals the node's current state (active, acked, message "active") ⇒ delta-gate sees
|
||||
// no change ⇒ NO event fires.
|
||||
sink.WriteAlarmCondition("alm-ack", Snapshot(active: true, acknowledged: true, message: "active"), DateTime.UtcNow, AddressSpaceRealm.Uns);
|
||||
|
||||
var afterReProject = (byte[]?)condition.EventId.Value?.Clone();
|
||||
var afterReProject = (byte[]?)condition.EventId!.Value.ToArray();
|
||||
// EventId is UNCHANGED ⇒ ReportConditionEvent did NOT run ⇒ E3 suppressed.
|
||||
afterReProject.ShouldBe(beforeReProject);
|
||||
|
||||
// The projection still applied (state is intact) — only the redundant event was suppressed.
|
||||
condition.ActiveState.Id.Value.ShouldBeTrue();
|
||||
condition.AckedState.Id.Value.ShouldBeTrue();
|
||||
condition.ActiveState!.Id!.Value.ShouldBeTrue();
|
||||
condition.AckedState!.Id!.Value.ShouldBeTrue();
|
||||
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
@@ -633,24 +628,24 @@ public sealed class SdkAddressSpaceSinkTests : IDisposable
|
||||
var condition = nm.TryGetAlarmCondition("alm-delta");
|
||||
condition.ShouldNotBeNull();
|
||||
|
||||
var beforeFirst = (byte[]?)condition!.EventId.Value?.Clone();
|
||||
var beforeFirst = (byte[]?)condition!.EventId!.Value.ToArray();
|
||||
|
||||
// Genuine transition: snapshot (active, unacked) differs from the materialise state
|
||||
// (inactive, acked) ⇒ delta ⇒ fires exactly one event (EventId changes).
|
||||
sink.WriteAlarmCondition("alm-delta", Snapshot(active: true, acknowledged: false, message: "active"), DateTime.UtcNow, AddressSpaceRealm.Uns);
|
||||
var afterFirst = (byte[]?)condition.EventId.Value?.Clone();
|
||||
var afterFirst = (byte[]?)condition.EventId!.Value.ToArray();
|
||||
afterFirst.ShouldNotBeNull();
|
||||
afterFirst!.ShouldNotBe(beforeFirst); // fired
|
||||
|
||||
// Identical re-projection: snapshot now EQUALS the node's current state ⇒ no delta ⇒ 0 more
|
||||
// events (EventId unchanged from the first fire).
|
||||
sink.WriteAlarmCondition("alm-delta", Snapshot(active: true, acknowledged: false, message: "active"), DateTime.UtcNow, AddressSpaceRealm.Uns);
|
||||
var afterSecond = (byte[]?)condition.EventId.Value?.Clone();
|
||||
var afterSecond = (byte[]?)condition.EventId!.Value.ToArray();
|
||||
afterSecond.ShouldBe(afterFirst); // suppressed
|
||||
|
||||
// A FURTHER genuine transition (clear) differs again ⇒ fires once more.
|
||||
sink.WriteAlarmCondition("alm-delta", Snapshot(active: false, acknowledged: true, message: "cleared"), DateTime.UtcNow, AddressSpaceRealm.Uns);
|
||||
var afterThird = (byte[]?)condition.EventId.Value?.Clone();
|
||||
var afterThird = (byte[]?)condition.EventId!.Value.ToArray();
|
||||
afterThird.ShouldNotBe(afterSecond); // fired
|
||||
|
||||
await host.DisposeAsync();
|
||||
|
||||
Reference in New Issue
Block a user