Files
wwtools/mbproxy/tests/Mbproxy.Tests/Admin/DebugDtoSerializationTests.cs
T
Joseph Doherty 374eecd205 mbproxy: fix the dashboard's C2/M-series review findings
Closes the on-demand-capture leak cluster from the code review. The capture's armed state was driven off SignalR's ConnectionId, which changes on every transport reconnect, so a reconnect-during-view leaked a subscriber and left the capture armed forever with no viewer. PlcSubscriptionTracker now keys on a stable per-page-load tabId, and StatusBroadcaster reconciles capture arm state from the live viewer set each push cycle — making arming single-threaded and reconnect-safe. Also fixes the TagValueCapture disarm-vs-record race, the bind-failure broadcaster/listener leak, removes dead JSON-context code, and reworks the frontend cold-start retry plus an unknown-PLC watchdog. Adds tracker / broadcaster-loop / race / wire-shape test coverage.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 16:12:43 -04:00

44 lines
1.8 KiB
C#

using System.Text.Json;
using Mbproxy.Admin;
using Shouldly;
using Xunit;
namespace Mbproxy.Tests.Admin;
/// <summary>
/// Locks the SignalR payload wire shape. The hub serialises detail / fleet payloads
/// with a camelCase property policy (see <c>AdminEndpointHost</c>'s <c>AddJsonProtocol</c>),
/// and the dashboard JS reads camelCase field names — so a regression to the naming
/// policy would silently break every field on the live feed with no other failing test.
/// </summary>
[Trait("Category", "Unit")]
public sealed class DebugDtoSerializationTests
{
// The exact policy AdminEndpointHost configures on the hub's PayloadSerializerOptions.
private static readonly JsonSerializerOptions HubOptions =
new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
[Fact]
public void PlcDetailResponse_SerializesWithCamelCaseFieldNames()
{
var detail = new PlcDetailResponse(
Plc: null,
Debug: new PlcDebugSnapshot(
CaptureArmed: true,
Tags: [new TagValueDto(
Address: 100, Width: 16, Name: "Left AirSP", HasValue: true,
Direction: "read", RawHex: "0x1234", DecodedValue: 1234,
UpdatedAtUtc: "2026-05-16T00:00:00Z", AgeSeconds: 1.5)]));
string json = JsonSerializer.Serialize(detail, HubOptions);
// Case.Sensitive throughout — Shouldly's string contains defaults to
// case-insensitive, which would not distinguish camelCase from PascalCase.
json.ShouldContain("\"captureArmed\"", Case.Sensitive);
json.ShouldContain("\"decodedValue\"", Case.Sensitive);
json.ShouldContain("\"updatedAtUtc\"", Case.Sensitive);
json.ShouldNotContain("\"CaptureArmed\"", Case.Sensitive);
json.ShouldNotContain("\"DecodedValue\"", Case.Sensitive);
}
}