From 54d0cdfa753d457ef4fedaa7321c904cd41b2baf Mon Sep 17 00:00:00 2001 From: "Kit (OpenClaw)" Date: Wed, 4 Mar 2026 19:27:15 -0500 Subject: [PATCH 1/4] Fix ActiveJob adapter setup when Sidekiq configured --- core/lib/workarea/configuration/sidekiq.rb | 9 ++++++++- .../lib/workarea/configuration/sidekiq_test.rb | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/lib/workarea/configuration/sidekiq.rb b/core/lib/workarea/configuration/sidekiq.rb index 836226721..33c452723 100644 --- a/core/lib/workarea/configuration/sidekiq.rb +++ b/core/lib/workarea/configuration/sidekiq.rb @@ -76,7 +76,14 @@ def configure_workarea! end def configure_plugins! - ActiveJob::Base.queue_adapter = :sidekiq + # Ensure ActiveJob-backed features (notably ActionMailer deliver_later) + # enqueue through Sidekiq by default. + # + # Don't override the :test adapter in test suites, since Workarea relies + # on ActiveJob's test adapter helpers (perform_enqueued_jobs, etc.). + unless ActiveJob::Base.queue_adapter.is_a?(ActiveJob::QueueAdapters::TestAdapter) + ActiveJob::Base.queue_adapter = :sidekiq + end # Sidekiq 7 enables strict argument checking by default, but Workarea # commonly passes BSON::ObjectId and other non-JSON-native types. diff --git a/core/test/lib/workarea/configuration/sidekiq_test.rb b/core/test/lib/workarea/configuration/sidekiq_test.rb index f030f7a60..44bfe1684 100644 --- a/core/test/lib/workarea/configuration/sidekiq_test.rb +++ b/core/test/lib/workarea/configuration/sidekiq_test.rb @@ -95,6 +95,21 @@ def test_sidekiq_defaults_timeout_matches_resolved_value_when_no_env expected = (defaults[:timeout] || defaults['timeout']).to_i assert_equal expected, Configuration::Sidekiq.timeout end + + # --------------------------------------------------------------------------- + # ActiveJob adapter compatibility + # --------------------------------------------------------------------------- + + def test_configure_plugins_does_not_override_test_adapter + original_adapter = ActiveJob::Base.queue_adapter + ActiveJob::Base.queue_adapter = :test + + Workarea::Configuration::Sidekiq.configure_plugins! + + assert_equal 'test', ActiveJob::Base.queue_adapter_name.to_s + ensure + ActiveJob::Base.queue_adapter = original_adapter + end end end end From eebf25388a712b70750b84a59a18988160c1cf37 Mon Sep 17 00:00:00 2001 From: "Kit (OpenClaw)" Date: Wed, 4 Mar 2026 22:33:14 -0500 Subject: [PATCH 2/4] Add ActiveJob Sidekiq adapter coverage --- .../workarea/configuration/sidekiq_test.rb | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/core/test/lib/workarea/configuration/sidekiq_test.rb b/core/test/lib/workarea/configuration/sidekiq_test.rb index 44bfe1684..026909576 100644 --- a/core/test/lib/workarea/configuration/sidekiq_test.rb +++ b/core/test/lib/workarea/configuration/sidekiq_test.rb @@ -3,6 +3,10 @@ module Workarea module Configuration class SidekiqTest < TestCase + class EnqueueTestJob < ActiveJob::Base + queue_as :default + def perform; end + end # --------------------------------------------------------------------------- # SIDEKIQ_DEFAULTS resolution # --------------------------------------------------------------------------- @@ -101,8 +105,10 @@ def test_sidekiq_defaults_timeout_matches_resolved_value_when_no_env # --------------------------------------------------------------------------- def test_configure_plugins_does_not_override_test_adapter - original_adapter = ActiveJob::Base.queue_adapter - ActiveJob::Base.queue_adapter = :test + require 'active_job/queue_adapters/test_adapter' + + original_adapter = ActiveJob::Base.queue_adapter_name.to_s.to_sym + ActiveJob::Base.queue_adapter = ActiveJob::QueueAdapters::TestAdapter.new Workarea::Configuration::Sidekiq.configure_plugins! @@ -110,6 +116,63 @@ def test_configure_plugins_does_not_override_test_adapter ensure ActiveJob::Base.queue_adapter = original_adapter end + + end + + class SidekiqActiveJobAdapterTest < ::Minitest::Test + class EnqueueTestJob < ActiveJob::Base + queue_as :default + def perform; end + end + + def setup + @original_adapter = ActiveJob::Base.queue_adapter_name.to_s.to_sym + end + + def teardown + ActiveJob::Base.queue_adapter = @original_adapter + end + + def test_configure_plugins_sets_sidekiq_adapter_when_not_using_test_adapter + ActiveJob::Base.queue_adapter = :async + refute ActiveJob::Base.queue_adapter.is_a?(ActiveJob::QueueAdapters::TestAdapter) + + Workarea::Configuration::Sidekiq.configure_plugins! + + assert_equal 'sidekiq', ActiveJob::Base.queue_adapter_name.to_s + end + + def test_active_job_enqueues_into_sidekiq_queue + require 'sidekiq/testing' + + ::Sidekiq::Testing.fake! do + ::Sidekiq::Worker.clear_all + + ActiveJob::Base.queue_adapter = :async + Workarea::Configuration::Sidekiq.configure_plugins! + + assert_equal 'sidekiq', ActiveJob::Base.queue_adapter_name.to_s + + assert_equal 0, ::Sidekiq::Worker.jobs.size + + EnqueueTestJob.perform_later + + assert_equal 1, ::Sidekiq::Worker.jobs.size + end + end + + def test_configure_plugins_emits_no_deprecation_warnings + original_deprecated = Warning[:deprecated] + Warning[:deprecated] = true + + _stdout, stderr = capture_io do + Workarea::Configuration::Sidekiq.configure_plugins! + end + + assert_equal '', stderr + ensure + Warning[:deprecated] = original_deprecated + end end end end From 6741f2856ff53644015a248ed40aa01e59748ef1 Mon Sep 17 00:00:00 2001 From: "Kit (OpenClaw)" Date: Wed, 4 Mar 2026 23:04:42 -0500 Subject: [PATCH 3/4] Fix rubocop: remove extra empty line at class body end --- core/test/lib/workarea/configuration/sidekiq_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/core/test/lib/workarea/configuration/sidekiq_test.rb b/core/test/lib/workarea/configuration/sidekiq_test.rb index 026909576..de44fb210 100644 --- a/core/test/lib/workarea/configuration/sidekiq_test.rb +++ b/core/test/lib/workarea/configuration/sidekiq_test.rb @@ -116,7 +116,6 @@ def test_configure_plugins_does_not_override_test_adapter ensure ActiveJob::Base.queue_adapter = original_adapter end - end class SidekiqActiveJobAdapterTest < ::Minitest::Test From c617612edeb3ffe721775144a64111e9c392e873 Mon Sep 17 00:00:00 2001 From: "Kit (OpenClaw)" Date: Wed, 4 Mar 2026 23:48:54 -0500 Subject: [PATCH 4/4] Address review findings: execution test, scope notes, public API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add ExecutionTrackingJob + test_active_job_executes_successfully_in_sidekiq_inline_mode to cover the 'Jobs execute successfully' acceptance criterion (#755) - Add inline SCOPE NOTE comments for retries, scheduled jobs, and unique-jobs acceptance criteria — these are pre-existing Sidekiq behaviors unaffected by the configure_plugins! guard change - Switch guard condition from is_a?(TestAdapter) to queue_adapter_name.to_s == 'test' (public Rails 5.2+ API; works even when TestAdapter constant not yet loaded) --- core/lib/workarea/configuration/sidekiq.rb | 5 +- .../workarea/configuration/sidekiq_test.rb | 70 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/core/lib/workarea/configuration/sidekiq.rb b/core/lib/workarea/configuration/sidekiq.rb index 33c452723..ec02edd29 100644 --- a/core/lib/workarea/configuration/sidekiq.rb +++ b/core/lib/workarea/configuration/sidekiq.rb @@ -81,7 +81,10 @@ def configure_plugins! # # Don't override the :test adapter in test suites, since Workarea relies # on ActiveJob's test adapter helpers (perform_enqueued_jobs, etc.). - unless ActiveJob::Base.queue_adapter.is_a?(ActiveJob::QueueAdapters::TestAdapter) + # Uses the public queue_adapter_name API (Rails 5.2+) rather than + # is_a?(TestAdapter) so it works even when the adapter constant is not + # yet loaded at call time. + unless ActiveJob::Base.queue_adapter_name.to_s == 'test' ActiveJob::Base.queue_adapter = :sidekiq end diff --git a/core/test/lib/workarea/configuration/sidekiq_test.rb b/core/test/lib/workarea/configuration/sidekiq_test.rb index de44fb210..5195e1db9 100644 --- a/core/test/lib/workarea/configuration/sidekiq_test.rb +++ b/core/test/lib/workarea/configuration/sidekiq_test.rb @@ -7,6 +7,16 @@ class EnqueueTestJob < ActiveJob::Base queue_as :default def perform; end end + + # Job that records execution so tests can assert it actually ran. + class ExecutionTrackingJob < ActiveJob::Base + queue_as :default + cattr_accessor :executed, default: false + + def perform + self.class.executed = true + end + end # --------------------------------------------------------------------------- # SIDEKIQ_DEFAULTS resolution # --------------------------------------------------------------------------- @@ -112,6 +122,7 @@ def test_configure_plugins_does_not_override_test_adapter Workarea::Configuration::Sidekiq.configure_plugins! + # Guard uses queue_adapter_name public API — verify it holds assert_equal 'test', ActiveJob::Base.queue_adapter_name.to_s ensure ActiveJob::Base.queue_adapter = original_adapter @@ -172,6 +183,65 @@ def test_configure_plugins_emits_no_deprecation_warnings ensure Warning[:deprecated] = original_deprecated end + + # --------------------------------------------------------------------------- + # Acceptance criteria: job execution + # + # Verifies that once configure_plugins! sets the :sidekiq adapter, + # jobs actually execute (not just enqueue) when Sidekiq runs inline. + # This covers the "Jobs execute successfully" acceptance criterion from #755. + # --------------------------------------------------------------------------- + + def test_active_job_executes_successfully_in_sidekiq_inline_mode + require 'sidekiq/testing' + + SidekiqTest::ExecutionTrackingJob.executed = false + + ::Sidekiq::Testing.inline! do + ActiveJob::Base.queue_adapter = :async + Workarea::Configuration::Sidekiq.configure_plugins! + + assert_equal 'sidekiq', ActiveJob::Base.queue_adapter_name.to_s + + SidekiqTest::ExecutionTrackingJob.perform_later + + assert SidekiqTest::ExecutionTrackingJob.executed, + 'Expected job to execute synchronously in Sidekiq inline mode' + end + ensure + SidekiqTest::ExecutionTrackingJob.executed = false + end + + # --------------------------------------------------------------------------- + # Acceptance criteria: retries — SCOPE NOTE + # + # Retry behavior (sidekiq_retries_exhausted, retry_in, retry_on) is + # standard Sidekiq/ActiveJob infrastructure that is NOT affected by this + # guard change. The PR only prevents configure_plugins! from clobbering the + # :test adapter; it does not modify Sidekiq retry configuration. Retry + # integration tests would require an actual Sidekiq server process and are + # covered by upstream Sidekiq/sidekiq-unique-jobs test suites. + # --------------------------------------------------------------------------- + + # --------------------------------------------------------------------------- + # Acceptance criteria: scheduled jobs — SCOPE NOTE + # + # Scheduled job support (perform_in, perform_at, scheduled_at) is provided + # by Sidekiq's scheduler and is not touched by this PR. The guard change + # has no impact on scheduling behavior. Scheduled-job integration tests + # require Sidekiq's scheduler process and are outside the scope of this + # unit-level fix. + # --------------------------------------------------------------------------- + + # --------------------------------------------------------------------------- + # Acceptance criteria: unique-jobs enforcement — SCOPE NOTE + # + # Unique-job constraints are enforced by SidekiqUniqueJobs middleware, which + # is wired in configure_workarea! (not configure_plugins!). This PR does not + # change that middleware chain. Uniqueness enforcement requires a live Redis + # connection and Sidekiq server and is tested by the sidekiq-unique-jobs gem + # itself. It is out of scope for this adapter-guard unit test. + # --------------------------------------------------------------------------- end end end