Fix test failures by invalidating EditorConfigurationCache#651
Conversation
…ing EditorPrefs 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>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures tests that manipulate EditorPrefs see fresh configuration values by explicitly refreshing the editor configuration cache in affected test setup/arrange blocks. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThree test files modified to add cache refresh calls after setting configuration values, ensuring cached configuration changes are applied before tests proceed. Changes total four lines across test files without altering public APIs or core logic. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
✨ Finishing touches
🧪 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.
Hey - I've found 1 issue, and left some high level feedback:
- In
WriteToConfigTests.SetUpyou callEditorConfigCache.Instance.Refresh()while the other changes useEditorConfigurationCache.Instance.Refresh(); please confirm the class name is correct and consistent across tests. - Since several tests now repeat the pattern of setting
EditorPrefsand then refreshing the configuration cache, consider extracting a small helper method to centralize this logic and reduce duplication.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `WriteToConfigTests.SetUp` you call `EditorConfigCache.Instance.Refresh()` while the other changes use `EditorConfigurationCache.Instance.Refresh()`; please confirm the class name is correct and consistent across tests.
- Since several tests now repeat the pattern of setting `EditorPrefs` and then refreshing the configuration cache, consider extracting a small helper method to centralize this logic and reduce duplication.
## Individual Comments
### Comment 1
<location> `TestProjects/UnityMCPTests/Assets/Tests/EditMode/Helpers/WriteToConfigTests.cs:69` </location>
<code_context>
// Force HTTP transport defaults so expectations match current behavior
EditorPrefs.SetBool(UseHttpTransportPrefKey, true);
EditorPrefs.SetString(HttpUrlPrefKey, "http://localhost:8080");
+ EditorConfigCache.Instance.Refresh();
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Potential typo/inconsistency in cache type name used in tests
Other tests use `EditorConfigurationCache.Instance.Refresh()`, but this one uses `EditorConfigCache`. Unless this is a different, intentional type, this mismatch could cause a compile error or refresh the wrong cache and leave stale values in the test. Please verify and align the type name with the others if needed.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| // Force HTTP transport defaults so expectations match current behavior | ||
| EditorPrefs.SetBool(UseHttpTransportPrefKey, true); | ||
| EditorPrefs.SetString(HttpUrlPrefKey, "http://localhost:8080"); | ||
| EditorConfigCache.Instance.Refresh(); |
There was a problem hiding this comment.
issue (bug_risk): Potential typo/inconsistency in cache type name used in tests
Other tests use EditorConfigurationCache.Instance.Refresh(), but this one uses EditorConfigCache. Unless this is a different, intentional type, this mismatch could cause a compile error or refresh the wrong cache and leave stale values in the test. Please verify and align the type name with the others if needed.
Summary
Fixes test failures caused by EditorConfigurationCache returning stale cached values. Several tests were setting EditorPrefs directly without refreshing the singleton cache.
Changes
EditorConfigurationCache.Instance.Refresh()calls after setting EditorPrefs in:ServerCommandBuilderTests.TryBuildCommand_RemoteUrl_ReturnsFalse()ServerCommandBuilderTests.TryBuildCommand_LocalUrl_ReturnsCommandOrError()ServerManagementServiceCharacterizationTests.TryGetLocalHttpServerCommand_RemoteUrl_ReturnsFalseWithError()WriteToConfigTests.SetUp()Test Plan
🤖 Generated with Claude Code
Summary by Sourcery
Ensure editor configuration-dependent tests use refreshed cached preferences after mutating EditorPrefs.
Tests:
Summary by CodeRabbit
Tests
✏️ Tip: You can customize this high-level summary in your review settings.