Fix test isolation to prevent order-dependent failures#539
Conversation
Add/enhance [TestCleanup] methods across 10 test classes to properly reset shared static state (Engine.Player, Items, Mobiles, aliases, Options) after each test. Replace Engine.Install() with Initialize() + InitializePlugin() in EngineTests to prevent SplashWindow from appearing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughUpdated tests to initialize the engine differently in EngineTests and to add or extend Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
ClassicAssist.Tests/EngineTests.cs (1)
113-114: Extract repeated engine/plugin initialisation into one helper.These four tests duplicate the same setup block. Centralising it will reduce drift and keep initialisation changes in one place.
♻️ Proposed refactor
+ private unsafe void InitializeEngineAndPlugin() + { + fixed ( void* func = &_pluginHeader ) + { + Engine.Initialize(); + Engine.InitializePlugin( (PluginHeader*) func ); + } + } [TestMethod] public unsafe void WillSendPacket() { - fixed ( void* func = &_pluginHeader ) - { - Engine.Initialize(); - Engine.InitializePlugin( (PluginHeader*) func ); - } + InitializeEngineAndPlugin(); } [TestMethod] public unsafe void WillFilterSendPacket() { - fixed ( void* func = &_pluginHeader ) - { - Engine.Initialize(); - Engine.InitializePlugin( (PluginHeader*) func ); - } + InitializeEngineAndPlugin(); } [TestMethod] public unsafe void WillFilterReceivedPacket() { - fixed ( void* func = &_pluginHeader ) - { - Engine.Initialize(); - Engine.InitializePlugin( (PluginHeader*) func ); - } + InitializeEngineAndPlugin(); } [TestMethod] public unsafe void WillReceivePacket() { - fixed ( void* func = &_pluginHeader ) - { - Engine.Initialize(); - Engine.InitializePlugin( (PluginHeader*) func ); - } + InitializeEngineAndPlugin(); }Also applies to: 153-154, 202-203, 252-253
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ClassicAssist.Tests/EngineTests.cs` around lines 113 - 114, Four tests duplicate the same Engine initialization block (calls to Engine.Initialize and Engine.InitializePlugin((PluginHeader*) func)); extract that repeated setup into a single private helper method (e.g., InitializeEngineWithPlugin or SetupEngineAndPlugin) that performs Engine.Initialize and Engine.InitializePlugin with the provided func pointer, then replace the duplicated lines in the tests with a call to the new helper; ensure the helper is accessible to the test methods and preserves any existing test state or return values required by those tests.ClassicAssist.Tests/MacroCommands/AliasCommandTests.cs (1)
22-27: Make teardown null-safe to avoid cleanup masking test failures.If
_aliasesis ever uninitialised in a future test path, cleanup throws and hides the original failure signal.Suggested fix
[TestCleanup] public void Cleanup() { Engine.Player = null; - AliasCommands._aliases.Clear(); + AliasCommands._aliases?.Clear(); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ClassicAssist.Tests/MacroCommands/AliasCommandTests.cs` around lines 22 - 27, The teardown can throw if AliasCommands._aliases is null, masking real test failures; modify the Cleanup method to null-check before clearing (e.g., only call AliasCommands._aliases.Clear() if AliasCommands._aliases != null) and keep Engine.Player = null as-is so cleanup is safe even when _aliases was never initialized.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ClassicAssist.Tests/MacroCommands/PropertiesCommandTests.cs`:
- Around line 121-127: Cleanup does not unsubscribe the InternalPacketSentEvent
handler, causing leaks if WillWaitForProperties fails; modify
WillWaitForProperties to assign the delegate to a field (e.g.
_internalPacketSentHandler = OnInternalPacketSentEvent) before subscribing with
Engine.InternalPacketSentEvent += _internalPacketSentHandler, and update
Cleanup() to check and unsubscribe (Engine.InternalPacketSentEvent -=
_internalPacketSentHandler) and null the field so tests are fully isolated.
---
Nitpick comments:
In `@ClassicAssist.Tests/EngineTests.cs`:
- Around line 113-114: Four tests duplicate the same Engine initialization block
(calls to Engine.Initialize and Engine.InitializePlugin((PluginHeader*) func));
extract that repeated setup into a single private helper method (e.g.,
InitializeEngineWithPlugin or SetupEngineAndPlugin) that performs
Engine.Initialize and Engine.InitializePlugin with the provided func pointer,
then replace the duplicated lines in the tests with a call to the new helper;
ensure the helper is accessible to the test methods and preserves any existing
test state or return values required by those tests.
In `@ClassicAssist.Tests/MacroCommands/AliasCommandTests.cs`:
- Around line 22-27: The teardown can throw if AliasCommands._aliases is null,
masking real test failures; modify the Cleanup method to null-check before
clearing (e.g., only call AliasCommands._aliases.Clear() if
AliasCommands._aliases != null) and keep Engine.Player = null as-is so cleanup
is safe even when _aliases was never initialized.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e2c15699-48f7-4f37-af17-6b9baec5b2f7
📒 Files selected for processing (10)
ClassicAssist.Tests/EngineTests.csClassicAssist.Tests/IncomingPacketHandlerTests.csClassicAssist.Tests/MacroCommands/ActionCommandTests.csClassicAssist.Tests/MacroCommands/AliasCommandTests.csClassicAssist.Tests/MacroCommands/JournalCommandsTests.csClassicAssist.Tests/MacroCommands/ObjectCommandTests.csClassicAssist.Tests/MacroCommands/PropertiesCommandTests.csClassicAssist.Tests/MacroCommands/TargetCommandTests.csClassicAssist.Tests/OutgoingPacketHandlerTests.csClassicAssist.Tests/SpellCommandsTests.cs
Store InternalPacketSentEvent handler in a field and unsubscribe in TestCleanup so the handler doesn't leak if WillWaitForProperties fails. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add/enhance [TestCleanup] methods across 10 test classes to properly reset shared static state (Engine.Player, Items, Mobiles, aliases, Options) after each test. Replace Engine.Install() with Initialize() + InitializePlugin() in EngineTests to prevent SplashWindow from appearing.
Summary by CodeRabbit