Fix test teardown to avoid dropping MCP bridge (#487)
* Fix test teardown to avoid dropping MCP bridge CodexConfigHelperTests was calling MCPServiceLocator.Reset() in TearDown, which disposes the active bridge/transport during MCP-driven test runs. Replace with restoring only the mutated service (IPlatformService). * Avoid leaking PlatformService in CodexConfigHelperTests Capture the original IPlatformService before this fixture runs and restore it in TearDown. This preserves the MCP connection safety fix (no MCPServiceLocator.Reset()) while avoiding global state leakage to subsequent tests.main
parent
8e3bd1d70c
commit
523e81bf15
|
|
@ -32,6 +32,7 @@ namespace MCPForUnityTests.Editor.Helpers
|
||||||
private string _originalGitOverride;
|
private string _originalGitOverride;
|
||||||
private bool _hadHttpTransport;
|
private bool _hadHttpTransport;
|
||||||
private bool _originalHttpTransport;
|
private bool _originalHttpTransport;
|
||||||
|
private IPlatformService _originalPlatformService;
|
||||||
|
|
||||||
[OneTimeSetUp]
|
[OneTimeSetUp]
|
||||||
public void OneTimeSetUp()
|
public void OneTimeSetUp()
|
||||||
|
|
@ -40,6 +41,7 @@ namespace MCPForUnityTests.Editor.Helpers
|
||||||
_originalGitOverride = EditorPrefs.GetString(EditorPrefKeys.GitUrlOverride, string.Empty);
|
_originalGitOverride = EditorPrefs.GetString(EditorPrefKeys.GitUrlOverride, string.Empty);
|
||||||
_hadHttpTransport = EditorPrefs.HasKey(EditorPrefKeys.UseHttpTransport);
|
_hadHttpTransport = EditorPrefs.HasKey(EditorPrefKeys.UseHttpTransport);
|
||||||
_originalHttpTransport = EditorPrefs.GetBool(EditorPrefKeys.UseHttpTransport, true);
|
_originalHttpTransport = EditorPrefs.GetBool(EditorPrefKeys.UseHttpTransport, true);
|
||||||
|
_originalPlatformService = MCPServiceLocator.Platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
|
|
@ -54,8 +56,16 @@ namespace MCPForUnityTests.Editor.Helpers
|
||||||
[TearDown]
|
[TearDown]
|
||||||
public void TearDown()
|
public void TearDown()
|
||||||
{
|
{
|
||||||
// Reset service locator after each test
|
// IMPORTANT:
|
||||||
MCPServiceLocator.Reset();
|
// These tests can be executed while an MCP session is active (e.g., when running tests via MCP).
|
||||||
|
// MCPServiceLocator.Reset() disposes the bridge + transport manager, which can kill the MCP connection
|
||||||
|
// mid-run. Instead, restore only what this fixture mutates.
|
||||||
|
// To avoid leaking global state to other tests/fixtures, restore the original platform service
|
||||||
|
// instance captured before this fixture started running.
|
||||||
|
if (_originalPlatformService != null)
|
||||||
|
{
|
||||||
|
MCPServiceLocator.Register<IPlatformService>(_originalPlatformService);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[OneTimeTearDown]
|
[OneTimeTearDown]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue