Skip to content

Fix test failures by invalidating EditorConfigurationCache#651

Merged
dsarno merged 1 commit into
CoplayDev:betafrom
dsarno:fix/test-cache-invalidation
Jan 29, 2026
Merged

Fix test failures by invalidating EditorConfigurationCache#651
dsarno merged 1 commit into
CoplayDev:betafrom
dsarno:fix/test-cache-invalidation

Conversation

@dsarno

@dsarno dsarno commented Jan 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes test failures caused by EditorConfigurationCache returning stale cached values. Several tests were setting EditorPrefs directly without refreshing the singleton cache.

Changes

  • Added EditorConfigurationCache.Instance.Refresh() calls after setting EditorPrefs in:
    • ServerCommandBuilderTests.TryBuildCommand_RemoteUrl_ReturnsFalse()
    • ServerCommandBuilderTests.TryBuildCommand_LocalUrl_ReturnsCommandOrError()
    • ServerManagementServiceCharacterizationTests.TryGetLocalHttpServerCommand_RemoteUrl_ReturnsFalseWithError()
    • WriteToConfigTests.SetUp()

Test Plan

  • Tests now properly read the updated EditorPrefs values
  • ServerCommandBuilderTests errors now match expected patterns
  • WriteToConfigTests HTTP configuration assertions pass

🤖 Generated with Claude Code

Summary by Sourcery

Ensure editor configuration-dependent tests use refreshed cached preferences after mutating EditorPrefs.

Tests:

  • Refresh the editor configuration cache in server command builder and server management service tests after modifying EditorPrefs to prevent stale values.
  • Update WriteToConfigTests setup to refresh the editor config cache after setting HTTP-related EditorPrefs.

Summary by CodeRabbit

Tests

  • Updated test files to ensure proper cache refresh behavior during test execution across multiple test suites, verifying that configuration changes are correctly propagated before service evaluation.

✏️ Tip: You can customize this high-level summary in your review settings.

…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>
@sourcery-ai

sourcery-ai Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures tests that manipulate EditorPrefs see fresh configuration values by explicitly refreshing the editor configuration cache in affected test setup/arrange blocks.

File-Level Changes

Change Details Files
Refresh the EditorConfigurationCache after mutating EditorPrefs in server command builder tests to avoid stale configuration during command construction.
  • Call EditorConfigurationCache.Instance.Refresh() after setting UseHttpTransport and HttpBaseUrl for the remote URL test case.
  • Call EditorConfigurationCache.Instance.Refresh() after setting UseHttpTransport and HttpBaseUrl for the local URL test case.
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/Server/ServerCommandBuilderTests.cs
Refresh the editor configuration cache in WriteToConfigTests setup so assertions use the updated HTTP transport defaults.
  • Invoke EditorConfigCache.Instance.Refresh() after setting HTTP transport and URL EditorPrefs in SetUp().
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Helpers/WriteToConfigTests.cs
Refresh the EditorConfigurationCache prior to constructing ServerManagementService so it reads the current EditorPrefs for HTTP configuration.
  • Call EditorConfigurationCache.Instance.Refresh() after setting UseHttpTransport and HttpBaseUrl and before instantiating ServerManagementService in the remote URL characterization test.
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/Characterization/ServerManagementServiceCharacterizationTests.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Three 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

Cohort / File(s) Summary
HTTP Base URL Configuration Tests
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/Characterization/ServerManagementServiceCharacterizationTests.cs, TestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/Server/ServerCommandBuilderTests.cs
Added EditorConfigurationCache.Instance.Refresh() calls after setting EditorPrefs.HttpBaseUrl to ensure configuration cache is refreshed before service instantiation and command building.
Config Initialization Tests
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Helpers/WriteToConfigTests.cs
Added EditorConfigCache.Instance.Refresh() call at end of SetUp() to refresh editor config cache after setting HTTP transport defaults.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 Cache refresh brings order, tests now stand so tall,
Three little additions ensure nothing stalls,
EditorConfig awakens with each refresh call,
Configuration synchronized for all! ✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dsarno dsarno merged commit 402eab5 into CoplayDev:beta Jan 29, 2026
1 of 2 checks passed

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dsarno dsarno deleted the fix/test-cache-invalidation branch January 30, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant