A platform for community discussion. Free, open, simple.
FIX: Pass user to Discovery BotContext for usage tracking (#36493)
Rafael dos Santos Silva52a5bf46da88
diff --git a/plugins/discourse-ai/app/jobs/regular/stream_discover_reply.rb b/plugins/discourse-ai/app/jobs/regular/stream_discover_reply.rbindex 49e4a8895ca..63e4f1c151a 100644--- a/plugins/discourse-ai/app/jobs/regular/stream_discover_reply.rb+++ b/plugins/discourse-ai/app/jobs/regular/stream_discover_reply.rb@@ -35,6 +35,7 @@ module Jobscontext =DiscourseAi::Personas::BotContext.new(+ user: user,messages: [{ type: :user, content: query }],skip_show_thinking: true,feature_name: "discover",diff --git a/plugins/discourse-ai/spec/jobs/regular/stream_discover_reply_spec.rb b/plugins/discourse-ai/spec/jobs/regular/stream_discover_reply_spec.rbindex fe522a7d639..49cade68a2c 100644--- a/plugins/discourse-ai/spec/jobs/regular/stream_discover_reply_spec.rb+++ b/plugins/discourse-ai/spec/jobs/regular/stream_discover_reply_spec.rb@@ -51,5 +51,24 @@ RSpec.describe Jobs::StreamDiscoverReply doexpect(final_update[:ai_discover_reply]).to eq("dummy")endend++ it "passes the user to BotContext for proper usage tracking and permissions" do+ with_responses(["dummy"]) do+ # Spy on BotContext creation to verify user is passed+ context_spy = nil+ allow(DiscourseAi::Personas::BotContext).to receive(+ :new,+ ).and_wrap_original do |method, **args|+ context_spy = args+ method.call(**args)+ end++ job.execute(user_id: user.id, query: "Testing search")++ expect(context_spy).to be_present+ expect(context_spy[:user]).to eq(user)+ expect(context_spy[:feature_name]).to eq("discover")+ end+ endendend