fix: Prevent interrupted test runs from changing Play Mode settings#1253
fix: Prevent interrupted test runs from changing Play Mode settings#1253hatayama wants to merge 2 commits into
Conversation
Save the original Enter Play Mode settings before disabling domain reload, and restore them from editor settings on Dispose or the next editor load so interrupted PlayMode test runs do not leave DisableDomainReload persisted.
Keep same-domain nested scopes active until the last Dispose while still treating pending restore data as abandoned after editor reload, preventing domain reload from being re-enabled mid-run.
📝 WalkthroughWalkthroughThis PR resolves a critical issue where ChangesCrash-safe domain reload recovery
Sequence DiagramssequenceDiagram
participant Editor as Unity Editor Load
participant Recovery as DomainReloadDisableScopeRecovery
participant Settings as McpEditorSettingsData
participant Scope as DomainReloadDisableScope
Editor->>Recovery: InitializeOnLoadMethod (on editor load)
Recovery->>Settings: Check domainReloadDisableScopeRestorePending flag
alt Pending restore exists
Recovery->>Settings: Read stored enterPlayModeOptions(Enabled)
Recovery->>Editor: Restore EditorSettings from stored values
Recovery->>Settings: Clear pending flag and stored options
end
Scope->>Recovery: Constructor (first scope created)
Recovery->>Settings: Check if already saved via flag
alt Not yet saved
Recovery->>Editor: Read current EditorSettings
Recovery->>Settings: Save current settings and set pending flag
end
Scope->>Editor: Apply DisableDomainReload
Scope->>Recovery: Dispose (last scope disposed)
Recovery->>Settings: Restore and clear pending via RestoreIfPending
stateDiagram-v2
[*] --> NoScope
NoScope --> FirstScopeCreated: new DomainReloadDisableScope()
FirstScopeCreated --> RestorePending: RestoreIfPending()
RestorePending --> SaveCurrent: SaveCurrentSettingsIfNeeded()
SaveCurrent --> DisableDomainReload: Apply DisableDomainReload
DisableDomainReload --> ActiveScope: _activeScopeCount = 1
ActiveScope --> NestedScope: new DomainReloadDisableScope()
NestedScope --> ActiveScope: _activeScopeCount++
ActiveScope --> FirstDispose: Dispose() on first/nested scope
FirstDispose --> ActiveScope: _activeScopeCount--
ActiveScope --> LastDispose: Dispose() on last scope
LastDispose --> RestoreSettings: RestoreIfPending()
RestoreSettings --> [*]
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
🧹 Nitpick comments (1)
Assets/Tests/Editor/DomainReloadDisableScopeTests.cs (1)
35-117: ⚡ Quick winAdd one non-default round-trip test.
All current cases start from
enterPlayModeOptionsEnabled = falseandEnterPlayModeOptions.None, so a bug that always restores defaults would still pass. Please add one scenario that starts from a non-default user setting, such asenabled = truewith a non-Noneoption, to prove the original values survive both restore paths.Suggested test shape
+[Test] +public void Dispose_RestoresNonDefaultOriginalSettings() +{ + SetEnterPlayModeSettings(true, EnterPlayModeOptions.DisableSceneReload); + + using (DomainReloadDisableScope scope = new DomainReloadDisableScope()) + { + Assert.That(EditorSettings.enterPlayModeOptionsEnabled, Is.True); + Assert.That(EditorSettings.enterPlayModeOptions, Is.EqualTo(EnterPlayModeOptions.DisableDomainReload)); + } + + Assert.That(EditorSettings.enterPlayModeOptionsEnabled, Is.True); + Assert.That(EditorSettings.enterPlayModeOptions, Is.EqualTo(EnterPlayModeOptions.DisableSceneReload)); +}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Assets/Tests/Editor/DomainReloadDisableScopeTests.cs` around lines 35 - 117, Add a new unit test that starts from a non-default Enter Play Mode setting (e.g., call SetEnterPlayModeSettings(true, EnterPlayModeOptions.DisableDomainReload)) and then exercises both restore paths: 1) create and Dispose a DomainReloadDisableScope and assert original settings are restored, and 2) create a DomainReloadDisableScope and simulate abandonment by not disposing it, call DomainReloadDisableScopeRecovery.RestoreIfPending(), and assert the original non-default settings are restored and McpEditorSettings.domainReloadDisableScopeRestorePending is cleared; reference DomainReloadDisableScope, DomainReloadDisableScopeRecovery.RestoreIfPending, SetEnterPlayModeSettings, and use System.GC.KeepAlive(scope) where appropriate to prevent premature collection.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@Assets/Tests/Editor/DomainReloadDisableScopeTests.cs`:
- Around line 35-117: Add a new unit test that starts from a non-default Enter
Play Mode setting (e.g., call SetEnterPlayModeSettings(true,
EnterPlayModeOptions.DisableDomainReload)) and then exercises both restore
paths: 1) create and Dispose a DomainReloadDisableScope and assert original
settings are restored, and 2) create a DomainReloadDisableScope and simulate
abandonment by not disposing it, call
DomainReloadDisableScopeRecovery.RestoreIfPending(), and assert the original
non-default settings are restored and
McpEditorSettings.domainReloadDisableScopeRestorePending is cleared; reference
DomainReloadDisableScope, DomainReloadDisableScopeRecovery.RestoreIfPending,
SetEnterPlayModeSettings, and use System.GC.KeepAlive(scope) where appropriate
to prevent premature collection.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4c5aae19-d398-4ee0-8fe8-bec0293bcaa6
⛔ Files ignored due to path filters (2)
Assets/Tests/Editor/DomainReloadDisableScopeTests.cs.metais excluded by none and included by nonePackages/src/Editor/Core/CoreTools/Util/DomainReloadDisableScopeRecovery.cs.metais excluded by none and included by none
📒 Files selected for processing (4)
Assets/Tests/Editor/DomainReloadDisableScopeTests.csPackages/src/Editor/Config/McpEditorSettings.csPackages/src/Editor/Core/CoreTools/Util/DomainReloadDisableScope.csPackages/src/Editor/Core/CoreTools/Util/DomainReloadDisableScopeRecovery.cs
|
Superseded by #1255. |
Summary
User Impact
Changes
Verification
Fixes #1243