Skip to content

Start Spring server process in directory where command was called #621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

adrianna-chang-shopify
Copy link
Contributor

When a Spring server boots, it maintains its directory
for the duration of its life-cycle. This means that if you've changed
directories and run a Spring command, the process will start within the
context of the original directory.

This is problematic in the use case of engines, where an engine command
may be run from the context of the host application, and then run again
from the engine directory. In this scenario, the process will assume its
working directory is the host application instead of the engine.

The solution proposed here is to change the current directory to where
the Spring command was called from. The directory is taken from ENV['PWD']

STEPS TO REPRODUCE:

  1. bin/rails test engines/foo in main application => correctly runs the engines/foo test suite
  2. cd engines/foo; bin/rails test => runs the main application tests, and Dir.pwd in the rails binstubs is the main application

When a Spring server boots, it maintains its directory
for the duration of its life-cycle. This means that if you've changed
directories and run a Spring command, the process will start within the
context of the original directory.

This is problematic in the use case of engines, where an engine command
may be run from the context of the host application, and then run again
from the engine directory. In this scenario, the process will assume its
working directory is the host application instead of the engine.

The solution proposed here is to change the current directory to where
the Spring command was called from. The directory is taken from ENV['PWD']
@adrianna-chang-shopify adrianna-chang-shopify force-pushed the spring-process-should-use-working-dir branch from 1166cef to 7abf456 Compare July 23, 2020 16:03
@tenderlove
Copy link
Member

I don't think this patch is related to the CI failures, so I'm going to merge it. But we should figure out why the CI is red at some point.

@deivid-rodriguez
Copy link
Contributor

Hello 👋 👋!

I found that this patch seems actually related to the CI failures. There are other permanent CI failures related to rubies and rails versions that reached their end of life, but if you restrict the matrix to newer ruby and rails, you can see in this PR how it was previously green, but red if including this patch.

In particular, the failing tests, for example

assert_success app.spring_test_command, stderr: "Running via Spring preloader in process"

try to start a rake task in the root of a generated test application, however due to this change, the rake task is started in the root of the spring repository, causing a missing bump/tasks require when reading the root Rakefile (bump is a development dependency of spring).

We were also hit by this in activeadmin, where a user reported that our generator was generating files not inside the target application, but in the folder where the generator was run.

I think the case this PR wanted to support might be already supported by setting Spring.application_root=? At least the README seems to imply that.

@deivid-rodriguez
Copy link
Contributor

A local repro:

$ git show

commit a85d32ef3726931b2b81abbb10a6e1c2964e7e32 (HEAD -> master, tag: v2.1.1, upstream/master, upstream/HEAD)
Author: Guillermo Iguaran <guilleiguaran@gmail.com>
Date:   Mon Aug 24 16:52:29 2020 -0700

    Prepare v2.1.1

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 59febc8..0c504ad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
 ## Next Release
 
+## 2.1.1
+
+* Avoid -I rubylibdir with default-gem bundler
 * Start server process in directory where command was called
 
 ## 2.1.0
diff --git a/lib/spring/version.rb b/lib/spring/version.rb
index 3ff8b1d..b82db2b 100644
--- a/lib/spring/version.rb
+++ b/lib/spring/version.rb
@@ -1,3 +1,3 @@
 module Spring
-  VERSION = "2.1.0"
+  VERSION = "2.1.1"
 end

$ bundle exec rake TESTOPTS=--name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs

/home/deivid/.rbenv/versions/2.7.2/bin/ruby -w -I"lib" -I"/home/deivid/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib" "/home/deivid/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb" "test/unit/client/help_test.rb" "test/unit/client/version_test.rb" "test/unit/commands_test.rb" "test/unit/process_title_updater_test.rb" "test/unit/watcher_test.rb" --name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs
Run options: --name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs --seed 45819

# Running:



Finished in 0.001342s, 0.0000 runs/s, 0.0000 assertions/s.

0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
/home/deivid/.rbenv/versions/2.7.2/bin/ruby -w -I"lib" -I"/home/deivid/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib" "/home/deivid/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb" "test/acceptance_test.rb" --name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs
Run options: --name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs --seed 25143

