Group strategies by base type and rank them by median hold time

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-11-17 19:29:53 +01:00
1 parent d2cbab5d4b
commit cbd9830143
12 files changed
+301 -35

No files matched your search

@@ -1,4 +1,7 @@
using System.Net;
using Flypaper.Core.Models;
using Flypaper.Storage.Entities;
using Flypaper.Web.Components.Shared;
using Flypaper.Storage.Dashboard;
using Flypaper.Tests.Fakes;
using Flypaper.Tests.Mcp;
@@ -47,19 +50,42 @@ public sealed class RecentCatchesTests : IDisposable
[Fact]
public async Task Matches_strategy_exactly()
{
var recent = await _queries.GetRecentAsync(new RecentFilter(Strategy: "env-drip"));
var recent = await _queries.GetRecentAsync(new RecentFilter(Strategy: StrategyNames.Group("env-drip")));
recent.Total.ShouldBe(2);
recent.Items.ShouldAllBe(e => e.Strategy == "env-drip");
}
[Fact]
public async Task Dashboard_ranks_strategies_among_catches()
public async Task Dashboard_lists_strategy_durations_among_catches()
{
var data = await _queries.GetAsync();
data.TopStrategies.Select(s => (s.Key, s.Count)).ShouldBe([("html-drip", 4), ("env-drip", 1)]);
data.TopStrategies[1].HoldTime.ShouldBe(TimeSpan.FromHours(1));
data.StrategyCatches.Count.ShouldBe(5);
data.StrategyCatches.Count(s => s.Strategy == "env-drip").ShouldBe(1);
data.StrategyCatches.Single(s => s.Strategy == "env-drip").DurationMs.ShouldBe(3_600_000);
}
[Fact]
public async Task Strategy_group_matches_all_variants_of_the_base_type_and_its_old_name()
{
await using (var db = _data.Factory.CreateDbContext())
{
foreach (var strategy in new[] { "drip", "html-drip 50-500ms 1-640B", "html-drip 5-20ms 1-64B head 1024B", "html-drip 50-500ms 1-1024B repeat", "html-drip 50-500ms 1-64B head 1024B repeat" })
{
db.TrapEvents.Add(TrapEventEntity.From(new TrapEvent(Guid.NewGuid(), TrapProtocol.Http, IPAddress.Parse("192.0.2.1"), strategy, McpTestData.Now, McpTestData.Now, 0, TrapOutcome.ClientAborted, null, null)));
}
await db.SaveChangesAsync();
}
async Task<IReadOnlyList<string>> Find(string group) =>
(await _queries.GetRecentAsync(new RecentFilter(Strategy: StrategyNames.Group(group)))).Items.Select(e => e.Strategy).OrderBy(s => s).ToList();
(await Find("html-drip")).Where(s => s != "html-drip").ShouldBe(["drip", "html-drip 50-500ms 1-640B"]);
(await Find("html-drip head")).ShouldBe(["html-drip 5-20ms 1-64B head 1024B"]);
(await Find("html-drip repeat")).ShouldBe(["html-drip 50-500ms 1-1024B repeat"]);
(await Find("html-drip head repeat")).ShouldBe(["html-drip 50-500ms 1-64B head 1024B repeat"]);
}
[Theory]