Add research page with MCP write tools, longer hold for repeat offenders and svn/hg decoys
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a25072e6fb
commit
e88dc415f9
48 files changed
+1983
-57
No files matched your search
@@ -0,0 +1,44 @@
|
||||
using System.Net;
|
||||
using Flypaper.Core.Models;
|
||||
using Flypaper.Storage.Entities;
|
||||
using Flypaper.Storage.Queries;
|
||||
using Flypaper.Tests.Mcp;
|
||||
using Shouldly;
|
||||
|
||||
namespace Flypaper.Tests.Storage;
|
||||
|
||||
public sealed class RepeatOffenderLookupTests : IDisposable
|
||||
{
|
||||
private readonly McpTestData _data = new();
|
||||
|
||||
[Fact]
|
||||
public async Task Finds_only_timeouts_of_the_same_ip_inside_the_window()
|
||||
{
|
||||
using (var db = _data.Factory.CreateDbContext())
|
||||
{
|
||||
Add(db, "203.0.113.50", hoursAgo: 48, TrapOutcome.Timeout);
|
||||
Add(db, "203.0.113.51", hoursAgo: 2, TrapOutcome.ClientAborted);
|
||||
Add(db, "2001:db8::7", hoursAgo: 3, TrapOutcome.Timeout);
|
||||
Add(db, "203.0.113.52", hoursAgo: 24 * 30, TrapOutcome.Timeout);
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
var lookup = new RepeatOffenderLookup(_data.Factory);
|
||||
var since = McpTestData.Now.UtcDateTime.AddDays(-7);
|
||||
|
||||
(await lookup.HasTimedOutSinceAsync(IPAddress.Parse("203.0.113.50"), since, default)).ShouldBeTrue();
|
||||
(await lookup.HasTimedOutSinceAsync(IPAddress.Parse("2001:db8::7"), since, default)).ShouldBeTrue();
|
||||
(await lookup.HasTimedOutSinceAsync(IPAddress.Parse("203.0.113.51"), since, default)).ShouldBeFalse();
|
||||
(await lookup.HasTimedOutSinceAsync(IPAddress.Parse("203.0.113.52"), since, default)).ShouldBeFalse();
|
||||
(await lookup.HasTimedOutSinceAsync(IPAddress.Parse("203.0.113.99"), since, default)).ShouldBeFalse();
|
||||
}
|
||||
|
||||
private static void Add(Flypaper.Storage.FlypaperDbContext db, string ip, int hoursAgo, TrapOutcome outcome)
|
||||
{
|
||||
var started = McpTestData.Now.AddHours(-hoursAgo);
|
||||
db.TrapEvents.Add(TrapEventEntity.From(new TrapEvent(
|
||||
Guid.NewGuid(), TrapProtocol.Http, IPAddress.Parse(ip), "html-drip", started, started.AddSeconds(3600), 100, outcome, "GET /", null)));
|
||||
}
|
||||
|
||||
public void Dispose() => _data.Dispose();
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using Flypaper.Storage.Entities;
|
||||
using Flypaper.Storage.Research;
|
||||
using Flypaper.Tests.Fakes;
|
||||
using Flypaper.Tests.Mcp;
|
||||
using Shouldly;
|
||||
|
||||
namespace Flypaper.Tests.Storage;
|
||||
|
||||
public sealed class ResearchStoreTests : IDisposable
|
||||
{
|
||||
private readonly McpTestData _data = new();
|
||||
private readonly ResearchStore _store;
|
||||
|
||||
public ResearchStoreTests() => _store = new ResearchStore(_data.Factory, new FixedTimeProvider(McpTestData.Now));
|
||||
|
||||
[Fact]
|
||||
public async Task Entries_are_listed_newest_first_and_filtered_by_kind_and_strategy()
|
||||
{
|
||||
await _store.CreateEntryAsync(new LabEntryInput("Alt", LabEntryKind.Experiment, "a", new DateTime(2026, 11, 10), Strategies: ["git-drip"]));
|
||||
await _store.CreateEntryAsync(new LabEntryInput("Neu", LabEntryKind.Observation, "b", new DateTime(2026, 11, 14), Strategies: ["maze-drip", "git-drip"]));
|
||||
await _store.CreateEntryAsync(new LabEntryInput("Heute", LabEntryKind.Experiment, "c"));
|
||||
|
||||
(await _store.ListEntriesAsync()).Select(e => e.Title).ShouldBe(["Heute", "Neu", "Alt"]);
|
||||
(await _store.ListEntriesAsync(LabEntryKind.Experiment)).Select(e => e.Title).ShouldBe(["Heute", "Alt"]);
|
||||
(await _store.ListEntriesAsync(strategy: "GIT-drip")).Select(e => e.Title).ShouldBe(["Neu", "Alt"]);
|
||||
(await _store.ListEntriesAsync(limit: 1)).ShouldHaveSingleItem().Title.ShouldBe("Heute");
|
||||
(await _store.ListEntriesAsync()).First().Date.ShouldBe(McpTestData.Now.UtcDateTime.Date);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Update_changes_only_given_fields_and_empty_values_clear_optional_ones()
|
||||
{
|
||||
var entry = await _store.CreateEntryAsync(new LabEntryInput("Titel", LabEntryKind.Hypothesis, "Text", Commit: "ABCDEF1", Strategies: ["git-drip"]));
|
||||
entry.Commit.ShouldBe("abcdef1");
|
||||
|
||||
var changed = await _store.UpdateEntryAsync(entry.Id, new LabEntryInput(Text: "Neu"));
|
||||
changed.ShouldNotBeNull();
|
||||
(changed.Title, changed.Text, changed.Commit, changed.Strategies).ShouldBe(("Titel", "Neu", "abcdef1", "git-drip"));
|
||||
|
||||
var cleared = await _store.UpdateEntryAsync(entry.Id, new LabEntryInput(Commit: "", Strategies: []));
|
||||
cleared.ShouldNotBeNull();
|
||||
(cleared.Commit, cleared.Strategies).ShouldBe((null, null));
|
||||
|
||||
(await _store.UpdateEntryAsync(999, new LabEntryInput(Title: "x"))).ShouldBeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", "Text", "abc1", "git-drip")]
|
||||
[InlineData("Titel", " ", "abc1", "git-drip")]
|
||||
[InlineData("Titel", "Text", "not-a-hash", "git-drip")]
|
||||
[InlineData("Titel", "Text", "abc1", "Git Drip!")]
|
||||
public async Task Invalid_entries_are_rejected(string title, string text, string commit, string strategy) =>
|
||||
await Should.ThrowAsync<ArgumentException>(() =>
|
||||
_store.CreateEntryAsync(new LabEntryInput(title, LabEntryKind.Method, text, Commit: commit, Strategies: [strategy])));
|
||||
|
||||
[Fact]
|
||||
public async Task Ideas_are_sorted_by_effort_then_efficiency_and_status_sets_implementation_date()
|
||||
{
|
||||
var hard = await _store.CreateIdeaAsync(new IdeaInput("Schwer", IdeaLevel.High, IdeaLevel.High, "r"));
|
||||
var cheap = await _store.CreateIdeaAsync(new IdeaInput("Billig", IdeaLevel.Low, IdeaLevel.Medium, "r"));
|
||||
var cheapBetter = await _store.CreateIdeaAsync(new IdeaInput("Billig und gut", IdeaLevel.Low, IdeaLevel.High, "r"));
|
||||
|
||||
(await _store.ListIdeasAsync()).Select(i => i.Title).ShouldBe(["Billig und gut", "Billig", "Schwer"]);
|
||||
|
||||
var done = await _store.UpdateIdeaAsync(cheap.Id, new IdeaInput(Status: IdeaStatus.Done, Commit: "abc123"));
|
||||
done.ShouldNotBeNull();
|
||||
(done.Status, done.ImplementedOn, done.Commit).ShouldBe((IdeaStatus.Done, McpTestData.Now.UtcDateTime.Date, "abc123"));
|
||||
|
||||
var reopened = await _store.UpdateIdeaAsync(cheap.Id, new IdeaInput(Status: IdeaStatus.Open));
|
||||
reopened.ShouldNotBeNull().ImplementedOn.ShouldBeNull();
|
||||
|
||||
(await _store.ListIdeasAsync(IdeaStatus.Open)).Count.ShouldBe(3);
|
||||
hard.Status.ShouldBe(IdeaStatus.Open);
|
||||
cheapBetter.Status.ShouldBe(IdeaStatus.Open);
|
||||
(await _store.UpdateIdeaAsync(999, new IdeaInput(Status: IdeaStatus.Done))).ShouldBeNull();
|
||||
}
|
||||
|
||||
public void Dispose() => _data.Dispose();
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public sealed class SettingsOverrideTests : IDisposable
|
||||
var store = host.Services.GetRequiredService<RuntimeSettingsStore>();
|
||||
string[] holdKeys = [.. SettingKeys.HoldMethod];
|
||||
|
||||
await store.SaveAsync(new HoldMethodSettings(DripContent.Text, TimeSpan.FromMilliseconds(200), TimeSpan.FromSeconds(2), 8, 16, 256, false, 0, "/trap-a/", TimeSpan.FromMinutes(5)));
|
||||
await store.SaveAsync(new HoldMethodSettings(DripContent.Text, TimeSpan.FromMilliseconds(200), TimeSpan.FromSeconds(2), 8, 16, 256, false, 0, "/trap-a/", TimeSpan.FromMinutes(5), 7, TimeSpan.FromHours(24)));
|
||||
await store.SaveAsync(new RuntimeSettings(50, 4, 90, true));
|
||||
|
||||
drip.CurrentValue.Content.ShouldBe(DripContent.Text);
|
||||
@@ -103,7 +103,7 @@ public sealed class SettingsOverrideTests : IDisposable
|
||||
core.CurrentValue.MaxConnections.ShouldBe(50);
|
||||
(await store.HasOverridesAsync(holdKeys)).ShouldBeTrue();
|
||||
|
||||
await store.SaveAsync(new HoldMethodSettings(DripContent.Text, TimeSpan.FromMilliseconds(200), TimeSpan.FromSeconds(2), 8, 16, 256, false, 0, "", TimeSpan.FromMinutes(5)));
|
||||
await store.SaveAsync(new HoldMethodSettings(DripContent.Text, TimeSpan.FromMilliseconds(200), TimeSpan.FromSeconds(2), 8, 16, 256, false, 0, "", TimeSpan.FromMinutes(5), 0, TimeSpan.FromHours(2)));
|
||||
drip.CurrentValue.BaitPaths.ShouldBe("");
|
||||
|
||||
await store.ResetAsync(holdKeys);
|
||||
|
||||
Reference in new issue
Block a user