Skip to content

Commit 69784fb

Browse files
ndbroadbentclaude
andcommitted
fix puma detection via ARGV for gosu wrapper scripts
When running puma through wrapper scripts like gosu, $PROGRAM_NAME is the wrapper path (e.g., /usr/bin/gosu) not puma. This fix adds ARGV checking so puma is detected when ARGV contains "puma" arguments. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent cb2848f commit 69784fb

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

.cspell/project-words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Fanout
2121
favicons
2222
gettime
2323
goodjob
24+
gosu
2425
Healthcheck
2526
Honeybadger
2627
hostnames

lib/log_struct/concerns/configuration.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,12 @@ def server_process?
145145
sig { returns(T::Boolean) }
146146
def puma_server?
147147
# Just checking defined?(::Puma::Server) is not reliable - Puma might be installed
148-
# but not running. Check $PROGRAM_NAME to verify we're actually running puma.
149-
$PROGRAM_NAME.include?("puma")
148+
# but not running. Check $PROGRAM_NAME and ARGV to verify we're actually running puma.
149+
# ARGV check is needed when running through wrapper scripts like gosu.
150+
return true if $PROGRAM_NAME.include?("puma")
151+
return true if current_argv.any? { |arg| arg.include?("puma") }
152+
153+
false
150154
end
151155

152156
sig { returns(T::Boolean) }

test/log_struct/configuration_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,5 +391,35 @@ def test_various_ci_env_values
391391
end
392392
end
393393
end
394+
395+
# Test puma detection via ARGV when running through wrapper scripts (e.g., gosu)
396+
# In this scenario, $PROGRAM_NAME is the wrapper (e.g., /usr/bin/gosu) but ARGV
397+
# contains "puma" arguments like: ["deploy", "puma", "-C", "config/puma.rb"]
398+
def test_enabled_for_puma_via_argv_in_production
399+
original_server_mode = LogStruct.server_mode?
400+
had_rails_server = defined?(::Rails::Server)
401+
402+
# Reset all server detection state
403+
LogStruct.server_mode = false
404+
::Rails.send(:remove_const, :Server) if defined?(::Rails::Server)
405+
406+
LogStruct.config.enabled = false
407+
LogStruct.config.enabled_environments = [:production]
408+
409+
# Simulate gosu wrapper: ARGV contains puma arguments but $PROGRAM_NAME is gosu
410+
original_argv = ::ARGV.dup
411+
::ARGV.replace(["deploy", "puma", "-C", "config/puma.rb"])
412+
413+
Rails.stub(:env, ActiveSupport::StringInquirer.new("production")) do
414+
LogStruct.set_enabled_from_rails_env!
415+
416+
assert LogStruct.config.enabled,
417+
"LogStruct should be enabled when puma is detected via ARGV (gosu wrapper scenario)"
418+
end
419+
ensure
420+
::ARGV.replace(original_argv) if defined?(original_argv)
421+
LogStruct.server_mode = T.must(original_server_mode)
422+
::Rails.const_set(:Server, Class.new) if had_rails_server && !defined?(::Rails::Server)
423+
end
394424
end
395425
end

0 commit comments

Comments
 (0)