# Running:

[DEPRECATED] `Bundler.with_clean_env` has been deprecated in favor of `Bundler.with_unbundled_env`. If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env` (called at /home/deivid/Code/spring/test/support/application_generator.rb:34)
[DEPRECATED] `Bundler.with_clean_env` has been deprecated in favor of `Bundler.with_unbundled_env`. If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env` (called at /home/deivid/Code/spring/test/support/application.rb:111)
F

Finished in 61.749341s, 0.0162 runs/s, 0.0648 assertions/s.

  1) Failure:
AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs [/home/deivid/Code/spring/test/support/acceptance_test.rb:111]:
expected successful exit status

$ bin/rake test /home/deivid/Code/spring/test/apps/tmp/test/controllers/posts_controller_test.rb
--- stderr ---
/home/deivid/Code/spring/lib/spring/version.rb:2: warning: already initialized constant Spring::VERSION
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/spring-2.1.1/lib/spring/version.rb:2: warning: previous definition of VERSION was here
Running via Spring preloader in process 43660
rake aborted!
LoadError: cannot load such file -- bump/tasks
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:293:in `require'
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:293:in `block in require'
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:259:in `load_dependency'
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:293:in `require'
/home/deivid/Code/spring/Rakefile:4:in `<top (required)>'
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `load'
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `block in load'
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:259:in `load_dependency'
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `load'
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `load'
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `block in load'
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:259:in `load_dependency'
/home/deivid/Code/spring/test/apps/gems/2.7.2/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `load'
-e:1:in `<main>'
(See full trace by running task with --trace)
--- log ---
[2020-10-08 11:47:52 +0200] [43643] [server] accepted client
[2020-10-08 11:47:52 +0200] [43643] [server] running command rake
[2020-10-08 11:47:52 +0200] [43655] [client] sending command
[2020-10-08 11:47:52 +0200] [43643] [application_manager:test] child not running; starting
[2020-10-08 11:47:52 +0200] [43656] [application:test] initialized -> running
[2020-10-08 11:47:52 +0200] [43656] [application:test] got client
[2020-10-08 11:47:52 +0200] [43656] [application:test] preloading app
[2020-10-08 11:47:52 +0200] [43656] [watcher:test] start: poller=nil
[2020-10-08 11:47:53 +0200] [43656] [watcher:test] watcher: add: [["/home/deivid/Code/spring/test/apps/tmp/config/boot.rb", "/home/deivid/Code/spring/test/apps/tmp/config/application.rb", "/home/deivid/Code/spring/test/apps/tmp/config/environments/test.rb", "/home/deivid/Code/spring/test/apps/tmp/config/environment.rb"]]
[2020-10-08 11:47:53 +0200] [43656] [watcher:test] subjects_changed: mtime 0 -> 1602150469.7544591
[2020-10-08 11:47:53 +0200] [43656] [watcher:test] watcher: add: [#<Pathname:/home/deivid/Code/spring/test/apps/tmp/Gemfile>, "/home/deivid/Code/spring/test/apps/tmp/Gemfile.lock"]
[2020-10-08 11:47:53 +0200] [43656] [watcher:test] subjects_changed: mtime 1602150469.7544591 -> 1602150469.7544591
[2020-10-08 11:47:53 +0200] [43656] [watcher:test] watcher: add: [#<Rails::Paths::Path:0x00005594c90c5e50 @paths=["config/initializers"], @current="config/initializers", @root=#<Rails::Paths::Root:0x00005594c90c6850 @current=nil, @path=#<Pathname:/home/deivid/Code/spring/test/apps/tmp>, @root={"app"=>#<Rails::Paths::Path:0x00005594c90c6760 @paths=["app"], @current="app", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="{*,*/concerns}", @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/assets"=>#<Rails::Paths::Path:0x00005594c90c6698 @paths=["app/assets"], @current="app/assets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "app/controllers"=>#<Rails::Paths::Path:0x00005594c90c65f8 @paths=["app/controllers"], @current="app/controllers", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/channels"=>#<Rails::Paths::Path:0x00005594c90c6530 @paths=["app/channels"], @current="app/channels", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="**/*_channel.rb", @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/helpers"=>#<Rails::Paths::Path:0x00005594c90c6490 @paths=["app/helpers"], @current="app/helpers", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/models"=>#<Rails::Paths::Path:0x00005594c90c63f0 @paths=["app/models"], @current="app/models", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/mailers"=>#<Rails::Paths::Path:0x00005594c90c6350 @paths=["app/mailers"], @current="app/mailers", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/views"=>#<Rails::Paths::Path:0x00005594c90c62b0 @paths=["app/views"], @current="app/views", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib"=>#<Rails::Paths::Path:0x00005594c90c6210 @paths=["lib"], @current="lib", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=true>, "lib/assets"=>#<Rails::Paths::Path:0x00005594c90c6148 @paths=["lib/assets"], @current="lib/assets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib/tasks"=>#<Rails::Paths::Path:0x00005594c90c6080 @paths=["lib/tasks"], @current="lib/tasks", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="**/*.rake", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config"=>#<Rails::Paths::Path:0x00005594c90c5fe0 @paths=["config"], @current="config", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/environments"=>#<Rails::Paths::Path:0x00005594c90c5f18 @paths=["config/environments"], @current="config/environments", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="test.rb", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/initializers"=>#<Rails::Paths::Path:0x00005594c90c5e50 ...>, "config/locales"=>#<Rails::Paths::Path:0x00005594c90c5d88 @paths=["config/locales"], @current="config/locales", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*.{rb,yml}", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/routes.rb"=>#<Rails::Paths::Path:0x00005594c90c5ce8 @paths=["config/routes.rb"], @current="config/routes.rb", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db"=>#<Rails::Paths::Path:0x00005594c90c5c48 @paths=["db"], @current="db", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db/migrate"=>#<Rails::Paths::Path:0x00005594c90c5ba8 @paths=["db/migrate"], @current="db/migrate", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db/seeds.rb"=>#<Rails::Paths::Path:0x00005594c90c5b08 @paths=["db/seeds.rb"], @current="db/seeds.rb", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "vendor"=>#<Rails::Paths::Path:0x00005594c90c5a68 @paths=["vendor"], @current="vendor", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=true>, "vendor/assets"=>#<Rails::Paths::Path:0x00005594c90c59a0 @paths=["vendor/assets"], @current="vendor/assets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/database"=>#<Rails::Paths::Path:0x00005594c90c58d8 @paths=["config/database.yml"], @current="config/database", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/secrets"=>#<Rails::Paths::Path:0x00005594c90c5810 @paths=["config/secrets.yml"], @current="config/secrets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/environment"=>#<Rails::Paths::Path:0x00005594c90c5748 @paths=["config/environment.rb"], @current="config/environment", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib/templates"=>#<Rails::Paths::Path:0x00005594c90c56a8 @paths=["lib/templates"], @current="lib/templates", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "log"=>#<Rails::Paths::Path:0x00005594c90c55e0 @paths=["log/test.log"], @current="log", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public"=>#<Rails::Paths::Path:0x00005594c90c5540 @paths=["public"], @current="public", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public/javascripts"=>#<Rails::Paths::Path:0x00005594c90c54a0 @paths=["public/javascripts"], @current="public/javascripts", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public/stylesheets"=>#<Rails::Paths::Path:0x00005594c90c5400 @paths=["public/stylesheets"], @current="public/stylesheets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "tmp"=>#<Rails::Paths::Path:0x00005594c90c5360 @paths=["tmp"], @current="tmp", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/cable"=>#<Rails::Paths::Path:0x00005594c90aba50 @paths=["config/cable.yml"], @current="config/cable", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>}>, @glob="**/*.rb", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>]
[2020-10-08 11:47:53 +0200] [43656] [watcher:test] subjects_changed: mtime 1602150469.7544591 -> 1602150469.7544591
[2020-10-08 11:47:53 +0200] [43656] [watcher:test] watcher: add: [#<Rails::Paths::Path:0x00005594c90c58d8 @paths=["config/database.yml"], @current="config/database", @root=#<Rails::Paths::Root:0x00005594c90c6850 @current=nil, @path=#<Pathname:/home/deivid/Code/spring/test/apps/tmp>, @root={"app"=>#<Rails::Paths::Path:0x00005594c90c6760 @paths=["app"], @current="app", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="{*,*/concerns}", @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/assets"=>#<Rails::Paths::Path:0x00005594c90c6698 @paths=["app/assets"], @current="app/assets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "app/controllers"=>#<Rails::Paths::Path:0x00005594c90c65f8 @paths=["app/controllers"], @current="app/controllers", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/channels"=>#<Rails::Paths::Path:0x00005594c90c6530 @paths=["app/channels"], @current="app/channels", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="**/*_channel.rb", @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/helpers"=>#<Rails::Paths::Path:0x00005594c90c6490 @paths=["app/helpers"], @current="app/helpers", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/models"=>#<Rails::Paths::Path:0x00005594c90c63f0 @paths=["app/models"], @current="app/models", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/mailers"=>#<Rails::Paths::Path:0x00005594c90c6350 @paths=["app/mailers"], @current="app/mailers", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/views"=>#<Rails::Paths::Path:0x00005594c90c62b0 @paths=["app/views"], @current="app/views", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib"=>#<Rails::Paths::Path:0x00005594c90c6210 @paths=["lib"], @current="lib", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=true>, "lib/assets"=>#<Rails::Paths::Path:0x00005594c90c6148 @paths=["lib/assets"], @current="lib/assets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib/tasks"=>#<Rails::Paths::Path:0x00005594c90c6080 @paths=["lib/tasks"], @current="lib/tasks", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="**/*.rake", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config"=>#<Rails::Paths::Path:0x00005594c90c5fe0 @paths=["config"], @current="config", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/environments"=>#<Rails::Paths::Path:0x00005594c90c5f18 @paths=["config/environments"], @current="config/environments", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="test.rb", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/initializers"=>#<Rails::Paths::Path:0x00005594c90c5e50 @paths=["config/initializers"], @current="config/initializers", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="**/*.rb", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/locales"=>#<Rails::Paths::Path:0x00005594c90c5d88 @paths=["config/locales"], @current="config/locales", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*.{rb,yml}", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/routes.rb"=>#<Rails::Paths::Path:0x00005594c90c5ce8 @paths=["config/routes.rb"], @current="config/routes.rb", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db"=>#<Rails::Paths::Path:0x00005594c90c5c48 @paths=["db"], @current="db", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db/migrate"=>#<Rails::Paths::Path:0x00005594c90c5ba8 @paths=["db/migrate"], @current="db/migrate", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db/seeds.rb"=>#<Rails::Paths::Path:0x00005594c90c5b08 @paths=["db/seeds.rb"], @current="db/seeds.rb", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "vendor"=>#<Rails::Paths::Path:0x00005594c90c5a68 @paths=["vendor"], @current="vendor", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=true>, "vendor/assets"=>#<Rails::Paths::Path:0x00005594c90c59a0 @paths=["vendor/assets"], @current="vendor/assets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/database"=>#<Rails::Paths::Path:0x00005594c90c58d8 ...>, "config/secrets"=>#<Rails::Paths::Path:0x00005594c90c5810 @paths=["config/secrets.yml"], @current="config/secrets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/environment"=>#<Rails::Paths::Path:0x00005594c90c5748 @paths=["config/environment.rb"], @current="config/environment", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib/templates"=>#<Rails::Paths::Path:0x00005594c90c56a8 @paths=["lib/templates"], @current="lib/templates", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "log"=>#<Rails::Paths::Path:0x00005594c90c55e0 @paths=["log/test.log"], @current="log", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public"=>#<Rails::Paths::Path:0x00005594c90c5540 @paths=["public"], @current="public", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public/javascripts"=>#<Rails::Paths::Path:0x00005594c90c54a0 @paths=["public/javascripts"], @current="public/javascripts", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public/stylesheets"=>#<Rails::Paths::Path:0x00005594c90c5400 @paths=["public/stylesheets"], @current="public/stylesheets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "tmp"=>#<Rails::Paths::Path:0x00005594c90c5360 @paths=["tmp"], @current="tmp", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/cable"=>#<Rails::Paths::Path:0x00005594c90aba50 @paths=["config/cable.yml"], @current="config/cable", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>}>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>]
[2020-10-08 11:47:53 +0200] [43656] [watcher:test] subjects_changed: mtime 1602150469.7544591 -> 1602150469.7544591
[2020-10-08 11:47:53 +0200] [43656] [watcher:test] watcher: add: [#<Rails::Paths::Path:0x00005594c90c5810 @paths=["config/secrets.yml"], @current="config/secrets", @root=#<Rails::Paths::Root:0x00005594c90c6850 @current=nil, @path=#<Pathname:/home/deivid/Code/spring/test/apps/tmp>, @root={"app"=>#<Rails::Paths::Path:0x00005594c90c6760 @paths=["app"], @current="app", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="{*,*/concerns}", @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/assets"=>#<Rails::Paths::Path:0x00005594c90c6698 @paths=["app/assets"], @current="app/assets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "app/controllers"=>#<Rails::Paths::Path:0x00005594c90c65f8 @paths=["app/controllers"], @current="app/controllers", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/channels"=>#<Rails::Paths::Path:0x00005594c90c6530 @paths=["app/channels"], @current="app/channels", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="**/*_channel.rb", @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/helpers"=>#<Rails::Paths::Path:0x00005594c90c6490 @paths=["app/helpers"], @current="app/helpers", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/models"=>#<Rails::Paths::Path:0x00005594c90c63f0 @paths=["app/models"], @current="app/models", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/mailers"=>#<Rails::Paths::Path:0x00005594c90c6350 @paths=["app/mailers"], @current="app/mailers", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/views"=>#<Rails::Paths::Path:0x00005594c90c62b0 @paths=["app/views"], @current="app/views", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib"=>#<Rails::Paths::Path:0x00005594c90c6210 @paths=["lib"], @current="lib", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=true>, "lib/assets"=>#<Rails::Paths::Path:0x00005594c90c6148 @paths=["lib/assets"], @current="lib/assets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib/tasks"=>#<Rails::Paths::Path:0x00005594c90c6080 @paths=["lib/tasks"], @current="lib/tasks", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="**/*.rake", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config"=>#<Rails::Paths::Path:0x00005594c90c5fe0 @paths=["config"], @current="config", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/environments"=>#<Rails::Paths::Path:0x00005594c90c5f18 @paths=["config/environments"], @current="config/environments", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="test.rb", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/initializers"=>#<Rails::Paths::Path:0x00005594c90c5e50 @paths=["config/initializers"], @current="config/initializers", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="**/*.rb", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/locales"=>#<Rails::Paths::Path:0x00005594c90c5d88 @paths=["config/locales"], @current="config/locales", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*.{rb,yml}", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/routes.rb"=>#<Rails::Paths::Path:0x00005594c90c5ce8 @paths=["config/routes.rb"], @current="config/routes.rb", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db"=>#<Rails::Paths::Path:0x00005594c90c5c48 @paths=["db"], @current="db", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db/migrate"=>#<Rails::Paths::Path:0x00005594c90c5ba8 @paths=["db/migrate"], @current="db/migrate", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db/seeds.rb"=>#<Rails::Paths::Path:0x00005594c90c5b08 @paths=["db/seeds.rb"], @current="db/seeds.rb", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "vendor"=>#<Rails::Paths::Path:0x00005594c90c5a68 @paths=["vendor"], @current="vendor", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=true>, "vendor/assets"=>#<Rails::Paths::Path:0x00005594c90c59a0 @paths=["vendor/assets"], @current="vendor/assets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob="*", @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/database"=>#<Rails::Paths::Path:0x00005594c90c58d8 @paths=["config/database.yml"], @current="config/database", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/secrets"=>#<Rails::Paths::Path:0x00005594c90c5810 ...>, "config/environment"=>#<Rails::Paths::Path:0x00005594c90c5748 @paths=["config/environment.rb"], @current="config/environment", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib/templates"=>#<Rails::Paths::Path:0x00005594c90c56a8 @paths=["lib/templates"], @current="lib/templates", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "log"=>#<Rails::Paths::Path:0x00005594c90c55e0 @paths=["log/test.log"], @current="log", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public"=>#<Rails::Paths::Path:0x00005594c90c5540 @paths=["public"], @current="public", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public/javascripts"=>#<Rails::Paths::Path:0x00005594c90c54a0 @paths=["public/javascripts"], @current="public/javascripts", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public/stylesheets"=>#<Rails::Paths::Path:0x00005594c90c5400 @paths=["public/stylesheets"], @current="public/stylesheets", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "tmp"=>#<Rails::Paths::Path:0x00005594c90c5360 @paths=["tmp"], @current="tmp", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/cable"=>#<Rails::Paths::Path:0x00005594c90aba50 @paths=["config/cable.yml"], @current="config/cable", @root=#<Rails::Paths::Root:0x00005594c90c6850 ...>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>}>, @glob=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>]
[2020-10-08 11:47:53 +0200] [43656] [watcher:test] subjects_changed: mtime 1602150469.7544591 -> 1602150469.7544591
[2020-10-08 11:47:53 +0200] [43656] [application:test] forked 43660
[2020-10-08 11:47:53 +0200] [43643] [application_manager:test] got worker pid 43660
[2020-10-08 11:47:53 +0200] [43655] [client] got pid: 43660
[2020-10-08 11:47:53 +0200] [43656] [application:test] 43660 exited with 1
[2020-10-08 11:47:53 +0200] [43655] [client] got exit status 1



1 runs, 4 assertions, 1 failures, 0 errors, 0 skips
rake aborted!
Command failed with status (1): [ruby -w -I"lib" -I"/home/deivid/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib" "/home/deivid/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb" "test/acceptance_test.rb" --name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs]
/home/deivid/.rbenv/versions/2.7.2/bin/bundle:23:in `load'
/home/deivid/.rbenv/versions/2.7.2/bin/bundle:23:in `<main>'
Tasks: TOP => default => test:all => test:acceptance
(See full trace by running task with --trace)

$ git revert 20d3a5f --no-edit

[master 11aa2fd] Revert "Start server process in dir where cmd was called"
 Date: Thu Oct 8 11:52:51 2020 +0200
 1 file changed, 6 deletions(-)

$ bundle exec rake TESTOPTS=--name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs

/home/deivid/.rbenv/versions/2.7.2/bin/ruby -w -I"lib" -I"/home/deivid/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib" "/home/deivid/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb" "test/unit/client/help_test.rb" "test/unit/client/version_test.rb" "test/unit/commands_test.rb" "test/unit/process_title_updater_test.rb" "test/unit/watcher_test.rb" --name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs
Run options: --name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs --seed 40822

# Running:



Finished in 0.001280s, 0.0000 runs/s, 0.0000 assertions/s.

0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
/home/deivid/.rbenv/versions/2.7.2/bin/ruby -w -I"lib" -I"/home/deivid/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib" "/home/deivid/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/rake_test_loader.rb" "test/acceptance_test.rb" --name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs
Run options: --name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs --seed 16746

# Running:

[DEPRECATED] `Bundler.with_clean_env` has been deprecated in favor of `Bundler.with_unbundled_env`. If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env` (called at /home/deivid/Code/spring/test/support/application.rb:111)
.

Finished in 10.912813s, 0.0916 runs/s, 0.5498 assertions/s.

1 runs, 6 assertions, 0 failures, 0 errors, 0 skips

@deivid-rodriguez
Copy link
Contributor

You can see the whole list of new failures by comparing the CI logs.

Sorry for the triple post 🙏, I just wanted to give as much information as possible.

@adrianna-chang-shopify
Copy link
Contributor Author

Hey @deivid-rodriguez ! Thanks for providing such a detailed writeup ❤️ Does seem like this introduced some failures, I'll dig into them.

In regards to

I think the case this PR wanted to support might be already supported by setting Spring.application_root=? At least the README seems to imply that.

The problem we were trying to solve here was not that Spring couldn't find the application root, but rather that switching between the host app and an engine and running rails commands with Spring enabled got Spring confused about where the current working directory was.

I suspect we need an extra conditional somewhere - I'll take a look.

@tenderlove if the fix for this is more obvious to you, let me know 😄

@deivid-rodriguez
Copy link
Contributor

deivid-rodriguez commented Oct 8, 2020

Hei, thanks!

I think I might've figured out a patch to get your use case working. I did the following:

  • Generate a dummy application with rails new.
  • Generate a dummy plugin inside it with rails plugin new.
  • Add spring to the plugin's Gemfile, and added bin/spring and a snippet to load spring to bin/rails inside the plugin (I think spring provides a command to do this, but I copied it manually from the app).
  • Create a config/spring.rb file inside the plugin with Spring.application_root = File.expand_path("../test/dummy", __dir__).
  • Revert this PR, and as a replacement, add the following patch, so that it first tries to load the rails script present in the CWD if it exists:
diff --git a/lib/spring/commands/rails.rb b/lib/spring/commands/rails.rb
index f62fe6b..00c683f 100644
--- a/lib/spring/commands/rails.rb
+++ b/lib/spring/commands/rails.rb
@@ -3,7 +3,7 @@ module Spring
     class Rails
       def call
         ARGV.unshift command_name
-        load Dir.glob(::Rails.root.join("{bin,script}/rails")).first
+        load Dir.glob(Pathname.new(Dir.pwd).join("{bin,script}/rails")).first || Dir.glob(::Rails.root.join("{bin,script}/rails")).first
       end
 
       def description

With these steps, things seem to work as expected, and both test runs work fine and use spring.

@deivid-rodriguez
Copy link
Contributor

Oh, actually, my patch fixes the second case, but breaks your first usage:

bin/rails test engines/foo in main application => correctly runs the engines/foo test suite

😞

@deivid-rodriguez
Copy link
Contributor

Well, actually, without any changes, bin/rails test engines/foo doesn't work either on my dummy setup. So my idea might still be on the right track, probably better that you play around with it on your realworld setup.

@adrianna-chang-shopify
Copy link
Contributor Author

Hey @deivid-rodriguez -- so unfortunately haven't had much success (or time haha) digging into this. This is not a blocker for our setup (we were testing out a monolithic application divided into engines, and so this patch was to get spring operable in the engines). Let's just get this reverted, and my team can reinvestigate at a later point when it becomes higher priority. Thanks again for the writeup, that'll help us out and make sure we don't accidentally cause another regression!

@deivid-rodriguez
Copy link
Contributor

That's very nice of you @adrianna-chang-shopify ❤️.

May I create a PR to revert this PR, then?

@deivid-rodriguez
Copy link
Contributor

I went ahead and created #629 👍

entcheva pushed a commit to thoughtbot/factory_bot_rails that referenced this pull request Jan 12, 2021
Changes introduced in spring 2.1.1
(rails/spring#621) are breaking some tests. That
change was reverted in rails/spring#629, but
hasn't been released yet. Until #629 is released, this PR skips Spring
version 2.1.1.

Co-authored-by: Daniel J. Colson <daniel.colson@hey.com>
entcheva pushed a commit to thoughtbot/factory_bot_rails that referenced this pull request Jan 12, 2021
* Skip Spring version 2.1.1

Changes introduced in spring 2.1.1
(rails/spring#621) are breaking some tests. That
change was reverted in rails/spring#629, but
hasn't been released yet. Until #629 is released, this PR skips Spring
version 2.1.1.

* Bump to latest standard to match CI

We are using the latest standard on CI. This bumps the version in the
dev Gemfile to match, and fixes one violation.

Co-authored-by: Daniel J. Colson <daniel.colson@hey.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants