Skip to content

Migrate tests off sorbet-runtime and replace type-erasure casts with total methods#71

Merged
dduugg merged 4 commits into
mainfrom
migrate-tests-off-sorbet-runtime
May 29, 2026
Merged

Migrate tests off sorbet-runtime and replace type-erasure casts with total methods#71
dduugg merged 4 commits into
mainfrom
migrate-tests-off-sorbet-runtime

Conversation

@dduugg
Copy link
Copy Markdown
Contributor

@dduugg dduugg commented May 29, 2026

Summary

Completes the sorbet-runtime removal 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 and lib/) with total methods.

#68 migrated lib/ to RBS comments and dropped the sorbet-runtime dependency, but the tests still used extend T::Sig, sig {}, T.must, T.unsafe, and T.bind. That only kept working because packwerk transitively loaded sorbet-runtime. packwerk 3.3.0 drops sorbet-runtime, so the suite now fails with uninitialized constant T (surfaced by the Dependabot bump in #70). Rather than re-introduce a sorbet-runtime dependency — even for development — this finishes the migration in test/ the same way as lib/.

Changes

Migrate test/ off the Sorbet runtime DSL

  • Translate sig blocks to #: RBS comments and remove extend T::Sig across the unit and integration tests.
  • In the fixture helper, replace extend T::Helpers + requires_ancestor { Kernel } + T.bind(self, Minitest::Runnable) with a single # @requires_ancestor: Minitest::Runnable annotation (which provides name plus Kernel).

Replace type-erasure / non-nil casts with total methods (no T.must/T.unsafe, no #: as casts left anywhere)

  • Integration specs: Packwerk::Checker.all.any?(Packwerk::Privacy::Checker) (uses === as a pattern) instead of casting the abstract Packwerk::Checker element to untyped to call is_a?.
  • Fixture helper: FileUtils.mkdir_p(...).fetch(-1) instead of .last with a #: as !nil cast.
  • lib/packwerk/privacy/checker.rb: publicized_locations.fetch(location) and lines.first(5) instead of […] / [0..4] with #: as !nil casts.

Dependencies

  • Drop the redundant sorbet-static dev dependency — the sorbet gem already depends on it.

Verification

  • bundle exec srb tc → No errors
  • bundle exec rake test → 88 runs, 0 failures
  • bundle exec rubocop → no offenses

Note

This should merge before the Dependabot bump (#70), which needs this fix on main to pass CI on packwerk 3.3.0.

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).
@dduugg dduugg requested a review from a team as a code owner May 29, 2026 23:02
@github-project-automation github-project-automation Bot moved this to Triage in Modularity May 29, 2026
dduugg added 3 commits May 29, 2026 16:06
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)
@dduugg dduugg changed the title Migrate test suite off sorbet-runtime Migrate tests off sorbet-runtime and replace type-erasure casts with total methods May 29, 2026
@dduugg dduugg merged commit 9ff8074 into main May 29, 2026
6 checks passed
@dduugg dduugg deleted the migrate-tests-off-sorbet-runtime branch May 29, 2026 23:15
@github-project-automation github-project-automation Bot moved this from Triage to Done in Modularity May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant