Files
AutopilotMonitor/src/Backend/AutopilotMonitor.Functions.Tests/RuleHitSessionsFunctionTests.cs
T
Oliver Kieselbach 842db1603a insights: fleet context on analysis cards + rule-filtered session deep link
Each fired analyze rule on the session detail page now reads "Fired in N
enrollment(s) in the last 14 days" (summed client-side from the existing
rule-stats trend — enrollments, never devices; RuleStats carries no serial)
with a "View sessions" deep link. The dashboard accepts ?ruleId=, fetches
the rule's hit-session ids once from the new GET /api/metrics/rule-hit-sessions
endpoint (MemberRead + QueryParam scoping, capped 2000 with a truncated flag)
and filters the loaded list client-side behind a clearable chip.

Side fix: the section's stats fetch now follows the session's tenant for
GA/delegated viewers (global route + tenantId) instead of showing the
viewer's own-tenant numbers next to a foreign session. Dashboard links in
fleet/fleet-health now go through the new canonical dashboardUrl() builder.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-13 13:38:52 +02:00

36 lines
1.3 KiB
C#

using AutopilotMonitor.Functions.Functions.Metrics;
namespace AutopilotMonitor.Functions.Tests;
/// <summary>
/// Window parsing for the fleet-context deep-link endpoint
/// (<see cref="RuleHitSessionsFunction"/>, GET metrics/rule-hit-sessions).
/// Default 14 days; clamped to 1..90 because RuleResults follow the session
/// retention cascade — a larger window could never widen the hit set.
/// </summary>
public class RuleHitSessionsFunctionTests
{
[Theory]
[InlineData(null, 14)] // not supplied → default window
[InlineData("", 14)] // empty → default
[InlineData("garbage", 14)] // non-numeric → default
[InlineData("14", 14)]
[InlineData("1", 1)]
[InlineData("0", 1)] // below range → clamped up
[InlineData("-5", 1)]
[InlineData("90", 90)]
[InlineData("365", 90)] // above range → clamped down
public void ParseDays_Defaults_And_Clamps(string? raw, int expected)
{
Assert.Equal(expected, RuleHitSessionsFunction.ParseDays(raw));
}
[Fact]
public void MaxSessionIds_Matches_Repository_Default_Cap()
{
// The truncated flag compares against this constant; it must stay in sync
// with the GetRuleHitSessionIdsAsync default cap (2000).
Assert.Equal(2000, RuleHitSessionsFunction.MaxSessionIds);
}
}