diff --git a/spec/requests/admin/ai_llms_controller_spec.rb b/spec/requests/admin/ai_llms_controller_spec.rb index cf79c9dc..b9ed8226 100644 --- a/spec/requests/admin/ai_llms_controller_spec.rb +++ b/spec/requests/admin/ai_llms_controller_spec.rb @@ -49,20 +49,19 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController do it "lists enabled features on appropriate LLMs" do SiteSetting.ai_bot_enabled = true + fake_model = assign_fake_provider_to(:ai_default_llm_model) # setting the setting calls the model DiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) do - assign_fake_provider_to(:ai_default_llm_model) + SiteSetting.ai_helper_proofreader_persona = ai_persona.id SiteSetting.ai_helper_enabled = true end DiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) do - assign_fake_provider_to(:ai_default_llm_model) SiteSetting.ai_summarization_enabled = true end DiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) do - assign_fake_provider_to(:ai_default_llm_model) SiteSetting.ai_embeddings_semantic_search_enabled = true end @@ -71,15 +70,18 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController do llms = response.parsed_body["ai_llms"] model_json = llms.find { |m| m["id"] == llm_model.id } - expect(model_json["used_by"]).to contain_exactly( - { "type" => "ai_bot" }, - { "type" => "ai_helper" }, - ) + expect(model_json["used_by"]).to contain_exactly({ "type" => "ai_bot" }) model2_json = llms.find { |m| m["id"] == llm_model2.id } expect(model2_json["used_by"]).to contain_exactly( { "type" => "ai_persona", "name" => "Cool persona", "id" => ai_persona.id }, + { "type" => "ai_helper", "name" => "Proofread text" }, + ) + + model3_json = llms.find { |m| m["id"] == fake_model.id } + + expect(model3_json["used_by"]).to contain_exactly( { "type" => "ai_summarization" }, { "type" => "ai_embeddings_semantic_search" }, ) @@ -514,13 +516,15 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController do expect(history.subject).to eq(model_display_name) # Verify subject is set to display_name end - it "validates the model is not in use" do - fake_llm = assign_fake_provider_to(:ai_helper_model) + context "with llms configured" do + fab!(:ai_persona) { Fabricate(:ai_persona, default_llm_id: llm_model.id) } - delete "/admin/plugins/discourse-ai/ai-llms/#{fake_llm.id}.json" - - expect(response.status).to eq(409) - expect(fake_llm.reload).to eq(fake_llm) + before { assign_fake_provider_to(:ai_helper_model) } + it "validates the model is not in use" do + delete "/admin/plugins/discourse-ai/ai-llms/#{llm_model.id}.json" + expect(response.status).to eq(409) + expect(llm_model.reload).to eq(llm_model) + end end it "cleans up companion users before deleting the model" do