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

Include excluded gems in verify logic #1058

Merged
merged 1 commit into from
Jul 14, 2022

Conversation

adisonlampert
Copy link
Contributor

@adisonlampert adisonlampert commented Jul 12, 2022

Motivation

Closes #658
Excluded gems shouldn't be verified.

Implementation

I went into the verify implementation and added in some logic to skip over any excluded gems so that it doesn't error due to them being removed.

Tests

I updated the related test and all local tests passed.

Additionally, I spun up an instance of Shopify/shopify and added a random gem (colorize) to the list of excluded gems then bin/tapioca gem to remove the colorize gem and bin/tapioca --verify which caused no errors. Once I removed colorize from the excluded list, bin/tapioca --verify errored as expected.

@adisonlampert adisonlampert marked this pull request as ready for review July 12, 2022 21:15
@adisonlampert adisonlampert requested a review from a team as a code owner July 12, 2022 21:15
@adisonlampert adisonlampert self-assigned this Jul 12, 2022
diff = {}

removed_rbis.each do |gem_name|
filename = existing_rbi(gem_name)
diff[filename] = :removed
unless exclude.include?(gem_name)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to do the same in the loop below for added_rbis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exclude prevents the creation of an RBI for the excluded gem and if one exists, deletes it so my understanding is that there really shouldn't be a case where an excluded RBI ends up in theadded_rbis array

@@ -1604,30 +1604,23 @@ class User; end
assert_success_status(result)
end

it "advises of removed file(s) and returns exit_status 1" do
it "is aware of exclude option and does not error due to removed files" do
Copy link
Member

Choose a reason for hiding this comment

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

I think the previous test has value. Can we add a new example instead of modifying the existing one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I can do that! I am a bit confused though because this code change means there won't be a warning of removed file(s) & won't return exist_status 1 with gem --verify --exclude foo bar so I'm not sure how to leave this test unmodified since what it is testing is no longer the expected behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

The test was probably using exclude to simplify the setup, but the scenario is still valid. We should still warn users of removed gems and exit with status 1.

Instead of running Tapioca with the exclude flag, you'll need to somehow remove the fake foo or bar gems from @project and then see that the RBI is removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe we already have a test for that scenario here:

it "advises of added/removed/changed file(s) and returns exit_status 1" do
@project.tapioca("gem")
@project.remove("sorbet/rbi/gems/foo@0.0.1.rbi")
@project.write("sorbet/rbi/gems/outdated@5.0.0.rbi")
@project.move("sorbet/rbi/gems/bar@0.3.0.rbi", "sorbet/rbi/gems/bar@0.2.0.rbi")
result = @project.tapioca("gem --verify")
assert_equal(<<~OUT, result.out)
Checking for out-of-date RBIs...
RBI files are out-of-date. In your development environment, please run:
`bin/tapioca gem`
Once it is complete, be sure to commit and push any changes
Reason:
File(s) added:
- sorbet/rbi/gems/foo@0.0.1.rbi
File(s) changed:
- sorbet/rbi/gems/bar@0.3.0.rbi
File(s) removed:
- sorbet/rbi/gems/outdated@5.0.0.rbi
OUT
# Does not actually modify anything
refute_project_file_exist("sorbet/rbi/gems/foo@0.0.1.rbi")
assert_project_file_exist("sorbet/rbi/gems/outdated@5.0.0.rbi")
assert_project_file_exist("sorbet/rbi/gems/bar@0.2.0.rbi")
assert_empty_stderr(result)
refute_success_status(result)
end
end

Copy link
Member

Choose a reason for hiding this comment

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

Oh, okay. In that case, I think we're covered. Thanks for looking into it!

diff = {}

removed_rbis.each do |gem_name|
filename = existing_rbi(gem_name)
diff[filename] = :removed
unless exclude.include?(gem_name)
Copy link
Member

Choose a reason for hiding this comment

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

Can we instead do:

Suggested change
unless exclude.include?(gem_name)
next if exclude.include?(gem_name)

so that the code is easier to read and not deeply nested?

@adisonlampert adisonlampert force-pushed the al/include-exclude-in-verify-logic branch 2 times, most recently from a7692db to 3a148e9 Compare July 14, 2022 14:08
Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

Should spec/tapioca/.DS_Store be added?

@adisonlampert
Copy link
Contributor Author

adisonlampert commented Jul 14, 2022

@stanjdev no LOL that was a mistake 🤣 I'm googling how to remove it
Edit: It's gone whew

@adisonlampert adisonlampert force-pushed the al/include-exclude-in-verify-logic branch from 3a148e9 to aa2c443 Compare July 14, 2022 14:13
@adisonlampert adisonlampert merged commit 4494334 into main Jul 14, 2022
@adisonlampert adisonlampert deleted the al/include-exclude-in-verify-logic branch July 14, 2022 14:43
@shopify-shipit shopify-shipit bot temporarily deployed to production July 14, 2022 18:56 Inactive
@shopify-shipit shopify-shipit bot temporarily deployed to 0-9-stable August 22, 2022 21:36 Inactive
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.

Difference in gems per architecture causes --verify to fail on CI
5 participants