fix(acl): folder event verdict invalidation reaches orphaned items, decides on the live instance, skips ACL-off; alarm-bearing reference map (#826 review)

1. Orphaned subscriptions (session closed without deleting subs) have Session == null, so the public
   MonitoredNode2.InvalidatePermissionCacheForSession never reached their items: a cached allow survived a
   deploy, the moved alarm's events were queued and delivered on TransferSubscriptions. Each notifier's
   cache is now cleared whole through the SDK's private MonitoredNode2.InvalidatePermissionCaches
   (reflection, guard-tested; fallback = per-session drop + Remove/Add of session-less items).
2. The verdict is decided on the condition LIVE under the event's NodeId, not the event's own instance:
   the SDK key has no instance identity, so a replaced instance's late event cached a deny its successor
   inherited until the next invalidation.
3. Invalidation is skipped while enforcement is off (forced across an on/off authorizer transition) and is
   one O(cache) clear per node instead of a whole-cache scan per item.
4. TagReferencingEquipment carries alarm-bearing raw tags only (TagConfigIntent.Alarm); the snapshot adopts
   an OrdinalIgnoreCase set instead of copying it again.

Tests (each fails with its fix reverted): FolderEventVerdictInvalidationTests (orphan + deploy + transfer;
replaced instance's late event; ACL-off skip; SDK private-method guard), DeploymentArtifactScopePathTests
(alarm-bearing projection).
This commit is contained in:
Joseph Doherty
2026-11-11 02:25:24 -05:00
parent 8e1e73f93c
commit 489664d105
7 changed files with 355 additions and 37 deletions
@@ -314,27 +314,62 @@ public sealed class DeploymentArtifactScopePathTests
}
/// <summary>
/// Gitea #826 — the projection says which equipment each raw tag is projected into, keyed on the RawPath the
/// same resolver builds (a native alarm's <c>ConditionId</c>), so the node manager can tell a native alarm's
/// still-referenced equipment folders from one whose reference the generation dropped.
/// Gitea #826 — the projection says which equipment each ALARM-BEARING raw tag is projected into, keyed on the
/// RawPath the same resolver builds (a native alarm's <c>ConditionId</c>), so the node manager can tell a native
/// alarm's still-referenced equipment folders from one whose reference the generation dropped. Plain value tags
/// are never looked up and are left out (review: memory).
/// </summary>
[Fact]
public void The_projection_carries_each_raw_tags_referencing_equipment_under_its_raw_path()
public void The_projection_carries_each_alarm_bearing_raw_tags_referencing_equipment_under_its_raw_path()
{
var projection = DeploymentArtifact.ParseDataPlaneAuthority(Encoding.UTF8.GetBytes(Artifact), NodeId);
var projection = DeploymentArtifact.ParseDataPlaneAuthority(Encoding.UTF8.GetBytes(AlarmArtifact), NodeId);
const string rawPath = "Plant/Line1/ModbusDrv/dev1/Fast/Speed";
projection.TagReferencingEquipment.Keys.ShouldBe([rawPath]);
projection.TagReferencingEquipment[rawPath].ShouldBe(["EQ-mixer"]);
const string hot = "Plant/Line1/ModbusDrv/dev1/Fast/Hot";
projection.TagReferencingEquipment.Keys.ShouldBe([hot], "the plain Speed tag is not alarm-bearing");
projection.TagReferencingEquipment[hot].Order(StringComparer.Ordinal).ShouldBe(["EQ-mixer", "EQ-oven"]);
var snapshot = new DataPlaneAuthorityState().Apply(
"c1", "rev-1", projection.Keys, projection.Grants, projection.ScopePaths, projection.EquipmentScopePaths,
projection.ScriptedAlarmOwners, projection.UnsFolderScopes, projection.TagReferencingEquipment);
snapshot.IsTagReferencedBy(rawPath, "EQ-mixer").ShouldBeTrue();
snapshot.IsTagReferencedBy(rawPath, "eq-MIXER").ShouldBeTrue("equipment ids compare as identifiers");
snapshot.IsTagReferencedBy(rawPath, "EQ-other").ShouldBeFalse();
snapshot.IsTagReferencedBy("Plant/Line1/ModbusDrv/dev1/Fast/Other", "EQ-mixer").ShouldBeFalse();
snapshot.IsTagReferencedBy(hot, "EQ-oven").ShouldBeTrue();
snapshot.IsTagReferencedBy(hot, "eq-MIXER").ShouldBeTrue("equipment ids compare as identifiers");
snapshot.IsTagReferencedBy(hot, "EQ-other").ShouldBeFalse();
snapshot.IsTagReferencedBy("Plant/Line1/ModbusDrv/dev1/Fast/Speed", "EQ-mixer").ShouldBeFalse();
new DataPlaneAuthorityState().Apply("c1", "rev-1", [], [], projection.ScopePaths)
.IsTagReferencedBy(rawPath, "EQ-mixer").ShouldBeFalse("an absent map references nothing (fail closed)");
.IsTagReferencedBy(hot, "EQ-mixer").ShouldBeFalse("an absent map references nothing (fail closed)");
}
// The fixture's topology plus an alarm-bearing Hot tag referenced by two equipment; Speed stays a plain value.
private const string AlarmArtifact = """
{
"RawFolders": [
{"RawFolderId":"RF-plant","ClusterId":"c1","ParentRawFolderId":null,"Name":"Plant"},
{"RawFolderId":"RF-line1","ClusterId":"c1","ParentRawFolderId":"RF-plant","Name":"Line1"}
],
"DriverInstances": [
{"DriverInstanceId":"DI-modbus","ClusterId":"c1","RawFolderId":"RF-line1","Name":"ModbusDrv"}
],
"Devices": [{"DeviceId":"DV-1","DriverInstanceId":"DI-modbus","Name":"dev1"}],
"TagGroups": [{"TagGroupId":"TG-fast","DeviceId":"DV-1","ParentTagGroupId":null,"Name":"Fast"}],
"Tags": [
{"TagId":"TAG-speed","DeviceId":"DV-1","TagGroupId":"TG-fast","Name":"Speed"},
{"TagId":"TAG-hot","DeviceId":"DV-1","TagGroupId":"TG-fast","Name":"Hot",
"TagConfig":"{\"alarm\":{\"alarmType\":\"OffNormalAlarm\"}}"}
],
"UnsAreas": [{"UnsAreaId":"UA-w","ClusterId":"c1","Name":"West"}],
"UnsLines": [{"UnsLineId":"UL-1","UnsAreaId":"UA-w","Name":"L1"}],
"Equipment": [
{"EquipmentId":"EQ-mixer","UnsLineId":"UL-1","Name":"Mixer"},
{"EquipmentId":"EQ-oven","UnsLineId":"UL-1","Name":"Oven"}
],
"UnsTagReferences": [
{"UnsTagReferenceId":"REF-1","EquipmentId":"EQ-mixer","TagId":"TAG-speed"},
{"UnsTagReferenceId":"REF-2","EquipmentId":"EQ-mixer","TagId":"TAG-hot"},
{"UnsTagReferenceId":"REF-3","EquipmentId":"EQ-oven","TagId":"TAG-hot"}
],
"NodeAcls": [
{"NodeAclId":"acl-eq","ClusterId":"c1","Principal":"p","ScopeKind":4,"ScopeId":"EQ-mixer","PermissionFlags":16}
]
}
""";
}