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

@@ -13,7 +13,11 @@ public sealed class DashboardFilterTests
var filter = DashboardFilter.Parse("24h", "Abgelehnt", "hk", "as4134", " 203.0.113.9 ", "GET /.env", " env-drip ", " wp ", "100");
filter.ShouldBe(new DashboardFilter("24h", "abgelehnt", "HK", "AS4134", "203.0.113.9", "GET /.env", "env-drip", "wp", 100));
filter.ToRecentFilter().ShouldBe(new RecentFilter(TimeSpan.FromHours(24), TrapOutcome.Rejected, "HK", 4134, "203.0.113.9", "GET /.env", "env-drip", "wp", 100));
var recent = filter.ToRecentFilter();
recent.ShouldBe(new RecentFilter(TimeSpan.FromHours(24), TrapOutcome.Rejected, "HK", 4134, "203.0.113.9", "GET /.env", recent.Strategy, "wp", 100));
recent.Strategy!.Bases.ShouldBe(["env-drip"]);
recent.Strategy.With.ShouldBeEmpty();
recent.Strategy.Without.ShouldBe(["head", "link", "repeat"]);
}
[Theory]
@@ -44,8 +48,8 @@ public sealed class DashboardFilterTests
public void Builds_links_without_defaults_and_with_escaping()
{
new DashboardFilter().Href().ShouldBe("/#faenge");
new DashboardFilter(Land: "CN", Ziel: "GET example.com/a&b", Strategie: "html-drip 50-500ms 1-1024B", Limit: 100).Href("f50")
.ShouldBe("/?land=CN&ziel=GET%20example.com%2Fa%26b&strategie=html-drip%2050-500ms%201-1024B&limit=100#f50");
new DashboardFilter(Land: "CN", Ziel: "GET example.com/a&b", Strategie: "html-drip head", Limit: 100).Href("f50")
.ShouldBe("/?land=CN&ziel=GET%20example.com%2Fa%26b&strategie=html-drip%20head&limit=100#f50");
}
[Fact]
@@ -58,6 +62,13 @@ public sealed class DashboardFilterTests
.ShouldBe(filter);
}
[Theory]
[InlineData("html-drip 50-500ms 1-1024B", "html-drip")]
[InlineData("drip", "html-drip")]
[InlineData("html-drip 50-500ms 1-64B head 1024B", "html-drip head")]
public void Normalizes_strategy_links_to_the_group(string strategy, string expected) =>
DashboardFilter.Parse(null, null, null, null, null, null, strategy, null, null).Strategie.ShouldBe(expected);
[Fact]
public void Doubles_the_limit_up_to_the_maximum()
{
@@ -1,4 +1,5 @@
using Flypaper.Core.Strategies;
using Flypaper.Storage.Dashboard;
using Flypaper.Web.Components.Shared;
using Shouldly;
@@ -63,4 +64,44 @@ public sealed class StrategyNamesTests
StrategyNames.Matching("").ShouldBeEmpty();
StrategyNames.Matching("nichts").ShouldBeEmpty();
}
[Fact]
public void Groups_variants_by_base_type_and_shows_only_content_differences_as_badges()
{
StrategyNames.Describe("html-drip 50-500ms 1-1024B").GroupKey.ShouldBe("html-drip");
StrategyNames.Describe("html-drip 50-500ms 1-640B").GroupKey.ShouldBe("html-drip");
var variant = StrategyNames.Describe("html-drip 5-20ms 1-64B head 1024B repeat");
variant.GroupKey.ShouldBe("html-drip head repeat");
variant.Badges.ShouldBe(["Schnellstart", "Wiederholer"]);
StrategyNames.Describe("maze-drip 50-500ms 1-1024B head 1024B link 160B").Badges.ShouldBe(["Schnellstart"]);
}
[Fact]
public void Treats_drip_as_the_old_name_of_the_endless_page()
{
var info = StrategyNames.Describe("drip");
info.DisplayName.ShouldBe("Endlose Webseite");
info.GroupKey.ShouldBe("html-drip");
StrategyNames.Matching("endlose webseite").ShouldBe(["html-drip", "drip"]);
}
[Fact]
public void Ranks_groups_by_median_and_sinks_groups_with_few_catches()
{
var samples = new List<StrategySample>();
samples.AddRange(Enumerable.Repeat(new StrategySample("html-drip 50-500ms 1-1024B", 10_000), 3));
samples.AddRange(Enumerable.Repeat(new StrategySample("html-drip 50-500ms 1-640B", 20_000), 2));
samples.Add(new StrategySample("drip", 1_000_000));
samples.AddRange(Enumerable.Repeat(new StrategySample("env-drip 50-500ms 1-1024B", 30_000), 5));
samples.Add(new StrategySample("text-drip", 500_000_000));
var ranked = StrategyNames.Rank(samples, 10);
ranked.Select(r => r.Key).ShouldBe(["env-drip", "html-drip", "text-drip"]);
ranked[0].MedianHold.ShouldBe(TimeSpan.FromSeconds(30));
ranked[1].Count.ShouldBe(6);
ranked[1].MedianHold.ShouldBe(TimeSpan.FromSeconds(15));
ranked[1].HoldTime.ShouldBe(TimeSpan.FromMilliseconds(1_070_000));
}
}