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

Ensure we index non test files under test directories #3188

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Feb 12, 2025

Motivation

I noticed something with #3180. We can only accurately linearize ancestors for test files if we index files under the test directories that aren't tests, but support implementations.

For example, in our own codebase, we have lib/ruby_indexer/test/test_case.rb, which is not a test, but implements the parent class for all tests in the indexer. If we never index that parent class, it's impossible to linearize the ancestors of any of the tests and we can't discover them properly.

Implementation

I propose we start indexing non test files inside the test directory. In addition to allowing our improved test functionality to work, users often refer to these support declarations when writing the tests themselves.

I also simplified the code, which was hard to follow, while still trying to maintain the original performance gains applied by recent changes.

One small thing is that I couldn't think of a decent way to not exclude test_case and test_helper from indexing, since both of them are common names that may declare test parent classes and match our file exclusion glob. I created a special case to handle them.

I benchmarked this and it makes no substantial difference in indexing time in Core.

Automated Tests

Added a test verifying the behaviour changes.

Copy link
Member Author


How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vinistock vinistock added server This pull request should be included in the server gem's release notes other Changes that aren't bugfixes, enhancements or breaking changes labels Feb 12, 2025 — with Graphite App
@vinistock vinistock self-assigned this Feb 12, 2025
@vinistock vinistock marked this pull request as ready for review February 12, 2025 21:38
@vinistock vinistock requested a review from a team as a code owner February 12, 2025 21:38
@vinistock vinistock force-pushed the 02-12-ensure_we_index_non_test_files_under_test_directories branch 5 times, most recently from 541b20f to 0e44b1d Compare February 14, 2025 16:09
@vinistock vinistock force-pushed the 02-12-ensure_we_index_non_test_files_under_test_directories branch from 0e44b1d to af8bce2 Compare February 14, 2025 18:06

# Don't exclude the special files, unless they are under fixtures or inside a gem installed inside of the
# workspace
if excluded_from_ignore_test_files.include?(File.basename(path)) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a complex conditional, I think we can improve it by extracting out some helper methods or explaining variables.

File.join("spec", "**", "*"),
File.join("test", "**", "*"),
File.join("tmp", "**", "*"),
"**/{test,spec,features}/**/{*_test.rb,test_*.rb,*_spec.rb,*.feature}",
Copy link
Contributor

Choose a reason for hiding this comment

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

.feature files don't contain Ruby code, is there any need to list them here?

end

@included_patterns = T.let([File.join("**", "*.rb")], T::Array[String])
excluded_directories = ["tmp", "node_modules", "sorbet"]
top_level_directories = Dir.glob("#{Dir.pwd}/*").filter_map do |path|
Copy link
Contributor

Choose a reason for hiding this comment

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

We could extract top_level_directories to a method to avoid making initializer longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
other Changes that aren't bugfixes, enhancements or breaking changes server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants