Unify gateway styling and preserve identity through recovery
ci / java (push) Failing after 15m11s
ci / nightly-windev (push) Failing after 10m18s
ci / portable (push) Failing after 27m42s
ci / windows-x86 (push) Failing after 22m19s

This commit is contained in:
Joseph Doherty
2026-11-13 20:12:00 -05:00
parent b06921ce85
commit 26a90883fa
76 changed files with 20585 additions and 128 deletions
@@ -7,7 +7,7 @@
is owned by the kit's <details> + ThemeScripts (no JS interop here). *@
<ThemeShell Product="MXAccess Gateway" Accent="#2f5fd0">
<Nav>
<NavRailItem Href="/" Text="Dashboard" Match="NavLinkMatch.All" />
<NavRailItem Href="/" Text="Overview" Match="NavLinkMatch.All" />
<NavRailSection Title="Runtime" Key="runtime">
<NavRailItem Href="/sessions" Text="Sessions" />
<NavRailItem Href="/workers" Text="Workers" />
@@ -26,7 +26,7 @@
<NavRailItem Href="/browse" Text="Browse" />
</NavRailSection>
<NavRailSection Title="Admin" Key="admin">
<NavRailItem Href="/apikeys" Text="API Keys" />
<NavRailItem Href="/apikeys" Text="API keys" />
@* Gated on the SAME policy the mounted /admin/secrets page enforces, not on a role
literal, so nav visibility cannot drift from page access. In this host the two are
equivalent — GatewayOptionsValidator constrains Dashboard:GroupToRole values to
@@ -50,11 +50,11 @@
<span class="rail-user">@authState.User.Identity?.Name</span>
<form method="post" action="/logout" data-enhance="false">
<AntiforgeryToken />
<button class="rail-btn" type="submit">Sign Out</button>
<button class="rail-btn" type="submit">Sign out</button>
</form>
</Authorized>
<NotAuthorized>
<a class="rail-btn" href="/login">Sign In</a>
<a class="rail-btn" href="/login">Sign in</a>
</NotAuthorized>
</AuthorizeView>
</RailFooter>
@@ -4,7 +4,7 @@
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject IDashboardApiKeyManagementService ApiKeyManagementService
<PageTitle>Dashboard API Keys</PageTitle>
<PageTitle>MXAccess Gateway — API keys</PageTitle>
@if (Snapshot is null)
{
@@ -14,13 +14,13 @@ else
{
<div class="dashboard-page-header">
<div>
<h1>API Keys</h1>
<h1>API keys</h1>
<div class="text-secondary">@Snapshot.ApiKeys.Count key rows</div>
</div>
@if (CanManageApiKeys)
{
<button type="button" class="btn btn-primary" @onclick="OpenCreateDialog">
Create API Key
Create API key
</button>
}
</div>
@@ -60,7 +60,7 @@ else
form-label small, mb-2/mb-3 row wrappers, Save/Cancel
inline at the bottom of the card-body (no modal-footer). *@
<div class="modal-header">
<h2 class="modal-title h5" id="createApiKeyTitle">Create API Key</h2>
<h2 class="modal-title h5" id="createApiKeyTitle">Create API key</h2>
<button type="button" class="btn-close" aria-label="Close create API key" disabled="@IsBusy" @onclick="CloseCreateDialog"></button>
</div>
@if (!LastOperationSucceeded && !string.IsNullOrWhiteSpace(ResultMessage))
@@ -71,7 +71,7 @@ else
<EditForm Model="@CreateModel" OnSubmit="@CreateApiKeyAsync">
<div class="card mb-3">
<div class="card-body">
<h6 class="card-title">Create API Key</h6>
<h6 class="card-title">Create API key</h6>
<div class="mb-2">
<label for="keyId" class="form-label small">Key ID</label>
<input id="keyId" data-dialog-initial class="form-control form-control-sm" @bind="CreateModel.KeyId" @bind:event="oninput" />
@@ -9,7 +9,7 @@
@using ZB.MOM.WW.GalaxyRepository
@using ZB.MOM.WW.GalaxyRepository.Grpc
<PageTitle>Dashboard Browse</PageTitle>
<PageTitle>MXAccess Gateway — Browse</PageTitle>
<div class="dashboard-page-header">
<div>
@@ -52,7 +52,7 @@
{
@if (!string.IsNullOrWhiteSpace(_searchError))
{
<div class="alert alert-danger">Search failed: @_searchError</div>
<DashboardDiagnostic Title="Search unavailable. Your watched attributes are retained." Detail="@_searchError" RetryText="Retry search" OnRetry="@(() => ScheduleSearch(Search))" />
}
else if (_searchPending && _searchMatches.Count == 0)
{
@@ -107,7 +107,7 @@
<div class="browse-tree" role="region" aria-label="Galaxy hierarchy" tabindex="0">
@foreach (DashboardBrowseNode root in _roots)
{
<BrowseTreeNodeView Node="root"
<BrowseTreeNodeView @key="root.Object.GobjectId" Node="root"
OnAddTag="AddTagAsync"
OnTagContextMenu="OnTagContextMenu"
OnLoadChildren="LoadChildrenAsync" />
@@ -139,14 +139,12 @@
@if (!string.IsNullOrWhiteSpace(_readError))
{
<div class="alert alert-danger">Live read failed: @_readError</div>
<DashboardDiagnostic Title="Live values could not be refreshed. Watched attributes are retained." Detail="@_readError" RetryText="Retry live values" OnRetry="RetryReadAsync" />
}
@if (!string.IsNullOrWhiteSpace(_deployError))
{
<div class="alert alert-warning">
Galaxy redeploy notifications failed (retrying): @_deployError
</div>
<DashboardDiagnostic Severity="alert-warning" Title="Redeploy notifications unavailable. Reconnecting automatically." Detail="@_deployError" />
}
@if (_subscribed.Count == 0)
@@ -363,7 +361,7 @@
}
catch (Exception ex)
{
await ReportAsync(() => _deployError = ex.Message).ConfigureAwait(false);
await ReportAsync(() => _deployError = DashboardRedactor.Redact(ex.Message)).ConfigureAwait(false);
}
try
@@ -462,7 +460,7 @@
if (ReferenceEquals(_searchCts, searchCts))
{
_searchPending = false;
_searchError = ex.Message;
_searchError = DashboardRedactor.Redact(ex.Message);
}
}).ConfigureAwait(false);
}
@@ -632,7 +630,7 @@
}
catch (Exception ex)
{
await ReportAsync(() => _readError = ex.Message).ConfigureAwait(false);
await ReportAsync(() => _readError = DashboardRedactor.Redact(ex.Message)).ConfigureAwait(false);
}
}
}
@@ -655,35 +653,51 @@
}
}
private bool _reading;
private async Task RetryReadAsync()
{
try { await RefreshValuesAsync(); }
catch (OperationCanceledException) when (_cts.IsCancellationRequested) { }
catch (Exception ex) { _readError = DashboardRedactor.Redact(ex.Message); }
}
private async Task RefreshValuesAsync()
{
if (_subscribed.Count == 0)
if (_reading || _disposing) return;
_reading = true;
try
{
return;
}
string[] tags = [.. _subscribed];
DashboardLiveReadResult result = await LiveData.ReadAsync(tags, _viewerId, _cts.Token);
_readError = result.Error;
_workerPid = result.WorkerProcessId;
DateTimeOffset now = DateTimeOffset.UtcNow;
foreach (DashboardTagValue value in result.Values)
{
// Stamp the observed-change time only when the value/quality
// signature actually changes, so the Updated column does not
// tick on every poll for a static tag.
string signature = $"{value.ValueText}{value.Quality}{value.Ok}";
if (!_valueSignature.TryGetValue(value.TagAddress, out string? previous)
|| previous != signature)
if (_subscribed.Count == 0)
{
_valueSignature[value.TagAddress] = signature;
_observedChangeAt[value.TagAddress] = now;
return;
}
_values[value.TagAddress] = value;
}
string[] tags = [.. _subscribed];
DashboardLiveReadResult result = await LiveData.ReadAsync(tags, _viewerId, _cts.Token);
if (_disposing) return;
_readError = DashboardRedactor.Redact(result.Error);
_workerPid = result.WorkerProcessId;
DateTimeOffset now = DateTimeOffset.UtcNow;
foreach (DashboardTagValue value in result.Values)
{
// Stamp the observed-change time only when the value/quality
// signature actually changes, so the Updated column does not
// tick on every poll for a static tag.
string signature = $"{value.ValueText}{value.Quality}{value.Ok}";
if (!_valueSignature.TryGetValue(value.TagAddress, out string? previous)
|| previous != signature)
{
_valueSignature[value.TagAddress] = signature;
_observedChangeAt[value.TagAddress] = now;
}
StateHasChanged();
_values[value.TagAddress] = value;
}
StateHasChanged();
}
finally { _reading = false; }
}
/// <inheritdoc />
@@ -1,7 +1,7 @@
@page "/"
@inherits DashboardPageBase
<PageTitle>MXAccess Gateway Dashboard</PageTitle>
<PageTitle>MXAccess Gateway — Overview</PageTitle>
@if (Snapshot is null)
{
@@ -1,4 +1,6 @@
@using Microsoft.JSInterop
@using ZB.MOM.WW.GalaxyRepository.Grpc
@implements IDisposable
@*
Recursive Browse hierarchy node. Renders one Galaxy object, its child
@@ -16,7 +18,7 @@
<div class="tree-row @(Node.IsArea ? "tree-row-area" : "tree-row-object")">
@if (ShowToggle())
{
<button type="button" class="tree-node-toggle" @onclick="ToggleAsync"
<button @ref="_toggle" type="button" class="tree-node-toggle" @onclick="ToggleAsync"
aria-label="@($"{(_expanded ? "Collapse" : "Expand")} {Node.DisplayName}")"
aria-expanded="@(_expanded ? "true" : "false")" aria-controls="@ChildrenId">
<span class="tree-toggle" aria-hidden="true">@(_expanded ? "▾" : "▸")</span>
@@ -55,17 +57,16 @@
}
else if (Node.LoadState == BrowseLoadState.Error)
{
@* Abbreviated: sibling tree rows are nowrap inside a fixed-height
scroller, so a full COM/SQL error would stretch the whole pane. *@
<div class="tree-load-status text-danger" title="@Node.LoadError">
<span class="tree-toggle tree-toggle-empty"></span>
<span>Failed to load: @DashboardDisplay.Abbreviate(Node.LoadError, 60)</span>
</div>
<DashboardDiagnostic Title="@($"Could not load {Node.DisplayName}.")" Detail="@Node.LoadError"
DetailsLabel="@($"Show diagnostic details for {Node.DisplayName}")"
RetryText="@($"Retry loading {Node.DisplayName}")" OnRetry="RetryAsync" />
}
@if (_recovered)
{ <p class="browse-search-note" role="status">Loaded @Node.DisplayName.</p> }
@foreach (DashboardBrowseNode child in Node.Children)
{
<BrowseTreeNodeView Node="child"
<BrowseTreeNodeView @key="child.Object.GobjectId" Node="child"
OnAddTag="OnAddTag"
OnTagContextMenu="OnTagContextMenu"
OnLoadChildren="OnLoadChildren" />
@@ -124,7 +125,33 @@
[Parameter]
public Func<DashboardBrowseNode, Task>? OnLoadChildren { get; set; }
private ElementReference _toggle;
private bool _expanded;
private bool _recovered;
private bool _retrying;
private bool _disposed;
private long _generation;
private DashboardBrowseNode? _currentNode;
/// <inheritdoc />
protected override void OnParametersSet()
{
if (ReferenceEquals(_currentNode, Node)) return;
_currentNode = Node;
++_generation;
_retrying = false;
_recovered = false;
}
private bool IsCurrent(DashboardBrowseNode node, long generation) =>
!_disposed && generation == _generation && ReferenceEquals(Node, node);
/// <inheritdoc />
public void Dispose()
{
_disposed = true;
++_generation;
}
// The triangle is shown whenever the projector says children exist (even
// pre-load), or attributes are already present, or already-loaded children
@@ -138,7 +165,7 @@
private async Task ToggleAsync()
{
if (!ShowToggle())
if (_disposed || !ShowToggle())
{
return;
}
@@ -150,17 +177,47 @@
&& Node.LoadState == BrowseLoadState.NotLoaded
&& OnLoadChildren is not null)
{
Node.LoadState = BrowseLoadState.Loading;
try
{
await OnLoadChildren(Node);
Node.LoadState = BrowseLoadState.Loaded;
}
catch (Exception ex)
{
Node.LoadState = BrowseLoadState.Error;
Node.LoadError = ex.Message;
}
await LoadAsync(Node, OnLoadChildren, _generation, false);
}
}
private async Task RetryAsync()
{
DashboardBrowseNode node = Node;
Func<DashboardBrowseNode, Task>? load = OnLoadChildren;
long generation = _generation;
if (_disposed || _retrying || node.LoadState != BrowseLoadState.Error || load is null) return;
_retrying = true;
try
{
// The user action removes Retry; focus the same object's stable toggle.
await _toggle.FocusAsync();
if (!IsCurrent(node, generation)) return;
await LoadAsync(node, load, generation, true);
}
catch (JSDisconnectedException) { }
catch (OperationCanceledException) when (!IsCurrent(node, generation)) { }
finally { if (IsCurrent(node, generation)) _retrying = false; }
}
private async Task LoadAsync(DashboardBrowseNode node, Func<DashboardBrowseNode, Task> load, long generation, bool retry)
{
if (!IsCurrent(node, generation) || node.LoadState == BrowseLoadState.Loading) return;
node.LoadState = BrowseLoadState.Loading;
_recovered = false;
try
{
await load(node);
if (!IsCurrent(node, generation)) return;
node.LoadState = BrowseLoadState.Loaded;
node.LoadError = null;
_recovered = retry;
}
catch (Exception ex)
{
if (!IsCurrent(node, generation)) return;
node.LoadState = BrowseLoadState.Error;
node.LoadError = DashboardRedactor.Redact(ex.Message);
}
}
@@ -0,0 +1,19 @@
<div class="alert @Severity dashboard-diagnostic">
<p class="mb-1" role="alert">@Title</p>
<details>
<summary>@DetailsLabel</summary>
<pre tabindex="0" role="region" aria-label="@($"{Title} details")">@DashboardRedactor.Redact(Detail)</pre>
</details>
@if (OnRetry.HasDelegate)
{
<button type="button" class="btn btn-outline-secondary btn-sm mt-2" @onclick="OnRetry">@RetryText</button>
}
</div>
@code {
[Parameter, EditorRequired] public string Title { get; set; } = string.Empty;
[Parameter] public string DetailsLabel { get; set; } = "Diagnostic details";
[Parameter] public string? Detail { get; set; }
[Parameter] public string Severity { get; set; } = "alert-danger";
[Parameter] public EventCallback OnRetry { get; set; }
[Parameter] public string RetryText { get; set; } = "Retry";
}
@@ -7,7 +7,7 @@ else if (Compact)
<div class="fault-summaries">
@foreach (DashboardFaultSummary fault in Faults)
{
<article class="fault-summary">
<article @key="(fault.SessionId, fault.Source, fault.WorkerProcessId, fault.Message)" class="fault-summary">
<div class="d-flex gap-2 flex-wrap align-items-center"><strong>@fault.Source</strong><StatusBadge Text="@fault.State" /></div>
@if (fault.Message.Length > 160)
{
@@ -47,7 +47,7 @@ else
<tbody>
@foreach (DashboardFaultSummary fault in Faults)
{
<tr>
<tr @key="(fault.SessionId, fault.Source, fault.WorkerProcessId, fault.Message)">
<td>@DashboardDisplay.DateTime(fault.ObservedAt)</td>
<td>@fault.Source</td>
<td>
@@ -22,8 +22,8 @@
<PackageReference Include="ZB.MOM.WW.Telemetry.Serilog" Version="0.3.1" />
<PackageReference Include="ZB.MOM.WW.GalaxyRepository" Version="0.2.0" />
<PackageReference Include="ZB.MOM.WW.Secrets" Version="0.6.2" />
<PackageReference Include="ZB.MOM.WW.Secrets.Abstractions" Version="0.6.2" />
<PackageReference Include="ZB.MOM.WW.Secrets.Ui" Version="0.6.2" />
<PackageReference Include="ZB.MOM.WW.Secrets.Abstractions" Version="0.6.6" />
<PackageReference Include="ZB.MOM.WW.Secrets.Ui" Version="1.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
@@ -41,7 +41,7 @@ body.dashboard-body { min-height: 100vh; }
/* ── KPI / aggregate cards ───────────────────────────────────────────────────
The MetricCard component renders .agg-card with label/value/sub; this is
the technical-light aggregate card — uppercase eyebrow, big mono number.
the technical-light aggregate card with a compact label and tabular value.
Class names align with master (ScadaLink CentralUI) for consistency. */
.metric-grid {
display: grid;
@@ -131,7 +131,7 @@ body.dashboard-body { min-height: 100vh; }
text-transform: uppercase;
letter-spacing: 0.05em;
color: var(--ink-faint);
background: #fbfbf9;
background: var(--zebra-bg);
white-space: nowrap;
}
.dashboard-table td {
@@ -141,7 +141,7 @@ body.dashboard-body { min-height: 100vh; }
overflow-wrap: break-word;
}
.dashboard-table tbody tr:last-child td { border-bottom: none; }
.dashboard-table tbody tr:hover { background: #f3f6fd; }
.dashboard-table tbody tr:hover { background: var(--hover-bg); }
/* Key/value detail tables: left label column, monospace values, zebra rows. */
.details-table th {
@@ -159,8 +159,8 @@ body.dashboard-body { min-height: 100vh; }
font-size: 0.82rem;
color: var(--ink);
}
.details-table tbody tr:nth-child(even) { background: #fbfbf9; }
.details-table tbody tr:hover { background: #fbfbf9; }
.details-table tbody tr:nth-child(even) { background: var(--zebra-bg); }
.details-table tbody tr:hover { background: var(--zebra-bg); }
/* Inline code: monospace, accent ink, no Bootstrap pink. */
code {
@@ -174,7 +174,7 @@ code {
/* ── Empty / placeholder state ───────────────────────────────────────────────*/
.empty-state {
background: #fbfbf9;
background: var(--zebra-bg);
border: 1px dashed var(--rule-strong);
border-radius: 6px;
color: var(--ink-faint);
@@ -196,17 +196,8 @@ code {
literal rather than --bs-btn-border-radius so .btn-sm cannot shrink it; the
.btn-group seam rules outrank .btn, so groups still render seamed. */
.btn { border-radius: 5px; font-weight: 500; white-space: nowrap; }
.btn-primary {
background: var(--accent);
border-color: var(--accent);
color: #fff;
}
.btn-primary:hover,
.btn-primary:focus {
background: var(--accent-deep);
border-color: var(--accent-deep);
color: #fff;
}
/* Pointer focus remains deep after the click; shared Theme owns normal/hover/active/disabled. */
.btn-primary:focus { background: var(--accent-deep); border-color: var(--accent-deep); color: var(--on-accent); }
.btn-outline-secondary {
color: var(--ink-soft);
background: var(--card);
@@ -214,18 +205,18 @@ code {
}
.btn-outline-secondary:hover {
color: var(--ink);
background: #f0f0ec;
background: var(--hover-bg);
border-color: var(--rule-strong);
}
.btn-outline-danger {
color: var(--bad);
color: var(--bad-ink);
background: var(--card);
border-color: #eec3c3;
border-color: var(--bad-border);
}
.btn-outline-danger:hover {
color: #fff;
color: var(--on-accent);
background: var(--bad);
border-color: var(--bad);
border-color: var(--bad-ink);
}
/* ── Forms ───────────────────────────────────────────────────────────────────*/
@@ -242,16 +233,10 @@ code {
border-color: var(--rule-strong);
border-radius: 5px;
}
.form-control:focus,
.form-select:focus {
border-color: var(--accent);
box-shadow: 0 0 0 0.15rem rgba(47, 95, 208, 0.15);
}
/* ── Alerts ──────────────────────────────────────────────────────────────────*/
.alert { border-radius: 6px; border-width: 1px; font-size: 0.85rem; }
.alert-success { color: var(--ok); background: var(--ok-bg); border-color: #c6e6cd; }
.alert-danger { color: var(--bad); background: var(--bad-bg); border-color: #eec3c3; }
.alert-success { color: var(--ok-ink); background: var(--ok-bg); border-color: var(--ok-border); }
.alert-danger { color: var(--bad-ink); background: var(--bad-bg); border-color: var(--bad-border); }
/* ── API key management ──────────────────────────────────────────────────────*/
.api-key-management-grid {
@@ -321,7 +306,7 @@ code {
border: 1px solid var(--rule);
border-radius: 6px;
padding: 0.3rem 0;
background: #fbfbf9;
background: var(--zebra-bg);
}
.browse-search-results { padding: 0.15rem 0; }
@@ -337,7 +322,7 @@ code {
white-space: nowrap;
}
.tree-row:hover,
.tree-attr:hover { background: #eef2fb; }
.tree-attr:hover { background: var(--hover-bg); }
.tree-toggle {
flex: none;
@@ -394,8 +379,8 @@ code {
padding: 0.02rem 0.28rem;
border-radius: 3px;
}
.attr-flag-alarm { color: var(--bad); background: var(--bad-bg); }
.attr-flag-hist { color: var(--accent-deep); background: #e7ecfb; }
.attr-flag-alarm { color: var(--bad-ink); background: var(--bad-bg); }
.attr-flag-hist { color: var(--accent-deep); background: var(--accent-tint); }
/* ── Subscription panel ───────────────────────────────────────────────────── */
.sub-panel-meta {
@@ -424,11 +409,11 @@ code {
padding: 0.05rem 0.4rem;
border-radius: 3px;
}
.quality-good { color: var(--ok); background: var(--ok-bg); }
.quality-bad { color: var(--bad); background: var(--bad-bg); }
.quality-good { color: var(--ok-ink); background: var(--ok-bg); }
.quality-bad { color: var(--bad-ink); background: var(--bad-bg); }
.sub-error {
margin-left: 0.3rem;
color: var(--bad);
color: var(--bad-ink);
font-weight: 700;
cursor: help;
}
@@ -447,7 +432,7 @@ code {
background: var(--card);
border: 1px solid var(--rule-strong);
border-radius: 6px;
box-shadow: 0 6px 20px rgba(27, 29, 33, 0.16);
box-shadow: 0 6px 20px color-mix(in srgb, var(--ink) 16%, transparent);
padding: 0.25rem;
}
.context-menu-head {
@@ -474,7 +459,7 @@ code {
border-radius: 4px;
cursor: pointer;
}
.context-menu-item:hover { background: #eef2fb; color: var(--accent-deep); }
.context-menu-item:hover { background: var(--hover-bg); color: var(--accent-deep); }
/* ── Alarms tab ───────────────────────────────────────────────────────────── */
.alarm-filters {
@@ -505,9 +490,9 @@ code {
border-radius: 3px;
white-space: nowrap;
}
.alarm-state-active { color: var(--bad); background: var(--bad-bg); }
.alarm-state-acked { color: var(--warn); background: var(--warn-bg); }
.alarm-state-other { color: var(--idle); background: var(--idle-bg); }
.alarm-state-active { color: var(--bad-ink); background: var(--bad-bg); }
.alarm-state-acked { color: var(--warn-ink); background: var(--warn-bg); }
.alarm-state-other { color: var(--idle-ink); background: var(--idle-bg); }
.alarm-severity {
font-family: var(--mono);
font-variant-numeric: tabular-nums;
@@ -580,3 +565,27 @@ code {
.fault-summary { min-width: 0; overflow-wrap: anywhere; }
.fault-summary + .fault-summary { border-top: 1px solid var(--rule); padding-top: 1rem; }
.fault-context { display: flex; flex-wrap: wrap; gap: .25rem 1rem; color: var(--ink-faint); font-size: .875rem; }
/* Bootstrap utilities need host adapters because its color declarations are !important. */
.text-success { color: var(--ok-ink) !important; }
.text-warning { color: var(--warn-ink) !important; }
.text-danger { color: var(--bad-ink) !important; }
.text-info { color: var(--info-ink) !important; }
.text-primary { color: var(--accent-deep) !important; }
.text-secondary, .text-muted { color: var(--ink-faint) !important; }
.alert-info { color: var(--info-ink); background: var(--info-bg); border-color: var(--info-border); }
.alert-warning { color: var(--warn-ink); background: var(--warn-bg); border-color: var(--warn-border); }
@media (prefers-reduced-motion: reduce) {
.dashboard-page-header, .metric-grid, .dashboard-section { animation: none; opacity: 1; transform: none; }
}
.dashboard-diagnostic { min-width: 0; overflow-wrap: anywhere; }
.dashboard-diagnostic pre { max-height: 16rem; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: inherit; }
.dashboard-diagnostic summary { cursor: pointer; }
@media (pointer: coarse) {
.dashboard-diagnostic summary, .fault-diagnostic > summary, .supporting-counters > summary {
min-height: 44px;
padding-block: .65rem;
}
}
@@ -0,0 +1,170 @@
using System.Reflection;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.HtmlRendering;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.JSInterop;
using ZB.MOM.WW.GalaxyRepository.Grpc;
using ZB.MOM.WW.MxGateway.Server.Dashboard;
using ZB.MOM.WW.MxGateway.Server.Dashboard.Components.Shared;
namespace ZB.MOM.WW.MxGateway.Tests.Dashboard;
/// <summary>Real component/event lifecycle regressions across the native focus interop await.</summary>
public sealed class BrowseTreeRetryLifecycleTests
{
/// <summary>An old Retry cannot follow a replacement parameter into another object's load.</summary>
[Fact]
public async Task Retry_NodeReplacedWhileFocusPending_DoesNotDispatchForEitherIdentity()
{
await using var fixture = await RetryFixture.CreateAsync();
Task retry = fixture.FireAsync("RetryAsync");
await fixture.JavaScript.FocusEntered.Task.WaitAsync(TimeSpan.FromSeconds(5));
DashboardBrowseNode replacement = ErrorNode(2, "Replacement");
try
{
await fixture.Renderer.Dispatcher.InvokeAsync(() => fixture.Component.SetParametersAsync(
Parameters(replacement, fixture.LoadAsync)));
}
finally { fixture.JavaScript.ReleaseFocus.TrySetResult(); }
await retry.WaitAsync(TimeSpan.FromSeconds(5));
Assert.Equal(1, fixture.JavaScript.FocusCalls);
Assert.Empty(fixture.LoadedNodes);
Assert.Equal(BrowseLoadState.Error, replacement.LoadState);
string html = await fixture.Renderer.Dispatcher.InvokeAsync(fixture.Root.ToHtmlString);
Assert.DoesNotContain("Loaded Replacement.", html, StringComparison.Ordinal);
}
/// <summary>Disposing the actual renderer during focus prevents a later load callback.</summary>
[Fact]
public async Task Retry_RendererDisposedWhileFocusPending_DoesNotDispatchAfterDisposal()
{
await using var fixture = await RetryFixture.CreateAsync();
Task retry = fixture.FireAsync("RetryAsync");
await fixture.JavaScript.FocusEntered.Task.WaitAsync(TimeSpan.FromSeconds(5));
try { await fixture.DisposeRendererAsync(); }
finally { fixture.JavaScript.ReleaseFocus.TrySetResult(); }
await retry.WaitAsync(TimeSpan.FromSeconds(5));
Assert.Equal(1, fixture.JavaScript.FocusCalls);
Assert.Empty(fixture.LoadedNodes);
Assert.Equal(BrowseLoadState.Error, fixture.Original.LoadState);
}
private static DashboardBrowseNode ErrorNode(int id, string name) => new()
{
Object = new GalaxyObject { GobjectId = id, BrowseName = name, TagName = name },
HasChildrenHint = true,
LoadState = BrowseLoadState.Error,
LoadError = "Synthetic child load failure",
};
private static ParameterView Parameters(DashboardBrowseNode node, Func<DashboardBrowseNode, Task> load)
=> ParameterView.FromDictionary(new Dictionary<string, object?>
{
[nameof(BrowseTreeNodeView.Node)] = node,
[nameof(BrowseTreeNodeView.OnLoadChildren)] = load,
});
private sealed class RetryFixture : IAsyncDisposable
{
private readonly ServiceProvider _services;
private bool _rendererDisposed;
public HtmlRenderer Renderer { get; }
public HtmlRootComponent Root { get; private set; }
public BrowseTreeNodeView Component { get; private set; } = null!;
public DeferredFocusRuntime JavaScript { get; } = new();
public DashboardBrowseNode Original { get; } = ErrorNode(1, "Original");
public List<DashboardBrowseNode> LoadedNodes { get; } = [];
private RetryFixture()
{
ServiceCollection services = new();
services.AddLogging();
services.AddSingleton<IJSRuntime>(JavaScript);
services.AddSingleton<IComponentActivator, CapturingActivator>();
_services = services.BuildServiceProvider();
Renderer = new(_services, _services.GetRequiredService<ILoggerFactory>());
}
public static async Task<RetryFixture> CreateAsync()
{
var fixture = new RetryFixture();
fixture.Root = await fixture.Renderer.Dispatcher.InvokeAsync(() =>
fixture.Renderer.RenderComponentAsync<BrowseTreeNodeView>(Parameters(fixture.Original, fixture.LoadAsync)));
fixture.Component = fixture._services.GetRequiredService<IComponentActivator>() is CapturingActivator activator
? activator.Component! : throw new InvalidOperationException("Component activator was not used.");
Assert.NotNull(fixture.Component);
await fixture.FireAsync("ToggleAsync");
// HtmlRenderer is deliberately DOM-free. Give only its native ElementReference
// the normal web context; FocusAsync itself still executes the actual runtime seam.
FieldInfo field = typeof(BrowseTreeNodeView).GetField("_toggle", BindingFlags.Instance | BindingFlags.NonPublic)!;
field.SetValue(fixture.Component, new ElementReference("synthetic-retry-toggle", new WebElementReferenceContext(fixture.JavaScript)));
return fixture;
}
public Task LoadAsync(DashboardBrowseNode node)
{
LoadedNodes.Add(node);
return Task.CompletedTask;
}
public Task FireAsync(string handler)
{
MethodInfo method = typeof(BrowseTreeNodeView).GetMethod(handler, BindingFlags.Instance | BindingFlags.NonPublic)!;
var callback = (Func<Task>)method.CreateDelegate(typeof(Func<Task>), Component);
// EventCallback invokes ComponentBase.IHandleEvent, including its real async
// render lifecycle; this is not a detached new component or a declaration check.
return Renderer.Dispatcher.InvokeAsync(() => EventCallback.Factory.Create(Component, callback).InvokeAsync());
}
public async ValueTask DisposeRendererAsync()
{
if (_rendererDisposed) return;
_rendererDisposed = true;
await Renderer.DisposeAsync();
}
public async ValueTask DisposeAsync()
{
JavaScript.ReleaseFocus.TrySetResult();
await DisposeRendererAsync();
await _services.DisposeAsync();
}
}
private sealed class CapturingActivator : IComponentActivator
{
public BrowseTreeNodeView? Component { get; private set; }
public IComponent CreateInstance(Type componentType)
{
var component = (IComponent)Activator.CreateInstance(componentType)!;
if (component is BrowseTreeNodeView node) Component = node;
return component;
}
}
private sealed class DeferredFocusRuntime : IJSRuntime
{
public TaskCompletionSource FocusEntered { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously);
public TaskCompletionSource ReleaseFocus { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously);
public int FocusCalls { get; private set; }
public ValueTask<TValue> InvokeAsync<TValue>(string identifier, object?[]? args)
{
Assert.Equal("Blazor._internal.domWrapper.focus", identifier);
Assert.IsType<ElementReference>(args![0]);
FocusCalls++;
FocusEntered.TrySetResult();
return new(AwaitFocusAsync<TValue>());
}
public ValueTask<TValue> InvokeAsync<TValue>(string identifier, CancellationToken cancellationToken, object?[]? args)
=> InvokeAsync<TValue>(identifier, args);
private async Task<TValue> AwaitFocusAsync<TValue>()
{
await ReleaseFocus.Task;
return default!;
}
}
}
@@ -0,0 +1,45 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using ZB.MOM.WW.MxGateway.Server.Dashboard.Components.Shared;
namespace ZB.MOM.WW.MxGateway.Tests.Dashboard;
/// <summary>Recoverable diagnostics preserve escaped detail and the existing redaction boundary.</summary>
public sealed class DashboardDiagnosticRenderTests
{
/// <summary>A sensitive exception must not reach the visible or disclosed diagnostic.</summary>
[Theory]
[InlineData("password=fixture-sensitive")]
[InlineData("authorization: fixture-sensitive")]
[InlineData("api_key=fixture-sensitive")]
public async Task SensitiveDiagnostic_IsRedacted(string error)
{
string html = await RenderAsync(error);
Assert.DoesNotContain("fixture-sensitive", html, StringComparison.Ordinal);
Assert.Contains("Diagnostic details", html, StringComparison.Ordinal);
Assert.Contains("role=\"alert\"", html, StringComparison.Ordinal);
}
/// <summary>Long non-sensitive detail remains complete, escaped and accessible without hover.</summary>
[Fact]
public async Task LongDiagnostic_PreservesCompleteEscapedText()
{
string error = new('x', 600);
string html = await RenderAsync(error + "<script>fixture</script>");
Assert.Contains(error, html, StringComparison.Ordinal);
Assert.Contains("&lt;script&gt;fixture&lt;/script&gt;", html, StringComparison.Ordinal);
Assert.Contains("tabindex=\"0\"", html, StringComparison.Ordinal);
Assert.DoesNotContain("<script>", html, StringComparison.Ordinal);
}
private static async Task<string> RenderAsync(string error)
{
ServiceCollection services = new(); services.AddLogging();
await using ServiceProvider provider = services.BuildServiceProvider();
await using HtmlRenderer renderer = new(provider, provider.GetRequiredService<ILoggerFactory>());
return await renderer.Dispatcher.InvokeAsync(async () => (await renderer.RenderComponentAsync<DashboardDiagnostic>(
ParameterView.FromDictionary(new Dictionary<string, object?> { [nameof(DashboardDiagnostic.Title)] = "Load unavailable", [nameof(DashboardDiagnostic.Detail)] = error }))).ToHtmlString());
}
}