RynthDreamWeave: final-review fixes (malformed code lines never shown, wording)

- LaunchWire.IsSuccessShaped: a server line starting "[WEB] Launch code",
  well formed or not. OnChatLine keeps a malformed one out of chat: a
  pending request takes it as Refused with the unexpected-reply message;
  otherwise Stale inside the stale window, NotOurs after. TryParse and
  its pins are unchanged.
- An empty "[WEB] " refusal is an unexpected reply too.
- Wording: "an unexpected reply (is RynthDreamWeave up to date?)",
  "Wait a few seconds between website opens.", "Couldn't open the
  website."
- Tests: the raw-string guard covers only the DreamWeave files the scan
  parses; the scan test's name says its catch logs through LogTagged;
  the directory walkers added on this branch use
  ServerProjectsTests.PluginsDir().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-07 15:43:49 -08:00
commit 7003094f56
4 changed files with 107 additions and 32 deletions

View file

@ -28,8 +28,9 @@ internal static class DreamWeaveWebTests
r.Add("dreamweave web: a late code is eaten while it could still be valid", LateCodeIsStale);
r.Add("dreamweave web: overlapping requests never leak a code to chat", OverlappingRequests);
r.Add("dreamweave web: profile keys separate accounts", ProfileKeys);
r.Add("dreamweave web: ImGui only in WebButtons, no context switching, no host calls from draw", ThreadRules);
r.Add("dreamweave web: ImGui only in WebButtons, no context switching, draw makes no host calls (its catch logs via LogTagged)", ThreadRules);
r.Add("dreamweave web: an open's answer lands only on its own request", ResultGeneration);
r.Add("dreamweave web: a malformed launch-code line never reaches chat", MalformedSuccess);
r.Add("dreamweave web: the source scan's helpers read code, not comments or strings", ScanHelpers);
r.Add("dreamweave web: the plugin's shared hooks hand off to the web tools first", HooksHandOff);
}
@ -37,15 +38,6 @@ internal static class DreamWeaveWebTests
// -- Host wiring (source scan: the plugin is NativeAOT, so its host code can't run here) --
// The rules are allow-lists: what may appear is named, so a new spelling of a forbidden call fails.
private static string PluginsRoot()
{
string? dir = AppContext.BaseDirectory;
while (dir != null && !Directory.Exists(Path.Combine(dir, "Plugins", "Shared", "ServerPack")))
dir = Path.GetDirectoryName(dir);
if (dir == null) throw new DirectoryNotFoundException("Plugins not found above " + AppContext.BaseDirectory);
return Path.Combine(dir, "Plugins");
}
private static IEnumerable<string> SourceFiles(string root)
=> Directory.GetFiles(root, "*.cs", SearchOption.AllDirectories)
.Where(p => !p.Contains(Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)
@ -212,7 +204,7 @@ internal static class DreamWeaveWebTests
// panel: each hands off to its Web* method before its own code, so no gate of theirs comes first.
private static void HooksHandOff()
{
string dw = Path.Combine(PluginsRoot(), "RynthCore.Plugin.RynthDreamWeave");
string dw = Path.Combine(ServerProjectsTests.PluginsDir(), "RynthCore.Plugin.RynthDreamWeave");
string plugin = StripComments(File.ReadAllText(Path.Combine(dw, "DreamWeavePlugin.cs")));
string skills = StripComments(File.ReadAllText(Path.Combine(dw, "DreamWeaveSkills.cs")));
(string Code, string Head, string Call)[] hooks =
@ -242,9 +234,11 @@ internal static class DreamWeaveWebTests
Check.False(web.Contains("partial void " + hook + "(", StringComparison.Ordinal), "DreamWeaveWebTools.cs leaves " + hook + " to the hub");
}
// The draw path makes no host calls. ServerCardActions' catch (render thread) does log through
// LogTagged once per failure, the shared pattern RenderEmbedded's own catch already follows.
private static void ThreadRules()
{
string plugins = PluginsRoot();
string plugins = ServerProjectsTests.PluginsDir();
string dw = Path.Combine(plugins, "RynthCore.Plugin.RynthDreamWeave");
string buttonsPath = Path.Combine(dw, "DreamWeave", "WebButtons.cs");
string hostPath = Path.Combine(dw, "DreamWeaveWebTools.cs");
@ -266,14 +260,15 @@ internal static class DreamWeaveWebTests
}
}
// StripComments does not model raw string literals: a DreamWeave file with one must fail, not scan
// wrongly. Only the files this scan parses in depth are held to it (the web tools' files and the two hub
// files HooksHandOff reads), so another server, or another DreamWeave feature, can't break it.
foreach (string f in WebFiles(dw).Concat(new[] { Path.Combine(dw, "DreamWeavePlugin.cs"), Path.Combine(dw, "DreamWeaveSkills.cs") }))
Check.False(File.ReadAllText(f).Contains("\"\"\"", StringComparison.Ordinal), Path.GetFileName(f) + ": no raw string literal (the scan does not support them)");
var processStart = new System.Text.RegularExpressions.Regex(@"\bProcess\s*\.\s*Start\b");
foreach (string f in SourceFiles(plugins))
{
string raw = File.ReadAllText(f);
// StripComments does not model raw string literals: a file with one must fail, not scan wrongly.
Check.False(raw.Contains("\"\"\"", StringComparison.Ordinal), Path.GetFileName(f) + ": no raw string literal (the scan does not support them)");
Check.False(processStart.IsMatch(StripComments(raw)), Path.GetFileName(f) + ": no Process.Start under Plugins (ShellExecuteW only)");
}
Check.False(processStart.IsMatch(StripComments(File.ReadAllText(f))), Path.GetFileName(f) + ": no Process.Start under Plugins (ShellExecuteW only)");
// Monitor would take the launcher's lock without a lock statement, out of the scan's sight.
var monitor = new System.Text.RegularExpressions.Regex(@"\bMonitor\s*\.");
@ -371,6 +366,61 @@ internal static class DreamWeaveWebTests
}
}
private static void MalformedSuccess()
{
string head = "[WEB] Launch code: ";
string long44 = head + Code + "A (single use, expires in 60 seconds)";
string dotted = head + Code + ".";
foreach (string l in new[] { long44, dotted })
{
Check.True(!Parse(l, 0x05, out _, out _), "TryParse still rejects it: " + l.Length + " chars");
Check.True(LaunchWire.IsSuccessShaped(l, 0x05), "success-shaped: " + l.Length + " chars");
Check.False(LaunchWire.IsSuccessShaped(l, 0x02), "a player's copy is not success-shaped");
}
Check.True(LaunchWire.IsSuccessShaped(" [WEB] Launch code", 0x05), "the stem alone, past leading space");
Check.False(LaunchWire.IsSuccessShaped("[WEB] Signing in is turned off.", 0x05), "a refusal is not success-shaped");
Check.False(LaunchWire.IsSuccessShaped(null, 0x05), "null is not success-shaped");
foreach (string l in new[] { long44, dotted })
{
// Pending: the request takes the line as an unexpected reply; nothing of the code survives.
var w = new WebLauncher();
w.Begin(Market, 0);
var k = w.OnChatLine(l, 0x05, 100, out var dest, out string code, out string msg);
Check.True(k == LaunchLine.Refused, "pending: a malformed code line is Refused (eaten), not NotOurs");
Check.True(ReferenceEquals(dest, Market), "pending: the destination is handed back");
Check.Eq(code, "", "pending: no code");
Check.Eq(msg, "an unexpected reply (is RynthDreamWeave up to date?)", "pending: the fixed message");
Check.Eq(w.Status, "Market: DreamWeave sent an unexpected reply (is RynthDreamWeave up to date?)", "pending: the status");
Check.True(w.Pending == null, "pending: cleared");
Check.False(w.Status.Contains(Code.Substring(0, 12), StringComparison.Ordinal) || msg.Contains(Code.Substring(0, 12), StringComparison.Ordinal), "pending: no code in status or message");
// A player's copy while pending is still not ours.
var p = new WebLauncher();
p.Begin(Market, 0);
Check.True(p.OnChatLine(l, 0x02, 100, out _, out _, out _) == LaunchLine.NotOurs, "player copy (0x02): not ours");
Check.True(p.Pending != null, "player copy leaves the request pending");
// Not pending: Stale inside the window, NotOurs after it.
var s = new WebLauncher();
s.Begin(Market, 0);
s.TakeTimedOut(10_000);
Check.True(s.OnChatLine(l, 0x05, 20_000, out dest, out code, out msg) == LaunchLine.Stale, "not pending, inside the window: Stale");
Check.True(dest == null && code == "" && msg == "", "Stale carries nothing");
Check.True(s.OnChatLine(l, 0x05, 70_001, out _, out _, out _) == LaunchLine.NotOurs, "after the window: NotOurs");
Check.True(new WebLauncher().OnChatLine(l, 0x05, 5, out _, out _, out _) == LaunchLine.NotOurs, "no Begin ever: NotOurs");
}
// An empty refusal is an unexpected reply too.
foreach (string l in new[] { "[WEB] ", "[WEB] " })
{
var e = new WebLauncher();
e.Begin(Market, 0);
Check.True(e.OnChatLine(l, 0x05, 10, out _, out _, out string msg) == LaunchLine.Refused, "empty refusal: Refused");
Check.Eq(msg, "an unexpected reply (is RynthDreamWeave up to date?)", "empty refusal: the fixed message");
}
}
private static void ResultGeneration()
{
var w = new WebLauncher();
@ -663,15 +713,15 @@ internal static class DreamWeaveWebTests
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.Eq(msg, "an unexpected reply (is RynthDreamWeave up to date?)", "fixed replacement text");
Check.Eq(w.Status, "Market: DreamWeave sent an unexpected reply (is RynthDreamWeave up to date?)", "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");
Check.Eq(msg, "an unexpected reply (is RynthDreamWeave up to date?)", "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);
@ -825,12 +875,8 @@ internal static class DreamWeaveWebTests
private static string[] ServerPluginIds()
{
string? dir = AppContext.BaseDirectory;
while (dir != null && !Directory.Exists(Path.Combine(dir, "Plugins", "Shared", "ServerPack")))
dir = Path.GetDirectoryName(dir);
if (dir == null) throw new DirectoryNotFoundException("Plugins not found above " + AppContext.BaseDirectory);
var ids = new List<string>();
foreach (string p in Directory.GetDirectories(Path.Combine(dir, "Plugins"), "RynthCore.Plugin.Rynth*"))
foreach (string p in Directory.GetDirectories(ServerProjectsTests.PluginsDir(), "RynthCore.Plugin.Rynth*"))
{
string csproj = Path.Combine(p, Path.GetFileName(p) + ".csproj");
if (!File.Exists(csproj)) continue;