RynthSuite/Tools/RynthCore.RynthAiHostTests/Program.cs
Daniel Wallace cf69899198 Plugin fixes: duplicate target requests, bounded name read, guarded exports
Selection: a selection change asked for an appraisal and a health query for every
object, and the dashboard asked for health again. The engine selects each
corpse it opens and each item it moves, so one object drew 4-6 identifies.
OnSelectedTargetChange now sends an identify only for a creature with no
cached appraisal (HasAppraisalData, else GetLastIdTime > 0) and a health
query only for creatures. The dashboard no longer queries health itself.
A target cached as Unknown (type not read yet) is undecided like an
uncached one: a corpse name ("Corpse of") rejects, the creature flag 0x10
accepts, a typed non-creature rejects, then ObjectIsAttackable decides, and
with nothing to go on it fails open.

Fellowship name read: FellowshipTracker.ReadPString read to a NUL with no bound. It now reads
at most 64 characters and never past the end of the probed region.

Exports: an exception escaping an UnmanagedCallersOnly export fail-fasts the
client under NativeAOT. The Shutdown exports of RynthAi, RynthNav, RynthNet,
RynthVision, RynthLua, RynthChat, RynthInventory, RynthOracle and
RynthTracker guard each step and log the error; the Name/Version exports of
RynthAi, RynthNav, RynthLua, RynthChat, RynthInventory, RynthNet,
RynthOracle, RynthTracker and RynthVision (a static initializer that throws
surfaces there) are wrapped.

Tests (PluginFixTests) with FakeHost QueryHealth and GetLastIdTime.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-12 17:35:42 -07:00

111 lines
5.2 KiB
C#

using System;
using System.IO;
using RynthCore.Plugin.RynthAi;
using RynthCore.Plugin.RynthAi.Meta;
using RynthCore.RynthAiHostTests.Tests;
using RynthCore.RynthAiTests.Harness;
namespace RynthCore.RynthAiHostTests;
// Offline tests for RynthAi's host-bound logic: loot rule matching and metas. Each test prints
// PASS / FAIL, or KNOWN for a registered real bug (which does not fail the run).
//
// Run: dotnet run -c Release (all tests)
// dotnet run -c Release -- vtank (tests whose name contains "vtank")
internal static class Program
{
/// <summary>Scratch folder next to the exe for files tests write. Emptied at start.</summary>
public static string TempRoot { get; } = Path.Combine(AppContext.BaseDirectory, "scratch");
/// <summary>DungeonHazardStore's folder before Main pointed it at the scratch folder.</summary>
public static string LiveHazardFolder { get; private set; } = "";
/// <summary>CreatureProfileStore's folder before Main pointed it at the scratch folder.</summary>
public static string LiveCreatureFolder { get; private set; } = "";
private static int Main(string[] args)
{
if (Directory.Exists(TempRoot)) Directory.Delete(TempRoot, recursive: true);
Directory.CreateDirectory(TempRoot);
// SAFETY: the expression engine reads and writes pvars/gvars (and reads ItemGiver
// profiles) under C:\Games\RynthSuite\RynthAi. Point them at the scratch folder before
// any engine exists. The "expr: safety" test checks this held.
ExpressionEngine.PvarsDir = Path.Combine(TempRoot, "pvars");
ExpressionEngine.GvarsPath = Path.Combine(TempRoot, "gvars.txt");
ExpressionEngine.ItemGiverDir = Path.Combine(TempRoot, "ItemGiver");
// The dungeon map bake writes floor plans under C:\Games\RynthSuite\RynthAi\Maps.
RynthCore.Plugin.RynthAi.Maps.DungeonMapBake.CacheDir = Path.Combine(TempRoot, "Maps");
// A sighted lava/acid hotspot is persisted under C:\Games\RynthSuite\RynthAi\DungeonHazards.
LiveHazardFolder = RynthCore.Plugin.RynthAi.DungeonHazardStore.Folder;
RynthCore.Plugin.RynthAi.DungeonHazardStore.Folder = Path.Combine(TempRoot, "DungeonHazards");
// Appraised creatures are saved to C:\Games\RynthSuite\RynthAi\CreatureData\creatures.json.
LiveCreatureFolder = RynthCore.Plugin.RynthAi.CreatureData.CreatureProfileStore.Folder;
RynthCore.Plugin.RynthAi.CreatureData.CreatureProfileStore.Folder = Path.Combine(TempRoot, "CreatureData");
// Spell names (item spells, spell expiry by name) come from the plugin's embedded table.
SpellDatabase.Load();
var runner = new Runner();
NativeLootTests.Register(runner);
VTankLootTests.Register(runner);
T11LootTests.Register(runner);
ExpressionTests.Register(runner);
MetaTests.Register(runner);
NoKillTests.Register(runner);
MetaSchedulerTests.Register(runner);
NavEngineTests.Register(runner);
NavReachTests.Register(runner);
PatrolDoorwayTests.Register(runner);
BuffTests.Register(runner);
CombatMathTests.Register(runner);
WeaponTests.Register(runner);
RadarSnapshotTests.Register(runner);
AmmoTests.Register(runner);
VTankYieldTests.Register(runner);
OffhandTests.Register(runner);
FloodPerfTests.Register(runner);
LootSalvageTests.Register(runner);
LootCorpseTests.Register(runner);
OwnCorpseTests.Register(runner);
UseRefusalTests.Register(runner);
CorpseKillerTests.Register(runner);
VitalsTests.Register(runner);
MultiTargetTests.Register(runner);
CastSafetyTests.Register(runner);
HealLatencyTests.Register(runner);
BlastTests.Register(runner);
ArcWhenClearTests.Register(runner);
WallTests.Register(runner);
CombatHookTests.Register(runner);
UseAtLoginTests.Register(runner);
LearnSpellsTests.Register(runner);
AttackLatencyTests.Register(runner);
TargetingTests.Register(runner);
LootAddItemTests.Register(runner);
GiveTests.Register(runner);
DungeonMapBakeTests.Register(runner);
MonsterEditorTests.Register(runner);
InstallPathsTests.Register(runner);
PetRefillTests.Register(runner);
IgnoreMonsterTests.Register(runner);
WorldCacheTypedTests.Register(runner);
ItemInfoTests.Register(runner);
NavOverlayTests.Register(runner);
ActionPacingTests.Register(runner);
HazardEscapeTests.Register(runner);
ManaStoneChoiceTests.Register(runner);
CustomDebuffTests.Register(runner);
ProfileLoadTests.Register(runner);
ActivityInterfaceTests.Register(runner);
CastNoDamageTests.Register(runner);
ManaReserveTests.Register(runner);
DamageRowsTests.Register(runner);
StuckCastTests.Register(runner);
PacerEdgeTests.Register(runner);
RecoveryRetryTests.Register(runner);
HpFailsafeTests.Register(runner);
PluginFixTests.Register(runner);
return runner.Run("RynthAi host tests", args.Length > 0 ? args[0] : null);
}
}