@@ -266,6 +266,97 @@ 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+ # Create a mock job where job.class returns the actual job class
282+ # rubocop:disable Sorbet/ConstantsFromStrings
283+ klass = Object . const_get ( :NoLogArgsJob )
284+ # rubocop:enable Sorbet/ConstantsFromStrings
285+ job = create_mock_job_with_class ( klass , "job_123" , "default" )
286+ event_data = create_test_event ( {
287+ job : job ,
288+ duration : 0.1
289+ } )
290+
291+ @subscriber . enqueue ( event_data )
292+ ::SemanticLogger . flush
293+
294+ output = @log_output . string
295+ log = JSON . parse ( output . lines . first . strip )
296+
297+ # Arguments should not be present when log_arguments? returns false
298+ refute log . key? ( "arguments" )
299+ ensure
300+ Object . send ( :remove_const , :NoLogArgsJob )
301+ end
302+ end
303+
304+ test "logs arguments by default when job class does not define log_arguments?" do
305+ clear_log_buffer ( @log_output )
306+
307+ # Standard job without log_arguments? defined - should log arguments
308+ job = create_mock_job ( "StandardJob" , "job_123" , "default" )
309+ event_data = create_test_event ( {
310+ job : job ,
311+ duration : 0.1
312+ } )
313+
314+ @subscriber . enqueue ( event_data )
315+ ::SemanticLogger . flush
316+
317+ output = @log_output . string
318+ log = JSON . parse ( output . lines . first . strip )
319+
320+ # Arguments should be present by default
321+ assert log . key? ( "arguments" )
322+ assert_equal [ "arg1" , "arg2" ] , log [ "arguments" ]
323+ end
324+
325+ test "logs arguments when job class log_arguments? returns true" do
326+ clear_log_buffer ( @log_output )
327+
328+ job_class = Class . new do
329+ def self . log_arguments?
330+ true
331+ end
332+ end
333+ Object . const_set ( :LogArgsJob , job_class )
334+
335+ begin
336+ # Create a mock job where job.class returns the actual job class
337+ # rubocop:disable Sorbet/ConstantsFromStrings
338+ klass = Object . const_get ( :LogArgsJob )
339+ # rubocop:enable Sorbet/ConstantsFromStrings
340+ job = create_mock_job_with_class ( klass , "job_123" , "default" )
341+ event_data = create_test_event ( {
342+ job : job ,
343+ duration : 0.1
344+ } )
345+
346+ @subscriber . enqueue ( event_data )
347+ ::SemanticLogger . flush
348+
349+ output = @log_output . string
350+ log = JSON . parse ( output . lines . first . strip )
351+
352+ # Arguments should be present when log_arguments? returns true
353+ assert log . key? ( "arguments" )
354+ assert_equal [ "arg1" , "arg2" ] , log [ "arguments" ]
355+ ensure
356+ Object . send ( :remove_const , :LogArgsJob )
357+ end
358+ end
359+
269360 private
270361
271362 def create_test_event ( payload_data , start_time : nil , finish_time : nil )
@@ -293,6 +384,23 @@ def create_mock_job(job_class, job_id, queue_name, extra_attributes = {})
293384 } . merge ( extra_attributes ) )
294385 end
295386
387+ # Create a mock job where job.class returns the actual job class (for testing log_arguments?)
388+ def create_mock_job_with_class ( klass , job_id , queue_name , extra_attributes = { } )
389+ mock = Object . new
390+ mock . define_singleton_method ( :class ) { klass }
391+ mock . define_singleton_method ( :job_class ) { klass . name }
392+ mock . define_singleton_method ( :job_id ) { job_id }
393+ mock . define_singleton_method ( :queue_name ) { queue_name }
394+ mock . define_singleton_method ( :arguments ) { [ "arg1" , "arg2" ] }
395+ mock . define_singleton_method ( :priority ) { 0 }
396+ mock . define_singleton_method ( :scheduled_at ) { nil }
397+ mock . define_singleton_method ( :enqueue_caller_location ) { nil }
398+ extra_attributes . each do |key , value |
399+ mock . define_singleton_method ( key ) { value }
400+ end
401+ mock
402+ end
403+
296404 def create_mock_execution ( attributes = { } )
297405 OpenStruct . new ( {
298406 executions : 1 ,
0 commit comments