Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuboCop::Server::Cache: explicitly require 'fileutils' #12248

Merged

Conversation

K-S-A
Copy link
Contributor

@K-S-A K-S-A commented Oct 6, 2023

This PR fixes #12076.

The reproduction script: https://gist.github.com/K-S-A/1d79105baaa88adde1b6e5f6b05d641a

Please, suggest on how to proceed with the "tests" checklist item.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

…Cache

The "fileutils.rb" item is dynamically added to the `$LOADED_FEATURES`
due to the autoloading when calling the `RuboCop::Server::Cache.dir`.

Explicit require is added to achieve idempotency when initializing
the `RuboCop::ResultCache.rubocop_required_features`.

This change resolves the issue where the top level cache folder was
named differently during two consecutive runs of rubocop.
@koic
Copy link
Member

koic commented Oct 10, 2023

I can't say for certain without a detailed investigation, but it might be possible to write a reproduction test in https://github.com/rubocop/rubocop/blob/master/spec/rubocop/server/rubocop_server_spec.rb.

@K-S-A
Copy link
Contributor Author

K-S-A commented Oct 10, 2023

@koic, I tried to add the test case here. The thing is that the line https://github.com/rubocop/rubocop/blob/master/lib/rubocop.rb#L764 prevents RuboCop::ResultCache.rubocop_required_features from being initialised.
At a first glance, this change was added to avoid issues with the caching in the test env.

Also, I tried to mess around with mocks and stubs, but the intermediate result looked flaky and unmaintainable.

Another option that I didn't tried is to create a separate folder with its own Gemfile and run some kind of the black-box test there.

@bbatsov bbatsov merged commit 4025422 into rubocop:master Oct 11, 2023
28 checks passed
@bbatsov
Copy link
Collaborator

bbatsov commented Oct 11, 2023

I'll merge this as is, so we can ship the bug fix with the incoming next RuboCop release. We can sort out how to test this separately.

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.

Inconsistent cache key is generated for ruby 3.1.4
3 participants