fix(grpc-data): H4 review 5+6 — AdminUI display: 'unavailable' without handshake evidence; every bit rendered

HistoryServed reads 'unavailable' when neither features nor variants were reported. Features()
and DroppedBits() render every set bit across all 32 (bit 31 included), named when known and hex
otherwise, so an unknown bit is never hidden beside a known one (#919).
This commit is contained in:
Joseph Doherty
2026-11-24 08:39:46 -05:00
parent 79cf50d50e
commit 2fba036176
2 changed files with 18 additions and 7 deletions
@@ -26,17 +26,23 @@ public static class DataConnectionDiagnostics
"auth-failed" => "Authentication failed", "backoff" => "Backoff", _ => "Unavailable"
};
/// <summary>H4: the features the last handshake negotiated; "none (v1)" when the peer negotiated nothing optional.</summary>
/// <remarks>Every set bit is shown — a name when this AdminUI knows it, hex otherwise (H4 review: never hidden by a known one).</remarks>
public static string Features(DataFeatures? features) => features switch
{
null => "unavailable",
DataFeatures.None => "none (v1 behaviour)",
{ } f => string.Join(", ", Enum.GetValues<DataFeatures>().Where(x => x != DataFeatures.None && f.HasFlag(x)).Select(x => x.ToString())
.DefaultIfEmpty($"0x{(int)f:X}")),
{ } f => Bits((uint)(int)f, bit => Enum.IsDefined((DataFeatures)(int)bit) ? ((DataFeatures)(int)bit).ToString() : null),
};
/// <summary>Each set bit of <paramref name="value"/> across all 32, low to high: its name, or hex when unnamed.</summary>
private static string Bits(uint value, Func<uint, string?> name) =>
string.Join(", ", Enumerable.Range(0, 32).Select(i => 1u << i).Where(bit => (value & bit) != 0)
.Select(bit => name(bit) ?? $"0x{bit:X}"));
/// <summary>H4: the history variants and aggregate count the origin advertised to this caller.</summary>
public static string HistoryServed(DataConnectionDiagnosticsSnapshot row) =>
row.HistoryVariants is not { } variants ? "not advertised"
row.NegotiatedFeatures is null && row.HistoryVariants is null ? "unavailable"
: row.HistoryVariants is not { } variants ? "not advertised"
: variants.Count == 0 ? "advertised, no variant granted"
: string.Join(", ", variants) + (row.HistoryAggregateCount is { } n ? $" ({n} aggregates)" : "");
@@ -53,8 +59,7 @@ public static class DataConnectionDiagnostics
{
null => "unavailable",
DataOperations.None => "none",
{ } b => string.Join(", ", Enumerable.Range(0, 31).Select(i => (DataOperations)(1 << i)).Where(x => b.HasFlag(x))
.Select(x => Enum.IsDefined(x) ? DataOperationAuthoring.Label(x) : $"0x{(int)x:X}")),
{ } b => Bits((uint)(int)b, bit => Enum.IsDefined((DataOperations)(int)bit) ? DataOperationAuthoring.Label((DataOperations)(int)bit) : null),
};
/// <summary>#919: true when the drop deserves the "node build is older than the authored feature" hint.</summary>
@@ -20,13 +20,17 @@ public sealed class GrpcDataHistoryDiagnosticsDisplayTests
DataConnectionDiagnostics.Features(DataFeatures.None).ShouldBe("none (v1 behaviour)");
DataConnectionDiagnostics.Features(DataFeatures.History).ShouldBe("History");
DataConnectionDiagnostics.Features(DataFeatures.History | DataFeatures.Conditions).ShouldBe("History, Conditions");
// H4 review 6: an unknown bit is never hidden by a known one.
DataConnectionDiagnostics.Features(DataFeatures.History | (DataFeatures)8).ShouldBe("History, 0x8");
DataConnectionDiagnostics.Features((DataFeatures)int.MinValue).ShouldBe("0x80000000");
}
[Fact]
public void Origin_history_shows_the_advertised_variants_and_aggregate_count()
{
DataConnectionDiagnostics.HistoryServed(Row()).ShouldBe("not advertised");
DataConnectionDiagnostics.HistoryServed(Row() with { HistoryVariants = [] }).ShouldBe("advertised, no variant granted");
DataConnectionDiagnostics.HistoryServed(Row()).ShouldBe("unavailable", "no handshake evidence at all (H4 review 5)");
DataConnectionDiagnostics.HistoryServed(Row() with { NegotiatedFeatures = DataFeatures.None }).ShouldBe("not advertised");
DataConnectionDiagnostics.HistoryServed(Row() with { NegotiatedFeatures = DataFeatures.History, HistoryVariants = [] }).ShouldBe("advertised, no variant granted");
DataConnectionDiagnostics.HistoryServed(Row() with { HistoryVariants = ["raw", "processed", "attime"], HistoryAggregateCount = 12 })
.ShouldBe("raw, processed, attime (12 aggregates)");
}
@@ -45,6 +49,8 @@ public sealed class GrpcDataHistoryDiagnosticsDisplayTests
DataConnectionDiagnostics.DroppedBits(DataOperations.None).ShouldBe("none");
DataConnectionDiagnostics.DroppedBits(DataOperations.HistoryRead | DataOperations.AlarmSubscribe).ShouldBe("HistoryRead, AlarmSubscribe");
DataConnectionDiagnostics.DroppedBits((DataOperations)(1 << 20)).ShouldBe("0x100000");
// H4 review 6: the full width, bit 31 included, beside a known bit.
DataConnectionDiagnostics.DroppedBits(DataOperations.HistoryRead | (DataOperations)int.MinValue).ShouldBe("HistoryRead, 0x80000000");
}
[Fact]