fix(grpc-data): A3 condition items carry the origin's canonical root view (metadata asked like the browse resolver) — live a3b-cond-2 found map-uns refused Denied

This commit is contained in:
Joseph Doherty
2026-11-24 17:48:16 -05:00
parent 404a664ca3
commit 82ecc1164c
2 changed files with 51 additions and 9 deletions
@@ -114,6 +114,18 @@ public sealed class GrpcDataProjectedConditionMethodTests
f.Connections.Sent.Count.ShouldBe(sent);
}
[Fact]
public async Task The_condition_item_carries_the_origins_canonical_root_view_learned_from_metadata()
{
// Live a3b-cond-2: a UNS root item built from the address alone (subject = the opaque EquipmentId) was refused Denied.
await using var f = new Fixture(uns: true);
using var demand = f.Access.AcquireEventDemand(null);
var stream = await f.Connections.Streams.Reader.ReadAsync(TestContext.Current.CancellationToken);
var open = await stream.Opened.Task.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
f.Connections.MetadataViews.Single().Subject.ShouldBe("EQ-0001", "metadata is asked as the browse resolver asks it (RemoteRootEntityId)");
open.Items.Single().View.Subject.ShouldBe("area/line/plc", "the item uses the origin's own view of the root");
}
// ---------------------------------------------------------------------------------------------------------------------
private sealed class Fixture : IAsyncDisposable
@@ -126,7 +138,7 @@ public sealed class GrpcDataProjectedConditionMethodTests
public ProjectedConditionAccess Access { get; }
public RemoteNamespaceMapping Mapping => _placement.Mapping;
public Fixture()
public Fixture(bool uns = false)
{
Grant(NodePermissions.Browse | NodePermissions.Subscribe);
var mapping = new RemoteNamespaceMapping
@@ -138,9 +150,16 @@ public sealed class GrpcDataProjectedConditionMethodTests
ConditionMethodTimeoutMilliseconds = 4321, BranchName = "map-a", RemoteNamespaceUri = "https://zb.com/otopcua/raw",
RemoteIdentifierKind = "string", RemoteIdentifier = "Plant",
};
if (uns)
{
mapping.Realm = mapping.RemoteRealm = DataRealm.Uns;
mapping.RemoteNamespaceUri = "https://zb.com/otopcua/uns";
mapping.RemoteIdentifier = "EQ-0001";
mapping.RemoteRootEntityId = "EQ-0001";
}
var segments = new[] { "Plant", "map-a" };
var anchor = new DataView(new DataAddress("origin", mapping.RemoteNamespaceUri, "string", "Plant"), DataRealm.Raw, "map-a", 1, "Plant/map-a");
var scope = new NodeScope { ClusterId = "c1", Kind = NodeHierarchyKind.Raw, Segments = segments };
var anchor = new DataView(new DataAddress("origin", mapping.RemoteNamespaceUri, "string", mapping.RemoteIdentifier), mapping.Realm, "map-a", 1, "Plant/map-a");
var scope = new NodeScope { ClusterId = "c1", Kind = uns ? NodeHierarchyKind.Uns : NodeHierarchyKind.Raw, Segments = segments };
_placement = new ProjectedMappingPlacement(mapping, anchor, anchor, scope, ["local-parent"], new ActiveAuthority());
var policy = new DataOperationPolicy(_state, new TriePermissionEvaluator(_state.Tries, TimeProvider.System), TimeProvider.System);
Access = new ProjectedConditionAccess(new GrpcDataProjectedConditionAccessTests.FakeMappings([_placement]), Connections, policy,
@@ -189,6 +208,7 @@ public sealed class GrpcDataProjectedConditionMethodTests
private int _acquired;
public Channel<FakeStream> Streams { get; } = Channel.CreateUnbounded<FakeStream>();
public List<DataConditionMethodRequest> Sent { get; } = [];
public List<DataView> MetadataViews { get; } = [];
public DataConditionMethodResult Result { get; set; } = new(DataWriteState.AcceptedUnconfirmed, 0, null);
public bool Refuse { get; set; }
public volatile bool Down;
@@ -215,8 +235,14 @@ public sealed class GrpcDataProjectedConditionMethodTests
public TimeProvider Clock => TimeProvider.System;
public Task<DataCapabilities> GetCapabilitiesAsync(DataBudget budget, CancellationToken cancellationToken) => throw new NotSupportedException();
public Task<DataBrowseBranch> BrowseAsync(BrowseRequest request, CancellationToken cancellationToken) => throw new NotSupportedException();
public Task<IReadOnlyList<DataItemResult<DataMetadata>>> GetMetadataAsync(MetadataRequest request, CancellationToken cancellationToken) =>
Task.FromResult<IReadOnlyList<DataItemResult<DataMetadata>>>([]);
public Task<IReadOnlyList<DataItemResult<DataMetadata>>> GetMetadataAsync(MetadataRequest request, CancellationToken cancellationToken)
{
lock (owner.MetadataViews) owner.MetadataViews.AddRange(request.Views);
// The origin answers with ITS canonical view of the root (subject = its browse path, not the opaque id).
return Task.FromResult<IReadOnlyList<DataItemResult<DataMetadata>>>(request.Views.Select(v => new DataItemResult<DataMetadata>("0",
DataItemStatus.Good, new DataMetadata(v with { Subject = "area/line/plc" }, "plc", "Folder", DataValueKind.Null, -1, [], false,
DataOperations.Browse, 1, null, null, false), null)).ToArray());
}
public Task<IReadOnlyList<ReadResult>> ReadAsync(ReadRequest request, CancellationToken cancellationToken) => throw new NotSupportedException();
public Task<IReadOnlyList<WriteItemResult>> WriteAsync(WriteBatch request, CancellationToken cancellationToken) => throw new NotSupportedException();
public Task<IDataSubscription> SubscribeAsync(CancellationToken cancellationToken)
@@ -239,7 +265,12 @@ public sealed class GrpcDataProjectedConditionMethodTests
{
private readonly Channel<DataSubscriptionFrame> _frames = Channel.CreateUnbounded<DataSubscriptionFrame>();
public ServingIdentity Serving => GrpcDataProjectedConditionMethodTests.Serving;
public Task SendAsync(DataSubscriptionCommand command, CancellationToken cancellationToken) => Task.CompletedTask;
public TaskCompletionSource<OpenSubscription> Opened { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously);
public Task SendAsync(DataSubscriptionCommand command, CancellationToken cancellationToken)
{
if (command is OpenSubscription open) Opened.TrySetResult(open);
return Task.CompletedTask;
}
public IAsyncEnumerable<DataSubscriptionFrame> ReadAllAsync(CancellationToken cancellationToken) => _frames.Reader.ReadAllAsync(cancellationToken);
public void End() => _frames.Writer.TryComplete();
public ValueTask DisposeAsync() { _frames.Writer.TryComplete(); return ValueTask.CompletedTask; }