From 0336aa163411e295925491d2d84c1719197a51df Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Tue, 2 Jul 2024 09:43:43 +0200 Subject: [PATCH] Fix bundler env being copied to Ruby runner Fix issues with the wrong bundle of gems being used as context for the runner. This failed to find the Ruby gem as it was using this project's test suite Gemfile instead. Wrap commands with `Bundler.with_unbundled_env` so it removes any Bundler context from the environment. It also clears some other env vars, so explicitly set them again in the base `run_env` method. --- ruby/Gemfile.lock | 4 ++-- spec/support/runner.rb | 32 +++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock index 935d48e..77d0b6d 100644 --- a/ruby/Gemfile.lock +++ b/ruby/Gemfile.lock @@ -1,13 +1,13 @@ PATH remote: ../../../.. specs: - appsignal (3.0.15) + appsignal (3.9.2) rack GEM remote: https://rubygems.org/ specs: - rack (2.2.3) + rack (3.1.5) PLATFORMS ruby diff --git a/spec/support/runner.rb b/spec/support/runner.rb index ea2f19d..5823fb4 100644 --- a/spec/support/runner.rb +++ b/spec/support/runner.rb @@ -91,7 +91,11 @@ def install_report? end def run_env - { "APPSIGNAL_PUSH_API_KEY" => @push_api_key } + { + "APPSIGNAL_PUSH_API_KEY" => @push_api_key, + "APPSIGNAL_PUSH_API_ENDPOINT" => ENV["APPSIGNAL_PUSH_API_ENDPOINT"], + "APPSIGNAL_DIAGNOSE_ENDPOINT" => ENV["APPSIGNAL_DIAGNOSE_ENDPOINT"] + } end def run_command(_arguments) @@ -99,23 +103,29 @@ def run_command(_arguments) end def run # rubocop:disable Metrics/MethodLength - Dir.chdir directory do - before_setup - setup_commands.each do |command| - run_setup command + Bundler.with_unbundled_env do + Dir.chdir directory do + before_setup + setup_commands.each do |command| + run_setup command + end + after_setup end - after_setup end # Run the command prompt = @prompt ? %(echo "#{@prompt}" | ) : "" command = run_command(@arguments.dup) read, write = IO.pipe - pid = spawn( - run_env, - "#{prompt} #{command}", - { [:out, :err] => write, :chdir => directory } - ) + env = run_env + pid = + Bundler.with_unbundled_env do + spawn( + env, + "#{prompt} #{command}", + { [:out, :err] => write, :chdir => directory } + ) + end _pid, status = Process.wait2 pid # Wait until command exits write.close