Skip to content

Use env shebangs for RubyGems installs#4126

Merged
rafaelfranca merged 1 commit into
Shopify:mainfrom
joshheinrichs-shopify:env-shebang
Jun 9, 2026
Merged

Use env shebangs for RubyGems installs#4126
rafaelfranca merged 1 commit into
Shopify:mainfrom
joshheinrichs-shopify:env-shebang

Conversation

@joshheinrichs-shopify

@joshheinrichs-shopify joshheinrichs-shopify commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Motivation

RubyGems bin wrappers hardcode the Ruby used at install time. With Nix-style Ruby installs, that path can later be garbage-collected or replaced, leaving wrappers like ruby-lsp and bundle pointing at a stale store path.

Implementation

Ruby LSP already activates the project Ruby environment before installing or launching the server, so install the bootstrap ruby-lsp gem and any missing Bundler versions with RubyGems' env-shebang option. This lets generated wrappers resolve ruby from the activated PATH instead.

Bundler project binstubs already use env shebangs by default; this makes the RubyGems bin wrappers Ruby LSP relies on behave similarly.

Automated Tests

Yes.

Manual Tests

In a clean project, ruby-lsp and bundler should have #!/usr/bin/env ruby as the shebang.

RubyGems bin wrappers hardcode the Ruby used at install time. With
Nix-style Ruby installs, that path can later be garbage-collected or
replaced, leaving wrappers like ruby-lsp and bundle pointing at a stale
store path.

Ruby LSP already activates the project Ruby environment before installing
or launching the server, so install the bootstrap ruby-lsp gem and any
missing Bundler versions with RubyGems' env-shebang option. This lets
generated wrappers resolve ruby from the activated PATH instead.

Bundler project binstubs already use env shebangs by default; this makes
the RubyGems bin wrappers Ruby LSP relies on behave similarly.
@rafaelfranca rafaelfranca added vscode This pull request should be included in the VS Code extension's release notes server This pull request should be included in the server gem's release notes bugfix This PR will fix an existing bug labels Jun 6, 2026

@pcasaretto pcasaretto left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the fix, Josh. I tested this branch locally and this looks good to me.

Validation performed:

  • Ruby-side regression coverage passes: test/setup_bundler_test.rb completed with 41 runs, 189 assertions, and 0 failures/errors when run in a Nix shell with libyaml/pkg-config available for psych.
  • VS Code extension code compiles successfully.
  • The PR-specific VS Code assertions for installing/updating ruby-lsp with --env-shebang pass. I had to run from a short /tmp worktree because the deeper macOS path hit the Unix socket path length limit in vscode-test; unrelated Chruby/debugger environment tests still failed in that local setup, but the assertions added by this PR passed.
  • Manual RubyGems verification confirms the generated ruby-lsp wrapper starts with #!/usr/bin/env ruby when installed with --env-shebang.

This addresses the Nix/Ruby refresh failure mode we saw where generated binstubs captured an absolute stale Nix store Ruby path. The main boundary to keep in mind is that this prevents newly installed/updated wrappers from going stale; existing stale binstubs still need to be regenerated by an install/update/pristine path. That is an acceptable scope for this PR.

:shipit:

@rafaelfranca rafaelfranca marked this pull request as ready for review June 9, 2026 19:19
@rafaelfranca rafaelfranca requested a review from a team as a code owner June 9, 2026 19:19
@rafaelfranca rafaelfranca merged commit 88c3583 into Shopify:main Jun 9, 2026
21 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes vscode This pull request should be included in the VS Code extension's release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants