fix(dashboard): ShowTagValues now gates the alarms hub and /browse live values

This commit is contained in:
Joseph Doherty
2026-08-17 07:14:40 -04:00
parent 222b01f488
commit eff17d177c
9 changed files with 532 additions and 15 deletions
@@ -1,7 +1,9 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using ZB.MOM.WW.MxGateway.Contracts.Proto;
using ZB.MOM.WW.MxGateway.Server.Configuration;
using ZB.MOM.WW.MxGateway.Server.Dashboard;
using ZB.MOM.WW.MxGateway.Server.Sessions;
using ZB.MOM.WW.MxGateway.Server.Workers;
@@ -186,11 +188,68 @@ public sealed class DashboardLiveDataServiceTests
Assert.Equal(filler[0], worker.SubscribedTags[^1]);
}
private static DashboardLiveDataService CreateService(ISessionManager sessionManager)
/// <summary>
/// Verifies the <c>/browse</c> live-value seam honours
/// <c>MxGateway:Dashboard:ShowTagValues</c> (TST-16): with the flag off — the
/// default — the value text the page renders is the redaction placeholder,
/// never the formatted tag value.
/// </summary>
[Fact]
public async Task ReadAsync_WhenShowTagValuesFalse_RedactsValueTextButKeepsMetadata()
{
RecordingWorkerClient worker = new()
{
ReadValue = new MxValue { DataType = MxDataType.Double, DoubleValue = 42.5 },
};
await using FakeSessionManager sessionManager = new(worker);
await using DashboardLiveDataService service = CreateService(sessionManager, showTagValues: false);
DashboardLiveReadResult result = await service.ReadAsync(["Tank_001.PV"], CancellationToken.None);
DashboardTagValue value = Assert.Single(result.Values);
Assert.Equal(DashboardTagValue.RedactedValueText, value.ValueText);
Assert.DoesNotContain("42.5", value.ValueText, StringComparison.Ordinal);
// Everything that is not the value still renders: the panel stays useful.
Assert.Equal("Tank_001.PV", value.TagAddress);
Assert.True(value.Ok);
Assert.Equal("Double", value.DataType);
Assert.Equal(192, value.Quality);
Assert.True(value.QualityGood);
Assert.Null(value.Error);
}
/// <summary>Verifies the formatted value is served when the flag is on.</summary>
[Fact]
public async Task ReadAsync_WhenShowTagValuesTrue_ServesFormattedValue()
{
RecordingWorkerClient worker = new()
{
ReadValue = new MxValue { DataType = MxDataType.Double, DoubleValue = 42.5 },
};
await using FakeSessionManager sessionManager = new(worker);
await using DashboardLiveDataService service = CreateService(sessionManager, showTagValues: true);
DashboardLiveReadResult result = await service.ReadAsync(["Tank_001.PV"], CancellationToken.None);
DashboardTagValue value = Assert.Single(result.Values);
Assert.Equal("42.5", value.ValueText);
Assert.Equal("Double", value.DataType);
}
private static DashboardLiveDataService CreateService(
ISessionManager sessionManager,
bool showTagValues = false)
{
GatewayOptions gatewayOptions = new()
{
Dashboard = new DashboardOptions { ShowTagValues = showTagValues },
};
return new DashboardLiveDataService(
sessionManager,
new FakeGatewayAlarmService(),
Options.Create(gatewayOptions),
NullLogger<DashboardLiveDataService>.Instance);
}
@@ -322,6 +381,12 @@ public sealed class DashboardLiveDataServiceTests
/// <summary>Gets or sets a value indicating whether unsubscribe commands throw.</summary>
public bool FailUnsubscribe { get; set; }
/// <summary>
/// Gets or sets the value every bulk read returns. Null (the default) leaves
/// the read results value-less, which is all the advise-set tests need.
/// </summary>
public MxValue? ReadValue { get; set; }
/// <summary>Gets the item handle bound for a previously subscribed tag.</summary>
/// <param name="tagAddress">Tag address to look up.</param>
/// <returns>The bound item handle.</returns>
@@ -434,14 +499,21 @@ public sealed class DashboardLiveDataServiceTests
BulkReadReply readReply = new();
foreach (string tagAddress in tagAddresses)
{
readReply.Results.Add(new BulkReadResult
BulkReadResult readResult = new()
{
ServerHandle = RegisteredServerHandle,
TagAddress = tagAddress,
ItemHandle = _itemHandles.TryGetValue(tagAddress, out int itemHandle) ? itemHandle : 0,
WasSuccessful = true,
Quality = 192,
});
};
if (ReadValue is not null)
{
readResult.Value = ReadValue.Clone();
}
readReply.Results.Add(readResult);
}
return readReply;