discourse/plugins/discourse-ai/spec/evals/support/runner_helper.rb
Sam e3fae646d4
DEV: AI persona to agent migration (#38319)
Co-authored-by: Keegan George <kgeorge13@gmail.com>
2026-03-10 15:59:45 +11:00

28 lines
845 B
Ruby

# frozen_string_literal: true
module DiscourseAi
module Evals
module RunnerSpecHelper
def stub_runner_bot(
agent: instance_double(DiscourseAi::Agents::Agent, response_format: nil),
response: "ok",
&custom_block
)
bot_double = instance_double(DiscourseAi::Agents::Bot, agent: agent)
allow(AiAgent).to receive(:find_by_id_from_cache).and_return(nil)
allow(DiscourseAi::Agents::Bot).to receive(:as).and_return(bot_double)
if block_given?
allow(bot_double).to receive(:reply) { |*_, &blk| custom_block.call(blk) }
else
allow(bot_double).to receive(:reply) { |_ctx, &blk| blk.call(response, nil, nil) }
end
bot_double
end
end
end
end
RSpec.configure { |config| config.include DiscourseAi::Evals::RunnerSpecHelper }