Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def setup!
return run_bundle_install(@custom_gemfile)
end

@needs_update_path.delete if @needs_update_path.exist?
FileUtils.cp(@lockfile.to_s, @custom_lockfile.to_s)
correct_relative_remote_paths
@lockfile_hash_path.write(@lockfile_hash)
Expand Down
47 changes: 47 additions & 0 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,53 @@ def test_handles_http_error_during_bundle_install
end
end

def test_update_does_not_fail_when_lockfile_is_recopied_with_needs_update
in_temp_dir do |dir|
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gem "rdoc"
GEMFILE

capture_subprocess_io do
Bundler.with_unbundled_env do
system("bundle install")
# Run setup once to create the composed bundle (adds ruby-lsp to composed lockfile)
RubyLsp::SetupBundler.new(dir, launcher: true).setup!
end
end

# Modify the main bundle so the lockfile hash changes
capture_subprocess_io do
Bundler.with_unbundled_env do
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gem "rdoc"
gem "irb"
GEMFILE
system("bundle install")
end
end

# Simulate that a previous run flagged for update. This normally happens when
# should_bundle_update? returns true on a run where needs_update_path doesn't exist yet.
FileUtils.touch(File.join(dir, ".ruby-lsp", "needs_update"))

# Run setup again. The lockfile hash changed, so setup! copies the main lockfile
# (which doesn't have ruby-lsp) over the composed lockfile. Then needs_update
# causes run_bundle_install_directly to call update(), which tries
# `bundle update ruby-lsp` on a lockfile missing ruby-lsp, raising
# Bundler::GemNotFound.
capture_subprocess_io do
Bundler.with_unbundled_env do
RubyLsp::SetupBundler.new(dir, launcher: true).setup!
end
end

# The setup should handle this gracefully without recording an error
refute_path_exists(File.join(dir, ".ruby-lsp", "install_error"))
end
end

def test_is_resilient_to_pipe_being_closed_by_client_during_compose
in_temp_dir do |dir|
File.write(File.join(dir, "gems.rb"), <<~GEMFILE)
Expand Down
Loading