20 KiB
RynthCore.RynthAiTests
A console test runner for RynthAi's pure logic. It needs no game, no engine and no host.
It follows the house style of the other test tools here (RynthCore.LootSdkTests,
RynthCore.AutoVendorTests, RynthCore.MissileArcTests): a plain net10.0 exe, no test
framework, and exit code 0 when everything passes.
dotnet run -c Release # all tests
dotnet run -c Release -- weakness # only tests whose name contains "weakness"
Each test prints one line:
| Line | Meaning |
|---|---|
[PASS] |
Every check passed. |
[FAIL] |
At least one check failed, the test threw, or it made no checks. Each failed check is listed under the line. The run exits with code 1. |
[KNOWN] |
The test was registered with Runner.KnownFailure(name, reason, body) because it exposes a real bug that is not fixed yet. It still fails, but the run does not. |
[XPASS] |
A known-failure test now passes. The run fails so that the marker gets removed along with the fix. |
The run also exits with code 1 when no test runs (an empty registry or a filter that matches nothing).
Layout:
Harness/Check.cs: the assertion helper (True,False,Eq,Near,Null,NotNull,Throws). A failed check is recorded and the test keeps going, so one run shows every broken expectation.Harness/Runner.cs: registers tests, prints PASS/FAIL, handles known failures, sets the exit code.Tests/*.cs: one static class per area. Each has aRegister(Runner)method, whichProgram.cscalls.Fakes/: stand-ins for plugin classes that a linked file mentions but that are not linked.
To add a test: write a static void method that calls Check.*, then register it in that
area's Register method. For a new area, add a class and call its Register from
Program.cs. When the code under test lives in a new source file, add a <Compile Include ... Link=...> for it to the csproj.
Current smoke tests (13 tests, 142 checks, all passing on 2026-09-29):
- nav (
LegacyUi/NavRouteParser.cs): the trailer of every waypoint type, the EW-before-NS order, a write/read round trip, the fix that converts a Z stored in metres, Follow routes, and stopping with a warning at an unknown type instead of desyncing. - stall (
Combat/CombatStallWatchdog.cs): the whole 4-step ladder with its 6 s / 3 s / 30 s timings, recovery, the tick-gap reset, and the ineligible case. - weakness (
CreatureData/CreatureWeakness.cs): element aliases, server-table ranking (with a check that the wcid and the name agree), creature-type keywords (whole words only), and a learned element going first. Assertions that depend on the data are computed from the embedded tables, so regeneratingcreature_resists.tsv/creature_types.txtdoes not break them.
Second runner: Tools/RynthCore.RynthAiHostTests (added 2026-09-30). Loot rule matching
and metas are host-bound, so they are tested there, through the project-reference route
described below (net10.0-windows, win-x86, InternalsVisibleTo). It links this runner's
Harness/ files, so both print the same PASS / FAIL / KNOWN / XPASS lines. Its
Fakes/FakeHost.cs fills a RynthCoreApiNative with [UnmanagedCallersOnly] fakes, so a
test can set skills, level, item spells, vitals, position, enchantments and so on. Its
Program.cs points the pvar/gvar/ItemGiver paths at a scratch folder before any test runs
(the seam is ExpressionEngine.PvarsDir / GvarsPath / ItemGiverDir); MetaManager.Clock
and ExpressionEngine.TickMs make the timers testable without sleeping.
Both runners in one go: Tools\Run-RynthAiTests.ps1 (added 2026-09-30, -Filter text
optional). It builds and runs both and exits 1 only on FAIL or XPASS (or a build error).
Added 2026-09-30 (nav, buffs, combat numbers):
- here:
Tests/NavFormatTests.csreads the hand-written.navfiles inFixtures/nav(every route type and waypoint kind, malformed files). - host runner:
NavEngineTests(route walking on a fake clock: advancing, pause/chat/jump/recall points, the closest-point start, the 160 yd off-track rule, the rejoin choice, the different-area hold and its decision),BuffTests(tier by buffed skill, the spell every buff resolves to at every tier checked againstSpellData.txt, timer lengths, rebuff timing),CombatMathTests(damage text, element words, weapon choice by weakness, the target scan's range ring). Seams:NavigationEngine.Clock,INavRecoveryPlanner,NavRecoveryPlanner.ClassifyArea, and a few private helpers inBuffManager/CombatManagermade internal.
How the runner reaches RynthAi's code
Decision: link individual source files (<Compile Include ... Link=...>), the same way
the existing test tools do. The alternative was checked and works, but only with
conditions attached.
- Project reference from a plain net10.0 exe: not possible. The plugin targets
net10.0-windows, so restore fails withNU1201: Project RynthCore.Plugin.RynthAi is not compatible with net10.0. RynthCore.PluginSdk and PluginCore are alsonet10.0-windows. - Project reference from a
net10.0-windowsexe withPlatformTarget=x86andRuntimeIdentifier=win-x86: works. This was tried in a scratch project on 2026-09-29. NativeAOT does not get in the way:PublishAotandNativeLibonly apply when publishing, a normal build produces an ordinary IL dll, and the[UnmanagedCallersOnly]exports are just static methods nobody calls. The exe has to be x86, because the plugin dll is marked 32-bit and a 64-bit process would throw BadImageFormatException. That requires the x86 .NET runtime, which this PC has (10.0.7 underC:\Program Files (x86)\dotnet). The costs: the whole plugin compiles first (about 60 s and 100+ warnings); ImGui.NET comes along; and most classes areinternal, so tests need[assembly: InternalsVisibleTo("...")]in the plugin, which is an allowed seam.default(RynthCoreHost)works as a null host: everyHas*property is false and every call does nothing. With that host, the scratch probe (using reflection instead of InternalsVisibleTo) got these results:ExpressionEngine.Evaluate:1+2*3gave 7,setvar[x,5]then$x*2gave 10,listcount[listcreate[a,b,c]]gave 3, andiif[1>2,yes,no]gave no.LootEvaluator.Classify: matched aStringValue(Name)rule against aWorldObjectwhoseItemPropertyOverlaywas set and which had no cache.MetaManager.Think(): aDefaultstateAlways->SetMetaState Huntrule movedCurrentStatetoHunt.
Recommendation: keep this runner link-based and fast. For any area below, first check
whether a small seam (a pure helper moved into its own file with no dependencies) lets
the code link. If many host-bound classes need testing, add a second runner (for example
RynthCore.RynthAiHostTests: net10.0-windows, win-x86, a ProjectReference to the plugin,
and InternalsVisibleTo) rather than turning this one into it.
Safety note for any runner: some RynthAi paths are hard-coded to the live install.
ExpressionEngine has PvarsDir, GvarsPath and ItemGiverDir under
C:\Games\RynthSuite\RynthAi, and FlushVars writes pvars and gvars there.
CreatureProfileStore.Folder and the MonsterDamageStore files are also under C:\Games.
Tests must not call setpvar, setgvar or touchpvar, save stores, or run meta rules that
do, until those paths can be redirected. A redirect seam would be one internal settable
root, defaulting to the current path. This runner's Fakes/CreatureProfileStore.cs
points the creature override folder at a folder that does not exist, for exactly this
reason.
Seams, by area
"Linkable" means the file compiles into this plain net10.0 project as it is, with at most
a LootSdk ProjectReference and GlobalUsings.cs. "Host runner" means it is reachable today
only through the project-reference route above.
1. Loot rule matching
Loot/LootEvaluator.cs:Evaluate,MatchesandClassifyare public static and pure. Their only input they don't own isWorldObject(Combat/AcStubs.cs).WorldObjectcan already be fed without a cache: set its internalOverlayto anItemPropertyOverlaywithLiveFallback = falseand fill inInts,StringsandDoubles.- What blocks linking:
AcStubs.csalso containsCharacterSkills, which needsRynthCoreHostand therefore PluginSdk, which is net10.0-windows. It also containsSpellTableStub, which needsSpellDatabase. AndWorldObject.Cacheis typedWorldObjectCache(1843 lines, host-bound). - Seam (moves only, behaviour-neutral): put
WorldObject,ItemPropertyOverlayand theLongValueKey/StringValueKey/DoubleValueKeyenums in their own file. HaveWorldObjectread through a narrow interface thatWorldObjectCacheimplements:GetIntProperty,GetStringProperty,GetDoubleProperty,GetContainerId,GetWielderIdandGetWieldedLocation. ThenLootEvaluator.csand that file link on their own.CharacterSkillsis only used byCharacterSkillGECondition, andnullskills already mean "pass". - Worth pinning:
- The first matching rule wins, and a disabled rule never matches.
Classifyreturns(Sell, null)when nothing matches, and callers look at the null rule, not the action.- Unknown condition types pass (
_ => true). - A
StringValue(Name)condition falls back toWorldObject.Name(the 2026-09-28 healing-kit fix). MinDamageis computed asmax - variance * max.- Total ratings are summed over keys 370-376 and 379.
- What blocks linking:
Loot/VTankLootEvaluator.cs:Match(rule, item, ctx: null)is pure whenctxis null, because character and spell checks then pass. The file also containsVTankLootContext, which is host-bound. Seam: moveVTankLootContextto its own file, and give the evaluator an interface for the five lookups it uses: skill, level, empty pack slots, spell ids and palettes. It also usesMeta/RegexCache.cs, which links.Vendor/AutoVendorRules.csandAutoVendorPlanner.csare already covered byRynthCore.AutoVendorTests.
2. Meta: conditions, expressions, state transitions
- .af parsing and writing: linkable now.
Meta/AfFileParser.cs,AfFileWriter.cs,MetaSchema.cs,LoadedMeta.cs,RegexCache.cs,LegacyUi/LegacyUiSettings.cs(which holdsMetaRuleand the condition/action enums),LegacyUi/NavRouteParser.csandGlobalUsings.cs, plus a LootSdk reference, compile and run in a plain net10.0 exe. This was verified in a scratch project on 2026-09-29. Next tests:- Parse, write and parse again, and compare the results.
- Check that every
MetaConditionTypeandMetaActionTypehas exactly one keyword inMetaSchema, in both directions. This guards against the "SecsOnSpell _LE -> _GE" loss the schema comment mentions. - Check that embedded nav routes use
NavRouteParser.TrailerLineCount. MetFileParser.cs(.met) looks similar (it depends only on LegacyUi) but was not tried.
- Expression evaluation (
Meta/ExpressionEngine.cs, about 3900 lines): host runner. It needsRynthCoreHost,WorldObjectCache,FellowshipTracker,QuestTracker,LegacyUiSettingsand the loot types. It works with a null host (see above), but mind the pvar/gvar paths.ToBoolis alreadyinternal staticand pure. Seam for linking (larger): the nestedParser(operator precedence,||down to unary), together with the private static list, dict and string helpers (EvalListAdd,EvalListRemove,NewList,EvalCstrf,EvalIif,TryParseCoordObjectand the rest), could move into a dependency-freeExpressionCore.csthat calls back into the engine for function calls and variables. Worth pinning:- Operator precedence, including the single-character disambiguation of
&,|,<and>. - Numeric versus string coercion per operator.
- The recursion caps:
MaxEvalDepth64 andMaxParenDepth256, which exist to prevent an uncatchable StackOverflow in acclient. - List handles.
- Found by the probe, not investigated:
getregexmatch[abc123,[0-9]+]returned an empty string. It may be argument splitting on the brackets, and deserves a test.
- Operator precedence, including the single-character disambiguation of
- State transitions (
Meta/MetaManager.cs): host runner. It can be built fromnew LegacyUiSettings(),default(RynthCoreHost)andnew PlayerVitalsCache(), andThink()runs. Seam: it readsDateTime.Nowdirectly (seconds in state, the watchdog, the 1 s chat window), so injecting aFunc<DateTime>clock (internal, defaulting toDateTime.Now) would make timing rules testable without sleeping.EvaluateConditionis private. It becomes testable throughThink()once the class can be constructed, or directly with InternalsVisibleTo if made internal. Worth pinning:HasFiredlatches untilForceStateReset.- A state change stops the rest of that tick's rules.
- The
CallMetaState/ReturnFromCallstack. - Disabled rules are never indexed.
- Composite conditions with no children:
Allgives true,Anygives true,Notgives false. TheAnycase is surprising and should be compared with VTank before anyone relies on it. - Vital conditions read the public
PlayerVitalsCache.
3. Nav: route parsing, rejoin, closest point, 159 yd, different area
- Parsing:
LegacyUi/NavRouteParser.csis linked, and the tests above cover it. - Rejoin, closest point, off track and area all live inside
NavigationEngine(about 2500 lines, instance state,_host,_settings,_linearDir). None of it links today. The pure parts are:PickRejoinIndex(route, idx, ns, ew, out skipped): the nearest of the target and up to 8 waypoints after it (RejoinLookaheadPts), never more than 20 yd of route ahead (RejoinLookaheadYards), stopping at any point that is not walkable, with 0.5 yd of hysteresis.DistanceToSegmentYd,PrevIndexandNextInOrder: pure given the route type and_linearDir.NavYdandIsWalkTarget: already private static.- The closest-point start in
ResumeFromNearestWaypoint: an inline loop over plain waypoints. It starts from the current index on a Once route. Note thatMetaManager.StartIndexForRoute/FindNearestWaypointis a second, different rule: a Once route there always starts at 0. Pin both. - The closest-approach sweep:
_prevDist < ArrivalYards * SweepMult && dist > _prevDist + 0.3, inline in the tick. - Off track, the "159 yd" rule:
OffTrackYards = max(160, NavOffTrackYards)(the default is 170).CheckOffTrackarms when within the limit, is disarmed by everyStop()(combat, loot, buff, doors, metas), waits a 5 s grace and starts one recovery per excursion. - Area-grace overshoot: walks 4 yd on through the last waypoint when within 10 yd of it, for 6 s.
- Seam (a pure move): a dependency-free
NavRouteMathstatic class holdingNavYd,IsWalkTarget,PrevIndex/NextInOrder(routeType, count, cur, linearDir),DistanceToSegmentYd,PickRejoinIndexandNearestPlainWaypoint(route, from, ns, ew).NavigationEnginewould call it. A smallOffTrackGateclass in the style ofCombatStallWatchdog(Tick(nowMs, offYd)returns whether to start recovery, plusDisarm()) would carry the arming and grace logic. Next tests:- 159 yd off never triggers.
- 161 yd triggers once, after 5 s.
- A pause disarms it, and coming back within the limit re-arms it.
- A rejoin never goes backwards and never passes a Portal, Recall or Chat point.
- A Linear route in reverse.
- Different area:
NavRecoveryPlanner.CheckAreaneeds dat geometry (CellDat), so it is not pure. The decision inputs are pure: the landblock iscell >> 16, "indoors" is(cell & 0xFFFF) >= 0x0100, and nav-to-landblock math is inLegacyUi/NavCoordinateHelper.TryConvertPoseToCoords, which is pure but sits in a file that imports PluginSdk. Seam: moveTryConvertPoseToCoordsinto its own file. Pull the classification (same dungeon / other dungeon / dungeon versus landscape / unknown) out into a static function that takesFunc<uint,bool> isDungeonLandblockand a cell-reach callback, and test it with fakes.
4. Buff and spell choice
SpellManager.ComputeTieris private instance code over_charSkills[skill].Buffed(250 when there are no skills). Seam:static int TierFor(int buffed, int t2..t8). Note that thet1threshold is never read, and anything belowt2gives tier 1. Pin that.SpellManager.GetDynamicSelfBuffIdbuilds candidate names (Incantation of X Self, Aura of ..., the lore names inLoreNames, Roman numerals) and checks them againstSpellDictionaryand the known and unresolvable sets. The known-spell refresh needs the host. Seam: a static candidate-name generator,IEnumerable<string> CandidateNames(baseName, tier), testable without a spellbook.BuffManager:SkillForBuff,IsItemEnchantmentandGetSpellLevel(SpellInfo)are private static and pure, butBuffManager.cs(2800+ lines) does not link. Seam: move them into a smallBuffNames.cs. Worth probing (not confirmed as bugs):GetSpellLeveltestsContains(" V")after" VI", so a name with no numeral and a word starting with V (for example "... Vulnerability ...") would read as level 5." I "has a similar risk.- Impregnability must map to Creature Enchantment and Impenetrability to Item Enchantment, as the comment in
SkillForBuffinsists.
- The
CharacterSkillszero-artifact rule (AcStubs.cs): a success with buffed 0 for a trained skill, or for one that read a real value before, is ignored. Seam:static bool IsZeroArtifact(buffed, training, hadGood, prevBuffed). Combat/CastGateWatchdog.csdepends only on System and is linkable now.Combat/PetChoice.cs:Order,ElementFromNameandNormalizeElementare pure, but the file imports PluginSdk forElementOf(host, ...). With a null host,ElementOffalls back to the name. Seam: moveElementOfout, or use the host runner. Worth probing:ElementFromNamematches substrings, so "Ice" hits any name containing "ice" (Justice, Price, Vice).
5. Other pure, valuable logic
- Weapon weakness selection: the data side,
CreatureData/CreatureWeakness.cs, is linked and tested. The choice itself is inline inCombatManager(around lines 2930-2960). It tries, in order: the Monsters rule's element, then the weakness order filtered to weapons of the sameWeaponKindas the first usable Items entry (so a bow character with a buff wand listed is not switched to magic), then the Damage tab's learned best weapon. Seam:static int PickWeapon(items, ranking, Func<int,bool> usable, Func<int,int> kind, ...)returning the id and the reason. - Damage-line parsing:
CombatManager.TryParseOutgoingDamageandWordAtare private static, allocation-free and pure. They handle ACE lines ("for N points with ") and retail lines ("points of X damage"), and reject incoming damage and vital drains.ElementFromWordandElementFromDamageTypeare similar. This is an ideal table-test target. Seam: move them into aCombatText.cs(a pure move). - Already covered elsewhere:
Raycasting/MissileBallistics.cs(MissileArcTests) and the AutoVendor rules and planner (AutoVendorTests). - Linkable now, no tests yet:
Combat/CastGateWatchdog.cs.Combat/AmmoRecipes.cs+AmmoRecipes.Data.cs: System and LINQ only.Meta/RegexCache.csandMeta/MetaSchema.cs.
- Needs a clock seam:
Combat/WeaponSwapGate.csreadsEnvironment.TickCount64directly. An internalFunc<long>clock would make the 3 s gate testable without sleeping. - Host runner:
Combat/MonsterMatchEvaluator.cs(the vTank monster-match expressionsrange>5 && species==drudge). The parser is pure, but variables come fromWorldObjectCache. Not tried.