Merge branch 'review/wp5' into review/integration
This commit is contained in:
@@ -894,4 +894,39 @@ public class HealthPageTests : BunitContext
|
||||
Nodes: Array.Empty<SiteCallNodeKpiSnapshot>())));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-4: navigating away while the initial loads are still running
|
||||
/// disposes the page first; the load's continuation must then not create the 10 s refresh
|
||||
/// timer (it would never be disposed and would root the dead circuit).
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task DisposedDuringInitialLoad_CreatesNoRefreshTimer()
|
||||
{
|
||||
SeedSites("site-a");
|
||||
var entered = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var gate = new TaskCompletionSource<IReadOnlyList<KpiSeriesPoint>>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var kpiHistory = Substitute.For<IKpiHistoryQueryService>();
|
||||
kpiHistory.GetSeriesAsync(
|
||||
Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string?>(),
|
||||
Arg.Any<DateTime>(), Arg.Any<DateTime>(), Arg.Any<int?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_ => { entered.TrySetResult(); return gate.Task; });
|
||||
Services.AddSingleton(kpiHistory);
|
||||
|
||||
var host = RenderHealthPage();
|
||||
await entered.Task.WaitAsync(TimeSpan.FromSeconds(10)); // the last load phase is in flight
|
||||
var page = host.Instance;
|
||||
await host.InvokeAsync(page.Dispose);
|
||||
|
||||
gate.SetResult(SampleSeries());
|
||||
host.WaitForAssertion(() => Assert.False((bool)typeof(HealthPage)
|
||||
.GetField("_trendsLoading", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
|
||||
.GetValue(page)!));
|
||||
await host.InvokeAsync(() => { });
|
||||
|
||||
Assert.Null(typeof(HealthPage)
|
||||
.GetField("_refreshTimer", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
|
||||
.GetValue(page));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +179,56 @@ public class NotificationReportPageTests : BunitContext
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-11: a parked row whose source site no longer resolves (site
|
||||
/// deleted or renamed) stays visible; a system-wide user can Retry it, while a site-scoped
|
||||
/// user is still refused (there is no Site.Id to authorize against).
|
||||
/// </summary>
|
||||
/// <param name="siteScoped">Whether the caller carries a SiteId claim (site-scoped Deployer).</param>
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void Retry_OnRowFromADeletedSite_AllowedSystemWide_DeniedScoped(bool siteScoped)
|
||||
{
|
||||
_queryReply = _queryReply with
|
||||
{
|
||||
Notifications = new List<NotificationSummary>
|
||||
{
|
||||
new("notif-cccccccc-3333", "Email", "Ops On-Call", "Orphaned alert",
|
||||
"Parked", RetryCount: 5, LastError: "SMTP timeout", SourceSiteId: "deleted-site",
|
||||
SourceInstanceId: "Pump-009", CreatedAt: DateTimeOffset.UtcNow.AddMinutes(-30),
|
||||
DeliveredAt: null, IsStuck: false),
|
||||
},
|
||||
TotalCount = 1,
|
||||
};
|
||||
if (siteScoped)
|
||||
{
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(JwtTokenService.UsernameClaimType, "tester"),
|
||||
new Claim(JwtTokenService.RoleClaimType, "Deployer"),
|
||||
new Claim(JwtTokenService.SiteIdClaimType, "1"),
|
||||
};
|
||||
Services.AddSingleton<AuthenticationStateProvider>(
|
||||
new TestAuthStateProvider(new ClaimsPrincipal(new ClaimsIdentity(claims, "TestAuth"))));
|
||||
}
|
||||
|
||||
var cut = Render<NotificationReportPage>();
|
||||
cut.WaitForState(() => cut.Markup.Contains("Orphaned alert"));
|
||||
cut.FindAll("tbody tr").First(r => r.TextContent.Contains("Orphaned alert"))
|
||||
.QuerySelectorAll("button").First(b => b.TextContent.Contains("Retry")).Click();
|
||||
|
||||
if (siteScoped)
|
||||
{
|
||||
cut.WaitForAssertion(() => Assert.Contains("not permitted to act on notifications", cut.Markup));
|
||||
Assert.Empty(_retryRequests);
|
||||
}
|
||||
else
|
||||
{
|
||||
cut.WaitForAssertion(() => Assert.Equal("notif-cccccccc-3333", Assert.Single(_retryRequests).NotificationId));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a query failure shows an error message.</summary>
|
||||
[Fact]
|
||||
public void QueryFailure_ShowsErrorMessage()
|
||||
|
||||
@@ -221,6 +221,56 @@ public class SiteCallsReportPageTests : BunitContext
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-11: a parked cached call whose source site no longer resolves
|
||||
/// (site deleted or renamed) stays visible; a system-wide user can Retry it, while a
|
||||
/// site-scoped user is still refused.
|
||||
/// </summary>
|
||||
/// <param name="siteScoped">Whether the caller carries a SiteId claim (site-scoped Deployer).</param>
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void Retry_OnRowFromADeletedSite_AllowedSystemWide_DeniedScoped(bool siteScoped)
|
||||
{
|
||||
var orphanId = Guid.Parse("33333333-3333-3333-3333-333333333333");
|
||||
_queryReply = _queryReply with
|
||||
{
|
||||
SiteCalls = new List<SiteCallSummary>
|
||||
{
|
||||
new(orphanId, "deleted-site", "ApiOutbound", "ERP.Orphan", "Parked",
|
||||
RetryCount: 5, LastError: "HTTP 503", HttpStatus: 503,
|
||||
CreatedAtUtc: DateTime.UtcNow.AddMinutes(-30), UpdatedAtUtc: DateTime.UtcNow.AddMinutes(-5),
|
||||
TerminalAtUtc: null, IsStuck: false),
|
||||
},
|
||||
};
|
||||
if (siteScoped)
|
||||
{
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(JwtTokenService.UsernameClaimType, "tester"),
|
||||
new Claim(JwtTokenService.RoleClaimType, "Deployer"),
|
||||
new Claim(JwtTokenService.SiteIdClaimType, "1"),
|
||||
};
|
||||
Services.AddSingleton<AuthenticationStateProvider>(
|
||||
new TestAuthStateProvider(new ClaimsPrincipal(new ClaimsIdentity(claims, "TestAuth"))));
|
||||
}
|
||||
|
||||
var cut = Render<SiteCallsReportPage>();
|
||||
cut.WaitForState(() => cut.Markup.Contains("ERP.Orphan"));
|
||||
cut.FindAll("tbody tr").First(r => r.TextContent.Contains("ERP.Orphan"))
|
||||
.QuerySelectorAll("button").First(b => b.TextContent.Contains("Retry")).Click();
|
||||
|
||||
if (siteScoped)
|
||||
{
|
||||
cut.WaitForAssertion(() => Assert.Contains("not permitted to act on cached calls", cut.Markup));
|
||||
Assert.Empty(_retryRequests);
|
||||
}
|
||||
else
|
||||
{
|
||||
cut.WaitForAssertion(() => Assert.Equal(orphanId, Assert.Single(_retryRequests).TrackedOperationId));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Verifies that clicking Discard on a parked row relays the discard to the owning site.</summary>
|
||||
[Fact]
|
||||
public void ClickDiscard_OnParkedRow_RelaysDiscardToOwningSite()
|
||||
|
||||
Reference in New Issue
Block a user