Fix test failures by invalidating EditorConfigurationCache after setting EditorPrefs (#651)

Several tests were setting EditorPrefs values directly but not refreshing the
EditorConfigurationCache singleton, causing it to return stale cached values.
This led to tests expecting certain behavior (e.g., checking remote URL errors)
but getting unexpected errors (e.g., "HTTP transport is disabled").

Added EditorConfigurationCache.Instance.Refresh() calls to:
- ServerCommandBuilderTests.TryBuildCommand_RemoteUrl_ReturnsFalse()
- ServerCommandBuilderTests.TryBuildCommand_LocalUrl_ReturnsCommandOrError()
- ServerManagementServiceCharacterizationTests.TryGetLocalHttpServerCommand_RemoteUrl_ReturnsFalseWithError()
- WriteToConfigTests.SetUp()

This ensures the cache is refreshed when EditorPrefs are modified in tests.

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
main
dsarno 2026-01-29 15:44:43 -08:00 committed by GitHub
parent 13aca5fb1c
commit 402eab56f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 0 deletions

View File

@ -66,6 +66,7 @@ namespace MCPForUnityTests.Editor.Helpers
// Force HTTP transport defaults so expectations match current behavior
EditorPrefs.SetBool(UseHttpTransportPrefKey, true);
EditorPrefs.SetString(HttpUrlPrefKey, "http://localhost:8080");
EditorConfigCache.Instance.Refresh();
}
[TearDown]

View File

@ -215,6 +215,7 @@ namespace MCPForUnityTests.Editor.Services.Characterization
// Arrange
EditorPrefs.SetBool(EditorPrefKeys.UseHttpTransport, true);
EditorPrefs.SetString(EditorPrefKeys.HttpBaseUrl, "http://remote.server.com:8080");
EditorConfigurationCache.Instance.Refresh();
_service = new ServerManagementService();
// Act

View File

@ -237,6 +237,7 @@ namespace MCPForUnityTests.Editor.Services.Server
// Arrange
EditorPrefs.SetBool(EditorPrefKeys.UseHttpTransport, true);
EditorPrefs.SetString(EditorPrefKeys.HttpBaseUrl, "http://remote.server.com:8080");
EditorConfigurationCache.Instance.Refresh();
// Act
bool result = _builder.TryBuildCommand(out string fileName, out string arguments, out string displayCommand, out string error);
@ -253,6 +254,7 @@ namespace MCPForUnityTests.Editor.Services.Server
// Arrange
EditorPrefs.SetBool(EditorPrefKeys.UseHttpTransport, true);
EditorPrefs.SetString(EditorPrefKeys.HttpBaseUrl, "http://localhost:8080");
EditorConfigurationCache.Instance.Refresh();
// Act
bool result = _builder.TryBuildCommand(out string fileName, out string arguments, out string displayCommand, out string error);