-
Notifications
You must be signed in to change notification settings - Fork 340
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
Start Spring server process in directory where command was called #621
Conversation
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']
1166cef
to
7abf456
Compare
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. |
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 spring/test/support/acceptance_test.rb Line 111 in a85d32e
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 We were also hit by this in I think the case this PR wanted to support might be already supported by setting |
A local repro: $ git showcommit 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
$ git revert 20d3a5f --no-edit
$ bundle exec rake TESTOPTS=--name=AcceptanceTest#test_tells_the_user_that_Spring_is_being_used_when_used_automatically_via_binstubs
|
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. |
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
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 😄 |
Hei, thanks! I think I might've figured out a patch to get your use case working. I did the following:
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. |
Oh, actually, my patch fixes the second case, but breaks your first usage:
😞 |
Well, actually, without any changes, |
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! |
That's very nice of you @adrianna-chang-shopify ❤️. May I create a PR to revert this PR, then? |
I went ahead and created #629 👍 |
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>
* 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>
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:
bin/rails test engines/foo
in main application => correctly runs theengines/foo
test suitecd engines/foo; bin/rails test
=> runs the main application tests, andDir.pwd
in the rails binstubs is the main application