@@ -266,6 +266,67 @@ class LogSubscriberTest < ActiveSupport::TestCase
266266 assert_nil wait_time
267267 end
268268
269+ test "respects log_arguments? when job class opts out" do
270+ clear_log_buffer ( @log_output )
271+
272+ # Create a job class that opts out of logging arguments
273+ job_class = Class . new do
274+ def self . log_arguments?
275+ false
276+ end
277+ end
278+ Object . const_set ( :NoLogArgsJob , job_class )
279+
280+ begin
281+ log = run_enqueue_with_job_class ( :NoLogArgsJob )
282+
283+ refute log . key? ( "arguments" )
284+ ensure
285+ Object . send ( :remove_const , :NoLogArgsJob )
286+ end
287+ end
288+
289+ test "logs arguments by default when job class does not define log_arguments?" do
290+ clear_log_buffer ( @log_output )
291+
292+ # Standard job without log_arguments? defined - should log arguments
293+ job = create_mock_job ( "StandardJob" , "job_123" , "default" )
294+ event_data = create_test_event ( {
295+ job : job ,
296+ duration : 0.1
297+ } )
298+
299+ @subscriber . enqueue ( event_data )
300+ ::SemanticLogger . flush
301+
302+ output = @log_output . string
303+ log = JSON . parse ( output . lines . first . strip )
304+
305+ # Arguments should be present by default
306+ assert log . key? ( "arguments" )
307+ assert_equal [ "arg1" , "arg2" ] , log [ "arguments" ]
308+ end
309+
310+ test "logs arguments when job class log_arguments? returns true" do
311+ clear_log_buffer ( @log_output )
312+
313+ job_class = Class . new do
314+ def self . log_arguments?
315+ true
316+ end
317+ end
318+ Object . const_set ( :LogArgsJob , job_class )
319+
320+ begin
321+ log = run_enqueue_with_job_class ( :LogArgsJob )
322+
323+ assert log . key? ( "arguments" )
324+ assert_equal [ "arg1" , "arg2" ] , log [ "arguments" ]
325+ ensure
326+ Object . send ( :remove_const , :LogArgsJob )
327+ end
328+ end
329+
269330 private
270331
271332 def create_test_event ( payload_data , start_time : nil , finish_time : nil )
@@ -293,6 +354,35 @@ def create_mock_job(job_class, job_id, queue_name, extra_attributes = {})
293354 } . merge ( extra_attributes ) )
294355 end
295356
357+ # Create a mock job where job.class returns the actual job class (for testing log_arguments?)
358+ def create_mock_job_with_class ( klass , job_id , queue_name , extra_attributes = { } )
359+ mock = Object . new
360+ mock . define_singleton_method ( :class ) { klass }
361+ mock . define_singleton_method ( :job_class ) { klass . name }
362+ mock . define_singleton_method ( :job_id ) { job_id }
363+ mock . define_singleton_method ( :queue_name ) { queue_name }
364+ mock . define_singleton_method ( :arguments ) { [ "arg1" , "arg2" ] }
365+ mock . define_singleton_method ( :priority ) { 0 }
366+ mock . define_singleton_method ( :scheduled_at ) { nil }
367+ mock . define_singleton_method ( :enqueue_caller_location ) { nil }
368+ extra_attributes . each do |key , value |
369+ mock . define_singleton_method ( key ) { value }
370+ end
371+ mock
372+ end
373+
374+ # Run an enqueue event with a job class that has log_arguments? method and return the parsed log
375+ def run_enqueue_with_job_class ( job_class )
376+ # rubocop:disable Sorbet/ConstantsFromStrings
377+ klass = Object . const_get ( job_class )
378+ # rubocop:enable Sorbet/ConstantsFromStrings
379+ job = create_mock_job_with_class ( klass , "job_123" , "default" )
380+ event_data = create_test_event ( { job : job , duration : 0.1 } )
381+ @subscriber . enqueue ( event_data )
382+ ::SemanticLogger . flush
383+ JSON . parse ( @log_output . string . lines . first . strip )
384+ end
385+
296386 def create_mock_execution ( attributes = { } )
297387 OpenStruct . new ( {
298388 executions : 1 ,
0 commit comments