RynthCore as of 2026-11-10 (internal b7e3008): release 2026.11.10.1
This commit is contained in:
parent
7cb161cf44
commit
55e15c0ac4
59 changed files with 6963 additions and 1030 deletions
|
|
@ -115,6 +115,9 @@ internal static class Program
|
|||
("layout", "layout", "layout frob"),
|
||||
("layout", "layout reset confirm", "layout reset now"),
|
||||
("layout", "layout default", "layout default now"),
|
||||
("webpanel", "webpanel status", "webpanel open"),
|
||||
("webpanel", "webpanel", "webpanel frob"),
|
||||
("webpanel", "webpanel close", "webpanel close now"),
|
||||
};
|
||||
|
||||
private static void EveryVerbValidAndInvalid()
|
||||
|
|
@ -167,6 +170,8 @@ internal static class Program
|
|||
("flight", "flight mark here", "flight frob", "FlightRecorder.HandleCommand: its usage"),
|
||||
("autoid", "autoid limited", "autoid frob", "AutoIdService.HandleCommand: its usage"),
|
||||
("uicost", "uicost 80", "uicost frob", "UiCost.HandleCommand: its usage"),
|
||||
("chatwindow", "chatwindow open Combat", "chatwindow frob", "ChatWindows.Parse: unknown verb + usage"),
|
||||
("chatwindow", "chatwin close all", "chatwin close 9", "ChatWindows.Parse: no such window + usage"),
|
||||
("netmsg", "netmsg log on", "netmsg frob", "ServerMessageStream.HandleCommand: its usage"),
|
||||
("hotkeys", "hotkeys", "hotkeys frob", "HotkeyCommandParser: unknown verb + usage"),
|
||||
("settings", "settings Hotkeys", "settings frob", "SettingsCommand: no tab called 'frob' (tabs: ...)"),
|
||||
|
|
@ -341,6 +346,19 @@ internal static class Program
|
|||
Check(!Regex.IsMatch(src, @"\bReply\(\$?""[Uu]sage"), "no usage line is written as a success (they go through Fail)");
|
||||
Check(!Regex.IsMatch(src, @"\bReply\((usage|ServerUsage)\)"), "nor the usage constants");
|
||||
Check(!Regex.IsMatch(src, @"catch \(Exception ex\) \{ RynthLog\.Compat"), "no command's exception is only logged");
|
||||
|
||||
Case("RynthCoreChatCommands.cs: /rc webpanel never opens or navigates (an arbitrary-URL command would be a phishing vector)");
|
||||
int wpStart = src.IndexOf("private static void HandleWebPanelCommand", StringComparison.Ordinal);
|
||||
int wpEnd = src.IndexOf("private static void HandleLayoutCommand", StringComparison.Ordinal);
|
||||
Check(wpStart > 0 && wpEnd > wpStart, "found HandleWebPanelCommand");
|
||||
if (wpStart > 0 && wpEnd > wpStart)
|
||||
{
|
||||
string wp = src.Substring(wpStart, wpEnd - wpStart);
|
||||
Check(!Regex.IsMatch(wp, @"\bOpen\("), "HandleWebPanelCommand has no Open(");
|
||||
Check(!Regex.IsMatch(wp, @"\bNavigate\("), "HandleWebPanelCommand has no Navigate(");
|
||||
Check(!wp.Contains("ShellExecute", StringComparison.Ordinal), "HandleWebPanelCommand has no ShellExecute");
|
||||
Check(wp.Contains("WebPanelApi.Close(", StringComparison.Ordinal), "the scan reads the real body (it calls WebPanelApi.Close)");
|
||||
}
|
||||
}
|
||||
|
||||
private static string? FindRepoFile(string relative)
|
||||
|
|
|
|||
30
tools/ChatWindowTests/ChatWindowTests.csproj
Normal file
30
tools/ChatWindowTests/ChatWindowTests.csproj
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!--
|
||||
Offline checks for the extra chat windows (2026-11-09): src\RynthCore.Engine\UI\Data\ChatWindows.cs
|
||||
(window keys and numbers, the first free window, which tab a window shows when its own is gone, a
|
||||
rename followed, /rc chatwindow's parsing) and UI\PanelStateStore.cs's values (where a window's tab
|
||||
is saved: per layout, switched with it, written only when set, kept by an unknown reader), with
|
||||
BarLayout.cs and EngineSettingsFile.cs, compiled in with a stub RynthLog and EngineSettings. Also
|
||||
reads ChatCommandReplies.cs and ChatView.cs / ChatFace.cs as text (the catalog's usage line is
|
||||
ChatWindows.Usage; no face's code saves a tab on its own). Writes only to a temp folder (deleted
|
||||
at the end); never touches %LOCALAPPDATA% or C:\Games.
|
||||
Run: dotnet run -c Release (exit 0 = pass, 1 = fail)
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<RootNamespace>ChatWindowTests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\ChatWindows.cs" Link="Engine\ChatWindows.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\PanelStateStore.cs" Link="Engine\PanelStateStore.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\BarLayout.cs" Link="Engine\BarLayout.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Plugins\EngineSettingsFile.cs" Link="Engine\EngineSettingsFile.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
257
tools/ChatWindowTests/Program.cs
Normal file
257
tools/ChatWindowTests/Program.cs
Normal file
|
|
@ -0,0 +1,257 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using RynthCore.Engine.UI;
|
||||
using RynthCore.Engine.UI.Data;
|
||||
|
||||
namespace RynthCore.Engine
|
||||
{
|
||||
/// <summary>Stub of the engine's log (PanelStateStore writes load/save problems to it).</summary>
|
||||
internal static class RynthLog
|
||||
{
|
||||
internal static readonly List<string> Lines = new();
|
||||
internal static void UI(string msg) { lock (Lines) Lines.Add(msg); }
|
||||
}
|
||||
}
|
||||
|
||||
namespace RynthCore.Engine.Plugins
|
||||
{
|
||||
/// <summary>Stub of the one engine.json setting PanelStateStore reads.</summary>
|
||||
internal static class EngineSettings
|
||||
{
|
||||
public static bool RememberWindowLayout { get; set; } = true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ChatWindowTests
|
||||
{
|
||||
/// <summary>
|
||||
/// The extra chat windows without AC: their keys, the first free one, the tab each shows, the
|
||||
/// /rc chatwindow parser, and the panel layout values that keep each window's tab.
|
||||
/// </summary>
|
||||
internal static class Program
|
||||
{
|
||||
private static int _fails, _checks;
|
||||
private static string _case = "";
|
||||
|
||||
private static int Main()
|
||||
{
|
||||
Keys();
|
||||
FirstFree();
|
||||
Tabs();
|
||||
Parser();
|
||||
StoreValues();
|
||||
Sources();
|
||||
Console.WriteLine(_fails == 0 ? $"PASS ({_checks} checks)" : $"FAIL: {_fails} of {_checks} checks");
|
||||
return _fails == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
private static void Case(string name) { _case = name; Console.WriteLine("-- " + name); }
|
||||
|
||||
private static void Check(bool ok, string what)
|
||||
{
|
||||
_checks++;
|
||||
if (ok) return;
|
||||
_fails++;
|
||||
Console.WriteLine($" FAIL [{_case}] {what}");
|
||||
}
|
||||
|
||||
private static void Eq<T>(T got, T want, string what) =>
|
||||
Check(EqualityComparer<T>.Default.Equals(got, want), $"{what} (got '{got}', want '{want}')");
|
||||
|
||||
private static readonly string[] AllTabs =
|
||||
{ "All", "Chat", "Channels", "System", "Combat", "Rynth", "Items", "Other", "Loot Log" };
|
||||
|
||||
private static void Keys()
|
||||
{
|
||||
Case("window keys and numbers");
|
||||
Eq(ChatWindows.MaxWindows, 6, "six extra windows");
|
||||
Eq(ChatWindows.Key(2), "Chat 2", "the first extra window is Chat 2 (the main chat is Chat)");
|
||||
Eq(string.Join("|", ChatWindows.Keys()), "Chat 2|Chat 3|Chat 4|Chat 5|Chat 6|Chat 7", "every key, in order");
|
||||
Check(ChatWindows.TryNumber("Chat 4", out int n) && n == 4, "Chat 4 is window 4");
|
||||
Check(ChatWindows.TryNumber("chat 7", out n) && n == 7, "any case");
|
||||
Check(!ChatWindows.TryNumber("Chat", out _), "the main chat isn't an extra window");
|
||||
Check(!ChatWindows.TryNumber("Chat 1", out _), "nor window 1");
|
||||
Check(!ChatWindows.TryNumber("Chat 8", out _), "nor past the last");
|
||||
Check(!ChatWindows.TryNumber("Chat 2x", out _), "nor a longer word");
|
||||
Check(!ChatWindows.TryNumber("ChatFilters", out _), "nor the Filters panel");
|
||||
Check(!ChatWindows.TryNumber(null, out _), "nor nothing");
|
||||
Eq(ChatWindows.TabValueKey(3), "chatwin.3.tab", "where window 3's tab is saved");
|
||||
Eq(ChatWindows.HeaderText(3, "Combat"), "Chat 3 · Combat", "its header");
|
||||
}
|
||||
|
||||
private static void FirstFree()
|
||||
{
|
||||
Case("the first free window");
|
||||
Eq(ChatWindows.FirstFree(_ => false), 2, "none open: Chat 2");
|
||||
var open = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Chat 2", "Chat 4" };
|
||||
Eq(ChatWindows.FirstFree(open.Contains), 3, "a gap is filled first");
|
||||
Eq(ChatWindows.FirstFree(k => k != "Chat 7"), 7, "the last one");
|
||||
Eq(ChatWindows.FirstFree(_ => true), 0, "all open: none (0)");
|
||||
}
|
||||
|
||||
private static void Tabs()
|
||||
{
|
||||
Case("the tab a window shows");
|
||||
Eq(ChatWindows.EffectiveTab("Combat", AllTabs), "Combat", "its own");
|
||||
Eq(ChatWindows.EffectiveTab("combat", AllTabs), "Combat", "spelled as the tab is now");
|
||||
Eq(ChatWindows.EffectiveTab("loot log", AllTabs), "Loot Log", "a created tab, with a space");
|
||||
Eq(ChatWindows.EffectiveTab("Gone", AllTabs), "All", "a deleted tab: All (like the main chat)");
|
||||
Eq(ChatWindows.EffectiveTab("", AllTabs), "All", "nothing saved: All");
|
||||
Eq(ChatWindows.EffectiveTab(null, AllTabs), "All", "nothing saved (null): All");
|
||||
Eq(ChatWindows.Resolve(" Items ", AllTabs), "Items", "typed with spaces around it");
|
||||
Eq(ChatWindows.Resolve("Itemz", AllTabs), null, "no such tab: null");
|
||||
|
||||
Case("a rename followed");
|
||||
Eq(ChatWindows.FollowRename("Loot Log", "loot log", "Drops"), "Drops", "the window showing it follows");
|
||||
Eq(ChatWindows.FollowRename("Combat", "Loot Log", "Drops"), null, "another window: no change");
|
||||
Eq(ChatWindows.FollowRename(null, "Loot Log", "Drops"), null, "nothing saved: no change");
|
||||
Eq(ChatWindows.FollowRename("Loot Log", "Loot Log", " "), null, "a blank new name: no change");
|
||||
}
|
||||
|
||||
private static void Parser()
|
||||
{
|
||||
Case("/rc chatwindow parsing");
|
||||
Eq(ChatWindows.Parse("").Verb, ChatWindowVerb.List, "alone: the list");
|
||||
Eq(ChatWindows.Parse(" list ").Verb, ChatWindowVerb.List, "list");
|
||||
Eq(ChatWindows.Parse("status").Verb, ChatWindowVerb.List, "status");
|
||||
var open = ChatWindows.Parse("open Loot Log");
|
||||
Check(open.Verb == ChatWindowVerb.Open && open.Tab == "Loot Log", "open <tab with a space>");
|
||||
var bare = ChatWindows.Parse("open");
|
||||
Check(bare.Verb == ChatWindowVerb.Open && bare.Tab == "", "open alone: the main chat's tab");
|
||||
Eq(ChatWindows.Parse("new Combat").Verb, ChatWindowVerb.Open, "new = open");
|
||||
var close = ChatWindows.Parse("close 3");
|
||||
Check(close.Verb == ChatWindowVerb.Close && close.Number == 3, "close 3");
|
||||
close = ChatWindows.Parse("close chat 3");
|
||||
Check(close.Verb == ChatWindowVerb.Close && close.Number == 3, "close chat 3");
|
||||
Eq(ChatWindows.Parse("CLOSE ALL").Verb, ChatWindowVerb.CloseAll, "close all, any case");
|
||||
var tab = ChatWindows.Parse("tab 5 Loot Log");
|
||||
Check(tab.Verb == ChatWindowVerb.Tab && tab.Number == 5 && tab.Tab == "Loot Log", "tab 5 <tab>");
|
||||
tab = ChatWindows.Parse("tab chat 5 Combat");
|
||||
Check(tab.Verb == ChatWindowVerb.Tab && tab.Number == 5 && tab.Tab == "Combat", "tab chat 5 <tab>");
|
||||
|
||||
foreach (string bad in new[] { "frob", "close", "close 9", "close 1", "close 3 x", "close x", "tab", "tab 3", "tab 9 Combat", "tab Combat" })
|
||||
{
|
||||
var c = ChatWindows.Parse(bad);
|
||||
Check(c.Verb == ChatWindowVerb.Error && c.Error.EndsWith(ChatWindows.Usage, StringComparison.Ordinal),
|
||||
$"'/rc chatwindow {bad}': why, then the usage (got {c.Verb}: {c.Error})");
|
||||
Check(!c.Error.StartsWith("Usage", StringComparison.Ordinal) || c.Error == ChatWindows.Usage, $"'{bad}': one usage line");
|
||||
}
|
||||
Check(ChatWindows.Parse("frob").Error.StartsWith("Unknown", StringComparison.Ordinal), "an unknown verb starts 'Unknown' (a failure in red)");
|
||||
Check(ChatWindows.Usage.StartsWith("Usage: /rc chatwindow", StringComparison.Ordinal), "the usage names the command");
|
||||
}
|
||||
|
||||
private static string NewDir(string name)
|
||||
{
|
||||
string d = Path.Combine(Path.GetTempPath(), "rynth-chatwindowtests-" + Environment.ProcessId, name);
|
||||
Directory.CreateDirectory(d);
|
||||
return d;
|
||||
}
|
||||
|
||||
private static void StoreValues()
|
||||
{
|
||||
Case("a window's tab in the panel layout (PanelStateStore values)");
|
||||
string root = NewDir("store");
|
||||
try
|
||||
{
|
||||
string a = Path.Combine(root, "a", "panel_state.txt");
|
||||
string b = Path.Combine(root, "b", "panel_state.txt");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(a)!);
|
||||
const string aText = "# A\r\npanel.Chat=open,10,20,300,200,docked,0,0\r\npanel.Chat 2=open,400,20,300,200,floating,900,100\r\n";
|
||||
File.WriteAllText(a, aText);
|
||||
PanelStateStore.SwitchTo(a, flushCurrent: false);
|
||||
int gen = PanelStateStore.Generation;
|
||||
Check(!PanelStateStore.TryGetValue("chatwin.2.tab", out string v) && v == "", "nothing saved: no value");
|
||||
Check(PanelStateStore.TryGetPanel("Chat 2", out var w2) && w2.Open && w2.Floating && w2.FloatingLeft == 900,
|
||||
"an extra window's place, open and popped-out state are an ordinary panel row");
|
||||
Eq(File.ReadAllText(a), aText, "reading writes nothing");
|
||||
|
||||
PanelStateStore.SetValue("chatwin.2.tab", "Loot Log");
|
||||
Check(PanelStateStore.TryGetValue("chatwin.2.tab", out v) && v == "Loot Log", "set, then read back");
|
||||
Check(File.ReadAllText(a).Contains("value.chatwin.2.tab=Loot Log", StringComparison.Ordinal), "saved in the layout's file");
|
||||
Check(File.ReadAllText(a).Contains("panel.Chat 2=open,400,20,300,200,floating,900,100", StringComparison.Ordinal), "the panel rows are kept");
|
||||
string before = File.ReadAllText(a);
|
||||
PanelStateStore.SetValue("chatwin.2.tab", "Loot Log");
|
||||
Eq(File.ReadAllText(a), before, "the same value again writes nothing new");
|
||||
|
||||
PanelStateStore.SetValue("chatwin.3.tab", "Tab = with, commas");
|
||||
Check(PanelStateStore.TryGetValue("chatwin.3.tab", out v) && v == "Tab = with, commas", "'=' and ',' in a value survive in memory");
|
||||
|
||||
PanelStateStore.SwitchTo(b, flushCurrent: true);
|
||||
Check(PanelStateStore.Generation != gen, "a switch moves the generation (open windows read their tab again)");
|
||||
Check(!PanelStateStore.TryGetValue("chatwin.2.tab", out _), "another layout: its own values (none)");
|
||||
Check(!File.Exists(b), "reading a layout without a file makes none");
|
||||
|
||||
PanelStateStore.SwitchTo(a, flushCurrent: false);
|
||||
Check(PanelStateStore.TryGetValue("chatwin.2.tab", out v) && v == "Loot Log", "back: the value is read from the file");
|
||||
Check(PanelStateStore.TryGetValue("chatwin.3.tab", out v) && v == "Tab = with, commas", "'=' and ',' survive the file");
|
||||
|
||||
PanelStateStore.SetValue("chatwin.3.tab", "line\r\nbreak");
|
||||
Check(PanelStateStore.TryGetValue("chatwin.3.tab", out v) && !v.Contains('\n') && !v.Contains('\r'), "line breaks are dropped (one row per value)");
|
||||
PanelStateStore.SetValue("chatwin.3.tab", null);
|
||||
Check(!PanelStateStore.TryGetValue("chatwin.3.tab", out _), "null removes it");
|
||||
Check(!File.ReadAllText(a).Contains("chatwin.3", StringComparison.Ordinal), "and its row");
|
||||
|
||||
Case("PanelStateStore values: a file from an older build, and Remember Open Windows off");
|
||||
string old = Path.Combine(root, "old", "panel_state.txt");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(old)!);
|
||||
File.WriteAllText(old, "panel.Chat=open,1,2,3,4\r\n");
|
||||
PanelStateStore.SwitchTo(old, flushCurrent: false);
|
||||
Check(PanelStateStore.TryGetPanel("Chat", out _) && !PanelStateStore.TryGetValue("chatwin.2.tab", out _), "no value rows: loads as before");
|
||||
RynthCore.Engine.Plugins.EngineSettings.RememberWindowLayout = false;
|
||||
try
|
||||
{
|
||||
string oldText = File.ReadAllText(old);
|
||||
PanelStateStore.SetValue("chatwin.2.tab", "Combat");
|
||||
Check(PanelStateStore.TryGetValue("chatwin.2.tab", out v) && v == "Combat", "off: kept in memory");
|
||||
Eq(File.ReadAllText(old), oldText, "off: the file isn't written (as panel places)");
|
||||
}
|
||||
finally { RynthCore.Engine.Plugins.EngineSettings.RememberWindowLayout = true; }
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { Directory.Delete(Path.GetDirectoryName(root)!, recursive: true); } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
private static string? FindRepoFile(string relative)
|
||||
{
|
||||
string? dir = AppContext.BaseDirectory;
|
||||
while (dir != null)
|
||||
{
|
||||
string p = Path.Combine(dir, relative);
|
||||
if (File.Exists(p)) return p;
|
||||
dir = Path.GetDirectoryName(dir);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void Sources()
|
||||
{
|
||||
Case("sources: the catalog's usage, and nothing saves a tab by itself");
|
||||
string? replies = FindRepoFile(Path.Combine("src", "RynthCore.Engine", "Compatibility", "ChatCommandReplies.cs"));
|
||||
Check(replies != null && File.ReadAllText(replies).Contains("\"" + ChatWindows.Usage + "\"", StringComparison.Ordinal),
|
||||
"ChatCommandReplies' chatwindow row has ChatWindows.Usage");
|
||||
|
||||
string? face = FindRepoFile(Path.Combine("src", "RynthCore.Engine", "ImGui", "Panels", "ChatWindowFace.cs"));
|
||||
Check(face != null, "found ChatWindowFace.cs");
|
||||
if (face != null)
|
||||
{
|
||||
string src = File.ReadAllText(face);
|
||||
int from = src.IndexOf("public void OnShown()", StringComparison.Ordinal);
|
||||
int to = src.IndexOf("// ── Opening, closing", StringComparison.Ordinal);
|
||||
Check(from > 0 && to > from, "found the face's open/draw code");
|
||||
if (from > 0 && to > from)
|
||||
{
|
||||
string body = src.Substring(from, to - from);
|
||||
Check(!body.Contains("SaveTab(", StringComparison.Ordinal) && !body.Contains("SetValue(", StringComparison.Ordinal),
|
||||
"opening, reading and drawing a window never saves its tab (only a player's pick, open or rename does)");
|
||||
}
|
||||
}
|
||||
|
||||
string? view = FindRepoFile(Path.Combine("src", "RynthCore.Engine", "ImGui", "Panels", "ChatView.cs"));
|
||||
Check(view != null, "found ChatView.cs");
|
||||
if (view != null)
|
||||
Eq(Regex.Matches(File.ReadAllText(view), @"_selectTab\(").Count, 2,
|
||||
"a view picks a tab in two places only: a click in the tab list, and a tab it created");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -58,6 +58,7 @@ namespace EngineSettingsTests
|
|||
Run(nameof(MaxHotReloadsReadAndKept), MaxHotReloadsReadAndKept);
|
||||
Run(nameof(CloseOnServerDisconnectDefaultOnAndSaved), CloseOnServerDisconnectDefaultOnAndSaved);
|
||||
Run(nameof(TransitionGateDefaultOnAndSaved), TransitionGateDefaultOnAndSaved);
|
||||
Run(nameof(WebPanelDefaultOnAndSaved), WebPanelDefaultOnAndSaved);
|
||||
Run(nameof(HoldReloadInWorldOptInAndSaved), HoldReloadInWorldOptInAndSaved);
|
||||
Run(nameof(IltServerNamesEdit), IltServerNamesEdit);
|
||||
Run(nameof(DisplaySettingsDefaultsAndSaved), DisplaySettingsDefaultsAndSaved);
|
||||
|
|
@ -118,6 +119,8 @@ namespace EngineSettingsTests
|
|||
case "dcclose-on": EngineSettings.CloseOnServerDisconnect = true; break;
|
||||
case "tgate-off": EngineSettings.TransitionGate = false; break;
|
||||
case "tgate-on": EngineSettings.TransitionGate = true; break;
|
||||
case "webpanel-off": EngineSettings.WebPanel = false; break;
|
||||
case "webpanel-on": EngineSettings.WebPanel = true; break;
|
||||
case "borderless-on": EngineSettings.BorderlessWindowed = true; break;
|
||||
case "borderless-off": EngineSettings.BorderlessWindowed = false; break;
|
||||
case "layout-on": EngineSettings.RememberWindowLayout = true; break;
|
||||
|
|
@ -148,6 +151,7 @@ namespace EngineSettingsTests
|
|||
Console.WriteLine("MaxHotReloads=" + EngineSettings.MaxHotReloads);
|
||||
Console.WriteLine("CloseOnServerDisconnect=" + EngineSettings.CloseOnServerDisconnect);
|
||||
Console.WriteLine("TransitionGate=" + EngineSettings.TransitionGate);
|
||||
Console.WriteLine("WebPanel=" + EngineSettings.WebPanel);
|
||||
Console.WriteLine("BorderlessWindowed=" + EngineSettings.BorderlessWindowed);
|
||||
Console.WriteLine("RememberWindowLayout=" + EngineSettings.RememberWindowLayout);
|
||||
Console.WriteLine("PanelLayoutPerCharacter=" + EngineSettings.PanelLayoutPerCharacter);
|
||||
|
|
@ -415,6 +419,7 @@ namespace EngineSettingsTests
|
|||
(new[] { "ilt-add", "Frosthaven" }, "IltServerNames", null),
|
||||
(new[] { "autoid", "all" }, "AutoIdMode", "\"All\""),
|
||||
(new[] { "tgate-off" }, "TransitionGate", "false"),
|
||||
(new[] { "webpanel-off" }, "WebPanel", "false"),
|
||||
(new[] { "add-plugin", plugin }, "PluginPaths", null),
|
||||
(new[] { "remove-plugin", "0" }, "PluginPaths", null),
|
||||
};
|
||||
|
|
@ -622,6 +627,36 @@ namespace EngineSettingsTests
|
|||
}
|
||||
}
|
||||
|
||||
// engine.json WebPanel (2026-11-07, the v94 web panel kill switch): default on, only a hand-set false is
|
||||
// written, other saves keep it, a value that is not a boolean is ignored.
|
||||
private static void WebPanelDefaultOnAndSaved()
|
||||
{
|
||||
string dir = NewDir("webpanel");
|
||||
string path = Path.Combine(dir, "engine.json");
|
||||
|
||||
File.WriteAllText(path, LauncherFile);
|
||||
Eq(DumpValue(RunChild(path, "dump").Out, "WebPanel"), "True", "missing: on");
|
||||
Eq(RunChild(path, "hook-off", "StartTooltip").Exit, 0, "save with the default");
|
||||
Check(!ReadJson(path).TryGetProperty("WebPanel", out _), "the default isn't written to the file");
|
||||
|
||||
var (exit, output) = RunChild(path, "webpanel-off");
|
||||
Eq(exit, 0, "turn off (" + output.Trim() + ")");
|
||||
Eq(ReadJson(path).GetProperty("WebPanel").GetRawText(), "false", "off is saved");
|
||||
Check(ReadJson(path).TryGetProperty("LauncherWindow", out _), "launcher keys kept");
|
||||
Eq(DumpValue(RunChild(path, "dump").Out, "WebPanel"), "False", "off read back at the next start");
|
||||
Eq(RunChild(path, "hook-off", "CheckTooltip").Exit, 0, "another save");
|
||||
Eq(ReadJson(path).GetProperty("WebPanel").GetRawText(), "false", "off survives other saves");
|
||||
|
||||
Eq(RunChild(path, "webpanel-on").Exit, 0, "turn on");
|
||||
Check(!ReadJson(path).TryGetProperty("WebPanel", out _), "on again: dropped from the file");
|
||||
|
||||
foreach (string bad in new[] { "\"no\"", "0", "null" })
|
||||
{
|
||||
File.WriteAllText(path, LauncherFile.Replace("\"LoggingLevel\"", $"\"WebPanel\": {bad}, \"LoggingLevel\""));
|
||||
Eq(DumpValue(RunChild(path, "dump").Out, "WebPanel"), "True", $"{bad}: ignored, on");
|
||||
}
|
||||
}
|
||||
|
||||
// Settings > Display (2026-10-18): BorderlessWindowed off and RememberAcWindowPosition off by default,
|
||||
// RememberWindowLayout on (panels have always been remembered). Only the non-default is written;
|
||||
// other saves keep it; a value that is not a boolean is ignored.
|
||||
|
|
|
|||
|
|
@ -59,6 +59,10 @@ internal static class Program
|
|||
Run(nameof(SdkApiVersionCannotDrift), SdkApiVersionCannotDrift);
|
||||
Run(nameof(TrainingStructsMirror), TrainingStructsMirror);
|
||||
Run(nameof(ContainerOrderSlots), ContainerOrderSlots);
|
||||
Run(nameof(WebPanelFieldsAppended), WebPanelFieldsAppended);
|
||||
Run(nameof(WebPanelStructsMatch), WebPanelStructsMatch);
|
||||
Run(nameof(WebPanelCodesMatch), WebPanelCodesMatch);
|
||||
Run(nameof(HasWebPanel_FalseOnOldOrPartialTable), HasWebPanel_FalseOnOldOrPartialTable);
|
||||
Run(nameof(ManifestAttributeDrivesRuntimeMinimum), ManifestAttributeDrivesRuntimeMinimum);
|
||||
Run(nameof(DedupeSamePathTwice), DedupeSamePathTwice);
|
||||
Run(nameof(DedupeCaseAndSlashes), DedupeCaseAndSlashes);
|
||||
|
|
@ -565,6 +569,7 @@ internal static class Program
|
|||
{
|
||||
Eq(RynthCoreHost.CurrentApiVersion, PluginContractVersion.Current, "RynthCoreHost.CurrentApiVersion");
|
||||
Check(RynthCoreHost.BaselineApiVersion <= RynthCoreHost.CurrentApiVersion, "baseline at or below current");
|
||||
Check(PluginContractVersion.BarMenu <= PluginContractVersion.Current, "BarMenu (the barMenu manifest key's version) is at or below current");
|
||||
|
||||
// The SDK's copy of the table must reach as far as the engine's (same field count, same size).
|
||||
int sdkFields = typeof(RynthCoreApiNative).GetFields().Length;
|
||||
|
|
@ -589,6 +594,102 @@ internal static class Program
|
|||
"targets: the manifest and the runtime attribute both use the derived minimum");
|
||||
}
|
||||
|
||||
// v94: the web panel's four slots are appended right after GetMonsterHealthFn, in order, on both sides.
|
||||
private static void WebPanelFieldsAppended()
|
||||
{
|
||||
string[] slots = { "WebPanelOpenFn", "WebPanelNavigateFn", "WebPanelCloseFn", "WebPanelGetStateFn" };
|
||||
string prev = "GetMonsterHealthFn";
|
||||
foreach (string slot in slots)
|
||||
{
|
||||
Eq((int)Marshal.OffsetOf<RynthCore.Engine.Plugins.RynthCoreAPI>(slot),
|
||||
(int)Marshal.OffsetOf<RynthCore.Engine.Plugins.RynthCoreAPI>(prev) + IntPtr.Size, "engine " + slot + " right after " + prev);
|
||||
Eq((int)Marshal.OffsetOf<RynthCore.PluginSdk.RynthCoreApiNative>(slot),
|
||||
(int)Marshal.OffsetOf<RynthCore.PluginSdk.RynthCoreApiNative>(prev) + IntPtr.Size, "SDK " + slot + " right after " + prev);
|
||||
prev = slot;
|
||||
}
|
||||
Eq(typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).SkipLast(4).Last(), "GetMonsterHealthFn", "engine table: GetMonsterHealthFn precedes the four");
|
||||
Eq(typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).SkipLast(4).Last(), "GetMonsterHealthFn", "SDK table: GetMonsterHealthFn precedes the four");
|
||||
}
|
||||
|
||||
private static void StructMirror(Type engine, Type sdk, int size)
|
||||
{
|
||||
Eq(Marshal.SizeOf(engine), size, "engine " + engine.Name + " size");
|
||||
Eq(Marshal.SizeOf(sdk), size, "SDK " + sdk.Name + " size");
|
||||
var ef = engine.GetFields().Select(f => f.Name).ToArray();
|
||||
var sf = sdk.GetFields().Select(f => f.Name).ToArray();
|
||||
Check(ef.SequenceEqual(sf), engine.Name + " field names/order match: " + string.Join(",", ef) + " vs " + string.Join(",", sf));
|
||||
foreach (string f in ef)
|
||||
Eq((int)Marshal.OffsetOf(sdk, f), (int)Marshal.OffsetOf(engine, f), engine.Name + "." + f + " offset");
|
||||
}
|
||||
|
||||
// v94: the SDK's WebPanelOpenNative/WebPanelStateNative are the engine's, byte for byte.
|
||||
private static void WebPanelStructsMatch()
|
||||
{
|
||||
int p = IntPtr.Size;
|
||||
StructMirror(typeof(RynthCore.Engine.Plugins.WebPanelOpenNative), typeof(RynthCore.PluginSdk.WebPanelOpenNative), 8 + 4 * p + 8 + 16);
|
||||
StructMirror(typeof(RynthCore.Engine.Plugins.WebPanelStateNative), typeof(RynthCore.PluginSdk.WebPanelStateNative), 48);
|
||||
Eq((int)Marshal.OffsetOf<RynthCore.Engine.Plugins.WebPanelOpenNative>("Reserved"), 8 + 4 * p + 8, "engine WebPanelOpenNative.Reserved offset (32 on x86)");
|
||||
// The 32-bit AC client's contract: 48 bytes, Reserved at 32 (only checked when this run is x86).
|
||||
if (IntPtr.Size == 4)
|
||||
{
|
||||
Eq(Marshal.SizeOf<RynthCore.Engine.Plugins.WebPanelOpenNative>(), 48, "x86 engine WebPanelOpenNative size");
|
||||
Eq(Marshal.SizeOf<RynthCore.PluginSdk.WebPanelOpenNative>(), 48, "x86 SDK WebPanelOpenNative size");
|
||||
Eq((int)Marshal.OffsetOf<RynthCore.Engine.Plugins.WebPanelOpenNative>("Reserved"), 32, "x86 engine WebPanelOpenNative.Reserved offset");
|
||||
Eq((int)Marshal.OffsetOf<RynthCore.PluginSdk.WebPanelOpenNative>("Reserved"), 32, "x86 SDK WebPanelOpenNative.Reserved offset");
|
||||
Eq(Marshal.SizeOf<RynthCore.Engine.Plugins.WebPanelStateNative>(), 48, "x86 engine WebPanelStateNative size");
|
||||
Eq(Marshal.SizeOf<RynthCore.PluginSdk.WebPanelStateNative>(), 48, "x86 SDK WebPanelStateNative size");
|
||||
}
|
||||
Console.WriteLine($" (WebPanelStructsMatch ran with IntPtr.Size={IntPtr.Size})");
|
||||
}
|
||||
|
||||
// v94: every code value agrees between the engine's enums and the SDK's.
|
||||
private static void WebPanelCodesMatch()
|
||||
{
|
||||
Dictionary<string, long> Vals(Type t) => Enum.GetNames(t).ToDictionary(n => n, n => Convert.ToInt64(Enum.Parse(t, n)));
|
||||
var engine = Vals(typeof(RynthCore.Engine.Plugins.WebPanelCode));
|
||||
var sdk = Vals(typeof(RynthCore.PluginSdk.WebPanelResult));
|
||||
Eq(sdk.Count, engine.Count, "WebPanelCode vs WebPanelResult member count");
|
||||
foreach (var kv in engine)
|
||||
Check(sdk.TryGetValue(kv.Key, out long v) && v == kv.Value, "WebPanelResult." + kv.Key + " = " + kv.Value);
|
||||
var es = Vals(typeof(RynthCore.Engine.Plugins.WebPanelStatusCode));
|
||||
var ss = Vals(typeof(RynthCore.PluginSdk.WebPanelStatus));
|
||||
Eq(ss.Count, es.Count, "WebPanelStatusCode vs WebPanelStatus member count");
|
||||
foreach (var kv in es)
|
||||
Check(ss.TryGetValue(kv.Key, out long v) && v == kv.Value, "WebPanelStatus." + kv.Key + " = " + kv.Value);
|
||||
Eq((uint)RynthCore.PluginSdk.WebPanelStateFlags.Visible, 1u, "state flag Visible");
|
||||
Eq((uint)RynthCore.PluginSdk.WebPanelStateFlags.Focused, 2u, "state flag Focused");
|
||||
Eq((uint)RynthCore.PluginSdk.WebPanelStateFlags.OpenedInBrowser, 4u, "state flag OpenedInBrowser");
|
||||
Eq((uint)RynthCore.PluginSdk.WebPanelFlags.FallbackToBrowser, 1u, "open flag FallbackToBrowser");
|
||||
Eq((uint)RynthCore.PluginSdk.WebPanelFlags.PageKeepsEscape, 2u, "open flag PageKeepsEscape");
|
||||
}
|
||||
|
||||
// v94: HasWebPanel needs Version >= 94 AND all four slots (an old engine's table is shorter and the
|
||||
// runtime copies the full new-size struct, so slots past its end are garbage, not zero).
|
||||
private static void HasWebPanel_FalseOnOldOrPartialTable()
|
||||
{
|
||||
IntPtr x = (IntPtr)0xDEAD;
|
||||
RynthCoreHost Host(uint version, IntPtr a, IntPtr b, IntPtr c, IntPtr d)
|
||||
=> new RynthCoreHost(new RynthCoreApiNative { Version = version, WebPanelOpenFn = a, WebPanelNavigateFn = b, WebPanelCloseFn = c, WebPanelGetStateFn = d });
|
||||
Check(!Host(93, x, x, x, x).HasWebPanel, "Version 93 with garbage slots: false");
|
||||
Check(!Host(94, IntPtr.Zero, x, x, x).HasWebPanel, "Open zero: false");
|
||||
Check(!Host(94, x, IntPtr.Zero, x, x).HasWebPanel, "Navigate zero: false");
|
||||
Check(!Host(94, x, x, IntPtr.Zero, x).HasWebPanel, "Close zero: false");
|
||||
Check(!Host(94, x, x, x, IntPtr.Zero).HasWebPanel, "GetState zero: false");
|
||||
Check(Host(94, x, x, x, x).HasWebPanel, "Version 94, all four: true");
|
||||
var old = Host(93, x, x, x, x);
|
||||
Eq(old.OpenWebPanel(new WebPanelOptions { Url = "https://a.example/", Allowlist = new[] { "a.example" } }), (int)WebPanelResult.Unavailable, "Open without the API: Unavailable");
|
||||
Eq(old.NavigateWebPanel(1, "https://a.example/"), (int)WebPanelResult.Unavailable, "Navigate without the API: Unavailable");
|
||||
Eq(old.CloseWebPanel(1), (int)WebPanelResult.Unavailable, "Close without the API: Unavailable");
|
||||
Eq(old.GetWebPanelState(1, out var st), WebPanelStatus.None, "GetState without the API: None");
|
||||
Eq(st.Handle, 0, "GetState without the API: default state");
|
||||
// Bad arguments are refused before the engine is called (the slots hold garbage, so a call would crash).
|
||||
var live = Host(94, x, x, x, x);
|
||||
Eq(live.OpenWebPanel(new WebPanelOptions { Url = "", Allowlist = new[] { "a" } }), (int)WebPanelResult.BadArgs, "empty URL: BadArgs");
|
||||
Eq(live.OpenWebPanel(new WebPanelOptions { Url = "https://a/", Allowlist = Array.Empty<string>() }), (int)WebPanelResult.BadArgs, "empty allowlist: BadArgs");
|
||||
Eq(live.OpenWebPanel(new WebPanelOptions { Url = "https://a/", Allowlist = new[] { "a\nb" } }), (int)WebPanelResult.BadArgs, "newline in an entry: BadArgs");
|
||||
Eq(live.NavigateWebPanel(1, ""), (int)WebPanelResult.BadArgs, "navigate empty URL: BadArgs");
|
||||
}
|
||||
|
||||
// v79: the SDK's copies of the training structs must be the engine's, byte for byte.
|
||||
private static void TrainingStructsMirror()
|
||||
{
|
||||
|
|
@ -603,11 +704,11 @@ internal static class Program
|
|||
Eq(RynthCore.PluginSdk.TrainingInfoFlags.Busy, RynthCore.Engine.Plugins.TrainingInfoFlags.Busy, "info flag bits");
|
||||
Eq(RynthCore.PluginSdk.TrainingEntryFlags.Trainable, RynthCore.Engine.Plugins.TrainingEntryFlags.Trainable, "entry flag bits");
|
||||
// The three v79 slots follow v78's, then v80's two and v81's GetMergeStackResultFn (v82-v91 follow:
|
||||
// eleven slots to v89, then v90's thirteen, v91's two and v93's one).
|
||||
var names = typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).SkipLast(27).TakeLast(6).ToArray();
|
||||
// eleven slots to v89, then v90's thirteen, v91's two, v93's one and v94's four).
|
||||
var names = typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).SkipLast(31).TakeLast(6).ToArray();
|
||||
Check(names.SequenceEqual(new[] { "GetTrainingInfoFn", "RaiseFn", "TrainSkillFn", "GetContainerOrderFn", "PutItemInContainerFn", "GetMergeStackResultFn" }),
|
||||
"v79, v80 then v81 slots last: " + string.Join(",", names));
|
||||
var sdkNames = typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).SkipLast(27).TakeLast(6).ToArray();
|
||||
var sdkNames = typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).SkipLast(31).TakeLast(6).ToArray();
|
||||
Check(sdkNames.SequenceEqual(names), "SDK v79, v80 and v81 slots in the same order");
|
||||
}
|
||||
|
||||
|
|
@ -618,6 +719,12 @@ internal static class Program
|
|||
{
|
||||
var all = typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).ToArray();
|
||||
var sdkAll = typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).ToArray();
|
||||
// v94: the web panel's four slots end the table; the checks after these are on the table before them.
|
||||
string[] v94 = { "WebPanelOpenFn", "WebPanelNavigateFn", "WebPanelCloseFn", "WebPanelGetStateFn" };
|
||||
Check(all.TakeLast(v94.Length).SequenceEqual(v94), "v94 slots last: " + string.Join(",", all.TakeLast(v94.Length)));
|
||||
Check(sdkAll.TakeLast(v94.Length).SequenceEqual(v94), "SDK v94 slots last: " + string.Join(",", sdkAll.TakeLast(v94.Length)));
|
||||
all = all.SkipLast(v94.Length).ToArray();
|
||||
sdkAll = sdkAll.SkipLast(v94.Length).ToArray();
|
||||
// v93: the monster plates' health readings end the table (2026-11-07), right after v91's two.
|
||||
Check(all.Last() == "GetMonsterHealthFn", "v93 slot last: " + all.Last());
|
||||
Check(sdkAll.Last() == "GetMonsterHealthFn", "SDK v93 slot last: " + sdkAll.Last());
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ internal static class Program
|
|||
WindowPlanChoices();
|
||||
WindowTakeOver();
|
||||
WindowFrameless();
|
||||
ManifestBarMenu();
|
||||
BarMenuHoverTiming();
|
||||
BarMenuReload();
|
||||
StackCheckAfterPluginDraw();
|
||||
|
||||
Console.WriteLine();
|
||||
|
|
@ -585,6 +588,167 @@ internal static class Program
|
|||
"chrome and fitHeight are in the signature (a change re-registers)");
|
||||
}
|
||||
|
||||
// -- Bar icon dropdown (v95) --
|
||||
|
||||
private static string BarMenuManifest(string windowExtra) =>
|
||||
"{ \"version\": 1, \"windows\": [ { \"id\": \"server\", \"title\": \"DreamWeave\", \"surface\": \"window:server\", \"bar\": true"
|
||||
+ windowExtra + " } ] }";
|
||||
|
||||
private static void ManifestBarMenu()
|
||||
{
|
||||
Case("plugin windows: barMenu (v95)");
|
||||
string storefront = ((char)0xE470).ToString(), shield = ((char)0xE40A).ToString(), sparkle = ((char)0xE6A2).ToString();
|
||||
string longTip = new string('T', 60);
|
||||
string longCommand = "/" + new string('c', 250);
|
||||
string items = """
|
||||
[
|
||||
{ "id": "market", "tooltip": "Market", "icon": "@STORE@", "command": "/rserver market" },
|
||||
{ "id": "nocmdslash", "tooltip": "No slash", "icon": "@STORE@", "command": "rserver x" },
|
||||
{ "id": "multiline", "tooltip": "Two lines", "icon": "@STORE@", "command": "/rserver a\n/rserver b" },
|
||||
{ "id": "toolong", "tooltip": "Too long", "icon": "@STORE@", "command": "@LONGCMD@" },
|
||||
{ "id": "", "tooltip": "No id", "icon": "@STORE@", "command": "/rserver x" },
|
||||
{ "id": "market", "tooltip": "Duplicate", "icon": "@STORE@", "command": "/rserver market" },
|
||||
{ "id": "notip", "tooltip": "", "icon": "@STORE@", "command": "/rserver x" },
|
||||
{ "id": "suit", "tooltip": "Suit Builder", "icon": "@SHIELD@", "command": "/rserver suit" },
|
||||
{ "id": "noicon", "tooltip": "No icon", "icon": "", "command": "/rserver x" },
|
||||
{ "id": "abilities", "tooltip": "Ability Planner", "icon": "@SPARKLE@", "command": "/rserver abilities" },
|
||||
{ "id": "longtip", "tooltip": "@LONGTIP@", "icon": "@STORE@", "command": "/rserver x" }
|
||||
]
|
||||
"""
|
||||
.Replace("@STORE@", storefront).Replace("@SHIELD@", shield).Replace("@SPARKLE@", sparkle)
|
||||
.Replace("@LONGCMD@", longCommand).Replace("@LONGTIP@", longTip);
|
||||
|
||||
SectionManifest m = SectionManifestParser.Parse("DW", BarMenuManifest(", \"barMenu\": " + items), out string err);
|
||||
Check(err.Length == 0 && m.Windows.Length == 1, "parses and the window is kept: " + err);
|
||||
SectionBarMenuItem[] menu = m.Windows[0].Menu;
|
||||
string[] ids = menu.Select(i => i.Id).ToArray();
|
||||
Check(ids.SequenceEqual(new[] { "market", "suit", "noicon", "abilities", "longtip" }),
|
||||
"bad items dropped, order kept: " + string.Join(",", ids));
|
||||
Check(menu[0] == new SectionBarMenuItem("market", "Market", storefront, "/rserver market"), "market: fields exactly equal");
|
||||
Check(menu[1] == new SectionBarMenuItem("suit", "Suit Builder", shield, "/rserver suit"), "suit: fields exactly equal");
|
||||
Check(menu[3] == new SectionBarMenuItem("abilities", "Ability Planner", sparkle, "/rserver abilities"), "abilities: fields exactly equal");
|
||||
Check(menu[2].Icon == "" && menu[2].Tooltip == "No icon", "an empty icon is kept as \"\"");
|
||||
Check(menu[4].Tooltip.Length == SectionManifestParser.MaxLabelLength && menu[4].Tooltip == longTip[..48],
|
||||
"an over-long tooltip is cut to 48: " + menu[4].Tooltip.Length);
|
||||
Check(SectionManifestParser.Command("/rserver a\n/rserver b").Length == 0 && SectionManifestParser.Command("rserver x").Length == 0
|
||||
&& SectionManifestParser.Command(longCommand).Length == 0, "(the rejected commands are ones Command() rejects)");
|
||||
|
||||
var many = new System.Text.StringBuilder("[");
|
||||
for (int i = 0; i < 20; i++)
|
||||
many.Append(i > 0 ? "," : "").Append($"{{ \"id\": \"item{i}\", \"tooltip\": \"Item {i}\", \"icon\": \"\", \"command\": \"/rserver x{i}\" }}");
|
||||
many.Append(']');
|
||||
m = SectionManifestParser.Parse("DW", BarMenuManifest(", \"barMenu\": " + many), out err);
|
||||
Check(SectionManifestParser.MaxBarMenuItems == 6 && m.Windows[0].Menu.Length == SectionManifestParser.MaxBarMenuItems,
|
||||
"twenty valid items give exactly MaxBarMenuItems: " + m.Windows[0].Menu.Length);
|
||||
Check(m.Windows[0].Menu[0].Id == "item0" && m.Windows[0].Menu[5].Id == "item5", "the first six are the ones kept");
|
||||
|
||||
m = SectionManifestParser.Parse("DW", BarMenuManifest(", \"barMenu\": \"nope\""), out err);
|
||||
Check(err.Length == 0 && m.Windows.Length == 1 && m.Windows[0].Menu.Length == 0, "barMenu not an array: window kept, no menu");
|
||||
m = SectionManifestParser.Parse("DW", BarMenuManifest(""), out err);
|
||||
Check(err.Length == 0 && m.Windows.Length == 1 && m.Windows[0].Menu.Length == 0, "no barMenu key: no menu");
|
||||
m = SectionManifestParser.Parse("DW", BarMenuManifest(", \"barMenu\": [ { \"id\": \"x\", \"tooltip\": \"X\", \"icon\": \"x\", \"command\": \"/rserver x\" } ]"), out err);
|
||||
Check(err.Length == 0 && m.Windows[0].Menu.Length == 1 && m.Windows[0].Menu[0].Icon == "" && m.Windows[0].Menu[0].Command == "/rserver x",
|
||||
"a non-glyph icon keeps the item with Icon \"\"");
|
||||
}
|
||||
|
||||
private static void BarMenuHoverTiming()
|
||||
{
|
||||
Case("bar dropdown: hover timer");
|
||||
var h = new BarMenuHover();
|
||||
h.Update("a", false, 0.0);
|
||||
h.Update("a", false, 0.10);
|
||||
Check(h.OpenFor == null, "hovering for 0.10 s: not open yet");
|
||||
h.Update("a", false, 0.16);
|
||||
Check(h.OpenFor == "a", "hovering for 0.16 s: open");
|
||||
|
||||
h = new BarMenuHover();
|
||||
h.Update("a", false, 0.0);
|
||||
h.Update("a", false, 0.10);
|
||||
h.Update(null, false, 0.11);
|
||||
h.Update(null, false, 0.20);
|
||||
h.Update(null, false, 0.30);
|
||||
Check(h.OpenFor == null, "a sweep across the icon (0.10 s) never opens it");
|
||||
|
||||
h = new BarMenuHover();
|
||||
h.Update("a", false, 0.0);
|
||||
h.Update("a", false, 0.20);
|
||||
Check(h.OpenFor == "a", "(setup) open on a");
|
||||
Feed(h, "a", 0.30, 0.90);
|
||||
h.Update(null, false, 1.0);
|
||||
h.Update(null, false, 1.10);
|
||||
h.Update(null, true, 1.20);
|
||||
h.Update(null, true, 1.25);
|
||||
Check(h.OpenFor == "a", "leaving the icon and reaching the dropdown 0.20 s later: still open (the gap is covered)");
|
||||
|
||||
h = new BarMenuHover();
|
||||
h.Update("a", false, 0.0);
|
||||
h.Update("a", false, 0.20);
|
||||
Feed(h, "a", 0.30, 0.90);
|
||||
h.Update(null, false, 1.0);
|
||||
h.Update(null, false, 1.29);
|
||||
Check(h.OpenFor == "a", "gone for 0.29 s: still open");
|
||||
h.Update(null, false, 1.31);
|
||||
Check(h.OpenFor == null, "gone for 0.31 s: closed");
|
||||
|
||||
h = new BarMenuHover();
|
||||
h.Update("a", false, 0.0);
|
||||
h.Update("a", false, 0.20);
|
||||
Feed(h, "a", 0.30, 1.90);
|
||||
h.Update("b", false, 2.0);
|
||||
Check(h.OpenFor == "b", "an open dropdown switches to another icon at once");
|
||||
|
||||
h = new BarMenuHover();
|
||||
h.Update("a", false, 0.0);
|
||||
h.Update("a", false, 0.20);
|
||||
h.Close();
|
||||
Check(h.OpenFor == null, "Close() closes");
|
||||
Feed(h, "a", 0.30, 4.90);
|
||||
h.Update("a", false, 5.0);
|
||||
Check(h.OpenFor == null, "still hovering the same icon: not reopened");
|
||||
h.Update(null, false, 5.10);
|
||||
Feed(h, null, 5.20, 5.90);
|
||||
h.Update("a", false, 6.0);
|
||||
Check(h.OpenFor == null, "hovered again but not for OpenDelay yet");
|
||||
h.Update("a", false, 6.16);
|
||||
Check(h.OpenFor == "a", "left and hovered again for OpenDelay: reopens");
|
||||
Check(BarMenuHover.OpenDelay == 0.15 && BarMenuHover.CloseDelay == 0.30, "delays are 0.15 s and 0.30 s");
|
||||
|
||||
// The popped-out bar draws in another ImGui context whose clock starts near 0.
|
||||
h = new BarMenuHover();
|
||||
h.Update("a", false, 0.0);
|
||||
h.Update("a", false, 0.20);
|
||||
h.Update(null, false, 1000.0);
|
||||
h.Update(null, false, 0.05);
|
||||
Check(h.OpenFor == null, "the clock jumping back (a pop-out's own context): reset, closed");
|
||||
|
||||
// A bar that wasn't drawn for a while sends no frames.
|
||||
h = new BarMenuHover();
|
||||
h.Update("a", false, 0.0);
|
||||
h.Update("a", false, 0.20);
|
||||
h.Update("a", false, 0.20 + BarMenuHover.ResetGap + 0.01);
|
||||
Check(h.OpenFor == null, "a forward gap of more than 0.5 s: reset, closed");
|
||||
}
|
||||
|
||||
// Frames from..to every 0.1 s (a real run draws every frame; the timer resets on a gap over 0.5 s).
|
||||
private static void Feed(BarMenuHover h, string? hovered, double from, double to)
|
||||
{
|
||||
for (double t = from; t <= to + 1e-9; t += 0.1) h.Update(hovered, false, t);
|
||||
}
|
||||
|
||||
private static void BarMenuReload()
|
||||
{
|
||||
Case("bar dropdown: a barMenu-only change is seen by the host");
|
||||
string one = BarMenuManifest(", \"barMenu\": [ { \"id\": \"a\", \"tooltip\": \"A\", \"icon\": \"\", \"command\": \"/rserver a\" } ]");
|
||||
SectionWindowDecl w1 = SectionManifestParser.Parse("DW", one, out _).Windows[0];
|
||||
SectionWindowDecl w1Again = SectionManifestParser.Parse("DW", one, out _).Windows[0];
|
||||
SectionWindowDecl w2 = SectionManifestParser.Parse("DW", one.Replace("/rserver a", "/rserver b"), out _).Windows[0];
|
||||
SectionWindowDecl w3 = SectionManifestParser.Parse("DW", BarMenuManifest(""), out _).Windows[0];
|
||||
Check(WindowPlan.Signature(w1) == WindowPlan.Signature(w2), "(the panel signature ignores the menu: no re-registration)");
|
||||
Check(WindowPlan.MenuSignature(w1) == WindowPlan.MenuSignature(w1Again), "the same menu parsed twice: same menu signature");
|
||||
Check(WindowPlan.MenuSignature(w1) != WindowPlan.MenuSignature(w2), "a changed command: new menu signature");
|
||||
Check(WindowPlan.MenuSignature(w1) != WindowPlan.MenuSignature(w3), "menu removed: new menu signature");
|
||||
Check(WindowPlan.MenuSignature(w3) == WindowPlan.MenuSignature(w3 with { BarMenu = null }), "no menu is always the same signature");
|
||||
}
|
||||
// ImGui 1.91.6's ImGuiErrorRecoveryState, in field order: windows, IDs, tree nodes, colours,
|
||||
// style vars, fonts, focus scopes, groups, item flags, popups, disabled. The base values are
|
||||
// the ones a 32-bit probe of our cimgui.dll read inside a panel's body child (2026-10-21).
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
<Compile Include="..\..\src\RynthCore.Engine\UI\Sections\SectionManifest.cs" Link="Engine\SectionManifest.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Sections\SectionCatalog.cs" Link="Engine\SectionCatalog.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Sections\WindowPlan.cs" Link="Engine\WindowPlan.cs" />
|
||||
<!-- The bar icon dropdown's hover timer (pure). -->
|
||||
<Compile Include="..\..\src\RynthCore.Engine\ImGui\BarMenuHover.cs" Link="Engine\BarMenuHover.cs" />
|
||||
<!-- What a plugin window's draw left on ImGui's stacks (the record ImGuiStackGuard takes). -->
|
||||
<Compile Include="..\..\src\RynthCore.Engine\ImGui\ImGuiStackState.cs" Link="Engine\ImGuiStackState.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Compatibility\IltDetect.cs" Link="Engine\IltDetect.cs" />
|
||||
|
|
|
|||
158
tools/WebPanelHarness.Payload/PayloadEntry.cs
Normal file
158
tools/WebPanelHarness.Payload/PayloadEntry.cs
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
// The harness's way into the web panel host. Everything crossing into the harness is a framework
|
||||
// type (int, string, IntPtr, arrays, Action<string>), so nothing of this collectible context is held
|
||||
// by the default one. The calls mirror WebPanelApi (the engine's ABI glue): Open reads the native
|
||||
// struct with WebPanelNativeArgs exactly as the engine does.
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using RynthCore.Engine.Plugins;
|
||||
|
||||
namespace RynthCore.Engine.WebPanel;
|
||||
|
||||
public static unsafe class PayloadEntry
|
||||
{
|
||||
private static StubEnvironment? _env;
|
||||
private static WebPanelHost? _host;
|
||||
|
||||
public static void Init(IntPtr gameHwnd, string runtimeDir, string localAppData, string panelDir, string otherDir,
|
||||
Action<string> log, Action<string> chat, Action<string> browser)
|
||||
{
|
||||
_env = new StubEnvironment(gameHwnd, runtimeDir, localAppData, panelDir, otherDir, log, chat, browser);
|
||||
_host = new WebPanelHost(_env);
|
||||
}
|
||||
|
||||
public static void SetEnvironmentDelay(int ms) => _env!.DelayMs = ms;
|
||||
public static void SetBrowserFolder(string? folder) => _env!.BrowserFolder = folder;
|
||||
public static void SetBrowserFails(bool fails) => _env!.BrowserFails = fails;
|
||||
public static void SetBrowserDelay(int ms) => _env!.BrowserDelayMs = ms;
|
||||
public static void SetWorld(string world) => _env!.World = world;
|
||||
|
||||
/// <summary>The engine's WebPanelApi.Open path: read the caller's struct, then the host.</summary>
|
||||
public static int Open(IntPtr nativeArgs)
|
||||
{
|
||||
int rc = WebPanelNativeArgs.TryBuildRequest((WebPanelOpenNative*)nativeArgs, _env!.LocalAppData, _env.WorldName, out WebPanelRequest? req);
|
||||
if (rc != 0) return rc;
|
||||
return _host!.Open(req!);
|
||||
}
|
||||
|
||||
public static int Navigate(int handle, string url) => _host!.Navigate(handle, url);
|
||||
public static int Close(int handle) => _host!.Close(handle);
|
||||
|
||||
/// <summary>[return, handle, status, flags, error, http, navigations].</summary>
|
||||
public static int[] GetState(int handle)
|
||||
{
|
||||
int r = _host!.GetState(handle, out WebPanelSnapshot s);
|
||||
return new[] { r, s.Handle, s.Status, (int)s.Flags, s.Error, s.LastHttpStatus, (int)s.NavigationCount };
|
||||
}
|
||||
|
||||
public static void Shutdown(int budgetMs) => _host!.Shutdown(budgetMs);
|
||||
public static string Describe() => _host!.Describe();
|
||||
|
||||
public static IntPtr HostHwnd => _host!.HostHwndForTests;
|
||||
public static int EnvironmentCount => _host!.EnvironmentCountForTests;
|
||||
public static int BrowserProcessId => (int)_host!.BrowserProcessIdForTests;
|
||||
public static int AcceleratorKeyEvents => _host!.AcceleratorKeyEventsForTests;
|
||||
public static string Source => _host!.SourceForTests;
|
||||
public static bool ThreadRunning => _host!.ThreadRunningForTests;
|
||||
public static bool PanelOpen => _host!.PanelOpenForTests;
|
||||
public static bool FailHandle(int handle) => _host!.FailForTests(handle);
|
||||
public static bool ReportUnresponsive() => _host!.UnresponsiveForTests();
|
||||
|
||||
public static string ProfileFolder(string world, string key) => WebPanelProfile.Folder(_env!.LocalAppData, world, key);
|
||||
|
||||
/// <summary>Runs script in the page on the panel thread; waits here (the harness thread), never there.</summary>
|
||||
public static string Eval(string js, int timeoutMs)
|
||||
{
|
||||
var done = new ManualResetEventSlim();
|
||||
string result = "TIMEOUT";
|
||||
bool posted = _host!.PostForTests(web =>
|
||||
{
|
||||
if (web == null) { result = "no webview"; done.Set(); return; }
|
||||
try
|
||||
{
|
||||
web.ExecuteScriptAsync(js).ContinueWith(t =>
|
||||
{
|
||||
result = t.IsCompletedSuccessfully ? t.Result : "ERR " + t.Exception?.GetBaseException().Message;
|
||||
done.Set();
|
||||
});
|
||||
}
|
||||
catch (Exception ex) { result = "ERR " + ex.Message; done.Set(); }
|
||||
});
|
||||
if (!posted) return "panel thread not running";
|
||||
done.Wait(timeoutMs);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>Drops this context's statics so nothing in it is reachable before the unload.</summary>
|
||||
public static void Release()
|
||||
{
|
||||
_host = null;
|
||||
_env = null;
|
||||
}
|
||||
|
||||
private sealed class StubEnvironment : IWebPanelEnvironment
|
||||
{
|
||||
private readonly Action<string> _log, _chat, _browser;
|
||||
private readonly string _panelDir, _otherDir;
|
||||
|
||||
public StubEnvironment(IntPtr game, string runtimeDir, string localAppData, string panelDir, string otherDir,
|
||||
Action<string> log, Action<string> chat, Action<string> browser)
|
||||
{
|
||||
GameHwnd = game;
|
||||
RuntimeDir = runtimeDir;
|
||||
LocalAppData = localAppData;
|
||||
_panelDir = panelDir;
|
||||
_otherDir = otherDir;
|
||||
_log = log;
|
||||
_chat = chat;
|
||||
_browser = browser;
|
||||
}
|
||||
|
||||
public volatile int DelayMs;
|
||||
public volatile string? BrowserFolder;
|
||||
public volatile bool BrowserFails; // OpenInBrowser returns false without recording a call
|
||||
public volatile int BrowserDelayMs; // OpenInBrowser sleeps first (a slow ShellExecute)
|
||||
public volatile string World = "Harness World";
|
||||
|
||||
public IntPtr GameHwnd { get; }
|
||||
public string RuntimeDir { get; }
|
||||
public string LocalAppData { get; }
|
||||
public string WorldName => World;
|
||||
public void Log(string line) => _log(line);
|
||||
public void Chat(string line) => _chat(line);
|
||||
public bool OpenInBrowser(string url)
|
||||
{
|
||||
if (!WebPanelUrlPolicy.IsBrowserSafe(url)) { _log("HARNESS: OpenInBrowser got an unsafe url"); return false; }
|
||||
if (BrowserDelayMs > 0) Thread.Sleep(BrowserDelayMs);
|
||||
if (BrowserFails) { _log("HARNESS: OpenInBrowser set to fail"); return false; }
|
||||
_browser(url);
|
||||
return true;
|
||||
}
|
||||
public Thread StartStaThread(string name, ThreadStart body)
|
||||
{
|
||||
var t = new Thread(body) { Name = name, IsBackground = true };
|
||||
t.SetApartmentState(ApartmentState.STA);
|
||||
t.Start();
|
||||
return t;
|
||||
}
|
||||
public int EnvironmentDelayMsForTests => DelayMs;
|
||||
public string? BrowserExecutableFolderForTests => BrowserFolder;
|
||||
|
||||
public Action<CoreWebView2>? ConfigureForTests => web =>
|
||||
{
|
||||
web.SetVirtualHostNameToFolderMapping("panel.test", _panelDir, CoreWebView2HostResourceAccessKind.Allow);
|
||||
web.SetVirtualHostNameToFolderMapping("other.test", _otherDir, CoreWebView2HostResourceAccessKind.Allow);
|
||||
// https://go.panel.test/redirect answers 302 to other.test. Not folder-mapped: WebResourceRequested
|
||||
// is not raised for a virtual host mapping's own requests (measured: the filter on panel.test/* never fired).
|
||||
web.AddWebResourceRequestedFilter("https://go.panel.test/*", CoreWebView2WebResourceContext.All);
|
||||
web.WebResourceRequested += (s, e) =>
|
||||
{
|
||||
if (!e.Request.Uri.StartsWith("https://go.panel.test/redirect", StringComparison.OrdinalIgnoreCase)) return;
|
||||
e.Response = web.Environment.CreateWebResourceResponse(null, 302, "Found",
|
||||
"Location: https://other.test/landing.html?code=SECRET123\r\nCache-Control: no-store");
|
||||
_log("HARNESS: served the 302 for /redirect");
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
52
tools/WebPanelHarness.Payload/WebPanelHarness.Payload.csproj
Normal file
52
tools/WebPanelHarness.Payload/WebPanelHarness.Payload.csproj
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!--
|
||||
The web panel host under test, as the CoreCLR engine compiles it: src\RynthCore.Engine\WebPanel\*.cs
|
||||
(host, Win32 interop, policies, layout store, ABI argument reader) and the ABI structs from
|
||||
Plugins\PluginContract.cs, plus a stub environment (PayloadEntry.cs). tools\WebPanelHarness loads this
|
||||
DLL into a collectible AssemblyLoadContext that mirrors the shim's EngineLoadContext, drives it, and
|
||||
checks the context unloads. Not a test project on its own (no "Test" in the name: Run-AllTests skips it).
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
|
||||
<SelfContained>false</SelfContained>
|
||||
<OutputType>Library</OutputType>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Nullable>enable</Nullable>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<RootNamespace>RynthCore.Engine.WebPanel</RootNamespace>
|
||||
<AssemblyName>WebPanelHarness.Payload</AssemblyName>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<WebView2UseWinRT>false</WebView2UseWinRT>
|
||||
<WebView2LoaderPreference>Dynamic</WebView2LoaderPreference>
|
||||
<GenerateDependencyFile>false</GenerateDependencyFile>
|
||||
<NoWarn>$(NoWarn);CS0649;CS0169</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2903.40" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Plugins\PluginContract.cs" Link="Engine\PluginContract.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelUrlPolicy.cs" Link="Engine\WebPanelUrlPolicy.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelWindowPolicy.cs" Link="Engine\WebPanelWindowPolicy.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelProfile.cs" Link="Engine\WebPanelProfile.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelNativeArgs.cs" Link="Engine\WebPanelNativeArgs.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelApiRules.cs" Link="Engine\WebPanelApiRules.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelLayoutStore.cs" Link="Engine\WebPanelLayoutStore.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\IWebPanelEnvironment.cs" Link="Engine\IWebPanelEnvironment.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelNative.cs" Link="Engine\WebPanelNative.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelHost.cs" Link="Engine\WebPanelHost.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- As the engine: no WinForms/WPF controls (RynthCore.Engine.csproj DropWebView2UiAssemblies). -->
|
||||
<Target Name="DropWebView2UiAssemblies" BeforeTargets="ResolveAssemblyReferences">
|
||||
<ItemGroup>
|
||||
<Reference Remove="@(Reference)" Condition="'%(Filename)' == 'Microsoft.Web.WebView2.WinForms' Or '%(Filename)' == 'Microsoft.Web.WebView2.Wpf'" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
1148
tools/WebPanelHarness/Program.cs
Normal file
1148
tools/WebPanelHarness/Program.cs
Normal file
File diff suppressed because it is too large
Load diff
52
tools/WebPanelHarness/WebPanelHarness.csproj
Normal file
52
tools/WebPanelHarness/WebPanelHarness.csproj
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!--
|
||||
Offline harness for the web panel host (src\RynthCore.Engine\WebPanel\WebPanelHost.cs): a 32-bit
|
||||
stand-in for acclient plus the engine. A fake game thread owns a top-level window and runs a
|
||||
PeekMessage loop; a fake 16 ms pump polls the panel state from another thread; the host (built into
|
||||
tools\WebPanelHarness.Payload) loads into a collectible AssemblyLoadContext that mirrors the shim's
|
||||
EngineLoadContext, and must unload after Shutdown. Pages come from local folders through WebView2
|
||||
virtual host mappings (https://panel.test/, https://other.test/): no network. Input is posted to
|
||||
specific windows; never SendInput (live game clients share this desktop).
|
||||
|
||||
Needs a desktop, the Evergreen WebView2 runtime and the x86 .NET 10 runtime; it opens windows.
|
||||
The folder name has no "Test" in it on purpose: scripts\Run-AllTests.ps1 does not run it.
|
||||
Run (foreground): dotnet run -c Release (WEBPANEL_HARNESS_FOREGROUND=1 to opt in, see below)
|
||||
The host's own Show calls SetForegroundWindow (pinned behaviour); with the opt-in the harness also asks for
|
||||
it for the fake game, so the foreground-dependent checks (Escape hand-back, same-process visibility) can run.
|
||||
Windows refuses either request while the user is active in another program: those checks then say UNVERIFIED.
|
||||
Each check prints "ok <name>", "FAIL <name>: ..." or "UNVERIFIED <name>: ..." (could not be shown
|
||||
offline; an owner in-game check). Exit 0 = every check ok, 1 = a FAIL, 2 = no FAIL but UNVERIFIED.
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
|
||||
<SelfContained>false</SelfContained>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<RootNamespace>WebPanelHarness</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Built first, never referenced: the payload must only ever load into the collectible context. -->
|
||||
<ProjectReference Include="..\WebPanelHarness.Payload\WebPanelHarness.Payload.csproj" ReferenceOutputAssembly="false" Private="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPayload" AfterTargets="Build">
|
||||
<MSBuild Projects="..\WebPanelHarness.Payload\WebPanelHarness.Payload.csproj" Targets="GetTargetPath" Properties="Configuration=$(Configuration)">
|
||||
<Output TaskParameter="TargetOutputs" ItemName="_PayloadTarget" />
|
||||
</MSBuild>
|
||||
<PropertyGroup>
|
||||
<_PayloadDir>@(_PayloadTarget->'%(RootDir)%(Directory)')</_PayloadDir>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<_PayloadFiles Include="$(_PayloadDir)**\*.*" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(_PayloadFiles)" DestinationFiles="@(_PayloadFiles->'$(OutDir)payload\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
326
tools/WebPanelTests/Program.cs
Normal file
326
tools/WebPanelTests/Program.cs
Normal file
|
|
@ -0,0 +1,326 @@
|
|||
using System.Text;
|
||||
using RynthCore.Engine.Plugins;
|
||||
using RynthCore.Engine.WebPanel;
|
||||
|
||||
namespace WebPanelTests;
|
||||
|
||||
/// <summary>The web panel's pure policies: URL allowlist, redaction, visibility, layout, profile folder.</summary>
|
||||
internal static unsafe class Program
|
||||
{
|
||||
private static int _checks, _failed;
|
||||
private static string _case = "";
|
||||
|
||||
private static readonly string[] Dw = { "*.acdreamweave.com" };
|
||||
|
||||
private static int Main()
|
||||
{
|
||||
Allowlist_ExactAndWildcard();
|
||||
Allowlist_LookalikesRejected();
|
||||
Allowlist_CaseIdnTrailingDot();
|
||||
Allowlist_BadEntries();
|
||||
Allowlist_ParseGood();
|
||||
BrowserSafe();
|
||||
BrowserGate();
|
||||
Redact();
|
||||
Visibility();
|
||||
Layout();
|
||||
Profile();
|
||||
ApiRules();
|
||||
NativeArgs();
|
||||
|
||||
Console.WriteLine(_failed == 0 ? $"PASS ({_checks} assertions)" : $"FAIL ({_failed} of {_checks} assertions)");
|
||||
return _failed == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
private static void Case(string name) { _case = name; Console.WriteLine("ok " + name); }
|
||||
|
||||
private static void Check(bool ok, string what)
|
||||
{
|
||||
_checks++;
|
||||
if (ok) return;
|
||||
_failed++;
|
||||
Console.WriteLine($"FAIL {_case}: {what}");
|
||||
}
|
||||
|
||||
private static void Eq<T>(T got, T want, string what) =>
|
||||
Check(EqualityComparer<T>.Default.Equals(got, want), $"{what}: got {got}, want {want}");
|
||||
|
||||
private static void BrowserGate()
|
||||
{
|
||||
Case("browser gate: off-list pages reach the system browser only after a click, rate-limited");
|
||||
var g = new WebPanelBrowserGate();
|
||||
Eq(g.Decide(userInitiated: false, 0), BrowserOpenVerdict.NotUserInitiated, "a page's own request (script, ad iframe) is dropped");
|
||||
Eq(g.Decide(userInitiated: true, 0), BrowserOpenVerdict.Open, "a click opens it");
|
||||
Eq(g.Decide(userInitiated: true, 500), BrowserOpenVerdict.TooSoon, "a second within the gap is dropped");
|
||||
Eq(g.Decide(userInitiated: false, 5000), BrowserOpenVerdict.NotUserInitiated, "no click is never opened, even after the gap");
|
||||
long t = 0;
|
||||
int opened = 1;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
t += WebPanelBrowserGate.MinGapMs;
|
||||
if (g.Decide(true, t) == BrowserOpenVerdict.Open) opened++;
|
||||
}
|
||||
Eq(opened, WebPanelBrowserGate.MaxPerMinute, "at most MaxPerMinute a minute, however spaced");
|
||||
Eq(g.Decide(true, 61_000 + WebPanelBrowserGate.MinGapMs), BrowserOpenVerdict.Open, "the minute passes: opens again");
|
||||
var fresh = new WebPanelBrowserGate();
|
||||
Eq(fresh.Decide(true, long.MinValue + 1), BrowserOpenVerdict.Open, "a first open at any clock value opens");
|
||||
}
|
||||
|
||||
private static void Allowlist_ExactAndWildcard()
|
||||
{
|
||||
Case("Allowlist_ExactAndWildcard");
|
||||
Check(WebPanelUrlPolicy.IsAllowed("https://www.acdreamweave.com/x", Dw), "www subdomain allowed");
|
||||
Check(WebPanelUrlPolicy.IsAllowed("https://a.b.acdreamweave.com/", Dw), "deep subdomain allowed");
|
||||
Check(!WebPanelUrlPolicy.IsAllowed("https://acdreamweave.com/", Dw), "wildcard does not match the suffix itself");
|
||||
Check(WebPanelUrlPolicy.IsAllowed("https://acdreamweave.com/", new[] { "acdreamweave.com" }), "exact entry matches");
|
||||
Check(!WebPanelUrlPolicy.IsAllowed("https://www.acdreamweave.com/", new[] { "acdreamweave.com" }), "exact entry does not match subdomain");
|
||||
Check(WebPanelUrlPolicy.IsAllowed("about:blank", Dw), "about:blank allowed");
|
||||
Check(!WebPanelUrlPolicy.IsAllowed(null, Dw), "null rejected");
|
||||
Check(!WebPanelUrlPolicy.IsAllowed("", Dw), "empty rejected");
|
||||
Check(!WebPanelUrlPolicy.IsAllowed("https://www.acdreamweave.com/", Array.Empty<string>()), "empty allowlist rejects all");
|
||||
}
|
||||
|
||||
private static void Allowlist_LookalikesRejected()
|
||||
{
|
||||
Case("Allowlist_LookalikesRejected");
|
||||
foreach (string u in new[]
|
||||
{
|
||||
"https://www.acdreamweave.com.evil.com/",
|
||||
"https://evilacdreamweave.com/",
|
||||
"https://www.acdreamweave.com@evil.com/",
|
||||
"https://evil.com/?h=.acdreamweave.com",
|
||||
"http://www.acdreamweave.com/",
|
||||
"https://www.acdreamweave.com:8443/",
|
||||
"https://user:pw@www.acdreamweave.com/",
|
||||
"file:///C:/x",
|
||||
"javascript:alert(1)",
|
||||
})
|
||||
Check(!WebPanelUrlPolicy.IsAllowed(u, Dw), "rejects " + u);
|
||||
Check(!WebPanelUrlPolicy.IsAllowed("https://www.acdreamweave.com/" + new string('a', 5000), Dw), "over MaxUrlBytes rejected");
|
||||
Check(!WebPanelUrlPolicy.IsAllowed("https://www.acdreamweave.c\u2100/", Dw), "invalid IDN char fails closed (no throw)");
|
||||
Check(!WebPanelUrlPolicy.IsAllowed("https://www.acdreamweave.c" + "\uD800" + "/", Dw), "lone-surrogate host fails closed (no throw)");
|
||||
}
|
||||
|
||||
private static void Allowlist_CaseIdnTrailingDot()
|
||||
{
|
||||
Case("Allowlist_CaseIdnTrailingDot");
|
||||
Check(WebPanelUrlPolicy.IsAllowed("https://WWW.AcDreamWeave.com./", Dw), "case and one trailing dot");
|
||||
Check(WebPanelUrlPolicy.IsAllowed("https://www.acdreamweave.com:443/", Dw), "explicit default port");
|
||||
string puny = new System.Globalization.IdnMapping().GetAscii("b\u00fccher.example");
|
||||
Check(WebPanelUrlPolicy.IsAllowed("https://b\u00fccher.example/", new[] { puny }), "unicode host matches its punycode entry");
|
||||
Check(WebPanelUrlPolicy.IsAllowed("https://" + puny + "/", new[] { puny }), "punycode host matches itself");
|
||||
Check(!WebPanelUrlPolicy.IsAllowed("https://bucher.example/", new[] { puny }), "ascii lookalike does not match punycode entry");
|
||||
Check(!WebPanelUrlPolicy.IsAllowed("https://xn--bcher-kva.example/", new[] { "bucher.example" }), "punycode host does not match other entry");
|
||||
}
|
||||
|
||||
private static void Allowlist_BadEntries()
|
||||
{
|
||||
Case("Allowlist_BadEntries");
|
||||
foreach (string bad in new[] { "*", "*.com", "https://x.com", "x.com/path", "x.com:443", "a.*.com", "", " ", "x.com.", "*.x.*.com", "a b.com", "*x.com" })
|
||||
Check(!WebPanelUrlPolicy.TryParseAllowlist(bad, out _), "rejects entry list '" + bad + "'");
|
||||
Check(!WebPanelUrlPolicy.TryParseAllowlist(null, out _), "null rejected");
|
||||
string seventeen = string.Join("\n", Enumerable.Range(0, 17).Select(i => $"h{i}.example.com"));
|
||||
Check(!WebPanelUrlPolicy.TryParseAllowlist(seventeen, out _), "17 entries rejected");
|
||||
string sixteen = string.Join("\n", Enumerable.Range(0, 16).Select(i => $"h{i}.example.com"));
|
||||
Check(WebPanelUrlPolicy.TryParseAllowlist(sixteen, out var e16) && e16.Length == 16, "16 entries accepted");
|
||||
Check(!WebPanelUrlPolicy.TryParseAllowlist("good.example.com\nbad/entry", out _), "one bad entry fails the list");
|
||||
Check(!WebPanelUrlPolicy.TryParseAllowlist(new string('a', 254) + ".com", out _), "over-long entry rejected");
|
||||
}
|
||||
|
||||
private static void Allowlist_ParseGood()
|
||||
{
|
||||
Case("Allowlist_ParseGood");
|
||||
Check(WebPanelUrlPolicy.TryParseAllowlist("*.AcDreamWeave.com\r\nlocalhost\n", out var e), "parses");
|
||||
Eq(e.Length, 2, "entry count");
|
||||
Eq(e[0], "*.acdreamweave.com", "lower-cased wildcard");
|
||||
Eq(e[1], "localhost", "single-label host ok");
|
||||
}
|
||||
|
||||
private static void BrowserSafe()
|
||||
{
|
||||
Case("BrowserSafe");
|
||||
Check(WebPanelUrlPolicy.IsBrowserSafe("https://example.com/a?b=c"), "https");
|
||||
Check(WebPanelUrlPolicy.IsBrowserSafe("http://example.com/"), "http");
|
||||
foreach (string u in new[] { "file:///C:/Windows/notepad.exe", "javascript:alert(1)", "ms-settings:network", "mailto:a@b.c", "/relative/path", "example.com", "https://u:p@example.com/", "https://u@example.com/", "", " " })
|
||||
Check(!WebPanelUrlPolicy.IsBrowserSafe(u), "not safe: " + u);
|
||||
Check(!WebPanelUrlPolicy.IsBrowserSafe(null), "null not safe");
|
||||
}
|
||||
|
||||
private static void Redact()
|
||||
{
|
||||
Case("Redact");
|
||||
string r = WebPanelUrlPolicy.Redact("https://www.acdreamweave.com/launch?code=SECRET&to=/Browse#f");
|
||||
Eq(r, "https://www.acdreamweave.com/launch", "query and fragment stripped");
|
||||
Check(!r.Contains("SECRET"), "secret absent");
|
||||
Eq(WebPanelUrlPolicy.Redact("https://user:pw@host.example:8443/p/q?x=1"), "https://host.example:8443/p/q", "userinfo dropped, port kept");
|
||||
Check(!WebPanelUrlPolicy.Redact("https://user:pw@host.example/p").Contains("pw"), "password absent");
|
||||
Eq(WebPanelUrlPolicy.Redact("not a url"), "<invalid url>", "garbage");
|
||||
Eq(WebPanelUrlPolicy.Redact(null), "<invalid url>", "null");
|
||||
Eq(WebPanelUrlPolicy.Redact(""), "<invalid url>", "empty");
|
||||
Check(!WebPanelUrlPolicy.Redact("mailto:secret@x.com").Contains("secret"), "non-hierarchical leaks nothing");
|
||||
}
|
||||
|
||||
private static void Visibility()
|
||||
{
|
||||
Case("Visibility");
|
||||
// open, alive, !iconic, visible, !fgNull, fgPid, ourPid
|
||||
Eq(WebPanelWindowPolicy.Visible(true, true, false, true, false, 5, 5), (bool?)true, "same process shows");
|
||||
Eq(WebPanelWindowPolicy.Visible(true, true, false, true, false, 6, 5), (bool?)false, "other process hides");
|
||||
Eq(WebPanelWindowPolicy.Visible(true, true, false, true, true, 0, 5), (bool?)null, "null foreground keeps current");
|
||||
Eq(WebPanelWindowPolicy.Visible(true, true, true, true, false, 5, 5), (bool?)false, "iconic hides");
|
||||
Eq(WebPanelWindowPolicy.Visible(false, true, false, true, false, 5, 5), (bool?)false, "closed hides");
|
||||
Eq(WebPanelWindowPolicy.Visible(true, false, false, true, false, 5, 5), (bool?)false, "dead game hides");
|
||||
Eq(WebPanelWindowPolicy.Visible(true, true, false, false, false, 5, 5), (bool?)false, "invisible game hides");
|
||||
Eq(WebPanelWindowPolicy.Visible(false, true, false, true, true, 0, 5), (bool?)false, "closed beats null foreground");
|
||||
Eq(WebPanelWindowPolicy.Visible(true, true, true, true, true, 0, 5), (bool?)false, "iconic beats null foreground");
|
||||
}
|
||||
|
||||
private static void Layout()
|
||||
{
|
||||
Case("Layout");
|
||||
var client = new PanelRect(100, 50, 1200, 800); // 1100 x 750
|
||||
var f = WebPanelWindowPolicy.Default(0, 0);
|
||||
Check(Math.Abs(f.W - 0.88) < 1e-9 && Math.Abs(f.H - 0.88) < 1e-9, "0 means 88 %");
|
||||
Check(Math.Abs(f.X - 0.06) < 1e-9 && Math.Abs(f.Y - 0.06) < 1e-9, "centered");
|
||||
var r = WebPanelWindowPolicy.Place(client, f);
|
||||
Eq(r.Width, 968, "88 % of 1100");
|
||||
Eq(r.Height, 660, "88 % of 750");
|
||||
Eq(r.Left - client.Left, client.Right - r.Right, "horizontally centered");
|
||||
Eq(r.Top - client.Top, client.Bottom - r.Bottom, "vertically centered");
|
||||
|
||||
var full = WebPanelWindowPolicy.Default(120, 120);
|
||||
Check(full.W == 1.0 && full.H == 1.0 && full.X == 0 && full.Y == 0, "120 clamps to 100");
|
||||
var small = WebPanelWindowPolicy.Default(5, 5);
|
||||
Check(Math.Abs(small.W - 0.30) < 1e-9, "5 clamps to 30");
|
||||
Eq(WebPanelWindowPolicy.Place(client, full), client, "100 % fills the client");
|
||||
|
||||
var tiny = new PanelRect(0, 0, 300, 200);
|
||||
Eq(WebPanelWindowPolicy.Place(tiny, WebPanelWindowPolicy.Default(0, 0)), tiny, "tiny client clamps to client");
|
||||
var mid = new PanelRect(0, 0, 600, 400);
|
||||
var m = WebPanelWindowPolicy.Place(mid, WebPanelWindowPolicy.Default(30, 30));
|
||||
Check(m.Width >= 480 && m.Height >= 320, "minimum size enforced");
|
||||
Check(m.Left >= mid.Left && m.Top >= mid.Top && m.Right <= mid.Right && m.Bottom <= mid.Bottom, "min size stays inside client");
|
||||
|
||||
// Off-screen fractions stay inside.
|
||||
var off = WebPanelWindowPolicy.Place(client, new PanelFractions(0.95, 0.95, 0.5, 0.5));
|
||||
Check(off.Left >= client.Left && off.Top >= client.Top && off.Right <= client.Right && off.Bottom <= client.Bottom, "never outside client");
|
||||
|
||||
// Round trip.
|
||||
var user = new PanelRect(300, 200, 1000, 700);
|
||||
var rt = WebPanelWindowPolicy.Place(client, WebPanelWindowPolicy.FromUserRect(client, user));
|
||||
Check(Math.Abs(rt.Left - user.Left) <= 1 && Math.Abs(rt.Top - user.Top) <= 1 &&
|
||||
Math.Abs(rt.Right - user.Right) <= 1 && Math.Abs(rt.Bottom - user.Bottom) <= 1, $"round trip within 1 px: {rt}");
|
||||
var wild = WebPanelWindowPolicy.FromUserRect(client, new PanelRect(-500, -500, 5000, 5000));
|
||||
Check(wild.X >= 0 && wild.Y >= 0 && wild.W <= 1 && wild.H <= 1 && wild.X + wild.W <= 1.000001, "FromUserRect clamps to 0..1");
|
||||
}
|
||||
|
||||
// WebPanelApi's pure parts (WebPanelApiRules): the kill switch and shutdown refusals, the GetState Size check.
|
||||
private static void ApiRules()
|
||||
{
|
||||
Case("ApiRules");
|
||||
Eq(WebPanelApiRules.OpenRefusal(shuttingDown: false, enabled: true), 0, "enabled, running: go on");
|
||||
Eq(WebPanelApiRules.OpenRefusal(false, false), (int)WebPanelCode.Unavailable, "engine.json WebPanel false: Unavailable");
|
||||
Eq(WebPanelApiRules.OpenRefusal(true, true), (int)WebPanelCode.ShuttingDown, "shutting down: ShuttingDown");
|
||||
Eq(WebPanelApiRules.OpenRefusal(true, false), (int)WebPanelCode.ShuttingDown, "shutting down wins over the kill switch");
|
||||
Eq(WebPanelApiRules.CallRefusal(false), 0, "calls go on while running");
|
||||
Eq(WebPanelApiRules.CallRefusal(true), (int)WebPanelCode.ShuttingDown, "calls refused after shutdown");
|
||||
|
||||
uint min = WebPanelApiRules.StateMinSize;
|
||||
Eq(min, 28u, "OffsetOf(Reserved) of the state struct (no pointer fields: 28 on x86 and x64)");
|
||||
Check(min > 0 && min < (uint)sizeof(WebPanelStateNative), "min size is inside the struct");
|
||||
Check(!WebPanelApiRules.StateArgsOk(null), "null state refused");
|
||||
WebPanelStateNative st = default;
|
||||
st.Size = min - 1;
|
||||
Check(!WebPanelApiRules.StateArgsOk(&st), "Size below OffsetOf(Reserved) refused");
|
||||
st.Size = min;
|
||||
Check(WebPanelApiRules.StateArgsOk(&st), "Size == OffsetOf(Reserved) accepted");
|
||||
st.Size = (uint)sizeof(WebPanelStateNative);
|
||||
Check(WebPanelApiRules.StateArgsOk(&st), "full Size accepted");
|
||||
|
||||
st.Reserved[0] = 0xDEADBEEF;
|
||||
WebPanelApiRules.WriteState(&st, new WebPanelSnapshot(7, 3, 5, -9, 200, 4));
|
||||
Eq(st.Handle, 7, "handle written");
|
||||
Eq(st.Status, 3, "status written");
|
||||
Eq(st.Flags, 5u, "flags written");
|
||||
Eq(st.Error, -9, "error written");
|
||||
Eq(st.LastHttpStatus, 200, "http written");
|
||||
Eq(st.NavigationCount, 4u, "navigations written");
|
||||
Eq(st.Reserved[0], 0xDEADBEEFu, "Reserved untouched");
|
||||
Eq(WebPanelApiRules.NoPanel(9).Status, (int)WebPanelStatusCode.Superseded, "no panel yet: Superseded");
|
||||
}
|
||||
|
||||
// WebPanelNativeArgs: the strings are copied out of the caller's buffers; bad arguments are BadArgs.
|
||||
private static void NativeArgs()
|
||||
{
|
||||
Case("NativeArgs");
|
||||
const string lad = @"C:\lad";
|
||||
Eq(WebPanelNativeArgs.TryBuildRequest(null, lad, "W", out _), (int)WebPanelCode.BadArgs, "null struct");
|
||||
|
||||
int Build(string? url, string? allow, string? key, string? title, uint size, uint flags, out WebPanelRequest? req)
|
||||
{
|
||||
byte[] u = Z(url), a = Z(allow), k = Z(key), ti = Z(title);
|
||||
fixed (byte* pu = u, pa = a, pk = k, pt = ti)
|
||||
{
|
||||
var o = new WebPanelOpenNative
|
||||
{
|
||||
Size = size, Flags = flags,
|
||||
Url = url == null ? null : pu, Allowlist = allow == null ? null : pa,
|
||||
ProfileKey = key == null ? null : pk, Title = title == null ? null : pt,
|
||||
};
|
||||
int rc = WebPanelNativeArgs.TryBuildRequest(&o, lad, "W", out req);
|
||||
Array.Fill(u, (byte)'Z'); Array.Fill(a, (byte)'Z'); // the caller's buffers die right after the call
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
static byte[] Z(string? s) => s == null ? new byte[1] : Encoding.UTF8.GetBytes(s + "\0");
|
||||
uint full = (uint)sizeof(WebPanelOpenNative);
|
||||
|
||||
Eq(Build("https://a.test/x?code=1", "a.test", "k", "T", full, 0xFF, out var r), 0, "good request");
|
||||
Eq(r?.Url, "https://a.test/x?code=1", "url copied before the buffer was overwritten");
|
||||
Eq(r?.Allowlist.Length, 1, "allowlist parsed");
|
||||
Eq(r?.Title, "T", "title copied");
|
||||
Eq(r?.Flags, 3u, "unknown flag bits dropped");
|
||||
Check(r != null && r.ProfileFolder.StartsWith(lad, StringComparison.Ordinal), "profile folder under LocalAppData");
|
||||
Eq(Build("https://a.test/", "a.test", null, null, full, 0, out r), 0, "null key and title");
|
||||
Eq(r?.Title, "", "null title is empty");
|
||||
Eq(Build("https://a.test/", "a.test", null, null, 31, 0, out _), (int)WebPanelCode.BadArgs, "Size below OffsetOf(Reserved)");
|
||||
Eq(Build(null, "a.test", null, null, full, 0, out _), (int)WebPanelCode.BadArgs, "no url");
|
||||
Eq(Build("", "a.test", null, null, full, 0, out _), (int)WebPanelCode.BadArgs, "empty url");
|
||||
Eq(Build("https://a.test/", null, null, null, full, 0, out _), (int)WebPanelCode.BadArgs, "no allowlist");
|
||||
Eq(Build("https://a.test/", "*.com", null, null, full, 0, out _), (int)WebPanelCode.BadArgs, "bad allowlist");
|
||||
Eq(Build("https://a.test/", "a.test", null, new string('t', 129), full, 0, out _), (int)WebPanelCode.BadArgs, "title over 128 bytes");
|
||||
Eq(Build("https://a.test/", "a.test", new string('k', 257), null, full, 0, out _), (int)WebPanelCode.BadArgs, "key over 256 bytes");
|
||||
Eq(Build("https://a.test/" + new string('p', 4096), "a.test", null, null, full, 0, out _), (int)WebPanelCode.BadArgs, "url over 4096 bytes");
|
||||
|
||||
byte[] bad = { 0x68, 0xC3, 0x28, 0 }; // invalid UTF-8
|
||||
fixed (byte* pb = bad) Check(!WebPanelNativeArgs.TryReadUtf8(pb, 16, true, out _), "invalid UTF-8 refused");
|
||||
}
|
||||
|
||||
private static void Profile()
|
||||
{
|
||||
Case("Profile");
|
||||
const string root = @"C:\Users\x\AppData\Local";
|
||||
string a = WebPanelProfile.Folder(root, "DreamWeave", "Alice");
|
||||
Eq(a, WebPanelProfile.Folder(root, "DreamWeave", " ALICE "), "case/space-insensitive key");
|
||||
Check(a != WebPanelProfile.Folder(root, "DreamWeave", "Bob"), "different keys differ");
|
||||
Check(a != WebPanelProfile.Folder(root, "Other", "Alice"), "different worlds differ");
|
||||
string leaf = Path.GetFileName(a);
|
||||
Eq(leaf.Length, 32, "hex is 32 chars");
|
||||
Check(leaf.All(c => (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')), "lowercase hex");
|
||||
// SHA-256("alice") first 16 bytes.
|
||||
Eq(leaf, Convert.ToHexString(System.Security.Cryptography.SHA256.HashData(System.Text.Encoding.UTF8.GetBytes("alice")), 0, 16).ToLowerInvariant(), "hash of lowered key");
|
||||
Eq(Path.GetFileName(WebPanelProfile.Folder(root, "W", "")), "default", "empty key");
|
||||
Eq(Path.GetFileName(WebPanelProfile.Folder(root, "W", null)), "default", "null key");
|
||||
|
||||
string evil = WebPanelProfile.Folder(root, "Dream/Weave..", "k");
|
||||
Check(!evil.Contains(".."), "no dot-dot");
|
||||
Eq(Path.GetFileName(Path.GetDirectoryName(evil)!), "Dream_Weave__", "world sanitized");
|
||||
Eq(Path.GetFileName(Path.GetDirectoryName(WebPanelProfile.Folder(root, null, "k"))!), "_default", "null world");
|
||||
Eq(Path.GetFileName(Path.GetDirectoryName(WebPanelProfile.Folder(root, " ", "k"))!), "_default", "blank world");
|
||||
Eq(Path.GetFileName(Path.GetDirectoryName(WebPanelProfile.Folder(root, new string('w', 100), "k"))!).Length, 64, "world capped at 64");
|
||||
Eq(Path.GetFileName(Path.GetDirectoryName(WebPanelProfile.Folder(root, @"..\..\x", "k"))!), "______x", "traversal neutralised");
|
||||
string full = Path.GetFullPath(evil);
|
||||
Check(full.StartsWith(Path.GetFullPath(root), StringComparison.OrdinalIgnoreCase), "under localAppData");
|
||||
Check(evil.Contains(Path.Combine("RynthCore", "WebPanel")), "RynthCore\\WebPanel layout");
|
||||
}
|
||||
}
|
||||
31
tools/WebPanelTests/WebPanelTests.csproj
Normal file
31
tools/WebPanelTests/WebPanelTests.csproj
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!--
|
||||
Offline checks for the web panel's pure policies (URL allowlist and redaction, window
|
||||
visibility and layout, profile folder): src\RynthCore.Engine\WebPanel\*.cs, compiled in.
|
||||
No AC, no Win32, no WebView2, no files.
|
||||
Run: dotnet run -c Release (exit 0 = pass, 1 = fail)
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<RootNamespace>WebPanelTests</RootNamespace>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<NoWarn>$(NoWarn);CS0649;CS0169</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelUrlPolicy.cs" Link="Engine\WebPanelUrlPolicy.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelBrowserGate.cs" Link="Engine\WebPanelBrowserGate.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelWindowPolicy.cs" Link="Engine\WebPanelWindowPolicy.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelProfile.cs" Link="Engine\WebPanelProfile.cs" />
|
||||
<!-- The ABI glue's pure parts (WebPanelApi.cs itself needs the engine): argument copy-out and refusals. -->
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Plugins\PluginContract.cs" Link="Engine\PluginContract.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelNativeArgs.cs" Link="Engine\WebPanelNativeArgs.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\WebPanel\WebPanelApiRules.cs" Link="Engine\WebPanelApiRules.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in a new issue