discourse/plugins/discourse-ai/spec/lib/agents/concept_finder_spec.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

63 lines
1.8 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe DiscourseAi::Agents::ConceptFinder do
let(:agent) { described_class.new }
before { enable_current_plugin }
describe ".default_enabled" do
it "is disabled by default" do
expect(described_class.default_enabled).to eq(false)
end
end
describe "#system_prompt" do
before do
Fabricate(:inferred_concept, name: "programming")
Fabricate(:inferred_concept, name: "testing")
Fabricate(:inferred_concept, name: "ruby")
end
it "includes existing concepts when available" do
prompt = agent.system_prompt
InferredConcept.all.each { |concept| expect(prompt).to include(concept.name) }
end
it "handles empty existing concepts" do
InferredConcept.destroy_all
prompt = agent.system_prompt
expect(prompt).not_to include("following concepts already exist")
expect(prompt).to include("advanced concept tagging system")
end
it "limits existing concepts to 100" do
manager = instance_double(DiscourseAi::InferredConcepts::Manager)
allow(DiscourseAi::InferredConcepts::Manager).to receive(:new).and_return(manager)
allow(manager).to receive(:list_concepts).with(limit: 100).and_return(%w[concept1 concept2])
agent.system_prompt
end
it "includes format instructions" do
prompt = agent.system_prompt
expect(prompt).to include('{"concepts": ["concept1", "concept2", "concept3"]}')
end
it "includes language preservation instruction" do
prompt = agent.system_prompt
expect(prompt).to include("original language of the text")
end
end
describe "#response_format" do
it "defines correct response format" do
format = agent.response_format
expect(format).to eq([{ "array_type" => "string", "key" => "concepts", "type" => "array" }])
end
end
end