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

Tests: Use YARP fixtures #788

Merged
merged 4 commits into from
Sep 20, 2023

Conversation

snutij
Copy link
Contributor

@snutij snutij commented Jun 27, 2023

Motivation

Closes: #448

Started with syntax-tree fixtures we decided during this PR to move forward and use YARP fixtures, which is a larger set.

Implementation

  • Add as a submodule the YARP repository
  • Edit CI Action to pull submodule dependency, see documentation
  • Ensure before running bin/test that the submodule is well initialized.
  • Then some fix for expectations_test_runner.rb:
    • include only ruby-lsp and YARP fixtures (and not other ruby files from YARP)
    • ensure unique test example name for YARP fixtures
    • rescue Rubocop errors as this is out of ruby-lsp control (I will report to them gradually)
  • Finally, some fix for requests on ruby-lsp side, that fixtures point out.

Automated Tests

More than 14k tests now, all should be green or skipped with "Fixture requires a fix from Rubocop" message.

Manual Tests

  • checkout this branch
  • git submodule update --init --recursive
  • bin/test

Then to have a complete stack trace of Rubocop fail: bin/rubocop -d path/for/fixture

@snutij snutij requested a review from a team as a code owner June 27, 2023 19:04
@snutij snutij requested review from andyw8 and st0012 June 27, 2023 19:04
@andyw8
Copy link
Contributor

andyw8 commented Jun 27, 2023

This looks great! Some of the failures might take a while to address, so it could be useful to have a way to mark those as known failures, which can be fixed incrementally in future.

@snutij
Copy link
Contributor Author

snutij commented Jun 28, 2023

  • I know that in test/expectations/expectations_test_runner.rb we already skip some tests (based on ruby version requirement). Maybe we can do something similar for tests files included in a WAINTING_FOR_RUBOCOP_FIX array, for example.
  • In the same time, I can open some issues on rubocop to report failing fixtures with the related stack trace, and keep an eye on it to update this array when fixes are released.

This is not ideal, but allow us to go forward, and already provide a lot more fixture. wdyt?

@andyw8
Copy link
Contributor

andyw8 commented Jun 28, 2023

Maybe we can do something similar for tests files included in a WAINTING_FOR_RUBOCOP_FIX array, for example.

That seems reasonable. I haven't looked in detail at the failures yet, are they all from RuboCop? I would have thought we might see some caused by bugs in ruby-lsp itself.

Btw, one thing I noticed when trying this locally: Initially everything was wrongly passing, because I hadn't run yet git submodule update --init, so test/fixtures/ruby-syntax-fixtures/ was empty. Maybe we should have a check that this is non-empty when running the tests?

@andyw8
Copy link
Contributor

andyw8 commented Jun 28, 2023

Also, @kddnewton suggested using https://github.com/ruby/yarp/tree/main/test/fixtures which is a larger set which includes all the syntax tree fixtures, but that could be done later.

Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

This is awesome and already showing value given that it caught many errors

test/expectations/expectations_test_runner.rb Show resolved Hide resolved
@andyw8
Copy link
Contributor

andyw8 commented Jun 28, 2023

👋 After some more internal discussion:

  • We would like to go with using https://github.com/ruby/yarp/tree/main/test/fixtures (still as a submodule) for testing against.
  • Let's leave out the Dependabot configuration for now - the fixtures don't change too often, and we can manually pull in the latest when needed.
  • For the failures due to InternalRuboCopError exceptions, let's report these upstream to RuboCop, but ignore them for our test suite, since they are outside of our control.
  • For the failures that are due to ruby-lsp's code, let's add the breaking examples to our own fixtures. Feel free to try and fix those if you would like to, otherwise we can assist.

Thanks again for your contribution!

@snutij
Copy link
Contributor Author

snutij commented Jun 28, 2023

Thanks for coming back @andyw8. 🙏

For the first point, YARP fixtures are not a repository (but only a subfolder from a repository). If we want to use it as a submodule, we have to point to the full git project (and pull the full YARP repo). It's look not ideal to me, maybe I'm missing your point? Perhaps there is a way to do that, that I'm not aware of yet. 😄

For the rest of your comment, I'll do it 👍

@andyw8
Copy link
Contributor

andyw8 commented Jun 28, 2023

Yes we're ok with pulling the full YARP repo, it's fairly small. (@kddnewton said he may publish the fixtures to a separate repo at some point).

@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from 1ed6c86 to 2d78109 Compare June 28, 2023 20:54
@snutij
Copy link
Contributor Author

snutij commented Jun 28, 2023

