RynthServers/Tools/RynthILT.Tests/MoveTests.cs

618 lines
42 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using RynthCore.Loot;
using RynthCore.Plugin.RynthILT;
using RynthCore.Plugin.RynthILT.Hub;
using RynthCore.Plugin.Shared;
using RynthCore.RynthAiTests.Harness;
namespace RynthILT.Tests;
// The ILT Hub's move out of RynthAi into RynthILT (2026-10-13): the saved data carried over from
// RynthAi's folders (copied, never moved), the RynthILT.Hub interface table RynthAi's Mini Remote
// reads, which "/ra" verbs RynthILT takes from RynthAi, and the host-backed object view that
// replaced RynthAi's WorldObjectCache.
internal static class MoveTests
{
public static void Register(Runner r)
{
r.Add("move: a character's RynthAi ILT Hub files are copied, the RynthAi copies left alone", MigratesCharacter);
r.Add("move: migration never overwrites RynthILT's files and runs once", MigrationIdempotent);
r.Add("move: the pre-per-server ACEmulator folder is found too", MigratesFromAceEmulatorFolder);
r.Add("move: shared Hub profiles and aug costs are copied once", MigratesShared);
r.Add("move: a migration copy that fails is reported (log + chat) and the shared ones retried", MigrationFailuresReported);
r.Add("move: a failed Hub save is reported once and retried", StoreSaveFailureReported);
r.Add("move: an unfinished copy blocks the character's Hub writes until the retry copies the original", PendingMigrationNeverShadowed);
r.Add("move: an old ilt-hub.json loads into RynthILT's state (ILT parts kept)", LegacyStateLoads);
r.Add("move: RynthAi's \"/ra\" verbs RynthILT takes (and the ones it leaves)", VerbRouting);
r.Add("move: item classes from the client's item type (the gear tools' checks)", Classification);
r.Add("move: the interface structs have the agreed layout", InterfaceLayout);
r.Add("move: server-list status lines", DescribeLines);
r.Add("move: off ILT nothing is sent, no tab or section shows; on ILT the login probe runs", DormantOffIlt);
r.Add("move: the charms JSON for RynthILT.Data readers carries the Guardian Hands", CharmsReaderJson);
r.Add("move: Character redirects to RynthOracle; Charms and Banking stay RynthILT's tabs", MovedSections);
r.Add("sections: RynthILT's manifest (rates, /fship, /qb, and the ILT tabs it shows) is valid schema-1 JSON the engine places", SectionsManifest);
// Last: Release() switches the table off for the rest of the process.
r.Add("move: the RynthILT.Hub table: query, functions, release", HubTable);
}
private static string Root(string name)
{
string dir = Path.Combine(Program.TempRoot, "move-" + name);
if (Directory.Exists(dir)) Directory.Delete(dir, recursive: true);
Directory.CreateDirectory(dir);
IltMigration.LegacyProfilesBase = Path.Combine(dir, "RynthAi", "SettingsProfiles");
IltMigration.LegacySharedRoot = Path.Combine(dir, "RynthAi");
return dir;
}
private const string LegacyHubJson = """
{
"SchemaVersion": 1,
"ForceLeaftideFeatures": false,
"UbSidecarsImported": true,
"Bank": { "Pyreals": 1234567, "Luminance": 89, "EnlightenedCoins": 42, "AutoRefreshSeconds": 300 },
"Pet": { "HealingEnabled": true, "HealPetName": "Healing Buddy", "PetLog": ["Fire Banshee"], "ShinyLog": [] },
"Character": {
"QuestFilter": "temple", "QbFilter": "wait", "QuestFavorites": ["foo"],
"AttrOrder": ["qui","coo","str","end","foc","sel","hea","sta","man"], "AttrRaiseStats": ["qui"],
"AugTargets": { "war": 1800 }
},
"Gear": { "AutoClap": true, "LastUsdPath": "C:\\vt\\x.usd", "LastEquipProfile": "Melee" },
"Guardian": { "AutoHandIn": true, "TurnInCounts": { "Strength": 3 } }
}
""";
private static string MakeLegacyChar(string world, string charName, bool withProfile = true)
{
string dir = Path.Combine(IltMigration.LegacyProfilesBase, IltMigration.RynthAiSafeName(world), IltMigration.RynthAiSafeName(charName));
Directory.CreateDirectory(Path.Combine(dir, "ilt-hub-profiles"));
File.WriteAllText(Path.Combine(dir, "ilt-hub.json"), LegacyHubJson);
File.WriteAllText(Path.Combine(dir, "ilt-hub-transactions.json"), "[{\"Type\":\"Received\",\"Currency\":\"Pyreals\",\"Amount\":5}]");
File.WriteAllText(Path.Combine(dir, "ilt-hub-profiles", "farm.json"), "{\"SchemaVersion\":1}");
if (withProfile)
{
File.WriteAllText(Path.Combine(dir, "active_profile.txt"), "Melee");
File.WriteAllText(Path.Combine(dir, "Melee.json"),
"{\"MetaDebug\":false,\"FeatureServerNames\":[\"InfiniteLeaftide\",\"*Leaftide*\",\"MyShard\"],\"ForceServerFeatures\":true}");
File.WriteAllText(Path.Combine(dir, "Default.json"), "{\"FeatureServerNames\":[\"Unused\"]}");
}
return dir;
}
private static void MigratesCharacter()
{
string root = Root("char");
string legacy = MakeLegacyChar("Infinite Leaftide", "Sir Tester");
string before = File.ReadAllText(Path.Combine(legacy, "ilt-hub.json"));
var settings = new IltSettings();
string dest = Path.Combine(root, "RynthILT", "Infinite Leaftide", "Sir Tester");
var done = IltMigration.MigrateCharacter(dest, "Infinite Leaftide", "Sir Tester", settings, out bool force);
Check.True(File.Exists(Path.Combine(dest, IltHubStore.StateFile)), "ilt-hub.json -> hub.json");
Check.Eq(File.ReadAllText(Path.Combine(dest, IltHubStore.StateFile)), before, "copied byte for byte");
Check.True(File.Exists(Path.Combine(dest, IltHubStore.TransactionsFile)), "transactions copied");
Check.True(File.Exists(Path.Combine(dest, IltHubStore.ProfilesFolder, "farm.json")), "per-character Hub profiles copied");
Check.True(File.Exists(Path.Combine(legacy, "ilt-hub.json")) && File.Exists(Path.Combine(legacy, "ilt-hub-transactions.json")),
"RynthAi's files are still there (copy, not move)");
Check.True(settings.ServerNames.Contains("MyShard"), "the active profile's server names are added");
Check.False(settings.ServerNames.Contains("Unused"), "only the ACTIVE profile is read");
Check.Eq(settings.ServerNames.Count(n => n.Equals("InfiniteLeaftide", StringComparison.OrdinalIgnoreCase)), 1, "no duplicates");
Check.True(force, "\"Force enable\" carries over as Treat this world as ILT");
Check.True(done.Count >= 4, "the log line lists what was carried over: " + string.Join(", ", done));
}
private static void MigrationIdempotent()
{
string root = Root("idem");
string legacy = MakeLegacyChar("InfiniteLeaftide", "Again", withProfile: false);
string dest = Path.Combine(root, "RynthILT", "InfiniteLeaftide", "Again");
Directory.CreateDirectory(dest);
File.WriteAllText(Path.Combine(dest, IltHubStore.TransactionsFile), "[]"); // RynthILT already has one
var settings = new IltSettings();
IltMigration.MigrateCharacter(dest, "InfiniteLeaftide", "Again", settings, out bool force);
Check.Eq(File.ReadAllText(Path.Combine(dest, IltHubStore.TransactionsFile)), "[]", "an existing RynthILT file is never overwritten");
Check.True(File.Exists(Path.Combine(dest, IltHubStore.StateFile)), "the missing hub.json is still copied");
Check.False(force, "no profile, no override");
File.WriteAllText(Path.Combine(legacy, "ilt-hub.json"), "{\"Bank\":{\"Pyreals\":1}}");
var second = IltMigration.MigrateCharacter(dest, "InfiniteLeaftide", "Again", settings, out _);
Check.Eq(second.Count, 0, "once hub.json exists the character is never migrated again");
Check.False(File.ReadAllText(Path.Combine(dest, IltHubStore.StateFile)).Contains("\"Pyreals\":1}"), "later RynthAi edits don't overwrite RynthILT's state");
var none = IltMigration.MigrateCharacter(Path.Combine(root, "RynthILT", "X", "Nobody"), "X", "Nobody", settings, out _);
Check.Eq(none.Count, 0, "a character RynthAi never saw: nothing to do");
Check.False(Directory.Exists(Path.Combine(root, "RynthILT", "X", "Nobody")), "and no folder is made for it");
}
private static void MigratesFromAceEmulatorFolder()
{
string root = Root("ace");
MakeLegacyChar("ACEmulator", "Old Timer", withProfile: false);
var settings = new IltSettings();
string dest = Path.Combine(root, "RynthILT", "InfiniteLeaftide", "Old Timer");
Check.NotNull(IltMigration.FindLegacyCharFolder("InfiniteLeaftide", "Old Timer"), "the world folder is missing, ACEmulator\\<char> is used");
IltMigration.MigrateCharacter(dest, "InfiniteLeaftide", "Old Timer", settings, out _);
Check.True(File.Exists(Path.Combine(dest, IltHubStore.StateFile)), "copied from the ACEmulator folder");
Check.Eq(IltMigration.RynthAiSafeName("Sir O'Neil-Smith"), "Sir_O'Neil-Smith", "RynthAi's folder names keep ' and - only");
}
private static void MigratesShared()
{
string root = Root("shared");
Directory.CreateDirectory(Path.Combine(IltMigration.LegacySharedRoot, "IltHubProfiles"));
File.WriteAllText(Path.Combine(IltMigration.LegacySharedRoot, "IltHubProfiles", "team.json"), "{}");
File.WriteAllText(Path.Combine(IltMigration.LegacySharedRoot, "ilt-aug-costs.json"), "{\"x\":1}");
var settings = new IltSettings();
string dest = Path.Combine(root, "RynthILT");
var done = IltMigration.MigrateShared(settings, dest);
Check.True(File.Exists(Path.Combine(dest, "Profiles", "team.json")), "shared profiles copied");
Check.True(File.Exists(Path.Combine(dest, "ilt-aug-costs.json")), "aug costs copied");
Check.True(settings.SharedFilesMigrated, "marked done in the settings");
Check.Eq(done.Count, 2, "both reported");
File.Delete(Path.Combine(dest, "ilt-aug-costs.json"));
Check.Eq(IltMigration.MigrateShared(settings, dest).Count, 0, "once only");
Check.False(File.Exists(Path.Combine(dest, "ilt-aug-costs.json")), "a file deleted afterwards isn't brought back");
}
// A copy that fails (here: the RynthAi file held open by another program) is never silent: it
// is logged and queued for chat with the reason, the rest still copies, and the shared files
// aren't marked done so the next login tries again.
private static void MigrationFailuresReported()
{
string root = Root("fail");
DataWriteGuard.Reset();
string legacy = MakeLegacyChar("InfiniteLeaftide", "Locked Out");
string dest = Path.Combine(root, "RynthILT", "InfiniteLeaftide", "Locked Out");
var settings = new IltSettings();
List<string> done;
using (new FileStream(Path.Combine(legacy, "ilt-hub-transactions.json"), FileMode.Open, FileAccess.Read, FileShare.None))
done = IltMigration.MigrateCharacter(dest, "InfiniteLeaftide", "Locked Out", settings, out _);
Check.True(File.Exists(Path.Combine(dest, IltHubStore.StateFile)), "the other files are still copied");
Check.False(File.Exists(Path.Combine(dest, IltHubStore.TransactionsFile)), "the held file isn't");
Check.True(done.Any(l => l.Contains("NOT copied") && l.Contains(legacy)), "the log line says so and where the originals are: " + string.Join(", ", done));
Check.Eq(DataWriteGuard.PendingCount, 1, "one chat line queued (shown on ILT)");
var lines = new List<string>();
DataWriteGuard.DrainChat(lines.Add);
Check.True(lines.Count == 1 && lines[0].StartsWith("[RynthILT]", StringComparison.Ordinal)
&& lines[0].Contains("ilt-hub-transactions.json") && lines[0].Contains("another program"),
"it names the file and the reason: " + string.Join(" | ", lines));
DataWriteGuard.Reset();
Directory.CreateDirectory(Path.Combine(IltMigration.LegacySharedRoot, "IltHubProfiles"));
File.WriteAllText(Path.Combine(IltMigration.LegacySharedRoot, "IltHubProfiles", "team.json"), "{}");
string aug = Path.Combine(IltMigration.LegacySharedRoot, "ilt-aug-costs.json");
File.WriteAllText(aug, "{\"x\":1}");
string sharedDest = Path.Combine(root, "RynthILT");
using (new FileStream(aug, FileMode.Open, FileAccess.Read, FileShare.None))
done = IltMigration.MigrateShared(settings, sharedDest);
Check.False(settings.SharedFilesMigrated, "a failed shared copy isn't marked done");
Check.True(done.Any(l => l.Contains("NOT copied")), "and is reported: " + string.Join(", ", done));
Check.True(DataWriteGuard.PendingCount >= 1, "in chat too");
done = IltMigration.MigrateShared(settings, sharedDest);
Check.True(File.Exists(Path.Combine(sharedDest, "ilt-aug-costs.json")), "the next login copies it");
Check.True(settings.SharedFilesMigrated, "then it is marked done");
Check.Eq(done.Count, 1, "only the missing file is copied the second time: " + string.Join(", ", done));
DataWriteGuard.Reset();
}
// A character whose ilt-hub.json couldn't be copied (held open by another program): the Hub
// runs from the RynthAi original read-only (or the defaults), writes no hub.json, bank log or
// per-character profile there, the pending mark survives a restart, and the next attempt copies
// the original byte for byte - never shadowed by a fresh file.
private static void PendingMigrationNeverShadowed()
{
string root = Root("pending");
DataWriteGuard.Reset();
string legacy = MakeLegacyChar("InfiniteLeaftide", "Held Open");
string legacyHub = Path.Combine(legacy, "ilt-hub.json");
string dest = Path.Combine(root, "RynthILT", "InfiniteLeaftide", "Held Open");
string hubJson = Path.Combine(dest, IltHubStore.StateFile);
var settings = new IltSettings();
// Held open by another program: neither copied nor readable.
using (var held = new FileStream(legacyHub, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
{
var done = IltMigration.MigrateCharacter(dest, "InfiniteLeaftide", "Held Open", settings, out _);
Check.False(File.Exists(hubJson), "the held ilt-hub.json isn't copied");
Check.True(IltMigration.IsPending(settings, dest), "the character is marked pending");
Check.True(done.Any(l => l.Contains("NOT copied")), "and the log says so: " + string.Join(", ", done));
var store = new IltHubStore(default, dest)
{
WritesBlocked = () => IltMigration.IsPending(settings, dest),
LegacyFolder = legacy,
};
IltHubState state = store.LoadState();
Check.Eq(state.Bank.Pyreals, 0L, "unreadable: the Hub runs from the defaults");
state.Bank.Pyreals = 1;
store.SaveStateIfDirty(state);
Check.False(File.Exists(hubJson), "no hub.json is written while the copy is unfinished");
Check.False(store.SaveProfile(state, "mine", shared: false, out string why), "nor a per-character profile");
Check.True(why.Contains("RynthAi"), "with the reason: " + why);
Check.True(store.SaveProfile(state, "team-" + Guid.NewGuid().ToString("N"), shared: true, out _), "shared profiles still save");
// A second login while still held: still pending, still nothing written.
IltMigration.MigrateCharacter(dest, "InfiniteLeaftide", "Held Open", settings, out _);
Check.True(IltMigration.IsPending(settings, dest) && !File.Exists(hubJson), "still pending, still no hub.json");
}
// Readable again but not yet retried: a Hub started now reads the original, still writes nothing.
var readOnly = new IltHubStore(default, dest)
{
WritesBlocked = () => IltMigration.IsPending(settings, dest),
LegacyFolder = legacy,
};
IltHubState fromLegacy = readOnly.LoadState();
Check.Eq(fromLegacy.Bank.Pyreals, 1234567L, "the Hub runs from the RynthAi original, read only");
fromLegacy.Bank.Pyreals = 2;
readOnly.SaveStateIfDirty(fromLegacy);
Check.False(File.Exists(hubJson), "and still writes no hub.json");
// The mark is in settings.json, so a client restart still knows the copy is unfinished.
IltSettingsStore.Save(settings);
IltSettings reloaded = IltSettingsStore.Load();
Check.True(IltMigration.IsPending(reloaded, dest), "pending survives a restart");
var finished = IltMigration.MigrateCharacter(dest, "InfiniteLeaftide", "Held Open", reloaded, out bool force);
Check.True(File.Exists(hubJson), "the next attempt copies it");
Check.Eq(File.ReadAllText(hubJson), File.ReadAllText(legacyHub), "byte for byte: the original, not a fresh file");
Check.False(IltMigration.IsPending(reloaded, dest), "no longer pending");
Check.True(force, "the profile's Force enable still carries over on the retry");
Check.True(finished.Any(l => l.Contains("complete")), "the log says it finished: " + string.Join(", ", finished));
var after = new IltHubStore(default, dest) { WritesBlocked = () => IltMigration.IsPending(reloaded, dest) };
IltHubState loaded = after.LoadState();
Check.Eq(loaded.Bank.Pyreals, 1234567L, "the restarted Hub loads the copied file");
loaded.Bank.Pyreals = 7;
after.SaveStateIfDirty(loaded);
Check.True(File.ReadAllText(hubJson).Contains("\"Pyreals\": 7"), "and saves normally from then on");
File.Delete(Path.Combine(IltSettingsStore.Folder, IltSettingsStore.FileName));
DataWriteGuard.Reset();
}
// RynthILT's own saves report a failure (DataWriteGuard) and try again on the next save.
private static void StoreSaveFailureReported()
{
string root = Root("storefail");
DataWriteGuard.Reset();
string blocker = Path.Combine(root, "NotAFolder");
File.WriteAllText(blocker, "a file where the character folder should be");
var store = new IltHubStore(default, blocker);
var state = new IltHubState();
store.SaveStateIfDirty(state);
Check.Eq(DataWriteGuard.PendingCount, 1, "the failed Hub save is queued for chat");
store.SaveStateIfDirty(state);
Check.Eq(DataWriteGuard.PendingCount, 1, "once per folder, not every retry");
File.Delete(blocker);
store.SaveStateIfDirty(state);
Check.True(File.Exists(Path.Combine(blocker, IltHubStore.StateFile)), "the next save retries and works");
DataWriteGuard.Reset();
}
private static void LegacyStateLoads()
{
string root = Root("state");
string dir = Path.Combine(root, "char");
Directory.CreateDirectory(dir);
File.WriteAllText(Path.Combine(dir, IltHubStore.StateFile), LegacyHubJson);
var store = new IltHubStore(default, dir);
var s = store.LoadState();
Check.Eq(s.Bank.Pyreals, 1234567L, "bank balances");
Check.Eq(s.Bank.AutoRefreshSeconds, 300, "bank settings");
Check.Eq(s.Pet.PetLog.FirstOrDefault(), "Fire Banshee", "the /pets log (an ILT part of the Pet section)");
Check.Eq(s.Character.QbFilter, "wait", "the /qb filter");
Check.Eq(s.Character.AttrOrder.FirstOrDefault(), "qui", "the attribute raiser's order");
Check.Eq(s.Character.AugTargets["war"], 1800, "aug targets");
Check.True(s.Gear.AutoClap && s.Gear.LastEquipProfile == "Melee", "gear settings");
Check.True(s.Guardian.AutoHandIn && s.Guardian.TurnInCounts["Strength"] == 3, "guardian settings");
Check.True(s.UbSidecarsImported, "the UB import isn't redone");
store.SaveStateIfDirty(s);
string saved = File.ReadAllText(Path.Combine(dir, IltHubStore.StateFile));
Check.False(saved.Contains("HealPetName"), "the Pets tab's settings (RynthAi's now) aren't written back here");
Check.False(saved.Contains("QuestFavorites"), "nor the Quests tab's");
}
private static void VerbRouting()
{
static bool Takes(string line) => RynthILTPlugin.IsIltVerb(line.Split(' ', StringSplitOptions.RemoveEmptyEntries));
Check.True(Takes("hub bank"), "hub bank");
Check.True(Takes("hub attr run"), "hub attr run");
Check.True(Takes("hub refresh"), "hub refresh");
Check.True(Takes("hub help"), "hub help (RynthILT prints the whole list)");
Check.True(Takes("hub open banking show"), "hub open <ILT tab>");
Check.True(Takes("hub open guardian"), "hub open guardian (the engine panel)");
Check.True(Takes("hub open bounties"), "hub open bounties");
Check.False(Takes("hub open pets"), "hub open pets is RynthAi's");
Check.False(Takes("hub open quests hide"), "hub open quests is RynthAi's");
Check.True(Takes("hub tab gear"), "hub tab <ILT tab>");
Check.False(Takes("hub tab quests"), "hub tab quests is RynthAi's");
Check.False(Takes("hub tab remote"), "the Remote tab is RynthAi's");
Check.False(Takes("hub"), "bare /ra hub toggles RynthAi's Mini Remote");
Check.True(Takes("guardian handin"), "guardian");
Check.True(Takes("bounty show") && Takes("bounties") && Takes("bountys"), "bounty, bounties, bountys");
Check.True(Takes("rates reset"), "rates reset (the Mini Remote's Reset XP)");
Check.False(Takes("quests refresh"), "/ra quests is RynthAi's");
Check.False(Takes("pets show"), "/ra pets is RynthAi's");
Check.False(Takes("start"), "anything else is RynthAi's");
// The VTank hotkey verbs (RynthAi 2026-10-13, RynthAiPlugin.VTankHotkeys.cs) stay RynthAi's.
foreach (string vt in new[] { "vtkeys", "targetlock", "recharge", "lootthis", "meleelow", "navprio", "lootprio", "navlootprio", "setmetastate Default", "testitem", "propertydump" })
Check.False(Takes(vt), $"{vt} is RynthAi's (VTank hotkeys)");
}
private static void Classification()
{
Check.Eq(IltObjects.ClassifyByItemType(0x00000800), AcObjectClass.Gem, "gem (aetheria)");
Check.Eq(IltObjects.ClassifyByItemType(0x00000001), AcObjectClass.MeleeWeapon, "melee weapon");
Check.Eq(IltObjects.ClassifyByItemType(0x00000100), AcObjectClass.MissileWeapon, "missile weapon");
Check.Eq(IltObjects.ClassifyByItemType(0x00008000), AcObjectClass.WandStaffOrb, "caster");
Check.Eq(IltObjects.ClassifyByItemType(0x40000000), AcObjectClass.Salvage, "salvage (white quartz)");
Check.Eq(IltObjects.ClassifyByItemType(0x00001000), AcObjectClass.SpellComponent, "spell component");
Check.Eq(IltObjects.ClassifyByItemType(0x00000200), AcObjectClass.Container, "pack");
Check.Eq(IltObjects.ClassifyByItemType(0x00000010), AcObjectClass.Monster, "creature");
Check.Eq(IltObjects.ClassifyByItemType(0x00000002 | 0x00000004), AcObjectClass.Armor, "armor wins over clothing");
Check.Eq(IltObjects.ClassifyByItemType(0), AcObjectClass.Unknown, "no type yet");
}
private static unsafe void InterfaceLayout()
{
Check.Eq(sizeof(ServerHubTabV1), 24 + 32 + 4 + 4 + 4, "ServerHubTabV1: id, label, width, height, flags");
Check.Eq((int)Marshal.OffsetOf<ServerHubTabV1>(nameof(ServerHubTabV1.Flags)), 64, "ServerHubTabV1.Flags offset");
// RynthILT.Hub grew on 2026-10-20 (append-only): readers accept any table at least BaseStructSize
// long (the first release's 9 functions) and check the appended ones with Has.
Check.Eq((int)RynthServerHubApiV1.BaseStructSize, 8 + 9 * IntPtr.Size, "RynthServerHubApiV1.BaseStructSize: the first release's 9 functions");
Check.Eq(RynthServerHubApiV1.AllowSummonOnEmptyOffset, 8 + 9 * IntPtr.Size, "AllowSummonOnEmpty right after Command");
Check.Eq((int)Marshal.OffsetOf<RynthServerHubApiV1>(nameof(RynthServerHubApiV1.AllowSummonOnEmpty)), RynthServerHubApiV1.AllowSummonOnEmptyOffset,
"AllowSummonOnEmptyOffset is where the field really is");
Check.Eq((int)Marshal.OffsetOf<RynthServerHubApiV1>(nameof(RynthServerHubApiV1.GetSubTabs)), RynthServerHubApiV1.GetSubTabsOffset,
"GetSubTabsOffset is where the field really is");
Check.Eq((int)Marshal.OffsetOf<RynthServerHubApiV1>(nameof(RynthServerHubApiV1.GetSetting)), RynthServerHubApiV1.GetSettingOffset,
"GetSettingOffset is where the field really is");
Check.Eq((int)Marshal.OffsetOf<RynthServerHubApiV1>(nameof(RynthServerHubApiV1.SetSetting)), RynthServerHubApiV1.SetSettingOffset,
"SetSettingOffset is where the field really is");
// SessionStatsMore was appended (2026-10-13); readers accept any table at least
// BaseStructSize long, so an older RynthAi still connects.
// VaultedDungeonsEnabled was appended (2026-10-18): the Vaulted Dungeons master switch.
// BackAwayFrom was appended (2026-10-20): the generic back-away RynthILT's Handler ring evade asks for.
// SetPlayerCounter too (2026-10-20): the T11 wield counters RynthILT reads from /aug.
// LootActions, VendorSells and TradeGives (2026-11-26): RynthSort's pack jobs; RynthILT doesn't call them.
Check.Eq(sizeof(RynthAiHubApiV1), 8 + 17 * IntPtr.Size, "RynthAiHubApiV1: header + 17 functions");
Check.Eq((int)Marshal.OffsetOf<RynthAiHubApiV1>(nameof(RynthAiHubApiV1.TradeGives)), RynthAiHubApiV1.TradeGivesOffset,
"TradeGivesOffset is where the field really is");
Check.Eq((int)Marshal.OffsetOf<RynthAiHubApiV1>(nameof(RynthAiHubApiV1.SetPlayerCounter)), RynthAiHubApiV1.SetPlayerCounterOffset,
"SetPlayerCounterOffset is where the field really is");
Check.Eq((int)Marshal.OffsetOf<RynthAiHubApiV1>(nameof(RynthAiHubApiV1.BackAwayFrom)), RynthAiHubApiV1.BackAwayFromOffset,
"BackAwayFromOffset is where the field really is");
Check.Eq((int)RynthAiHubApiV1.BaseStructSize, 8 + 10 * IntPtr.Size, "RynthAiHubApiV1.BaseStructSize: the first release's 10 functions");
Check.Eq(RynthAiHubApiV1.SessionStatsMoreOffset, (int)RynthAiHubApiV1.BaseStructSize, "SessionStatsMore right after the base table");
Check.Eq(RynthAiHubApiV1.VaultedDungeonsEnabledOffset, 8 + 11 * IntPtr.Size, "VaultedDungeonsEnabled right after SessionStatsMore");
Check.Eq((int)Marshal.OffsetOf<RynthAiHubApiV1>(nameof(RynthAiHubApiV1.VaultedDungeonsEnabled)), RynthAiHubApiV1.VaultedDungeonsEnabledOffset,
"VaultedDungeonsEnabledOffset is where the field really is");
Check.Eq(sizeof(QuestFlagV1), 24, "QuestFlagV1");
Check.Eq(sizeof(QuestStatusV1), 16, "QuestStatusV1");
Check.Eq(RynthIltHub.InterfaceName, "RynthILT.Hub", "interface name");
// The hub split into the neutral RynthServer.Hub (RynthServerHubApi.cs) on 2026-10-21: the ids are
// the wire format and kept their values.
Check.Eq(RynthServerHubApiV1.InterfaceName, "RynthServer.Hub", "the neutral interface name");
Check.Eq(string.Join(",", RynthServerHub.SectionRemoteBank, RynthServerHub.SectionRemoteGuardian, RynthServerHub.SectionRemoteStats,
RynthServerHub.SectionRemoteOptions, RynthServerHub.SectionPetCharms, RynthServerHub.SectionPetCapture,
RynthServerHub.SectionPetLogs, RynthServerHub.SectionServerStatus, RynthServerHub.SectionServerMenu),
"remote-bank,remote-guardian,remote-stats,remote-options,pets-charms,pets-capture,pets-logs,ilt-status,server-menu",
"section ids unchanged");
Check.Eq(string.Join(",", RynthServerHub.TabParentPets, RynthServerHub.TextSessionReport, RynthServerHub.TextServerId,
RynthServerHub.FeatureQuests, RynthServerHub.SettingVaultedDungeons),
"pets,session-report,server-id,quests,vaulted-dungeons", "tab, text, feature and setting ids unchanged");
Check.Eq((RynthServerHub.TabShown, RynthServerHub.TabAvailable), (1u, 2u), "tab flags unchanged");
Check.Eq(RynthAiHubApiV1.InterfaceName, "RynthAi.Hub", "RynthAi's interface name");
}
private static void DescribeLines()
{
var s = new IltSettings();
Check.True(ServerFeatureGate.Describe("InfiniteLeaftide", s, false).Contains("ON - matches 'InfiniteLeaftide'"), "on by name");
Check.True(ServerFeatureGate.Describe("Aelrynth", s, true).Contains("Treat this world as ILT"), "on by the override");
Check.True(ServerFeatureGate.Describe("Aelrynth", s, false).Contains("OFF"), "off");
Check.True(ServerFeatureGate.Describe("", s, false).Contains("not logged in"), "before login");
}
private static IltHubController NewHub(string world, string folder)
{
RynthCore.RynthAiHostTests.Fakes.FakeHost.Reset();
RynthCore.RynthAiHostTests.Fakes.FakeHost.WorldName = world;
var host = RynthCore.RynthAiHostTests.Fakes.FakeHost.Create(0x50000F01);
string dir = Path.Combine(Program.TempRoot, "move-" + folder);
Directory.CreateDirectory(dir);
return new IltHubController(host, dir, new IltSettings(), new RynthAiClient(host));
}
private static void TickFor(IltHubController hub, int ms)
{
var until = DateTime.UtcNow.AddMilliseconds(ms);
while (DateTime.UtcNow < until) { hub.Tick(); System.Threading.Thread.Sleep(50); }
}
/// <summary>
/// The charms JSON behind "RynthILT.Data" is valid JSON; on ILT it has a "hands" array (empty
/// with no hand carried) that the shared reader parses, off ILT it has none and still parses.
/// </summary>
private static void CharmsReaderJson()
{
var on = NewHub("InfiniteLeaftide", "charms-on");
string json = on.CharmsTab.BuildReaderJson();
using (var doc = System.Text.Json.JsonDocument.Parse(json))
Check.True(doc.RootElement.TryGetProperty("hands", out var hands) && hands.GetArrayLength() == 0,
"on ILT: an empty hands array with no Guardian Hand carried");
Check.True(json.All(c => c < 128), "ASCII only");
var view = IltCharmsView.Parse(json);
Check.True(view.Loaded && view.Hands.Count == 0, "the shared reader takes it");
var withHands = IltCharmsView.Parse("{\"available\":true,\"charms\":[],\"hands\":[" +
"{\"id\":1234,\"name\":\"Guardian Hand\",\"active\":\"on\",\"server\":\"off\"},{\"id\":0,\"name\":\"no id\"}]}");
Check.Eq(withHands.Hands.Count, 1, "a hand without an id is skipped (nothing to toggle)");
Check.True(withHands.Hands[0] == new IltHandRow(1234, "Guardian Hand", "on", "off"), "id, name, active, server");
var off = NewHub("Aeshnidae", "charms-off");
string offJson = off.CharmsTab.BuildReaderJson();
using (var doc = System.Text.Json.JsonDocument.Parse(offJson))
Check.False(doc.RootElement.TryGetProperty("hands", out _), "off ILT: no hands");
Check.True(IltCharmsView.Parse(offJson).Hands.Count == 0, "and the reader shows none");
}
/// <summary>The Character tab moved out (2026-10-13); every other ILT tab is still RynthILT's.</summary>
private static void MovedSections()
{
Check.Eq(IltSections.MovedCommand(IltSection.Character), IltSections.OracleCharacterCommand, "Character -> RynthOracle Character");
foreach (var kept in new[] { IltSection.Banking, IltSection.Gear, IltSection.Charms, IltSection.Games })
{
Check.True(IltSections.MovedCommand(kept) == null, $"{IltSections.Label(kept)} is still RynthILT's");
Check.True(IltSections.IsTab(kept), $"{IltSections.Label(kept)} is a Mini Remote tab");
}
Check.True(IltSections.MovedCommand(IltSection.VaultedDungeons) == null && IltSections.IsTab(IltSection.VaultedDungeons),
"Vaulted Dungeons is a RynthILT tab (shown only with the master switch, VaultedDungeonsTests)");
Check.True(IltSections.Tabs.SequenceEqual(new[] { IltSection.Banking, IltSection.Gear, IltSection.Charms, IltSection.Games, IltSection.VaultedDungeons }),
"the tab list is Banking, Gear, Charms, Games, Vaulted Dungeons");
Check.False(IltSections.IsTab(IltSection.Character) || IltSections.IsTab(IltSection.Guardian), "Character and the Guardian aren't tabs");
Check.True(IltSections.TryParse("char", out IltSection c) && c == IltSection.Character, "old Character names still parse (for the redirect)");
Check.Eq(IltSections.OracleCharacterCommand, "/ro character", "Oracle command");
}
/// <summary>
/// RynthILT's RynthPluginGetSectionsJson: schema 1 (UI/Sections/SectionManifest.cs in RynthCore),
/// every view an ILT one, each surface one RenderEmbed answers.
/// </summary>
private static void SectionsManifest()
{
// No Hub (before the character's name is known): the always-there views only.
string bare = IltSectionsManifest.Build(IltSectionsManifest.TabsOf(null));
using var doc = System.Text.Json.JsonDocument.Parse(bare);
var root = doc.RootElement;
Check.Eq(root.GetProperty("version").GetInt32(), 1, "schema 1");
var sections = root.GetProperty("sections");
Check.Eq(sections.GetArrayLength(), 2, "two sections of RynthILT's own");
Check.Eq(sections[0].GetProperty("id").GetString(), "quests", "a Quests section (the /qb list)");
Check.Eq(sections[1].GetProperty("id").GetString(), "games", "and Games (moved from RynthAi with the tabs)");
var surfaces = new System.Collections.Generic.List<string>();
foreach (var c in root.GetProperty("contributions").EnumerateArray())
{
Check.Eq(c.GetProperty("server").GetString(), "ilt", "an Infinite Leaftide view");
surfaces.Add(c.GetProperty("surface").GetString() ?? "");
}
Check.True(surfaces.SequenceEqual(new[] { RynthILTPlugin.RatesSurface, RynthILTPlugin.FellowshipSurface, RynthILTPlugin.QuestBonusSurface,
RynthILTPlugin.DynamicStampsSurface }),
"rates, fellowship, quest bonus, Dynamic Stamps (from RynthOracle 2026-10-21): " + string.Join(",", surfaces));
Check.True(surfaces.All(s => s.StartsWith("section:ilt-", StringComparison.Ordinal) && s.Length <= 64), "short section:ilt-* surfaces");
Check.True(bare.All(ch => ch < 128), "ASCII only");
// The Mini Remote ILT tabs the Hub shows (RynthAi listed them until 2026-10-20): Gear not reported yet,
// Games hidden, Charms and Banking shown.
var tabs = new[]
{
new IltSectionsManifest.Tab("banking", 560, 520, Shown: true, Available: true),
new IltSectionsManifest.Tab("gear", 560, 520, Shown: true, Available: false),
new IltSectionsManifest.Tab("charms", 560, 520, Shown: true, Available: true),
new IltSectionsManifest.Tab("games", 520, 440, Shown: false, Available: false),
new IltSectionsManifest.Tab("character", 520, 440, Shown: true, Available: true),
};
string json = IltSectionsManifest.Build(tabs);
var m = RynthCore.Engine.UI.Sections.SectionManifestParser.Parse("RynthILT", json, out string error);
Check.Eq(error, string.Empty, "the engine's parser takes it");
Check.Eq(m.Contributions.Length, 7, "rates, fellowship, /qb, Dynamic Stamps, Banking, Gear, Charms");
var stamps = m.Contributions.Single(c => c.Surface == RynthILTPlugin.DynamicStampsSurface);
Check.True(stamps.Section == "quests" && stamps.Primary && stamps.Server == "ilt" && stamps.Label == "Dynamic Stamps",
"Dynamic Stamps: a page of RynthILT's Quests section, on ILT only");
var gear = m.Contributions.Single(c => c.Surface == "section:gear");
Check.True(gear.Section == "inventory" && !gear.Enabled && gear.Note.Length > 0, "Gear in Inventory, disabled with a note until reported");
Check.True(m.Contributions.Any(c => c.Surface == "section:charms" && c.Enabled) && m.Contributions.Any(c => c.Surface == "section:banking" && c.Enabled),
"Charms and Banking stay RynthILT's tabs");
Check.False(m.Contributions.Any(c => c.Surface == "section:games"), "a hidden tab isn't listed");
Check.False(m.Contributions.Any(c => c.Surface == "section:character"), "Character moved out: never placed");
var iltOn = new RynthCore.Engine.UI.Sections.ServerState("ilt", "Infinite Leaftide", true, true, RynthCore.Engine.UI.Sections.ServerForce.Auto, true, "");
var on = RynthCore.Engine.UI.Sections.SectionCatalog.Build(new[] { m }, _ => false, new[] { iltOn });
Check.True(on.Single(v => v.Id == "inventory").Panes.Any(p => p.Title == "Charms" && p.Contribution?.Plugin == "RynthILT"),
"on ILT the engine shows RynthILT's Charms in Inventory (drawn by RynthILT)");
var off = RynthCore.Engine.UI.Sections.SectionCatalog.Build(new[] { m }, _ => false, new[] { iltOn with { Active = false } });
Check.False(off.Single(v => v.Id == "inventory").Panes.Any(p => p.Title == "Charms"), "off ILT: none");
Check.True(IltSectionsManifest.TryTabOf("section:banking", out IltSection bank) && bank == IltSection.Banking, "section:banking draws Banking");
Check.False(IltSectionsManifest.TryTabOf("section:bank", out _), "only the tab's own id");
Check.False(IltSectionsManifest.TryTabOf("section:pets", out _), "pets is RynthAi's");
Check.False(IltSectionsManifest.TryTabOf("section:ilt-rates", out _), "not a tab");
Check.True(RynthILTPlugin.IsParsedRemoteAction("servermenu") && RynthILTPlugin.IsParsedRemoteAction("ServerMenu")
&& !RynthILTPlugin.IsParsedRemoteAction("prog"), "RynthCore's servermenu push is answered, never queued as a verb");
}
private static void DormantOffIlt()
{
var off = NewHub("Aeshnidae", "dormant");
off.OnLoginComplete("Tester", forceFromMigration: false);
foreach (string line in new[] { "Your Pet Log:", "[BANK] Pyreals: 5", "Guardian of Strength tells you, \"x\"" }) off.OnChat(line);
TickFor(off, 6800); // past the 6 s login delay
Check.Eq(RynthCore.RynthAiHostTests.Fakes.FakeHost.ChatCommands.Count, 0, "off ILT: no probe, no command at all");
Check.False(off.Options.IsIltLikeWorld, "not an ILT world");
foreach (var s in IltSections.Tabs) Check.False(off.TabShown(s), $"no {IltSections.Label(s)} tab");
Check.False(off.RenderSection(RynthServerHub.SectionRemoteBank) || off.RenderSection(RynthIltHub.SectionQuestBonus)
|| off.RenderSection(RynthServerHub.SectionPetLogs) || off.RenderSection(RynthServerHub.SectionRemoteGuardian)
|| off.RenderSection(RynthServerHub.SectionServerMenu), "no ILT section draws (checked before any ImGui call)");
Check.True(off.BuildProgressionJson().StartsWith("{\"available\":false"), "Progression: not available");
off.OnLogout();
var on = NewHub("InfiniteLeaftide", "awake");
on.OnLoginComplete("Tester", forceFromMigration: false);
TickFor(on, 6800);
Check.True(on.Options.IsIltLikeWorld, "InfiniteLeaftide is ILT");
Check.True(RynthCore.RynthAiHostTests.Fakes.FakeHost.ChatCommands.Count > 0, "on ILT the login probe asks the server");
Check.False(RynthCore.RynthAiHostTests.Fakes.FakeHost.ChatCommands.Any(c => c.Contains("/ilt features", StringComparison.OrdinalIgnoreCase)),
"the server is never asked for a feature list (the ILT profile is Rynth-side)");
// Character moved out of the Mini Remote (RynthOracle's Character tab, Session Stats);
// Charms and Banking are Infinite Leaftide's own screens and stay RynthILT's tabs.
Check.False(on.TabShown(IltSection.Character), "Character is no Mini Remote tab any more");
Check.Eq(on.TabShown(IltSection.Gear), on.Available, "Gear shows once the server features are known");
Check.Eq(on.TabShown(IltSection.Charms), on.Available, "Charms too");
on.OnLogout();
var forced = NewHub("Aeshnidae", "forced");
forced.OnLoginComplete("Tester", forceFromMigration: true);
Check.True(forced.Options.IsIltLikeWorld, "a migrated \"Force enable\" makes the world ILT for this character");
forced.OnLogout();
}
private static unsafe void HubTable()
{
Check.Eq(HubInterface.Query("RynthAi.Hub", 1), IntPtr.Zero, "another interface's name: not ours");
Check.Eq(HubInterface.Query(RynthIltHub.InterfaceName, 2), IntPtr.Zero, "a newer version than we have: none");
var t = (RynthServerHubApiV1*)HubInterface.Query(RynthIltHub.InterfaceName, 1);
Check.True(t != null, "v1 is served");
Check.Eq(t->Version, 1u, "Version 1");
Check.Eq(t->StructSize, (uint)sizeof(RynthServerHubApiV1), "StructSize");
Check.True(t->IsServerWorld != null && t->GetFeature != null && t->GetRates != null && t->GetForceServer != null && t->SetForceServer != null
&& t->GetTabs != null && t->RenderTab != null && t->RenderSection != null && t->Command != null
&& t->AllowSummonOnEmpty != null && t->GetSubTabs != null && t->GetSetting != null && t->SetSetting != null,
"every function is filled in");
Check.True(RynthServerHubApiV1.Has(t, RynthServerHubApiV1.GetSubTabsOffset), "the appended functions are inside StructSize");
Check.Eq((IntPtr)t, HubInterface.Query(RynthIltHub.InterfaceName, 1), "the same table each time");
Check.Eq((IntPtr)t, HubInterface.Query(RynthServerHubApiV1.InterfaceName, 1),
"and under the server-neutral name RynthAi asks the active server's owner for (RynthServer.Hub)");
// No plugin instance here (not logged in): every function answers "nothing".
Check.Eq(t->IsServerWorld(), 0, "not ILT before login");
byte* key = stackalloc byte[] { (byte)'b', (byte)'a', (byte)'n', (byte)'k', 0 };
Check.Eq(t->GetFeature(key), -1, "feature unknown before login");
Check.Eq(t->GetTabs(null, 0), 0, "no tabs before login");
Check.Eq(t->Command(key), 0, "no command taken before login");
Check.Eq(t->AllowSummonOnEmpty(), 0, "no summon from empty before login");
byte* pets = stackalloc byte[] { (byte)'p', (byte)'e', (byte)'t', (byte)'s', 0 };
Check.Eq(t->GetSubTabs(pets, null, 0), 0, "no Pets sub-tabs before login");
Check.Eq(t->GetSetting(pets), -1, "no setting offered before login");
Check.Eq(t->SetSetting(pets, 1), 0, "and none taken");
HubInterface.Release();
Check.Eq(t->Version, 0u, "Release zeroes Version (callers re-query)");
Check.Eq(HubInterface.Query(RynthIltHub.InterfaceName, 1), IntPtr.Zero, "and nothing is served after shutdown");
Check.Eq(t->IsServerWorld(), 0, "the old table stays callable and answers nothing");
}
}