Fix tests-run state being wiped by PlayerPrefs.DeleteAll#870
Fix tests-run state being wiped by PlayerPrefs.DeleteAll#870Abhinav-0311 wants to merge 3 commits into
Conversation
|
Hi @Abhinav-0311, thanks for the contribution. Could you please explain, why is it needed for? PlayerPrefs survives domain reload already. |
|
You’re right that PlayerPrefs survives domain reload. The reason for this
change is different: tests can legitimately call PlayerPrefs.DeleteAll()
during SetUp/TearDown to clean game state.
In that case the test run starts normally and the request id is stored, but
while the run is in flight the user test deletes all PlayerPrefs. When
RunFinished later reads TestCallRequestID, it is empty, so
NotifyToolRequestCompleted is never called and the MCP client waits
indefinitely.
SessionState still survives the editor domain reload case needed by
tests-run, but it is editor-only session state and is not affected by
game/test code calling PlayerPrefs.DeleteAll(). So this keeps the existing
domain-reload behavior while protecting the MCP routing state from project
test fixtures.
That is the repro covered by #863.
…On Sun, Jul 12, 2026 at 6:22 AM Ivan Murzak ***@***.***> wrote:
*IvanMurzak* left a comment (IvanMurzak/Unity-MCP#870)
<#870 (comment)>
Hi @Abhinav-0311 <https://github.com/Abhinav-0311>, thanks for the
contribution.
Could you please explain, why is it needed for?
PlayerPrefs survives domain reload already.
—
Reply to this email directly, view it on GitHub
<#870?email_source=notifications&email_token=BKJBDPHTCFQRNZ4K2PQKVWL5ELOL3A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOJUHEZTQMZXG442M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4949383779>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BKJBDPDPYM23IBP337BBGXT5ELOL3AVCNFSNUABFKJSXA33TNF2G64TZHM4TKOJRGIZTIOJYHNEXG43VMU5TIOBWGI2TINZZHA42C5QC>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/BKJBDPA62K2DG7CQJBTVOUL5ELOL3A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOJUHEZTQMZXG442M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/BKJBDPFMKMLHNOMCMO64IHL5ELOL3A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOJUHEZTQMZXG442M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
@Abhinav-0311 Thanks for clarifying. Now I see the problem you want to fix. Hm... this PR doesn't fix it, it only moves the problem from PlayerPrefs.DeleteAll to EditorPrefs.DeleteAll. The data still could be deleted by tests run. |
|
Thanks, that makes sense as a concern. One clarification: this PR is not moving the data to So The specific bug I am trying to fix is the common test-fixture cleanup case: [TearDown]
public void TearDown()
{
PlayerPrefs.DeleteAll();
}That can currently wipe It is still true that editor test code could intentionally erase the package's exact |
|
Hey @Abhinav-0311, thanks for clarifying your vision. Please resolve merge conflicts, and I will run tests on this PR. |
# Conflicts: # Unity-MCP-Plugin/Packages/com.ivanmurzak.unity.mcp/Editor/Scripts/API/Tool/Tests.Run.cs # Unity-MCP-Plugin/Packages/com.ivanmurzak.unity.mcp/Editor/Scripts/API/Tool/Tests.cs
cb1984d to
207bc1d
Compare
|
Resolved the merge conflicts and pushed the rebased branch. While resolving against current Local verification:
I did not run Unity editor tests locally from this checkout. |
| ClearActiveTestRun(requestId); | ||
| if (string.IsNullOrEmpty(requestId)) | ||
| { | ||
| Debug.LogError("[TestRunner] Compilation failed after a deferred test run, but the pending MCP request id was missing. The error response cannot be delivered to the client."); |
There was a problem hiding this comment.
Need to use a proper logging wrapper from Unity-MCP project, that would respect the logging settings in AI Game Developer window.
| } | ||
| else | ||
| { | ||
| Debug.LogError("[TestRunner] Test run finished, but the pending MCP request id was missing. The test results cannot be delivered to the client."); |
There was a problem hiding this comment.
Need to use a proper logging wrapper from Unity-MCP project, that would respect the logging settings in AI Game Developer window.
| }; | ||
| } | ||
|
|
||
| public sealed class SessionStateString |
There was a problem hiding this comment.
Make a dedicated file for this new C# class
|
Addressed the requested changes in
Local verification:
I did not run Unity editor tests locally from this checkout. |
Fixes #863.\n\n## Summary\n- Moves the ests-run pending request id and response option state from PlayerPrefs to editor SessionState.\n- Keeps the state alive across domain reloads while preventing project/test code that calls PlayerPrefs.DeleteAll() from wiping the routing id mid-run.\n- Logs an explicit error if a completed/deferred test run cannot be routed because the request id is missing.\n\n## Testing\n- git diff --check\n- Not run: Unity editor tests / local compile because Unity and dotnet are not available in this environment.