Skip to content

A platform for community discussion. Free, open, simple.

DEV: Restore/remove/fix/update AI-related specs (#39539)

Jarek Radosz5c49e22a49f4
diff --git a/plugins/discourse-ai/spec/jobs/regular/run_problem_check_spec.rb b/plugins/discourse-ai/spec/jobs/regular/run_problem_check_spec.rb
deleted file mode 100644
index 03f5882d42b..00000000000
--- a/plugins/discourse-ai/spec/jobs/regular/run_problem_check_spec.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-# frozen_string_literal: true
-
-RSpec.describe Jobs::RunProblemCheck do
- subject(:run_check_job) { described_class.new }
-
- xdescribe "integration specs for AI-based problem checks" do
- before { enable_current_plugin }
-
- context "when running AI LLM status checks" do
- let(:identifier) { :ai_llm_status }
-
- let!(:llm_model) { assign_fake_provider_to(:ai_default_llm_model) }
-
- before { SiteSetting.ai_summarization_enabled = true }
-
- context "when everything is OK" do
- it "creates a problem check tracker that is targeting the tested model" do
- DiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) do
- run_check_job.execute(check_identifier: identifier)
- end
-
- created_trackers = ProblemCheckTracker.where(identifier: identifier)
-
- expect(created_trackers.size).to eq(1)
- expect(created_trackers.last.target).to eq(llm_model.id.to_s)
- end
- end
- end
-
- context "when running AI Credit soft limits checks" do
- let(:identifier) { :ai_credit_soft_limit }
-
- fab!(:llm_model) { Fabricate(:llm_model, id: -1) }
-
- context "when we haven't reach the soft limit yet" do
- it "creates a problem check tracker that is targeting the tested model" do
- Fabricate(
- :llm_credit_allocation,
- llm_model: llm_model,
- monthly_credits: 1000,
- monthly_used: 700,
- soft_limit_percentage: 80,
- )
-
- run_check_job.execute(check_identifier: identifier)
-
- created_trackers = ProblemCheckTracker.where(identifier: identifier)
-
- expect(created_trackers.size).to eq(1)
- expect(created_trackers.last.target).to eq(llm_model.id.to_s)
- end
- end
- end
-
- context "when running AI Credit hard limits checks" do
- let(:identifier) { :ai_credit_hard_limit }
-
- fab!(:llm_model) { Fabricate(:llm_model, id: -1) }
-
- context "when we haven't reach the soft limit yet" do
- it "creates a problem check tracker that is targeting the tested model" do
- Fabricate(
- :llm_credit_allocation,
- llm_model: llm_model,
- monthly_credits: 1000,
- monthly_used: 850,
- soft_limit_percentage: 80,
- )
-
- run_check_job.execute(check_identifier: identifier)
-
- created_trackers = ProblemCheckTracker.where(identifier: identifier)
-
- expect(created_trackers.size).to eq(1)
- expect(created_trackers.last.target).to eq(llm_model.id.to_s)
- end
- end
- end
- end
-end
diff --git a/plugins/discourse-ai/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rb
index c9b708497a4..e6cee4aab0b 100644
--- a/plugins/discourse-ai/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-xdescribe Jobs::CategoriesLocaleDetectionBackfill do
+describe Jobs::CategoriesLocaleDetectionBackfill do
subject(:job) { described_class.new }
fab!(:category) { Fabricate(:category, locale: nil) }
diff --git a/plugins/discourse-ai/spec/lib/utils/pdf_to_text_spec.rb b/plugins/discourse-ai/spec/lib/utils/pdf_to_text_spec.rb
index 4a526d514bb..8d59c9c011c 100644
--- a/plugins/discourse-ai/spec/lib/utils/pdf_to_text_spec.rb
+++ b/plugins/discourse-ai/spec/lib/utils/pdf_to_text_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe DiscourseAi::Utils::PdfToText do
end
describe "#extract_text" do
- xit "extracts text from PDF pages" do
+ it "extracts text from PDF pages" do
pdf_to_text = described_class.new(upload: upload)
pages = []
pdf_to_text.extract_text { |page| pages << page }
@@ -22,10 +22,13 @@ RSpec.describe DiscourseAi::Utils::PdfToText do
end
context "when improving PDF extraction with LLM" do
- xit "can properly simulate a file" do
- if ENV["CI"]
- skip "This test requires imagemagick is installed with ghostscript support - which is not available in CI"
- end
+ def imagemagick_with_ghostscript?
+ system("magick", "-version", out: File::NULL, err: File::NULL) &&
+ system("gs", "--version", out: File::NULL, err: File::NULL)
+ end
+
+ it "can properly simulate a file" do
+ skip "Requires imagemagick with ghostscript support" unless imagemagick_with_ghostscript?
responses = [
"<chunk>Page 1: LLM chunk 1</chunk><chunk>Page 1: LLM chunk 2</chunk>",
@@ -44,10 +47,9 @@ RSpec.describe DiscourseAi::Utils::PdfToText do
expect(pages).to eq(["Page 1: LLM chunk 1", "Page 1: LLM chunk 2", "Page 2: LLM chunk 3"])
end
- xit "works as expected" do
- if ENV["CI"]
- skip "This test requires imagemagick is installed with ghostscript support - which is not available in CI"
- end
+ it "works as expected" do
+ skip "Requires imagemagick with ghostscript support" unless imagemagick_with_ghostscript?
+
pdf_to_text = described_class.new(upload: upload, user: user, llm_model: llm_model)
pages = []
diff --git a/plugins/discourse-ai/spec/requests/discord/bot_controller_spec.rb b/plugins/discourse-ai/spec/requests/discord/bot_controller_spec.rb
index ea1a308e4f5..7b3807bb63c 100644
--- a/plugins/discourse-ai/spec/requests/discord/bot_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/discord/bot_controller_spec.rb
@@ -41,10 +41,10 @@ RSpec.describe "DiscourseAi::Discord::BotController", type: :request do
allow(SiteSetting).to receive(:ai_discord_allowed_guilds_map).and_return([guild_id])
end
- xit "enqueues a job to handle the interaction" do
- expect {
+ it "enqueues a job to handle the interaction" do
+ expect_enqueued_with(job: :stream_discord_reply, args: { interaction: interaction_body }) do
post "/discourse-ai/discord/interactions", params: interaction_body, headers: headers
- }.to have_enqueued_job(Jobs::StreamDiscordReply)
+ end
end
it "responds with a deferred message" do
diff --git a/plugins/discourse-ai/spec/system/embeddings/semantic_search_spec.rb b/plugins/discourse-ai/spec/system/embeddings/semantic_search_spec.rb
index d5c675ae7a2..4c4bc001527 100644
--- a/plugins/discourse-ai/spec/system/embeddings/semantic_search_spec.rb
+++ b/plugins/discourse-ai/spec/system/embeddings/semantic_search_spec.rb
@@ -1,47 +1,33 @@
# frozen_string_literal: true
-RSpec.describe "AI Composer helper" do
- let(:search_page) { PageObjects::Pages::Search.new }
- let(:query) { "apple_pie" }
- let(:hypothetical_post) { "This is an hypothetical post generated from the keyword apple_pie" }
-
- fab!(:user, :admin)
+RSpec.describe "AI semantic search in full-page search" do
+ fab!(:user)
+ fab!(:embedding_definition)
fab!(:topic)
- fab!(:post) { Fabricate(:post, topic: topic, raw: "Apple pie is a delicious dessert to eat") }
+ fab!(:post) { Fabricate(:post, topic:) }
+
+ let(:search_page) { PageObjects::Pages::Search.new }
+ let(:query) { "apple pie" }
+ let(:embedding) { [0.049382] * embedding_definition.dimensions }
before do
enable_current_plugin
+ SiteSetting.ai_embeddings_selected_model = embedding_definition.id
+ SiteSetting.ai_embeddings_semantic_search_enabled = true
- prompt = DiscourseAi::Embeddings::HydeGenerators::OpenAi.new.prompt(query)
- OpenAiCompletionsInferenceStubs.stub_response(
- prompt,
- hypothetical_post,
- req_opts: {
- max_tokens: 400,
- },
- )
-
- hyde_embedding = [0.049382, 0.9999]
- EmbeddingsGenerationStubs.hugging_face_service(hypothetical_post, hyde_embedding)
+ DiscourseAi::Embeddings::Schema.for(Topic).store(topic, embedding, "digest")
+ EmbeddingsGenerationStubs.hugging_face_service(query, embedding)
- SearchIndexer.enable
- SearchIndexer.index(topic, force: true)
- SiteSetting.ai_embeddings_semantic_search_enabled = true
sign_in(user)
end
- after do
- described_class.clear_cache_for(query)
- SearchIndexer.disable
- end
+ after { DiscourseAi::Embeddings::SemanticSearch.clear_cache_for(query) }
+
+ it "renders AI results in the toggle panel after a search" do
+ visit("/search?expanded=true")
+ search_page.type_in_search(query)
+ search_page.click_search_button
- describe "when performing a search in the full page search page" do
- skip "TODO: Implement test after doing LLM abstraction" do
- it "performs AI search in the background and hides results by default" do
- visit("/search?expanded=true")
- search_page.type_in_search("apple pie")
- search_page.click_search_button
- end
- end
+ expect(page).to have_css(".semantic-search__results .badge-notification", text: "1")
end
end