I moved from ruby-syntax-tree to YARP fixtures: between 40 and 60 errors depending on ruby version.

I'll dig asap on these errors to know which are on ruby-lsp side or not, to exclude correct files.

Please feel free to give feedback on the expectation_test_runner. I tried to make it simple, but I'm not sure if it worked. 😄

@snutij snutij changed the title Tests: Use shared ruby syntax tree fixtures Tests: Use YARP fixtures Jun 29, 2023
@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch 2 times, most recently from 1f7edb0 to 8840148 Compare June 30, 2023 16:19
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

There seems to be at least two failures that are also related to infinite loops in RuboCop when running formatting.

I think we should just use the same technique and ignore any RuboCop related errors by rescuing RubyLsp::Requests::Formatting::Error.

Rakefile Outdated Show resolved Hide resolved
test/expectations/expectations_test_runner.rb Outdated Show resolved Hide resolved
test/requests/hover_expectations_test.rb Outdated Show resolved Hide resolved
@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from 81c0b6f to f99c8e4 Compare July 5, 2023 10:33
@snutij
Copy link
Contributor Author

snutij commented Jul 5, 2023

@vinistock thanks for your feedbacks 🙏

rubocop and syntax-tree errors are now rescue and skip. Older ruby version fail on diagnostics requests because of the early return in case of invalid syntax (which are not in newer version), so the T.cast() is not as expected (nil instead of T::Array[RubyLsp::Requests::Support::RuboCopDiagnostic]). I'm looking to fix it.

@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from f99c8e4 to b69ab63 Compare July 5, 2023 17:46
@snutij
Copy link
Contributor Author

snutij commented Jul 6, 2023

Well, CI is green 🎉 feel free to review it! Do you want a refresh on PR description? This is not any more exact, as we move on YARP fixture.

lib/ruby_lsp/requests/code_action_resolve.rb Outdated Show resolved Hide resolved
test/expectations/expectations_test_runner.rb Outdated Show resolved Hide resolved
test/requests/diagnostics_expectations_test.rb Outdated Show resolved Hide resolved
@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from b69ab63 to 360c641 Compare July 6, 2023 16:09
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

This is amazing! Thank you very much for your work on this.

We'll need to wait for a Syntax Tree release with the fix, but it looks good to me.

lib/ruby_lsp/requests/code_action_resolve.rb Outdated Show resolved Hide resolved
test/expectations/expectations_test_runner.rb Outdated Show resolved Hide resolved
test/requests/diagnostics_expectations_test.rb Outdated Show resolved Hide resolved
@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from 360c641 to a7fa90b Compare July 13, 2023 09:09
@andyw8 andyw8 removed their request for review July 19, 2023 13:33
@vinistock vinistock added the pinned This issue or pull request is pinned and won't be marked as stale label Jul 20, 2023
@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from a7fa90b to 5e691b9 Compare August 4, 2023 12:14
@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from 5e691b9 to 09f1514 Compare August 4, 2023 12:45
@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from 09f1514 to 478c775 Compare August 28, 2023 15:44
bin/test Outdated Show resolved Hide resolved
@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from 478c775 to a7a3692 Compare August 30, 2023 10:26
@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch 2 times, most recently from 04c9eba to 93ecd46 Compare September 7, 2023 07:29
@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from 93ecd46 to 6d4f57a Compare September 19, 2023 18:05
@vinistock
Copy link
Member

Let's not wait for RuboCop to fix stuff. We should start benefiting from the fixtures right away.

In RuboCop Runner, let's include StandardError as part of the rescued exceptions that we raise as InternalRuboCopError.

That should get the CI passing and we can merge.

@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from 6d4f57a to e8ca109 Compare September 19, 2023 20:44
@snutij snutij force-pushed the use-shared-ruby-syntax-tree-fixture branch from e8ca109 to f030e5c Compare September 20, 2023 14:39
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

Thank you very much for pushing this over the finish line, I know it took a while.

Amazing contribution 🚀

@vinistock vinistock merged commit 2f8630f into Shopify:main Sep 20, 2023
15 checks passed
@andyw8
Copy link
Contributor

andyw8 commented Sep 20, 2023

I wonder if we should update the Dependabot config to periodically pull in the submodule updates, it's supported as a package-ecosystem option:

https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

@snutij
Copy link
Contributor Author

snutij commented Sep 20, 2023

@andyw8 yep we totally can, it was part of the first iteration based on SyntaxTree fixtures. If you want it, I can do it. 👍

@andyw8 andyw8 added the chore Chore task label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Chore task pinned This issue or pull request is pinned and won't be marked as stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use shared fixture repository for our tests
4 participants