Migrate tests off sorbet-runtime and replace type-erasure casts with total methods#71
Merged
Merged
Conversation
The migration in #68 left the test suite using Sorbet's runtime DSL (extend T::Sig, sig, T.must, T.unsafe, T.bind), which only worked because packwerk transitively loaded sorbet-runtime. packwerk 3.3.0 drops sorbet-runtime, so the suite fails with 'uninitialized constant T'. Rather than re-add a sorbet-runtime dependency, finish the migration in test/ the same way as lib/: - Translate sig blocks to #: RBS comments and drop extend T::Sig - Replace requires_ancestor/T.bind with a Minitest::Runnable @requires_ancestor annotation in the fixture helper - Convert T.must to '#: as !nil' and T.unsafe to '#: as untyped' casts Also drop the redundant 'sorbet-static' dev dependency (the 'sorbet' gem already depends on it).
Use Enumerable#any? with the class as a === pattern instead of casting the abstract Packwerk::Checker element to untyped to call is_a?. This keeps the check fully typed (no type erasure).
fetch(-1) returns a non-nil element type, so no '#: as !nil' cast is needed (and it raises IndexError rather than silently returning nil).
- publicized_locations.fetch(location) instead of [] with '#: as !nil' (the key is guaranteed present by the preceding key? guard) - lines.first(5) instead of lines[0..4] with '#: as !nil' (first(n) returns a non-nil Array)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Completes the
sorbet-runtimeremoval started in #68 by migrating the test suite off Sorbet's runtime DSL, and replaces the remaining type-erasure / non-nil casts (in both the tests andlib/) with total methods.#68 migrated
lib/to RBS comments and dropped thesorbet-runtimedependency, but the tests still usedextend T::Sig,sig {},T.must,T.unsafe, andT.bind. That only kept working because packwerk transitively loadedsorbet-runtime. packwerk 3.3.0 drops sorbet-runtime, so the suite now fails withuninitialized constant T(surfaced by the Dependabot bump in #70). Rather than re-introduce asorbet-runtimedependency — even for development — this finishes the migration intest/the same way aslib/.Changes
Migrate
test/off the Sorbet runtime DSLsigblocks to#:RBS comments and removeextend T::Sigacross the unit and integration tests.extend T::Helpers+requires_ancestor { Kernel }+T.bind(self, Minitest::Runnable)with a single# @requires_ancestor: Minitest::Runnableannotation (which providesnameplusKernel).Replace type-erasure / non-nil casts with total methods (no
T.must/T.unsafe, no#: ascasts left anywhere)Packwerk::Checker.all.any?(Packwerk::Privacy::Checker)(uses===as a pattern) instead of casting the abstractPackwerk::Checkerelement tountypedto callis_a?.FileUtils.mkdir_p(...).fetch(-1)instead of.lastwith a#: as !nilcast.lib/packwerk/privacy/checker.rb:publicized_locations.fetch(location)andlines.first(5)instead of[…]/[0..4]with#: as !nilcasts.Dependencies
sorbet-staticdev dependency — thesorbetgem already depends on it.Verification
bundle exec srb tc→ No errorsbundle exec rake test→ 88 runs, 0 failuresbundle exec rubocop→ no offensesNote
This should merge before the Dependabot bump (#70), which needs this fix on
mainto pass CI on packwerk 3.3.0.