From 08d2f3ddf97ae2594dc64ba3850e2e34870190a6 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Thu, 17 Jul 2025 11:36:19 -0700 Subject: [PATCH] FIX: spam --- .../discourse/components/ai-spam.gjs | 2 +- spec/system/ai_moderation/ai_spam_spec.rb | 54 ++++++++++--------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/assets/javascripts/discourse/components/ai-spam.gjs b/assets/javascripts/discourse/components/ai-spam.gjs index 7f4464cf..812660ac 100644 --- a/assets/javascripts/discourse/components/ai-spam.gjs +++ b/assets/javascripts/discourse/components/ai-spam.gjs @@ -127,7 +127,7 @@ export default class AiSpam extends Component { } get llmId() { - return this.selectedLLM.toString().split(":")[1]; + return this.selectedLLM; } @action diff --git a/spec/system/ai_moderation/ai_spam_spec.rb b/spec/system/ai_moderation/ai_spam_spec.rb index 4640b760..b48d2fac 100644 --- a/spec/system/ai_moderation/ai_spam_spec.rb +++ b/spec/system/ai_moderation/ai_spam_spec.rb @@ -2,47 +2,51 @@ RSpec.describe "AI Spam Configuration", type: :system, js: true do fab!(:admin) - let(:llm_model) { Fabricate(:llm_model) } before do SiteSetting.discourse_ai_enabled = true sign_in(admin) end - it "can properly configure spam settings" do - visit "/admin/plugins/discourse-ai/ai-spam" + context "when no LLMs are configured" do + it "shows the placeholder when no LLM is configured" do + visit "/admin/plugins/discourse-ai/ai-spam" - expect(page).to have_css(".ai-spam__llm-placeholder") + expect(page).to have_css(".ai-spam__llm-placeholder") - toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle") + toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle") - toggle.toggle - dialog = PageObjects::Components::Dialog.new - expect(dialog).to have_content(I18n.t("discourse_ai.llm.configuration.must_select_model")) - dialog.click_ok + toggle.toggle + dialog = PageObjects::Components::Dialog.new + expect(dialog).to have_content(I18n.t("discourse_ai.llm.configuration.must_select_model")) + dialog.click_ok - expect(toggle.unchecked?).to eq(true) + expect(toggle.unchecked?).to eq(true) + end + end + context "when LLMs are configured" do + fab!(:llm_model) + it "can properly configure spam settings" do + visit "/admin/plugins/discourse-ai/ai-spam" - llm_model - visit "/admin/plugins/discourse-ai/ai-spam" + toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle") + toggle.toggle - toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle") - toggle.toggle + try_until_success { expect(AiModerationSetting.spam&.llm_model_id).to eq(llm_model.id) } - try_until_success { expect(AiModerationSetting.spam&.llm_model_id).to eq(llm_model.id) } + find(".ai-spam__instructions-input").fill_in(with: "Test spam detection instructions") + find(".ai-spam__instructions-save").click - find(".ai-spam__instructions-input").fill_in(with: "Test spam detection instructions") - find(".ai-spam__instructions-save").click + toasts = PageObjects::Components::Toasts.new + expect(toasts).to have_content(I18n.t("js.discourse_ai.spam.settings_saved")) - toasts = PageObjects::Components::Toasts.new - expect(toasts).to have_content(I18n.t("js.discourse_ai.spam.settings_saved")) + expect(AiModerationSetting.spam.custom_instructions).to eq("Test spam detection instructions") - expect(AiModerationSetting.spam.custom_instructions).to eq("Test spam detection instructions") + visit "/admin/plugins/discourse-ai/ai-llms" - visit "/admin/plugins/discourse-ai/ai-llms" - - expect(find(".ai-llm-list-editor__usages")).to have_content( - I18n.t("js.discourse_ai.llms.usage.ai_spam"), - ) + expect(find(".ai-llm-list-editor__usages")).to have_content( + I18n.t("js.discourse_ai.llms.usage.ai_spam"), + ) + end end end