RynthDreamWeave: launch state review fixes
Code-shaped refusals are replaced, self-expiry in Begin, Reset keeps the throttle, late valid codes are eaten as Stale within the code lifetime, thread contract documented. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1eb8bf1e8a
commit
c03a38a3e8
3 changed files with 151 additions and 17 deletions
|
|
@ -22,7 +22,12 @@ internal static class DreamWeaveWebTests
|
|||
r.Add("dreamweave web: replies count only while asked, once", RepliesOnlyWhileAsked);
|
||||
r.Add("dreamweave web: one request at a time, never stuck", OneAtATime);
|
||||
r.Add("dreamweave web: the code never reaches a status or message", CodeNeverInStatus);
|
||||
r.Add("dreamweave web: a code-shaped refusal is replaced, never shown", CodeShapedRefusal);
|
||||
r.Add("dreamweave web: an expired request frees itself", SelfExpiry);
|
||||
r.Add("dreamweave web: reset keeps the throttle", ResetKeepsThrottle);
|
||||
r.Add("dreamweave web: a late code is eaten while it could still be valid", LateCodeIsStale);
|
||||
}
|
||||
|
||||
private const string Code = "AbCdEfGhIjKlMnOpQrStUvWxYz0123456789-_AbCde"; // 43 chars
|
||||
private const string Line = "[WEB] Launch code: " + Code + " (single use, expires in 60 seconds)";
|
||||
|
||||
|
|
@ -173,7 +178,7 @@ internal static class DreamWeaveWebTests
|
|||
// Timeout at exactly +10,000.
|
||||
var t = new WebLauncher();
|
||||
t.Begin(Market, 50_000);
|
||||
Check.True(t.OnChatLine(Line, 0x05, 60_000, out _, out _, out _) == LaunchLine.NotOurs, "line at +10,000 ms is late");
|
||||
Check.True(t.OnChatLine(Line, 0x05, 60_000, out _, out _, out _) == LaunchLine.Stale, "a valid code at +10,000 ms is late: stale, not a code");
|
||||
Check.True(t.TakeTimedOut(59_999) == null, "not timed out at +9,999");
|
||||
Check.True(ReferenceEquals(t.TakeTimedOut(60_000), Market), "timed out once at +10,000");
|
||||
Check.True(t.TakeTimedOut(60_001) == null, "and only once");
|
||||
|
|
@ -247,6 +252,88 @@ internal static class DreamWeaveWebTests
|
|||
Check.True(!f.Status.Contains(Code) && !msg.Contains(Code), "refusal status and message");
|
||||
}
|
||||
|
||||
private static void CodeShapedRefusal()
|
||||
{
|
||||
var w = new WebLauncher();
|
||||
w.Begin(Market, 0);
|
||||
var k = w.OnChatLine("[WEB] Try again later: " + Code, 0x05, 10, out var dest, out string code, out string msg);
|
||||
Check.True(k == LaunchLine.Refused, "still a refusal, so the caller eats the line");
|
||||
Check.True(ReferenceEquals(dest, Market), "destination handed back");
|
||||
Check.Eq(code, "", "no code");
|
||||
Check.True(!msg.Contains(Code), "message has no code");
|
||||
Check.True(!w.Status.Contains(Code), "status has no code");
|
||||
Check.Eq(msg, "DreamWeave sent an unexpected reply.", "fixed replacement text");
|
||||
Check.Eq(w.Status, "Market: DreamWeave said: DreamWeave sent an unexpected reply.", "status from the replacement");
|
||||
Check.True(w.Pending == null, "pending cleared");
|
||||
|
||||
// A long run of code chars anywhere, and a 42-char run (below the limit) left alone.
|
||||
var w2 = new WebLauncher();
|
||||
w2.Begin(Market, 0);
|
||||
w2.OnChatLine("[WEB] x " + Code + Code + " y", 0x05, 10, out _, out _, out msg);
|
||||
Check.Eq(msg, "DreamWeave sent an unexpected reply.", "longer run replaced");
|
||||
var w3 = new WebLauncher();
|
||||
w3.Begin(Market, 0);
|
||||
w3.OnChatLine("[WEB] id " + Code.Substring(1) + " ok", 0x05, 10, out _, out _, out msg);
|
||||
Check.Eq(msg, "id " + Code.Substring(1) + " ok", "42-char run is ordinary text");
|
||||
}
|
||||
private static void SelfExpiry()
|
||||
{
|
||||
var w = new WebLauncher();
|
||||
w.Begin(Market, 0);
|
||||
Check.True(w.Begin(Market, 9_999) == LaunchBegin.Busy, "before the deadline: busy");
|
||||
Check.True(w.Begin(Market, 10_001) != LaunchBegin.Busy, "past the deadline: not busy");
|
||||
|
||||
var x = new WebLauncher();
|
||||
x.Begin(Market, 0);
|
||||
Check.True(x.Begin(DreamWeaveWeb.ById("suit")!, 10_001) == LaunchBegin.Started, "expired, then started as normal");
|
||||
Check.True(x.Pending!.Id == "suit", "the new request is the pending one");
|
||||
Check.True(x.TakeTimedOut(10_001) == null, "the new request is not timed out yet");
|
||||
Check.Eq(x.TakeTimedOut(20_001)?.Id ?? "none", "suit", "and it times out at its own deadline");
|
||||
}
|
||||
private static void ResetKeepsThrottle()
|
||||
{
|
||||
var w = new WebLauncher();
|
||||
Check.True(w.Begin(Market, 1_000) == LaunchBegin.Started, "begin");
|
||||
w.Reset();
|
||||
Check.True(w.Pending == null, "reset clears pending");
|
||||
Check.True(w.Begin(Market, 1_001) == LaunchBegin.TooSoon, "throttle survives a relog");
|
||||
}
|
||||
|
||||
private static void LateCodeIsStale()
|
||||
{
|
||||
var w = new WebLauncher();
|
||||
w.Begin(Market, 0);
|
||||
var k = w.OnChatLine(Line, 0x05, 10_500, out var dest, out string code, out string msg);
|
||||
Check.True(k == LaunchLine.Stale, "valid code at +10,500 ms is stale");
|
||||
Check.True(dest == null && code == "" && msg == "", "stale carries nothing");
|
||||
Check.True(w.Pending != null, "stale does not clear pending");
|
||||
Check.True(!w.Status.Contains(Code), "status has no code");
|
||||
Check.True(ReferenceEquals(w.TakeTimedOut(10_500), Market), "timeout still fires once");
|
||||
Check.True(w.TakeTimedOut(10_501) == null, "and only once");
|
||||
Check.Eq(w.Status, "No reply from DreamWeave to /weblogin within 10 s, so nothing was opened.", "timeout status intact");
|
||||
Check.True(w.OnChatLine(Line, 0x05, 20_000, out dest, out code, out _) == LaunchLine.Stale, "still stale after the timeout was taken");
|
||||
Check.True(dest == null && code == "", "no destination or code");
|
||||
Check.True(w.OnChatLine(Line, 0x05, 69_999, out _, out _, out _) == LaunchLine.Stale, "last stale ms (+69,999)");
|
||||
Check.True(w.OnChatLine(Line, 0x05, 70_001, out _, out _, out _) == LaunchLine.NotOurs, "at +70,001 ms: not ours");
|
||||
Check.True(w.OnChatLine("[WEB] some refusal", 0x05, 20_000, out _, out _, out _) == LaunchLine.NotOurs, "a late refusal is not ours");
|
||||
Check.True(w.OnChatLine(Line, 0x02, 20_000, out _, out _, out _) == LaunchLine.NotOurs, "a late player copy is not ours");
|
||||
|
||||
var n = new WebLauncher();
|
||||
Check.True(n.OnChatLine(Line, 0x05, 10_500, out _, out _, out _) == LaunchLine.NotOurs, "no Begin ever: not ours");
|
||||
|
||||
// A consumed request leaves no stale window.
|
||||
var c = new WebLauncher();
|
||||
c.Begin(Market, 0);
|
||||
c.OnChatLine(Line, 0x05, 100, out _, out _, out _);
|
||||
Check.True(c.OnChatLine(Line, 0x05, 10_500, out _, out _, out _) == LaunchLine.NotOurs, "after a code: not ours");
|
||||
|
||||
// A new Begin ends the old stale window.
|
||||
var b = new WebLauncher();
|
||||
b.Begin(Market, 0);
|
||||
b.TakeTimedOut(10_000);
|
||||
b.Begin(Market, 20_000);
|
||||
Check.True(b.OnChatLine(Line, 0x05, 20_100, out _, out _, out _) == LaunchLine.Code, "new request takes the code");
|
||||
}
|
||||
private static string[] ServerPluginIds()
|
||||
{
|
||||
string? dir = AppContext.BaseDirectory;
|
||||
|
|
|
|||
Loading…
Reference in a new issue