b222362ce0
Fixes every finding from the codereviews/2026-05-16 multi-agent review (2 Critical, 20 Major, 38 Minor) and adds that review to the repo. Highlights: dashboard XSS escape; response cache invalidated on the write request (not just the response); ReloadValidator now runs at startup so port collisions / duplicate names / malformed Resilience profiles fail fast; AdminPort 0 genuinely disables the admin endpoint; PlcListener accept-loop faults propagate to the supervisor's faulted path; reconciler Restart builds before removing; Resilience pipelines are restart-only from a frozen snapshot; multiplexer connect-race leak, watchdog party-list snapshot, backend-response and FC16 framing validation; frontend reconnect retry and util.js load guard; plus the log-event/doc drift sweep and test-port hygiene. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
51 lines
2.0 KiB
C#
51 lines
2.0 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 configuration AdminEndpointHost applies to the hub's
|
|
// PayloadSerializerOptions — referenced, not copied, so the two cannot drift.
|
|
private static readonly JsonSerializerOptions HubOptions = BuildHubOptions();
|
|
|
|
private static JsonSerializerOptions BuildHubOptions()
|
|
{
|
|
var o = new JsonSerializerOptions();
|
|
AdminEndpointHost.ConfigureHubPayloadJson(o);
|
|
return o;
|
|
}
|
|
|
|
[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);
|
|
}
|
|
}
|