diff --git a/config/settings.yml b/config/settings.yml index 80348b31..43646ff6 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1,6 +1,6 @@ discourse_ai: discourse_ai_enabled: - default: true + default: false client: true ai_artifact_security: client: true diff --git a/db/migrate/20250721192553_enable_ai_if_already_installed.rb b/db/migrate/20250721192553_enable_ai_if_already_installed.rb new file mode 100644 index 00000000..cdc1d77c --- /dev/null +++ b/db/migrate/20250721192553_enable_ai_if_already_installed.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class EnableAiIfAlreadyInstalled < ActiveRecord::Migration[7.2] + def up + installed_at = DB.query_single(<<~SQL)&.first + SELECT created_at FROM schema_migration_details WHERE version='20230224165056' + SQL + + if installed_at && installed_at < 1.hour.ago + # The plugin was installed before we changed it to be disabled-by-default + # Therefore, if there is no existing database value, enable the plugin + execute <<~SQL + INSERT INTO site_settings(name, data_type, value, created_at, updated_at) + VALUES('discourse_ai_enabled', 5, 't', NOW(), NOW()) + ON CONFLICT (name) DO NOTHING + SQL + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/spec/configuration/feature_spec.rb b/spec/configuration/feature_spec.rb index 19368d12..1ae63f41 100644 --- a/spec/configuration/feature_spec.rb +++ b/spec/configuration/feature_spec.rb @@ -10,6 +10,8 @@ RSpec.describe DiscourseAi::Configuration::Feature do DiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) { block.call } end + before { enable_current_plugin } + describe "#llm_model" do context "when persona is not found" do it "returns nil when persona_id is invalid" do diff --git a/spec/configuration/llm_enumerator_spec.rb b/spec/configuration/llm_enumerator_spec.rb index 7737da45..7eea717f 100644 --- a/spec/configuration/llm_enumerator_spec.rb +++ b/spec/configuration/llm_enumerator_spec.rb @@ -8,6 +8,8 @@ RSpec.describe DiscourseAi::Configuration::LlmEnumerator do Fabricate(:automation, script: "llm_report", name: "some automation", enabled: true) end + before { enable_current_plugin } + describe "#values_for_serialization" do it "returns an array for that can be used for serialization" do fake_model.destroy! diff --git a/spec/configuration/llm_validator_spec.rb b/spec/configuration/llm_validator_spec.rb index 5c9fdecc..89c73c57 100644 --- a/spec/configuration/llm_validator_spec.rb +++ b/spec/configuration/llm_validator_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::Configuration::LlmValidator do + before { enable_current_plugin } + describe "#valid_value?" do context "when the parent module is enabled and we try to reset the selected model" do before do diff --git a/spec/configuration/spam_detection_validator_spec.rb b/spec/configuration/spam_detection_validator_spec.rb index bd359254..4da7c2ca 100644 --- a/spec/configuration/spam_detection_validator_spec.rb +++ b/spec/configuration/spam_detection_validator_spec.rb @@ -3,6 +3,8 @@ RSpec.describe DiscourseAi::Configuration::SpamDetectionValidator do let(:validator) { described_class.new } + before { enable_current_plugin } + it "always returns true if setting the value to false" do expect(validator.valid_value?("f")).to eq(true) end diff --git a/spec/db/migrate/20241031041242_migrate_sentiment_classification_result_format_spec.rb b/spec/db/migrate/20241031041242_migrate_sentiment_classification_result_format_spec.rb index ab152d5f..5d46ff43 100644 --- a/spec/db/migrate/20241031041242_migrate_sentiment_classification_result_format_spec.rb +++ b/spec/db/migrate/20241031041242_migrate_sentiment_classification_result_format_spec.rb @@ -8,11 +8,14 @@ require Rails.root.join( RSpec.describe MigrateSentimentClassificationResultFormat do let(:connection) { ActiveRecord::Base.connection } - before { connection.execute(<<~SQL) } + before do + enable_current_plugin + connection.execute(<<~SQL) INSERT INTO classification_results (model_used, classification, created_at, updated_at) VALUES ('sentiment', '{"neutral": 65, "negative": 20, "positive": 14}', NOW(), NOW()), ('emotion', '{"sadness": 10, "surprise": 15, "fear": 5, "anger": 20, "joy": 30, "disgust": 8, "neutral": 10}', NOW(), NOW()); SQL + end after { connection.execute("DELETE FROM classification_results") } @@ -21,7 +24,7 @@ RSpec.describe MigrateSentimentClassificationResultFormat do it "migrates sentiment classifications correctly" do sentiment_result = connection.execute(<<~SQL).first - SELECT * FROM classification_results + SELECT * FROM classification_results WHERE model_used = 'cardiffnlp/twitter-roberta-base-sentiment-latest'; SQL @@ -32,7 +35,7 @@ RSpec.describe MigrateSentimentClassificationResultFormat do it "migrates emotion classifications correctly" do emotion_result = connection.execute(<<~SQL).first - SELECT * FROM classification_results + SELECT * FROM classification_results WHERE model_used = 'j-hartmann/emotion-english-distilroberta-base'; SQL diff --git a/spec/db/migrate/20250125162658_fix_broken_open_ai_embeddings_config_spec.rb b/spec/db/migrate/20250125162658_fix_broken_open_ai_embeddings_config_spec.rb index 1c621a7b..5ba29227 100644 --- a/spec/db/migrate/20250125162658_fix_broken_open_ai_embeddings_config_spec.rb +++ b/spec/db/migrate/20250125162658_fix_broken_open_ai_embeddings_config_spec.rb @@ -21,6 +21,8 @@ RSpec.describe FixBrokenOpenAiEmbeddingsConfig do ).first end + before { enable_current_plugin } + describe "#up" do context "when embeddings are already configured" do fab!(:embedding_definition) diff --git a/spec/db/migrate/20250127145305_clean_unused_embedding_search_indexes_spec.rb b/spec/db/migrate/20250127145305_clean_unused_embedding_search_indexes_spec.rb index 2278692f..d89a91d0 100644 --- a/spec/db/migrate/20250127145305_clean_unused_embedding_search_indexes_spec.rb +++ b/spec/db/migrate/20250127145305_clean_unused_embedding_search_indexes_spec.rb @@ -8,6 +8,8 @@ require Rails.root.join( RSpec.describe CleanUnusedEmbeddingSearchIndexes do let(:connection) { ActiveRecord::Base.connection } + before { enable_current_plugin } + describe "#up" do before do # Copied from 20241008054440_create_binary_indexes_for_embeddings diff --git a/spec/jobs/regular/detect_translate_post_spec.rb b/spec/jobs/regular/detect_translate_post_spec.rb index 570b7093..6dc60ba7 100644 --- a/spec/jobs/regular/detect_translate_post_spec.rb +++ b/spec/jobs/regular/detect_translate_post_spec.rb @@ -7,7 +7,7 @@ describe Jobs::DetectTranslatePost do let(:locales) { %w[en ja] } before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin Fabricate(:fake_model).tap do |fake_llm| SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}") end diff --git a/spec/jobs/regular/detect_translate_topic_spec.rb b/spec/jobs/regular/detect_translate_topic_spec.rb index 80e5b8f1..e867c9e0 100644 --- a/spec/jobs/regular/detect_translate_topic_spec.rb +++ b/spec/jobs/regular/detect_translate_topic_spec.rb @@ -7,7 +7,7 @@ describe Jobs::DetectTranslateTopic do let(:locales) { %w[en ja] } before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin Fabricate(:fake_model).tap do |fake_llm| SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}") end @@ -32,7 +32,6 @@ describe Jobs::DetectTranslateTopic do end it "detects locale" do - SiteSetting.discourse_ai_enabled = true allow(DiscourseAi::Translation::TopicLocaleDetector).to receive(:detect_locale).with( topic, ).and_return("zh_CN") diff --git a/spec/jobs/regular/digest_rag_upload_spec.rb b/spec/jobs/regular/digest_rag_upload_spec.rb index d3b1ed58..75e4c055 100644 --- a/spec/jobs/regular/digest_rag_upload_spec.rb +++ b/spec/jobs/regular/digest_rag_upload_spec.rb @@ -20,6 +20,8 @@ RSpec.describe Jobs::DigestRagUpload do end before do + enable_current_plugin + SiteSetting.ai_embeddings_selected_model = cloudflare_embedding_def.id SiteSetting.ai_embeddings_enabled = true SiteSetting.authorized_extensions = "txt" diff --git a/spec/jobs/regular/fast_track_topic_gist_spec.rb b/spec/jobs/regular/fast_track_topic_gist_spec.rb index ef7dbc47..82ab2c82 100644 --- a/spec/jobs/regular/fast_track_topic_gist_spec.rb +++ b/spec/jobs/regular/fast_track_topic_gist_spec.rb @@ -7,6 +7,7 @@ RSpec.describe Jobs::FastTrackTopicGist do fab!(:post_2) { Fabricate(:post, topic: topic_1, post_number: 2) } before do + enable_current_plugin assign_fake_provider_to(:ai_summarization_model) SiteSetting.ai_summarization_enabled = true SiteSetting.ai_summary_gists_enabled = true diff --git a/spec/jobs/regular/generate_inferred_concepts_spec.rb b/spec/jobs/regular/generate_inferred_concepts_spec.rb index e7b53831..fc809518 100644 --- a/spec/jobs/regular/generate_inferred_concepts_spec.rb +++ b/spec/jobs/regular/generate_inferred_concepts_spec.rb @@ -5,7 +5,10 @@ RSpec.describe Jobs::GenerateInferredConcepts do fab!(:post) fab!(:concept) { Fabricate(:inferred_concept, name: "programming") } - before { SiteSetting.inferred_concepts_enabled = true } + before do + enable_current_plugin + SiteSetting.inferred_concepts_enabled = true + end describe "#execute" do it "does nothing with blank item_ids" do diff --git a/spec/jobs/regular/generate_rag_embeddings_spec.rb b/spec/jobs/regular/generate_rag_embeddings_spec.rb index 10558745..94533ea9 100644 --- a/spec/jobs/regular/generate_rag_embeddings_spec.rb +++ b/spec/jobs/regular/generate_rag_embeddings_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe Jobs::GenerateRagEmbeddings do + before { enable_current_plugin } + describe "#execute" do fab!(:vector_def) { Fabricate(:embedding_definition) } diff --git a/spec/jobs/regular/localize_categories_spec.rb b/spec/jobs/regular/localize_categories_spec.rb index bbcdfc6a..f0d5e886 100644 --- a/spec/jobs/regular/localize_categories_spec.rb +++ b/spec/jobs/regular/localize_categories_spec.rb @@ -10,7 +10,7 @@ describe Jobs::LocalizeCategories do end before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin Fabricate(:fake_model).tap do |fake_llm| SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}") end diff --git a/spec/jobs/regular/localize_posts_spec.rb b/spec/jobs/regular/localize_posts_spec.rb index 92aae58d..8c54839c 100644 --- a/spec/jobs/regular/localize_posts_spec.rb +++ b/spec/jobs/regular/localize_posts_spec.rb @@ -7,7 +7,7 @@ describe Jobs::LocalizePosts do let(:locales) { %w[en ja de] } before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin Fabricate(:fake_model).tap do |fake_llm| SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}") end diff --git a/spec/jobs/regular/localize_topics_spec.rb b/spec/jobs/regular/localize_topics_spec.rb index f091b915..d2f34add 100644 --- a/spec/jobs/regular/localize_topics_spec.rb +++ b/spec/jobs/regular/localize_topics_spec.rb @@ -7,7 +7,7 @@ describe Jobs::LocalizeTopics do let(:locales) { %w[en ja de] } before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin Fabricate(:fake_model).tap do |fake_llm| SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}") end diff --git a/spec/jobs/regular/manage_embedding_def_search_index_spec.rb b/spec/jobs/regular/manage_embedding_def_search_index_spec.rb index 21c9bb6d..21d3c275 100644 --- a/spec/jobs/regular/manage_embedding_def_search_index_spec.rb +++ b/spec/jobs/regular/manage_embedding_def_search_index_spec.rb @@ -3,6 +3,8 @@ RSpec.describe Jobs::ManageEmbeddingDefSearchIndex do fab!(:embedding_definition) + before { enable_current_plugin } + describe "#execute" do context "when there is no embedding def" do it "does nothing" do diff --git a/spec/jobs/regular/stream_composer_helper_spec.rb b/spec/jobs/regular/stream_composer_helper_spec.rb index 350f758f..e322254c 100644 --- a/spec/jobs/regular/stream_composer_helper_spec.rb +++ b/spec/jobs/regular/stream_composer_helper_spec.rb @@ -3,7 +3,10 @@ RSpec.describe Jobs::StreamComposerHelper do subject(:job) { described_class.new } - before { assign_fake_provider_to(:ai_helper_model) } + before do + enable_current_plugin + assign_fake_provider_to(:ai_helper_model) + end describe "#execute" do let!(:input) { "I liek to eet pie fur brakefast becuz it is delishus." } diff --git a/spec/jobs/regular/stream_discord_reply_spec.rb b/spec/jobs/regular/stream_discord_reply_spec.rb index 1543bb3f..7fb66ac5 100644 --- a/spec/jobs/regular/stream_discord_reply_spec.rb +++ b/spec/jobs/regular/stream_discord_reply_spec.rb @@ -17,6 +17,7 @@ RSpec.describe Jobs::StreamDiscordReply, type: :job do fab!(:persona) { Fabricate(:ai_persona, default_llm_id: llm_model.id) } before do + enable_current_plugin SiteSetting.ai_discord_search_enabled = true SiteSetting.ai_discord_search_mode = "persona" SiteSetting.ai_discord_search_persona = persona.id diff --git a/spec/jobs/regular/stream_discover_reply_spec.rb b/spec/jobs/regular/stream_discover_reply_spec.rb index 4736f03e..c1693c1d 100644 --- a/spec/jobs/regular/stream_discover_reply_spec.rb +++ b/spec/jobs/regular/stream_discover_reply_spec.rb @@ -3,6 +3,8 @@ RSpec.describe Jobs::StreamDiscoverReply do subject(:job) { described_class.new } + before { enable_current_plugin } + describe "#execute" do fab!(:user) fab!(:llm_model) diff --git a/spec/jobs/regular/stream_post_helper_spec.rb b/spec/jobs/regular/stream_post_helper_spec.rb index 06cb69d5..80b84890 100644 --- a/spec/jobs/regular/stream_post_helper_spec.rb +++ b/spec/jobs/regular/stream_post_helper_spec.rb @@ -3,7 +3,10 @@ RSpec.describe Jobs::StreamPostHelper do subject(:job) { described_class.new } - before { assign_fake_provider_to(:ai_helper_model) } + before do + enable_current_plugin + assign_fake_provider_to(:ai_helper_model) + end describe "#execute" do fab!(:topic) diff --git a/spec/jobs/regular/stream_topic_ai_summary_spec.rb b/spec/jobs/regular/stream_topic_ai_summary_spec.rb index 1591e701..f290af29 100644 --- a/spec/jobs/regular/stream_topic_ai_summary_spec.rb +++ b/spec/jobs/regular/stream_topic_ai_summary_spec.rb @@ -3,6 +3,8 @@ RSpec.describe Jobs::StreamTopicAiSummary do subject(:job) { described_class.new } + before { enable_current_plugin } + describe "#execute" do fab!(:topic) { Fabricate(:topic, highest_post_number: 2) } fab!(:post_1) { Fabricate(:post, topic: topic, post_number: 1) } diff --git a/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rb b/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rb index 31e96275..6fc1f56a 100644 --- a/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rb +++ b/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rb @@ -5,7 +5,7 @@ describe Jobs::CategoriesLocaleDetectionBackfill do subject(:job) { described_class.new } before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin Fabricate(:fake_model).tap do |fake_llm| SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}") end diff --git a/spec/jobs/scheduled/embeddings_backfill_spec.rb b/spec/jobs/scheduled/embeddings_backfill_spec.rb index dfb9b64a..822da388 100644 --- a/spec/jobs/scheduled/embeddings_backfill_spec.rb +++ b/spec/jobs/scheduled/embeddings_backfill_spec.rb @@ -24,6 +24,8 @@ RSpec.describe Jobs::EmbeddingsBackfill do fab!(:embedding_array) { Array.new(1024) { 1 } } before do + enable_current_plugin + SiteSetting.ai_embeddings_selected_model = vector_def.id SiteSetting.ai_embeddings_enabled = true SiteSetting.ai_embeddings_backfill_batch_size = 1 diff --git a/spec/jobs/scheduled/generate_concepts_from_popular_items_spec.rb b/spec/jobs/scheduled/generate_concepts_from_popular_items_spec.rb index 848a23ff..ae0b6fd7 100644 --- a/spec/jobs/scheduled/generate_concepts_from_popular_items_spec.rb +++ b/spec/jobs/scheduled/generate_concepts_from_popular_items_spec.rb @@ -5,6 +5,7 @@ RSpec.describe Jobs::GenerateConceptsFromPopularItems do fab!(:post) { Fabricate(:post, like_count: 8, post_number: 2) } before do + enable_current_plugin SiteSetting.inferred_concepts_enabled = true SiteSetting.inferred_concepts_daily_topics_limit = 20 SiteSetting.inferred_concepts_daily_posts_limit = 30 diff --git a/spec/jobs/scheduled/post_localization_backfill_spec.rb b/spec/jobs/scheduled/post_localization_backfill_spec.rb index f43d890d..7a21cc1f 100644 --- a/spec/jobs/scheduled/post_localization_backfill_spec.rb +++ b/spec/jobs/scheduled/post_localization_backfill_spec.rb @@ -2,13 +2,13 @@ describe Jobs::PostLocalizationBackfill do before do + enable_current_plugin SiteSetting.ai_translation_backfill_hourly_rate = 100 SiteSetting.content_localization_supported_locales = "en" Fabricate(:fake_model).tap do |fake_llm| SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}") end SiteSetting.ai_translation_enabled = true - SiteSetting.discourse_ai_enabled = true end it "does not enqueue post translation when translator disabled" do @@ -36,7 +36,6 @@ describe Jobs::PostLocalizationBackfill do end it "does not enqueue post translation if backfill limit is set to 0" do - SiteSetting.discourse_ai_enabled = true SiteSetting.ai_translation_enabled = true SiteSetting.ai_translation_backfill_hourly_rate = 0 @@ -46,7 +45,6 @@ describe Jobs::PostLocalizationBackfill do end it "enqueues post translation with correct limit" do - SiteSetting.discourse_ai_enabled = true SiteSetting.ai_translation_enabled = true SiteSetting.ai_translation_backfill_hourly_rate = 100 diff --git a/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rb b/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rb index dfbc46f9..926fa461 100644 --- a/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rb +++ b/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rb @@ -5,7 +5,7 @@ describe Jobs::PostsLocaleDetectionBackfill do subject(:job) { described_class.new } before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin Fabricate(:fake_model).tap do |fake_llm| SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}") end diff --git a/spec/jobs/scheduled/remove_orphaned_embeddings_spec.rb b/spec/jobs/scheduled/remove_orphaned_embeddings_spec.rb index 1ecee441..3cccca10 100644 --- a/spec/jobs/scheduled/remove_orphaned_embeddings_spec.rb +++ b/spec/jobs/scheduled/remove_orphaned_embeddings_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe Jobs::RemoveOrphanedEmbeddings do + before { enable_current_plugin } + describe "#execute" do fab!(:embedding_definition) fab!(:embedding_definition_2) { Fabricate(:embedding_definition) } diff --git a/spec/jobs/scheduled/sentiment_backfill_spec.rb b/spec/jobs/scheduled/sentiment_backfill_spec.rb index 05a2084c..878b3425 100644 --- a/spec/jobs/scheduled/sentiment_backfill_spec.rb +++ b/spec/jobs/scheduled/sentiment_backfill_spec.rb @@ -3,6 +3,8 @@ require_relative "../../support/sentiment_inference_stubs" RSpec.describe Jobs::SentimentBackfill do + before { enable_current_plugin } + describe "#execute" do fab!(:post) diff --git a/spec/jobs/scheduled/summaries_backfill_spec.rb b/spec/jobs/scheduled/summaries_backfill_spec.rb index ccf23b06..c3bdf415 100644 --- a/spec/jobs/scheduled/summaries_backfill_spec.rb +++ b/spec/jobs/scheduled/summaries_backfill_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Jobs::SummariesBackfill do let(:intervals) { 12 } # budget is split into intervals. Job runs every five minutes. before do + enable_current_plugin assign_fake_provider_to(:ai_summarization_model) SiteSetting.ai_summarization_enabled = true SiteSetting.ai_summary_backfill_maximum_topics_per_hour = limit diff --git a/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rb b/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rb index 92488331..88f27217 100644 --- a/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rb +++ b/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rb @@ -5,7 +5,7 @@ describe Jobs::TopicsLocaleDetectionBackfill do subject(:job) { described_class.new } before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin Fabricate(:fake_model).tap do |fake_llm| SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}") end diff --git a/spec/jobs/shared_conversation_adjust_upload_security_spec.rb b/spec/jobs/shared_conversation_adjust_upload_security_spec.rb index 5ad50f38..377ffe95 100644 --- a/spec/jobs/shared_conversation_adjust_upload_security_spec.rb +++ b/spec/jobs/shared_conversation_adjust_upload_security_spec.rb @@ -6,13 +6,14 @@ RSpec.describe Jobs::SharedConversationAdjustUploadSecurity do fab!(:claude_2) { Fabricate(:llm_model, name: "claude-2") } fab!(:bot_user) do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin toggle_enabled_bots(bots: [claude_2]) SiteSetting.ai_bot_enabled = true SiteSetting.ai_bot_allowed_groups = "10" SiteSetting.ai_bot_public_sharing_allowed_groups = "10" claude_2.reload.user end + fab!(:user) fab!(:topic) { Fabricate(:private_message_topic, user: user, recipient: bot_user) } fab!(:post_1) { Fabricate(:post, topic: topic, user: bot_user) } @@ -23,6 +24,8 @@ RSpec.describe Jobs::SharedConversationAdjustUploadSecurity do described_class.new.execute(params) end + before { enable_current_plugin } + context "when conversation is created" do let(:params) { { conversation_id: conversation.id } } diff --git a/spec/lib/completions/anthropic_message_processor_spec.rb b/spec/lib/completions/anthropic_message_processor_spec.rb index 94e5a0ee..f6594d8d 100644 --- a/spec/lib/completions/anthropic_message_processor_spec.rb +++ b/spec/lib/completions/anthropic_message_processor_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true describe DiscourseAi::Completions::AnthropicMessageProcessor do + before { enable_current_plugin } + it "correctly handles and combines partial thinking chunks into complete thinking objects" do processor = DiscourseAi::Completions::AnthropicMessageProcessor.new( diff --git a/spec/lib/completions/cancel_manager_spec.rb b/spec/lib/completions/cancel_manager_spec.rb index d57baa6b..a1f53183 100644 --- a/spec/lib/completions/cancel_manager_spec.rb +++ b/spec/lib/completions/cancel_manager_spec.rb @@ -3,7 +3,10 @@ describe DiscourseAi::Completions::CancelManager do fab!(:model) { Fabricate(:anthropic_model, name: "test-model") } - before { WebMock.allow_net_connect! } + before do + enable_current_plugin + WebMock.allow_net_connect! + end it "can stop monitoring for cancellation cleanly" do cancel_manager = DiscourseAi::Completions::CancelManager.new diff --git a/spec/lib/completions/dialects/chat_gpt_spec.rb b/spec/lib/completions/dialects/chat_gpt_spec.rb index 34c3832f..981369c5 100644 --- a/spec/lib/completions/dialects/chat_gpt_spec.rb +++ b/spec/lib/completions/dialects/chat_gpt_spec.rb @@ -6,6 +6,8 @@ RSpec.describe DiscourseAi::Completions::Dialects::ChatGpt do fab!(:llm_model) { Fabricate(:llm_model, max_prompt_tokens: 8192) } let(:context) { DialectContext.new(described_class, llm_model) } + before { enable_current_plugin } + describe "#translate" do it "translates a prompt written in our generic format to the ChatGPT format" do open_ai_version = [ diff --git a/spec/lib/completions/dialects/claude_spec.rb b/spec/lib/completions/dialects/claude_spec.rb index 0c9a9590..527351db 100644 --- a/spec/lib/completions/dialects/claude_spec.rb +++ b/spec/lib/completions/dialects/claude_spec.rb @@ -3,9 +3,9 @@ RSpec.describe DiscourseAi::Completions::Dialects::Claude do fab!(:llm_model) { Fabricate(:anthropic_model, name: "claude-3-opus") } - let :opus_dialect_klass do - DiscourseAi::Completions::Dialects::Dialect.dialect_for(llm_model) - end + let(:opus_dialect_klass) { DiscourseAi::Completions::Dialects::Dialect.dialect_for(llm_model) } + + before { enable_current_plugin } describe "#translate" do it "can insert OKs to make stuff interleve properly" do diff --git a/spec/lib/completions/dialects/dialect_spec.rb b/spec/lib/completions/dialects/dialect_spec.rb index 4a3a766d..7e3db718 100644 --- a/spec/lib/completions/dialects/dialect_spec.rb +++ b/spec/lib/completions/dialects/dialect_spec.rb @@ -27,6 +27,8 @@ end RSpec.describe DiscourseAi::Completions::Dialects::Dialect do fab!(:llm_model) + before { enable_current_plugin } + describe "#translate" do let(:five_token_msg) { "This represents five tokens." } let(:tools) do diff --git a/spec/lib/completions/dialects/gemini_spec.rb b/spec/lib/completions/dialects/gemini_spec.rb index c9ec3475..404e8b60 100644 --- a/spec/lib/completions/dialects/gemini_spec.rb +++ b/spec/lib/completions/dialects/gemini_spec.rb @@ -6,6 +6,8 @@ RSpec.describe DiscourseAi::Completions::Dialects::Gemini do fab!(:model) { Fabricate(:gemini_model) } let(:context) { DialectContext.new(described_class, model) } + before { enable_current_plugin } + describe "#translate" do it "translates a prompt written in our generic format to the Gemini format" do gemini_version = { diff --git a/spec/lib/completions/dialects/mistral_spec.rb b/spec/lib/completions/dialects/mistral_spec.rb index a929768b..b49ed257 100644 --- a/spec/lib/completions/dialects/mistral_spec.rb +++ b/spec/lib/completions/dialects/mistral_spec.rb @@ -11,6 +11,8 @@ RSpec.describe DiscourseAi::Completions::Dialects::Mistral do UploadCreator.new(image100x100, "image.jpg").create_for(Discourse.system_user.id) end + before { enable_current_plugin } + it "does not include user names" do prompt = DiscourseAi::Completions::Prompt.new( diff --git a/spec/lib/completions/dialects/nova_spec.rb b/spec/lib/completions/dialects/nova_spec.rb index aafbf6e4..ad4d3f5a 100644 --- a/spec/lib/completions/dialects/nova_spec.rb +++ b/spec/lib/completions/dialects/nova_spec.rb @@ -5,6 +5,8 @@ RSpec.describe DiscourseAi::Completions::Dialects::Nova do let(:nova_dialect_klass) { DiscourseAi::Completions::Dialects::Dialect.dialect_for(llm_model) } + before { enable_current_plugin } + it "finds the right dialect" do expect(nova_dialect_klass).to eq(DiscourseAi::Completions::Dialects::Nova) end diff --git a/spec/lib/completions/dialects/ollama_spec.rb b/spec/lib/completions/dialects/ollama_spec.rb index efd959d1..e0a2e8e1 100644 --- a/spec/lib/completions/dialects/ollama_spec.rb +++ b/spec/lib/completions/dialects/ollama_spec.rb @@ -7,6 +7,8 @@ RSpec.describe DiscourseAi::Completions::Dialects::Ollama do let(:context) { DialectContext.new(described_class, model) } let(:dialect_class) { DiscourseAi::Completions::Dialects::Dialect.dialect_for(model) } + before { enable_current_plugin } + describe "#translate" do context "when native tool support is enabled" do it "translates a prompt written in our generic format to the Ollama format" do diff --git a/spec/lib/completions/dialects/ollama_tools_spec.rb b/spec/lib/completions/dialects/ollama_tools_spec.rb index 6c4dd4fa..18d07229 100644 --- a/spec/lib/completions/dialects/ollama_tools_spec.rb +++ b/spec/lib/completions/dialects/ollama_tools_spec.rb @@ -3,6 +3,8 @@ require_relative "dialect_context" RSpec.describe DiscourseAi::Completions::Dialects::OllamaTools do + before { enable_current_plugin } + describe "#translated_tools" do it "translates a tool from our generic format to the Ollama format" do tool = { diff --git a/spec/lib/completions/dialects/open_ai_compatible_spec.rb b/spec/lib/completions/dialects/open_ai_compatible_spec.rb index 185a97e3..1e66b6eb 100644 --- a/spec/lib/completions/dialects/open_ai_compatible_spec.rb +++ b/spec/lib/completions/dialects/open_ai_compatible_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::Completions::Dialects::OpenAiCompatible do + before { enable_current_plugin } + context "when system prompts are disabled" do fab!(:model) do Fabricate(:vllm_model, vision_enabled: true, provider_params: { disable_system_prompt: true }) diff --git a/spec/lib/completions/endpoints/anthropic_spec.rb b/spec/lib/completions/endpoints/anthropic_spec.rb index 8a40c213..a454fcf2 100644 --- a/spec/lib/completions/endpoints/anthropic_spec.rb +++ b/spec/lib/completions/endpoints/anthropic_spec.rb @@ -47,6 +47,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Anthropic do prompt_with_tools end + before { enable_current_plugin } + it "does not eat spaces with tool calls" do body = <<~STRING event: message_start diff --git a/spec/lib/completions/endpoints/aws_bedrock_spec.rb b/spec/lib/completions/endpoints/aws_bedrock_spec.rb index 70bf9364..d75c8d5d 100644 --- a/spec/lib/completions/endpoints/aws_bedrock_spec.rb +++ b/spec/lib/completions/endpoints/aws_bedrock_spec.rb @@ -26,6 +26,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do Aws::EventStream::Encoder.new.encode(aws_message) end + before { enable_current_plugin } + it "should provide accurate max token count" do prompt = DiscourseAi::Completions::Prompt.new("hello") dialect = DiscourseAi::Completions::Dialects::Claude.new(prompt, model) diff --git a/spec/lib/completions/endpoints/cohere_spec.rb b/spec/lib/completions/endpoints/cohere_spec.rb index c4fb06b6..43e8ec61 100644 --- a/spec/lib/completions/endpoints/cohere_spec.rb +++ b/spec/lib/completions/endpoints/cohere_spec.rb @@ -58,6 +58,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Cohere do prompt end + before { enable_current_plugin } + it "is able to trigger a tool" do body = (<<~TEXT).strip {"is_finished":false,"event_type":"stream-start","generation_id":"1648206e-1fe4-4bb6-90cf-360dd55f575b"} diff --git a/spec/lib/completions/endpoints/gemini_spec.rb b/spec/lib/completions/endpoints/gemini_spec.rb index 3a6543ea..2496acb5 100644 --- a/spec/lib/completions/endpoints/gemini_spec.rb +++ b/spec/lib/completions/endpoints/gemini_spec.rb @@ -153,6 +153,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini do } end + before { enable_current_plugin } + it "correctly configures thinking when enabled" do model.update!(provider_params: { enable_thinking: "true", thinking_tokens: "10000" }) diff --git a/spec/lib/completions/endpoints/hugging_face_spec.rb b/spec/lib/completions/endpoints/hugging_face_spec.rb index df1ee481..56ade1aa 100644 --- a/spec/lib/completions/endpoints/hugging_face_spec.rb +++ b/spec/lib/completions/endpoints/hugging_face_spec.rb @@ -95,6 +95,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::HuggingFace do ) end + before { enable_current_plugin } + describe "#perform_completion!" do context "when using regular mode" do context "with simple prompts" do diff --git a/spec/lib/completions/endpoints/nova_spec.rb b/spec/lib/completions/endpoints/nova_spec.rb index aa2727f7..751ccf3c 100644 --- a/spec/lib/completions/endpoints/nova_spec.rb +++ b/spec/lib/completions/endpoints/nova_spec.rb @@ -27,6 +27,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do Aws::EventStream::Encoder.new.encode(aws_message) end + before { enable_current_plugin } + it "should be able to make a simple request" do proxy = DiscourseAi::Completions::Llm.proxy("custom:#{nova_model.id}") diff --git a/spec/lib/completions/endpoints/ollama_spec.rb b/spec/lib/completions/endpoints/ollama_spec.rb index 4f458283..3531a4a1 100644 --- a/spec/lib/completions/endpoints/ollama_spec.rb +++ b/spec/lib/completions/endpoints/ollama_spec.rb @@ -135,6 +135,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Ollama do EndpointsCompliance.new(self, endpoint, DiscourseAi::Completions::Dialects::Ollama, user) end + before { enable_current_plugin } + describe "#perform_completion!" do context "when using regular mode" do it "completes a trivial prompt and logs the response" do diff --git a/spec/lib/completions/endpoints/open_ai_responses_api_spec.rb b/spec/lib/completions/endpoints/open_ai_responses_api_spec.rb index f426da29..41a10351 100644 --- a/spec/lib/completions/endpoints/open_ai_responses_api_spec.rb +++ b/spec/lib/completions/endpoints/open_ai_responses_api_spec.rb @@ -30,6 +30,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenAi do prompt end + before { enable_current_plugin } + it "can perform simple streaming completion" do response_payload = <<~TEXT event: response.created diff --git a/spec/lib/completions/endpoints/open_ai_spec.rb b/spec/lib/completions/endpoints/open_ai_spec.rb index cd95476d..403f281b 100644 --- a/spec/lib/completions/endpoints/open_ai_spec.rb +++ b/spec/lib/completions/endpoints/open_ai_spec.rb @@ -174,6 +174,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenAi do UploadCreator.new(image100x100, "image.jpg").create_for(Discourse.system_user.id) end + before { enable_current_plugin } + describe "max tokens for reasoning models" do it "uses max_completion_tokens for reasoning models" do model.update!(name: "o3-mini", max_output_tokens: 999) diff --git a/spec/lib/completions/endpoints/open_router_spec.rb b/spec/lib/completions/endpoints/open_router_spec.rb index 8beb48ac..628c6f27 100644 --- a/spec/lib/completions/endpoints/open_router_spec.rb +++ b/spec/lib/completions/endpoints/open_router_spec.rb @@ -6,6 +6,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenRouter do subject(:endpoint) { described_class.new(open_router_model) } + before { enable_current_plugin } + it "supports provider quantization and order selection" do open_router_model.provider_params["provider_quantizations"] = "int8,int16" open_router_model.provider_params["provider_order"] = "Google, Amazon Bedrock" diff --git a/spec/lib/completions/endpoints/samba_nova_spec.rb b/spec/lib/completions/endpoints/samba_nova_spec.rb index 83839bf4..bacff00d 100644 --- a/spec/lib/completions/endpoints/samba_nova_spec.rb +++ b/spec/lib/completions/endpoints/samba_nova_spec.rb @@ -4,6 +4,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::SambaNova do fab!(:llm_model) { Fabricate(:samba_nova_model) } let(:llm) { llm_model.to_llm } + before { enable_current_plugin } + it "can stream completions" do body = <<~PARTS data: {"id": "4c5e4a44-e847-467d-b9cd-d2f6530678cd", "object": "chat.completion.chunk", "created": 1721336361, "model": "llama3-8b", "system_fingerprint": "fastcoe", "choices": [{"index": 0, "delta": {"content": "I am a bot"}, "logprobs": null, "finish_reason": null}]} diff --git a/spec/lib/completions/endpoints/vllm_spec.rb b/spec/lib/completions/endpoints/vllm_spec.rb index 824bcbe0..c91ce067 100644 --- a/spec/lib/completions/endpoints/vllm_spec.rb +++ b/spec/lib/completions/endpoints/vllm_spec.rb @@ -88,6 +88,8 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Vllm do let(:request_body) { model.default_options.merge(messages: prompt).to_json } let(:stream_request_body) { model.default_options.merge(messages: prompt, stream: true).to_json } + before { enable_current_plugin } + describe "tool support" do it "is able to invoke XML tools correctly" do xml = <<~XML diff --git a/spec/lib/completions/json_stream_decoder_spec.rb b/spec/lib/completions/json_stream_decoder_spec.rb index 831bad6f..5f0a92ff 100644 --- a/spec/lib/completions/json_stream_decoder_spec.rb +++ b/spec/lib/completions/json_stream_decoder_spec.rb @@ -3,6 +3,8 @@ describe DiscourseAi::Completions::JsonStreamDecoder do let(:decoder) { DiscourseAi::Completions::JsonStreamDecoder.new } + before { enable_current_plugin } + it "should be able to parse simple messages" do result = decoder << "data: #{{ hello: "world" }.to_json}" expect(result).to eq([{ hello: "world" }]) diff --git a/spec/lib/completions/llm_spec.rb b/spec/lib/completions/llm_spec.rb index 4f22c16f..ccc2c888 100644 --- a/spec/lib/completions/llm_spec.rb +++ b/spec/lib/completions/llm_spec.rb @@ -13,6 +13,8 @@ RSpec.describe DiscourseAi::Completions::Llm do fab!(:user) fab!(:model) { Fabricate(:llm_model) } + before { enable_current_plugin } + describe ".proxy" do it "raises an exception when we can't proxy the model" do fake_model = "unknown:unknown_v2" diff --git a/spec/lib/completions/prompt_messages_builder_spec.rb b/spec/lib/completions/prompt_messages_builder_spec.rb index 9da48ecb..229b8b13 100644 --- a/spec/lib/completions/prompt_messages_builder_spec.rb +++ b/spec/lib/completions/prompt_messages_builder_spec.rb @@ -14,6 +14,8 @@ describe DiscourseAi::Completions::PromptMessagesBuilder do Fabricate(:upload, user: user, original_filename: "image.png", extension: "png") end + before { enable_current_plugin } + it "correctly merges user messages with uploads" do builder.push(type: :user, content: "Hello", id: "Alice", upload_ids: [1]) builder.push(type: :user, content: "World", id: "Bob", upload_ids: [2]) diff --git a/spec/lib/completions/prompt_spec.rb b/spec/lib/completions/prompt_spec.rb index dafae3bd..4dbd73d2 100644 --- a/spec/lib/completions/prompt_spec.rb +++ b/spec/lib/completions/prompt_spec.rb @@ -8,6 +8,8 @@ RSpec.describe DiscourseAi::Completions::Prompt do let(:username) { "username1" } let(:image100x100) { plugin_file_from_fixtures("100x100.jpg") } + before { enable_current_plugin } + describe ".new" do it "raises for invalid attributes" do expect { described_class.new("a bot", messages: {}) }.to raise_error(ArgumentError) diff --git a/spec/lib/completions/structured_output_spec.rb b/spec/lib/completions/structured_output_spec.rb index 05322567..ef8e687e 100644 --- a/spec/lib/completions/structured_output_spec.rb +++ b/spec/lib/completions/structured_output_spec.rb @@ -26,6 +26,8 @@ RSpec.describe DiscourseAi::Completions::StructuredOutput do ) end + before { enable_current_plugin } + describe "Parsing structured output on the fly" do it "acts as a buffer for an streamed JSON" do chunks = [ diff --git a/spec/lib/completions/tool_definition_spec.rb b/spec/lib/completions/tool_definition_spec.rb index 699614fc..005df8ce 100644 --- a/spec/lib/completions/tool_definition_spec.rb +++ b/spec/lib/completions/tool_definition_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::Completions::ToolDefinition do + before { enable_current_plugin } + # Test case 1: Basic tool definition creation describe "#initialize" do it "creates a tool with name, description and parameters" do diff --git a/spec/lib/completions/upload_encoder_spec.rb b/spec/lib/completions/upload_encoder_spec.rb index d0434630..be1c9f9b 100644 --- a/spec/lib/completions/upload_encoder_spec.rb +++ b/spec/lib/completions/upload_encoder_spec.rb @@ -5,6 +5,8 @@ RSpec.describe DiscourseAi::Completions::UploadEncoder do let(:jpg) { plugin_file_from_fixtures("1x1.jpg") } let(:webp) { plugin_file_from_fixtures("1x1.webp") } + before { enable_current_plugin } + it "automatically converts gifs to pngs" do upload = UploadCreator.new(gif, "1x1.gif").create_for(Discourse.system_user.id) encoded = described_class.encode(upload_ids: [upload.id], max_pixels: 1_048_576) diff --git a/spec/lib/completions/xml_tag_stripper_spec.rb b/spec/lib/completions/xml_tag_stripper_spec.rb index 62275ffc..a7eabef2 100644 --- a/spec/lib/completions/xml_tag_stripper_spec.rb +++ b/spec/lib/completions/xml_tag_stripper_spec.rb @@ -3,6 +3,8 @@ describe DiscourseAi::Completions::PromptMessagesBuilder do let(:tag_stripper) { DiscourseAi::Completions::XmlTagStripper.new(%w[thinking results]) } + before { enable_current_plugin } + it "should strip tags correctly in simple cases" do result = tag_stripper << "xhello 768) + hash_including("dimensions" => 768), ) end end - + context "with LlmModel quotas" do before do # Create a quota for the model diff --git a/spec/lib/utils/best_effort_json_parser_spec.rb b/spec/lib/utils/best_effort_json_parser_spec.rb index 6fb85cf8..002d8586 100644 --- a/spec/lib/utils/best_effort_json_parser_spec.rb +++ b/spec/lib/utils/best_effort_json_parser_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::Utils::BestEffortJsonParser do + before { enable_current_plugin } + describe ".extract_key" do context "with string type schema" do let(:schema_type) { "string" } diff --git a/spec/lib/utils/diff_utils/hunk_diff_spec.rb b/spec/lib/utils/diff_utils/hunk_diff_spec.rb index e6f06789..de400a98 100644 --- a/spec/lib/utils/diff_utils/hunk_diff_spec.rb +++ b/spec/lib/utils/diff_utils/hunk_diff_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::Utils::DiffUtils::HunkDiff do + before { enable_current_plugin } + describe ".apply_hunk" do subject(:apply_hunk) { described_class.apply(original_text, diff) } diff --git a/spec/lib/utils/diff_utils/safety_checker_spec.rb b/spec/lib/utils/diff_utils/safety_checker_spec.rb index 19a8a861..1806ad5f 100644 --- a/spec/lib/utils/diff_utils/safety_checker_spec.rb +++ b/spec/lib/utils/diff_utils/safety_checker_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::Utils::DiffUtils::SafetyChecker do + before { enable_current_plugin } + describe "#safe?" do subject { described_class.new(text).safe? } diff --git a/spec/lib/utils/diff_utils/simple_diff_spec.rb b/spec/lib/utils/diff_utils/simple_diff_spec.rb index fe54e20b..b9625def 100644 --- a/spec/lib/utils/diff_utils/simple_diff_spec.rb +++ b/spec/lib/utils/diff_utils/simple_diff_spec.rb @@ -3,6 +3,8 @@ RSpec.describe DiscourseAi::Utils::DiffUtils::SimpleDiff do subject { described_class } + before { enable_current_plugin } + describe ".apply" do it "raises error for nil inputs" do expect { subject.apply(nil, "search", "replace") }.to raise_error(ArgumentError) diff --git a/spec/lib/utils/dns_srv_spec.rb b/spec/lib/utils/dns_srv_spec.rb index b54e8ed6..7b58ad09 100644 --- a/spec/lib/utils/dns_srv_spec.rb +++ b/spec/lib/utils/dns_srv_spec.rb @@ -12,6 +12,8 @@ describe DiscourseAi::Utils::DnsSrv do ] end + before { enable_current_plugin } + context "when there are several servers with the same priority" do before do Resolv::DNS.any_instance.stubs(:getresources).returns(weighted_dns_results) diff --git a/spec/lib/utils/pdf_to_text_spec.rb b/spec/lib/utils/pdf_to_text_spec.rb index 77c639cd..4a526d51 100644 --- a/spec/lib/utils/pdf_to_text_spec.rb +++ b/spec/lib/utils/pdf_to_text_spec.rb @@ -5,7 +5,11 @@ RSpec.describe DiscourseAi::Utils::PdfToText do fab!(:user) let(:pdf) { plugin_file_from_fixtures("2-page.pdf", "rag") } let(:upload) { UploadCreator.new(pdf, "2-page.pdf").create_for(Discourse.system_user.id) } - before { SiteSetting.authorized_extensions = "pdf|png|jpg|jpeg" } + + before do + enable_current_plugin + SiteSetting.authorized_extensions = "pdf|png|jpg|jpeg" + end describe "#extract_text" do xit "extracts text from PDF pages" do diff --git a/spec/lib/utils/research/filter_spec.rb b/spec/lib/utils/research/filter_spec.rb index 66fb6e71..dd239cf6 100644 --- a/spec/lib/utils/research/filter_spec.rb +++ b/spec/lib/utils/research/filter_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true describe DiscourseAi::Utils::Research::Filter do + before { enable_current_plugin } + describe "integration tests" do before_all do SiteSetting.min_topic_title_length = 3 diff --git a/spec/lib/utils/research/llm_formatter_spec.rb b/spec/lib/utils/research/llm_formatter_spec.rb index edc10363..3021ccc7 100644 --- a/spec/lib/utils/research/llm_formatter_spec.rb +++ b/spec/lib/utils/research/llm_formatter_spec.rb @@ -7,6 +7,8 @@ describe DiscourseAi::Utils::Research::LlmFormatter do let(:tokenizer) { DiscourseAi::Tokenizer::OpenAiTokenizer } let(:filter) { DiscourseAi::Utils::Research::Filter.new("@#{user.username}") } + before { enable_current_plugin } + describe "#truncate_if_needed" do it "returns original content when under token limit" do formatter = diff --git a/spec/lib/utils/search_spec.rb b/spec/lib/utils/search_spec.rb index 561aac20..a61449b0 100644 --- a/spec/lib/utils/search_spec.rb +++ b/spec/lib/utils/search_spec.rb @@ -1,7 +1,11 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::Utils::Search do - before { SearchIndexer.enable } + before do + enable_current_plugin + SearchIndexer.enable + end + after { SearchIndexer.disable } fab!(:admin) diff --git a/spec/models/ai_artifact_key_value_spec.rb b/spec/models/ai_artifact_key_value_spec.rb index 551a2452..c93ed925 100644 --- a/spec/models/ai_artifact_key_value_spec.rb +++ b/spec/models/ai_artifact_key_value_spec.rb @@ -4,6 +4,8 @@ RSpec.describe AiArtifactKeyValue, type: :model do fab!(:user) fab!(:ai_artifact) + before { enable_current_plugin } + describe "#validate_max_keys_per_user_per_artifact" do before { SiteSetting.ai_artifact_max_keys_per_user_per_artifact = 2 } diff --git a/spec/models/ai_persona_multisite_spec.rb b/spec/models/ai_persona_multisite_spec.rb index 84670303..d2c15085 100644 --- a/spec/models/ai_persona_multisite_spec.rb +++ b/spec/models/ai_persona_multisite_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe AiPersona, type: :multisite do + before { enable_current_plugin } + it "is able to amend settings on system personas on multisite" do persona = AiPersona.find_by(name: "Designer") expect(persona.allow_personal_messages).to eq(true) diff --git a/spec/models/ai_persona_spec.rb b/spec/models/ai_persona_spec.rb index 0e6b9d13..d93dbf34 100644 --- a/spec/models/ai_persona_spec.rb +++ b/spec/models/ai_persona_spec.rb @@ -14,6 +14,8 @@ RSpec.describe AiPersona do fab!(:llm_model) fab!(:seeded_llm_model) { Fabricate(:llm_model, id: -1) } + before { enable_current_plugin } + it "validates context settings" do expect(basic_persona.valid?).to eq(true) diff --git a/spec/models/ai_tool_spec.rb b/spec/models/ai_tool_spec.rb index 96a3f667..9417f241 100644 --- a/spec/models/ai_tool_spec.rb +++ b/spec/models/ai_tool_spec.rb @@ -27,6 +27,8 @@ RSpec.describe AiTool do ) end + before { enable_current_plugin } + it "it can run a basic tool" do tool = create_tool diff --git a/spec/models/inferred_concept_spec.rb b/spec/models/inferred_concept_spec.rb index 0d9ebd6d..e74b8720 100644 --- a/spec/models/inferred_concept_spec.rb +++ b/spec/models/inferred_concept_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe InferredConcept do + before { enable_current_plugin } + describe "validations" do it "requires a name" do concept = InferredConcept.new diff --git a/spec/models/llm_model_spec.rb b/spec/models/llm_model_spec.rb index d06eb1c5..9395bc50 100644 --- a/spec/models/llm_model_spec.rb +++ b/spec/models/llm_model_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe LlmModel do + before { enable_current_plugin } + describe "api_key" do fab!(:llm_model) { Fabricate(:seeded_model) } diff --git a/spec/models/llm_quota_spec.rb b/spec/models/llm_quota_spec.rb index 038e614a..1a6db357 100644 --- a/spec/models/llm_quota_spec.rb +++ b/spec/models/llm_quota_spec.rb @@ -4,7 +4,10 @@ RSpec.describe LlmQuota do fab!(:user) fab!(:llm_model) - before { group.add(user) } + before do + enable_current_plugin + group.add(user) + end describe ".check_quotas!" do it "returns true when user is nil" do diff --git a/spec/models/llm_quota_usage_spec.rb b/spec/models/llm_quota_usage_spec.rb index 6c58d8d8..2516c0cc 100644 --- a/spec/models/llm_quota_usage_spec.rb +++ b/spec/models/llm_quota_usage_spec.rb @@ -16,6 +16,8 @@ RSpec.describe LlmQuotaUsage do ) end + before { enable_current_plugin } + describe ".find_or_create_for" do it "creates a new usage record if none exists" do freeze_time diff --git a/spec/models/model_accuracy_spec.rb b/spec/models/model_accuracy_spec.rb index 11d247b3..f10083b9 100644 --- a/spec/models/model_accuracy_spec.rb +++ b/spec/models/model_accuracy_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true describe ModelAccuracy do + before { enable_current_plugin } + describe "#calculate_accuracy" do let(:accuracy) { ModelAccuracy.new(model: "test_model", classification_type: "test") } diff --git a/spec/models/rag_document_fragment_spec.rb b/spec/models/rag_document_fragment_spec.rb index 58824c47..52305e78 100644 --- a/spec/models/rag_document_fragment_spec.rb +++ b/spec/models/rag_document_fragment_spec.rb @@ -7,6 +7,7 @@ RSpec.describe RagDocumentFragment do fab!(:vector_def) { Fabricate(:embedding_definition) } before do + enable_current_plugin SiteSetting.ai_embeddings_selected_model = vector_def.id SiteSetting.ai_embeddings_enabled = true end diff --git a/spec/models/reviewable_ai_chat_message_spec.rb b/spec/models/reviewable_ai_chat_message_spec.rb index 6069587e..57e38f1e 100644 --- a/spec/models/reviewable_ai_chat_message_spec.rb +++ b/spec/models/reviewable_ai_chat_message_spec.rb @@ -7,6 +7,8 @@ RSpec.describe ReviewableAiChatMessage, type: :model do fab!(:chat_message) { Fabricate(:chat_message, chat_channel: chat_channel, user: user) } fab!(:reviewable) { described_class.needs_review!(target: chat_message, created_by: moderator) } + before { enable_current_plugin } + it "agree_and_keep agrees with the flag and doesn't delete the message" do reviewable.perform(moderator, :agree_and_keep_message) diff --git a/spec/models/reviewable_ai_post_spec.rb b/spec/models/reviewable_ai_post_spec.rb index 4e2d04e8..659876de 100644 --- a/spec/models/reviewable_ai_post_spec.rb +++ b/spec/models/reviewable_ai_post_spec.rb @@ -3,6 +3,8 @@ describe ReviewableAiPost do fab!(:target) { Fabricate(:post) } + before { enable_current_plugin } + describe "#build_actions" do let(:guardian) { Guardian.new } diff --git a/spec/models/shared_ai_conversation_spec.rb b/spec/models/shared_ai_conversation_spec.rb index 80f9b306..996790d5 100644 --- a/spec/models/shared_ai_conversation_spec.rb +++ b/spec/models/shared_ai_conversation_spec.rb @@ -6,7 +6,7 @@ RSpec.describe SharedAiConversation, type: :model do fab!(:claude_2) { Fabricate(:llm_model, name: "claude-2") } before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin SiteSetting.ai_bot_enabled = true toggle_enabled_bots(bots: [claude_2]) end diff --git a/spec/models/user_option_spec.rb b/spec/models/user_option_spec.rb index 34121ab9..ab1c966d 100644 --- a/spec/models/user_option_spec.rb +++ b/spec/models/user_option_spec.rb @@ -9,6 +9,8 @@ RSpec.describe UserOption do end before do + enable_current_plugin + assign_fake_provider_to(:ai_helper_model) assign_fake_provider_to(:ai_helper_image_caption_model) SiteSetting.ai_helper_enabled = true diff --git a/spec/plugin_spec.rb b/spec/plugin_spec.rb index 9a69041f..85052c52 100644 --- a/spec/plugin_spec.rb +++ b/spec/plugin_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe Plugin::Instance do - before { SiteSetting.discourse_ai_enabled = true } + before { enable_current_plugin } describe "current_user_serializer#ai_helper_prompts" do fab!(:user) diff --git a/spec/reports/sentiment_analysis_spec.rb b/spec/reports/sentiment_analysis_spec.rb index d251877c..d0b28216 100644 --- a/spec/reports/sentiment_analysis_spec.rb +++ b/spec/reports/sentiment_analysis_spec.rb @@ -8,7 +8,10 @@ RSpec.describe DiscourseAi::Sentiment::SentimentAnalysisReport do fab!(:post_2) { Fabricate(:post, user: admin, topic: topic) } fab!(:classification_result) { Fabricate(:classification_result, target: post) } - before { SiteSetting.ai_sentiment_enabled = true } + before do + enable_current_plugin + SiteSetting.ai_sentiment_enabled = true + end it "contains the correct filters" do report = Report.find("sentiment_analysis") diff --git a/spec/requests/admin/ai_embeddings_controller_spec.rb b/spec/requests/admin/ai_embeddings_controller_spec.rb index d2aeb50f..5c86ccd0 100644 --- a/spec/requests/admin/ai_embeddings_controller_spec.rb +++ b/spec/requests/admin/ai_embeddings_controller_spec.rb @@ -3,8 +3,6 @@ RSpec.describe DiscourseAi::Admin::AiEmbeddingsController do fab!(:admin) - before { sign_in(admin) } - let(:valid_attrs) do { display_name: "Embedding config test", @@ -21,6 +19,11 @@ RSpec.describe DiscourseAi::Admin::AiEmbeddingsController do } end + before do + enable_current_plugin + sign_in(admin) + end + describe "POST #create" do context "with valid attrs" do it "creates a new embedding definition" do diff --git a/spec/requests/admin/ai_features_controller_spec.rb b/spec/requests/admin/ai_features_controller_spec.rb index f826e0bc..f2e96a38 100644 --- a/spec/requests/admin/ai_features_controller_spec.rb +++ b/spec/requests/admin/ai_features_controller_spec.rb @@ -9,9 +9,9 @@ RSpec.describe DiscourseAi::Admin::AiFeaturesController do fab!(:alternate_summarizer_persona) { Fabricate(:ai_persona) } before do + enable_current_plugin sign_in(admin) SiteSetting.ai_bot_enabled = true - SiteSetting.discourse_ai_enabled = true end describe "#index" do diff --git a/spec/requests/admin/ai_llm_quotas_controller_spec.rb b/spec/requests/admin/ai_llm_quotas_controller_spec.rb index b3bdb36d..ec7691d9 100644 --- a/spec/requests/admin/ai_llm_quotas_controller_spec.rb +++ b/spec/requests/admin/ai_llm_quotas_controller_spec.rb @@ -6,9 +6,9 @@ RSpec.describe DiscourseAi::Admin::AiLlmQuotasController do fab!(:llm_model) before do + enable_current_plugin sign_in(admin) SiteSetting.ai_bot_enabled = true - SiteSetting.discourse_ai_enabled = true end describe "#index" do diff --git a/spec/requests/admin/ai_llms_controller_spec.rb b/spec/requests/admin/ai_llms_controller_spec.rb index e2146727..f62abdec 100644 --- a/spec/requests/admin/ai_llms_controller_spec.rb +++ b/spec/requests/admin/ai_llms_controller_spec.rb @@ -4,6 +4,7 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController do fab!(:admin) before do + enable_current_plugin sign_in(admin) SiteSetting.ai_bot_enabled = true end diff --git a/spec/requests/admin/ai_personas_controller_spec.rb b/spec/requests/admin/ai_personas_controller_spec.rb index 2c66d9d4..88376a39 100644 --- a/spec/requests/admin/ai_personas_controller_spec.rb +++ b/spec/requests/admin/ai_personas_controller_spec.rb @@ -7,6 +7,7 @@ RSpec.describe DiscourseAi::Admin::AiPersonasController do fab!(:llm_model) before do + enable_current_plugin sign_in(admin) SiteSetting.ai_embeddings_selected_model = embedding_definition.id SiteSetting.ai_embeddings_enabled = true diff --git a/spec/requests/admin/ai_spam_controller_spec.rb b/spec/requests/admin/ai_spam_controller_spec.rb index ef5444ea..713fc407 100644 --- a/spec/requests/admin/ai_spam_controller_spec.rb +++ b/spec/requests/admin/ai_spam_controller_spec.rb @@ -7,6 +7,8 @@ RSpec.describe DiscourseAi::Admin::AiSpamController do fab!(:user) fab!(:llm_model) + before { enable_current_plugin } + describe "#update" do context "when logged in as admin" do before { sign_in(admin) } diff --git a/spec/requests/admin/ai_tools_controller_spec.rb b/spec/requests/admin/ai_tools_controller_spec.rb index 8e696ebd..618435c2 100644 --- a/spec/requests/admin/ai_tools_controller_spec.rb +++ b/spec/requests/admin/ai_tools_controller_spec.rb @@ -24,6 +24,7 @@ RSpec.describe DiscourseAi::Admin::AiToolsController do end before do + enable_current_plugin sign_in(admin) SiteSetting.ai_embeddings_enabled = true end diff --git a/spec/requests/admin/ai_usage_controller_spec.rb b/spec/requests/admin/ai_usage_controller_spec.rb index f411ed41..21003349 100644 --- a/spec/requests/admin/ai_usage_controller_spec.rb +++ b/spec/requests/admin/ai_usage_controller_spec.rb @@ -8,7 +8,7 @@ RSpec.describe DiscourseAi::Admin::AiUsageController do fab!(:llm_model) let(:usage_report_path) { "/admin/plugins/discourse-ai/ai-usage-report.json" } - before { SiteSetting.discourse_ai_enabled = true } + before { enable_current_plugin } context "when logged in as admin" do before { sign_in(admin) } diff --git a/spec/requests/admin/rag_document_fragments_controller_spec.rb b/spec/requests/admin/rag_document_fragments_controller_spec.rb index 24b4b387..190f3488 100644 --- a/spec/requests/admin/rag_document_fragments_controller_spec.rb +++ b/spec/requests/admin/rag_document_fragments_controller_spec.rb @@ -7,6 +7,7 @@ RSpec.describe DiscourseAi::Admin::RagDocumentFragmentsController do fab!(:vector_def) { Fabricate(:embedding_definition) } before do + enable_current_plugin sign_in(admin) SiteSetting.ai_embeddings_selected_model = vector_def.id SiteSetting.ai_embeddings_enabled = true diff --git a/spec/requests/admin/reviewable_controller_spec.rb b/spec/requests/admin/reviewable_controller_spec.rb index 5f620eb5..eee480db 100644 --- a/spec/requests/admin/reviewable_controller_spec.rb +++ b/spec/requests/admin/reviewable_controller_spec.rb @@ -29,6 +29,9 @@ RSpec.describe ReviewablesController do fab!(:ai_spam_log_missed) do AiSpamLog.create!(is_spam: false, post_id: post1.id, llm_model_id: llm_model.id) end + + before { enable_current_plugin } + # we amend the behavior with a custom filter so we need to confirm it works it "properly applies custom filter" do sign_in(admin) diff --git a/spec/requests/ai_bot/artifact_key_values_controller_spec.rb b/spec/requests/ai_bot/artifact_key_values_controller_spec.rb index add30f0f..e55bf913 100644 --- a/spec/requests/ai_bot/artifact_key_values_controller_spec.rb +++ b/spec/requests/ai_bot/artifact_key_values_controller_spec.rb @@ -12,7 +12,7 @@ RSpec.describe DiscourseAi::AiBot::ArtifactKeyValuesController do fab!(:private_artifact) { Fabricate(:ai_artifact, post: private_message_post) } before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin SiteSetting.ai_bot_enabled = true end diff --git a/spec/requests/ai_bot/artifacts_controller_spec.rb b/spec/requests/ai_bot/artifacts_controller_spec.rb index 1e6ec962..0f2037e0 100644 --- a/spec/requests/ai_bot/artifacts_controller_spec.rb +++ b/spec/requests/ai_bot/artifacts_controller_spec.rb @@ -23,7 +23,7 @@ RSpec.describe DiscourseAi::AiBot::ArtifactsController do end before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin SiteSetting.ai_artifact_security = "strict" end diff --git a/spec/requests/ai_bot/bot_controller_spec.rb b/spec/requests/ai_bot/bot_controller_spec.rb index 385c37e0..552caa8d 100644 --- a/spec/requests/ai_bot/bot_controller_spec.rb +++ b/spec/requests/ai_bot/bot_controller_spec.rb @@ -7,13 +7,13 @@ RSpec.describe DiscourseAi::AiBot::BotController do fab!(:pm_post2) { Fabricate(:post, topic: pm_topic) } fab!(:pm_post3) { Fabricate(:post, topic: pm_topic) } - before { sign_in(user) } + before do + enable_current_plugin + sign_in(user) + end describe "#show_debug_info" do - before do - SiteSetting.ai_bot_enabled = true - SiteSetting.discourse_ai_enabled = true - end + before { SiteSetting.ai_bot_enabled = true } it "returns a 403 when the user cannot debug the AI bot conversation" do get "/discourse-ai/ai-bot/post/#{pm_post.id}/show-debug-info" diff --git a/spec/requests/ai_bot/shared_ai_conversations_controller_spec.rb b/spec/requests/ai_bot/shared_ai_conversations_controller_spec.rb index d0a78a9c..f4c91bec 100644 --- a/spec/requests/ai_bot/shared_ai_conversations_controller_spec.rb +++ b/spec/requests/ai_bot/shared_ai_conversations_controller_spec.rb @@ -4,7 +4,7 @@ require "rails_helper" RSpec.describe DiscourseAi::AiBot::SharedAiConversationsController do before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin toggle_enabled_bots(bots: [claude_2]) SiteSetting.ai_bot_enabled = true SiteSetting.ai_bot_allowed_groups = "10" @@ -19,7 +19,7 @@ RSpec.describe DiscourseAi::AiBot::SharedAiConversationsController do fab!(:user_pm) { Fabricate(:private_message_topic, recipient: user) } fab!(:bot_user) do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin toggle_enabled_bots(bots: [claude_2]) SiteSetting.ai_bot_enabled = true SiteSetting.ai_bot_allowed_groups = "10" diff --git a/spec/requests/ai_bot/topic_serialization_spec.rb b/spec/requests/ai_bot/topic_serialization_spec.rb index dbaa0d76..8d111e5f 100644 --- a/spec/requests/ai_bot/topic_serialization_spec.rb +++ b/spec/requests/ai_bot/topic_serialization_spec.rb @@ -5,6 +5,7 @@ RSpec.describe "AI Bot Post Serializer" do fab!(:bot_user) { Fabricate(:user) } before do + enable_current_plugin SiteSetting.ai_bot_enabled = true sign_in(current_user) end diff --git a/spec/requests/ai_helper/assistant_controller_spec.rb b/spec/requests/ai_helper/assistant_controller_spec.rb index 47d5d7d7..e9a4e064 100644 --- a/spec/requests/ai_helper/assistant_controller_spec.rb +++ b/spec/requests/ai_helper/assistant_controller_spec.rb @@ -1,10 +1,14 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::AiHelper::AssistantController do - before { assign_fake_provider_to(:ai_helper_model) } fab!(:newuser) fab!(:user) { Fabricate(:user, refresh_auto_groups: true) } + before do + enable_current_plugin + assign_fake_provider_to(:ai_helper_model) + end + describe "#stream_suggestion" do before do Jobs.run_immediately! @@ -409,6 +413,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do # UploadReference records works @original_provider = SiteSetting.provider SiteSetting.provider = SiteSettings::DbProvider.new(SiteSetting) + enable_current_plugin setup_s3 stub_s3_store assign_fake_provider_to(:ai_helper_image_caption_model) diff --git a/spec/requests/discord/bot_controller_spec.rb b/spec/requests/discord/bot_controller_spec.rb index f791f25c..7d152508 100644 --- a/spec/requests/discord/bot_controller_spec.rb +++ b/spec/requests/discord/bot_controller_spec.rb @@ -10,6 +10,7 @@ RSpec.describe "DiscourseAi::Discord::BotController", type: :request do let(:headers) { { "X-Signature-Ed25519" => signature, "X-Signature-Timestamp" => timestamp } } before do + enable_current_plugin SiteSetting.ai_discord_app_public_key = public_key allow_any_instance_of(DiscourseAi::Discord::BotController).to receive( :verify_request!, diff --git a/spec/requests/embeddings/embeddings_controller_spec.rb b/spec/requests/embeddings/embeddings_controller_spec.rb index 0408aa37..5b7dc233 100644 --- a/spec/requests/embeddings/embeddings_controller_spec.rb +++ b/spec/requests/embeddings/embeddings_controller_spec.rb @@ -5,6 +5,7 @@ describe DiscourseAi::Embeddings::EmbeddingsController do fab!(:vector_def) { Fabricate(:open_ai_embedding_def) } before do + enable_current_plugin SiteSetting.min_search_term_length = 3 SiteSetting.ai_embeddings_selected_model = vector_def.id DiscourseAi::Embeddings::SemanticSearch.clear_cache_for("test") diff --git a/spec/requests/sentiment/sentiment_controller_spec.rb b/spec/requests/sentiment/sentiment_controller_spec.rb index 6d6a2225..2f4e98e6 100644 --- a/spec/requests/sentiment/sentiment_controller_spec.rb +++ b/spec/requests/sentiment/sentiment_controller_spec.rb @@ -10,6 +10,7 @@ RSpec.describe DiscourseAi::Sentiment::SentimentController do fab!(:classification_result) { Fabricate(:classification_result, target: post) } before do + enable_current_plugin SiteSetting.ai_sentiment_enabled = true sign_in(admin) end diff --git a/spec/requests/summarization/chat_summary_controller_spec.rb b/spec/requests/summarization/chat_summary_controller_spec.rb index f23c447e..08ed32e8 100644 --- a/spec/requests/summarization/chat_summary_controller_spec.rb +++ b/spec/requests/summarization/chat_summary_controller_spec.rb @@ -5,6 +5,8 @@ RSpec.describe DiscourseAi::Summarization::ChatSummaryController do fab!(:group) before do + enable_current_plugin + group.add(current_user) assign_fake_provider_to(:ai_summarization_model) diff --git a/spec/requests/summarization/summary_controller_spec.rb b/spec/requests/summarization/summary_controller_spec.rb index 5c051f3d..782c9988 100644 --- a/spec/requests/summarization/summary_controller_spec.rb +++ b/spec/requests/summarization/summary_controller_spec.rb @@ -7,6 +7,7 @@ RSpec.describe DiscourseAi::Summarization::SummaryController do fab!(:post_2) { Fabricate(:post, topic: topic, post_number: 2) } before do + enable_current_plugin assign_fake_provider_to(:ai_summarization_model) SiteSetting.ai_summarization_enabled = true end diff --git a/spec/requests/topic_spec.rb b/spec/requests/topic_spec.rb index 479ef02b..85acb3ba 100644 --- a/spec/requests/topic_spec.rb +++ b/spec/requests/topic_spec.rb @@ -8,6 +8,8 @@ describe ::TopicsController do fab!(:user) { Fabricate(:admin) } before do + enable_current_plugin + SiteSetting.ai_embeddings_semantic_related_topics_enabled = true SiteSetting.ai_embeddings_semantic_related_topics = 2 diff --git a/spec/serializers/ai_chat_channel_serializer_spec.rb b/spec/serializers/ai_chat_channel_serializer_spec.rb index 9680538f..a7f010fd 100644 --- a/spec/serializers/ai_chat_channel_serializer_spec.rb +++ b/spec/serializers/ai_chat_channel_serializer_spec.rb @@ -3,6 +3,8 @@ RSpec.describe AiChatChannelSerializer do fab!(:admin) + before { enable_current_plugin } + describe "#title" do context "when the channel is a DM" do fab!(:dm_channel) { Fabricate(:direct_message_channel) } diff --git a/spec/serializers/ai_features_persona_serializer_spec.rb b/spec/serializers/ai_features_persona_serializer_spec.rb index 07330895..ea1438be 100644 --- a/spec/serializers/ai_features_persona_serializer_spec.rb +++ b/spec/serializers/ai_features_persona_serializer_spec.rb @@ -6,6 +6,8 @@ RSpec.describe AiFeaturesPersonaSerializer do fab!(:group) fab!(:group_2) { Fabricate(:group) } + before { enable_current_plugin } + describe "serialized attributes" do before do ai_persona.allowed_group_ids = [group.id, group_2.id] diff --git a/spec/services/discourse_ai/persona_exporter_spec.rb b/spec/services/discourse_ai/persona_exporter_spec.rb index 3b2c8686..8b35cc56 100644 --- a/spec/services/discourse_ai/persona_exporter_spec.rb +++ b/spec/services/discourse_ai/persona_exporter_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::PersonaExporter do + before { enable_current_plugin } + describe "#export" do subject(:export_json) { JSON.parse(exporter.export) } diff --git a/spec/services/discourse_ai/persona_importer_spec.rb b/spec/services/discourse_ai/persona_importer_spec.rb index c6cbe3b1..4c2c0cb5 100644 --- a/spec/services/discourse_ai/persona_importer_spec.rb +++ b/spec/services/discourse_ai/persona_importer_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::PersonaImporter do + before { enable_current_plugin } + describe "#import!" do context "when importing a persona with a custom tool" do fab!(:ai_tool) { Fabricate(:ai_tool, name: "Giphy Searcher", tool_name: "giphy_search") } diff --git a/spec/services/discourse_ai/topic_summarization_spec.rb b/spec/services/discourse_ai/topic_summarization_spec.rb index 444cfc67..b8a77bb1 100644 --- a/spec/services/discourse_ai/topic_summarization_spec.rb +++ b/spec/services/discourse_ai/topic_summarization_spec.rb @@ -7,6 +7,7 @@ describe DiscourseAi::TopicSummarization do fab!(:post_2) { Fabricate(:post, topic: topic, post_number: 2) } before do + enable_current_plugin assign_fake_provider_to(:ai_summarization_model) SiteSetting.ai_summarization_enabled = true end diff --git a/spec/services/problem_check/ai_llm_status_spec.rb b/spec/services/problem_check/ai_llm_status_spec.rb index b92274eb..11ef7abc 100644 --- a/spec/services/problem_check/ai_llm_status_spec.rb +++ b/spec/services/problem_check/ai_llm_status_spec.rb @@ -37,7 +37,7 @@ RSpec.describe ProblemCheck::AiLlmStatus do end context "with discourse-ai plugin enabled for the site" do - before { SiteSetting.discourse_ai_enabled = true } + before { enable_current_plugin } it "returns a problem with an LLM model" do stub_request(:post, post_url).to_return(status: 403, body: error_response, headers: {}) diff --git a/spec/shared/inference/openai_embeddings_spec.rb b/spec/shared/inference/openai_embeddings_spec.rb index 0040b30f..01135ba9 100644 --- a/spec/shared/inference/openai_embeddings_spec.rb +++ b/spec/shared/inference/openai_embeddings_spec.rb @@ -5,6 +5,8 @@ describe DiscourseAi::Inference::OpenAiEmbeddings do let(:dimensions) { 1000 } let(:model) { "text-embedding-ada-002" } + before { enable_current_plugin } + it "supports azure embeddings" do azure_url = "https://my-company.openai.azure.com/openai/deployments/embeddings-deployment/embeddings?api-version=2023-05-15" diff --git a/spec/shared/inference/stability_generator_spec.rb b/spec/shared/inference/stability_generator_spec.rb index 45ee4dbb..a8d334b8 100644 --- a/spec/shared/inference/stability_generator_spec.rb +++ b/spec/shared/inference/stability_generator_spec.rb @@ -9,6 +9,8 @@ describe DiscourseAi::Inference::StabilityGenerator do { image: "BASE64", seed: 1 }.to_json end + before { enable_current_plugin } + it "is able to generate sd3 images" do SiteSetting.ai_stability_engine = "sd3" SiteSetting.ai_stability_api_url = "http://www.a.b.c" diff --git a/spec/system/admin_ai_features_spec.rb b/spec/system/admin_ai_features_spec.rb index 39c07bbe..6df6ad5e 100644 --- a/spec/system/admin_ai_features_spec.rb +++ b/spec/system/admin_ai_features_spec.rb @@ -11,6 +11,7 @@ RSpec.describe "Admin AI features configuration", type: :system, js: true do let(:ai_features_page) { PageObjects::Pages::AdminAiFeatures.new } before do + enable_current_plugin summarization_persona.allowed_group_ids = [group_1.id, group_2.id] summarization_persona.save! assign_fake_provider_to(:ai_summarization_model) diff --git a/spec/system/admin_ai_persona_spec.rb b/spec/system/admin_ai_persona_spec.rb index 344073f3..763081d9 100644 --- a/spec/system/admin_ai_persona_spec.rb +++ b/spec/system/admin_ai_persona_spec.rb @@ -6,6 +6,7 @@ RSpec.describe "Admin AI persona configuration", type: :system, js: true do let(:form) { PageObjects::Components::FormKit.new("form") } before do + enable_current_plugin SiteSetting.ai_bot_enabled = true sign_in(admin) end diff --git a/spec/system/admin_dashboard_spec.rb b/spec/system/admin_dashboard_spec.rb index b59310e0..fd770656 100644 --- a/spec/system/admin_dashboard_spec.rb +++ b/spec/system/admin_dashboard_spec.rb @@ -3,6 +3,8 @@ RSpec.describe "Admin dashboard", type: :system do fab!(:admin) + before { enable_current_plugin } + xit "displays the sentiment dashboard" do SiteSetting.ai_sentiment_enabled = true sign_in(admin) diff --git a/spec/system/ai_artifact_key_value_api_spec.rb b/spec/system/ai_artifact_key_value_api_spec.rb index 40aaf309..8494d4f2 100644 --- a/spec/system/ai_artifact_key_value_api_spec.rb +++ b/spec/system/ai_artifact_key_value_api_spec.rb @@ -44,7 +44,7 @@ RSpec.describe "AI Artifact Key-Value API", type: :system, js: true do end before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin SiteSetting.ai_bot_enabled = true sign_in(user) end diff --git a/spec/system/ai_bot/ai_bot_helper_spec.rb b/spec/system/ai_bot/ai_bot_helper_spec.rb index b777c45a..9fca99e3 100644 --- a/spec/system/ai_bot/ai_bot_helper_spec.rb +++ b/spec/system/ai_bot/ai_bot_helper_spec.rb @@ -7,6 +7,7 @@ RSpec.describe "AI chat channel summarization", type: :system, js: true do fab!(:gpt_3_5_turbo) { Fabricate(:llm_model, name: "gpt-3.5-turbo") } before do + enable_current_plugin SiteSetting.ai_bot_enabled = true toggle_enabled_bots(bots: [gpt_4, gpt_3_5_turbo]) SiteSetting.ai_bot_allowed_groups = group.id.to_s diff --git a/spec/system/ai_bot/ai_share_conversation_spec.rb b/spec/system/ai_bot/ai_share_conversation_spec.rb index 985e3797..9361ac27 100644 --- a/spec/system/ai_bot/ai_share_conversation_spec.rb +++ b/spec/system/ai_bot/ai_share_conversation_spec.rb @@ -5,6 +5,7 @@ RSpec.describe "Share conversation via link", type: :system do fab!(:gpt_4) { Fabricate(:llm_model, name: "gpt-4") } before do + enable_current_plugin SiteSetting.ai_bot_enabled = true toggle_enabled_bots(bots: [gpt_4]) SiteSetting.ai_bot_public_sharing_allowed_groups = "1" # admin diff --git a/spec/system/ai_bot/artifact_key_value_spec.rb b/spec/system/ai_bot/artifact_key_value_spec.rb deleted file mode 100644 index e69de29b..00000000 diff --git a/spec/system/ai_bot/artifact_spec.rb b/spec/system/ai_bot/artifact_spec.rb index e5d8d25b..24282ddf 100644 --- a/spec/system/ai_bot/artifact_spec.rb +++ b/spec/system/ai_bot/artifact_spec.rb @@ -8,7 +8,7 @@ RSpec.describe "AI Artifact with Data Attributes", type: :system do fab!(:topic) { Fabricate(:topic, category: category, user: author) } fab!(:post) { Fabricate(:post, topic: topic, user: author) } - before { SiteSetting.discourse_ai_enabled = true } + before { enable_current_plugin } it "correctly passes data attributes and user info to a public AI artifact embedded in a post" do artifact_js = <<~JS diff --git a/spec/system/ai_bot/homepage_spec.rb b/spec/system/ai_bot/homepage_spec.rb index 203dd104..943dd158 100644 --- a/spec/system/ai_bot/homepage_spec.rb +++ b/spec/system/ai_bot/homepage_spec.rb @@ -32,6 +32,7 @@ RSpec.describe "AI Bot - Homepage", type: :system do ) end fab!(:bot_user) do + enable_current_plugin toggle_enabled_bots(bots: [claude_2, claude_2_dup]) SiteSetting.ai_bot_enabled = true claude_2.reload.user @@ -95,6 +96,8 @@ RSpec.describe "AI Bot - Homepage", type: :system do end before do + enable_current_plugin + pm.custom_fields[DiscourseAi::AiBot::TOPIC_AI_BOT_PM_FIELD] = "t" pm.save! diff --git a/spec/system/ai_bot/persona_spec.rb b/spec/system/ai_bot/persona_spec.rb index 5c3883e6..f9f85a84 100644 --- a/spec/system/ai_bot/persona_spec.rb +++ b/spec/system/ai_bot/persona_spec.rb @@ -5,6 +5,7 @@ RSpec.describe "AI personas", type: :system, js: true do fab!(:gpt_4) { Fabricate(:llm_model, name: "gpt-4") } before do + enable_current_plugin SiteSetting.ai_bot_enabled = true toggle_enabled_bots(bots: [gpt_4]) sign_in(admin) diff --git a/spec/system/ai_bot/share_spec.rb b/spec/system/ai_bot/share_spec.rb index 9e8c6803..8a3852fd 100644 --- a/spec/system/ai_bot/share_spec.rb +++ b/spec/system/ai_bot/share_spec.rb @@ -31,6 +31,7 @@ RSpec.describe "Share conversation", type: :system do let(:cdp) { PageObjects::CDP.new } before do + enable_current_plugin SiteSetting.ai_bot_enabled = true toggle_enabled_bots(bots: [gpt_4]) sign_in(admin) diff --git a/spec/system/ai_bot/tool_spec.rb b/spec/system/ai_bot/tool_spec.rb index b1bc90fd..abb65590 100644 --- a/spec/system/ai_bot/tool_spec.rb +++ b/spec/system/ai_bot/tool_spec.rb @@ -7,6 +7,7 @@ describe "AI Tool Management", type: :system do let(:page_header) { PageObjects::Components::DPageHeader.new } before do + enable_current_plugin SiteSetting.ai_embeddings_enabled = true sign_in(admin) end diff --git a/spec/system/ai_helper/ai_composer_helper_spec.rb b/spec/system/ai_helper/ai_composer_helper_spec.rb index 7cd5f319..e9ecd7a7 100644 --- a/spec/system/ai_helper/ai_composer_helper_spec.rb +++ b/spec/system/ai_helper/ai_composer_helper_spec.rb @@ -6,6 +6,7 @@ RSpec.describe "AI Composer helper", type: :system, js: true do fab!(:embedding_definition) before do + enable_current_plugin Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user) assign_fake_provider_to(:ai_helper_model) SiteSetting.ai_helper_enabled = true diff --git a/spec/system/ai_helper/ai_image_caption_spec.rb b/spec/system/ai_helper/ai_image_caption_spec.rb index d034d28a..0d31ab89 100644 --- a/spec/system/ai_helper/ai_image_caption_spec.rb +++ b/spec/system/ai_helper/ai_image_caption_spec.rb @@ -22,6 +22,7 @@ RSpec.describe "AI image caption", type: :system, js: true do end before do + enable_current_plugin Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user) assign_fake_provider_to(:ai_helper_model) assign_fake_provider_to(:ai_helper_image_caption_model) diff --git a/spec/system/ai_helper/ai_post_helper_spec.rb b/spec/system/ai_helper/ai_post_helper_spec.rb index 14c1b576..a836671e 100644 --- a/spec/system/ai_helper/ai_post_helper_spec.rb +++ b/spec/system/ai_helper/ai_post_helper_spec.rb @@ -27,6 +27,7 @@ RSpec.describe "AI Post helper", type: :system, js: true do let(:fast_editor) { PageObjects::Components::FastEditor.new } before do + enable_current_plugin Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user) assign_fake_provider_to(:ai_helper_model) SiteSetting.ai_helper_enabled = true diff --git a/spec/system/ai_helper/ai_proofreading_spec.rb b/spec/system/ai_helper/ai_proofreading_spec.rb index b2e00733..c9ed4619 100644 --- a/spec/system/ai_helper/ai_proofreading_spec.rb +++ b/spec/system/ai_helper/ai_proofreading_spec.rb @@ -6,6 +6,7 @@ RSpec.describe "AI Composer Proofreading Features", type: :system, js: true do fab!(:admin) { Fabricate(:admin, refresh_auto_groups: true) } before do + enable_current_plugin assign_fake_provider_to(:ai_helper_model) SiteSetting.ai_helper_enabled = true diff --git a/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb b/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb index 6cb3bdd9..8a6b7803 100644 --- a/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb +++ b/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb @@ -38,6 +38,7 @@ RSpec.describe "AI Post helper", type: :system, js: true do fab!(:embedding_definition) before do + enable_current_plugin Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user) assign_fake_provider_to(:ai_helper_model) SiteSetting.ai_helper_enabled = true diff --git a/spec/system/ai_moderation/ai_spam_spec.rb b/spec/system/ai_moderation/ai_spam_spec.rb index 4640b760..baf320d6 100644 --- a/spec/system/ai_moderation/ai_spam_spec.rb +++ b/spec/system/ai_moderation/ai_spam_spec.rb @@ -5,7 +5,7 @@ RSpec.describe "AI Spam Configuration", type: :system, js: true do let(:llm_model) { Fabricate(:llm_model) } before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin sign_in(admin) end diff --git a/spec/system/ai_user_preferences_spec.rb b/spec/system/ai_user_preferences_spec.rb index e5379da5..105b624b 100644 --- a/spec/system/ai_user_preferences_spec.rb +++ b/spec/system/ai_user_preferences_spec.rb @@ -9,7 +9,7 @@ RSpec.describe "User AI preferences", type: :system, js: true do end before do - SiteSetting.discourse_ai_enabled = true + enable_current_plugin SiteSetting.ai_bot_discover_persona = discovery_persona.id Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user) assign_fake_provider_to(:ai_helper_model) diff --git a/spec/system/embeddings/ai_embedding_definition_spec.rb b/spec/system/embeddings/ai_embedding_definition_spec.rb index 481fdac9..f465ecff 100644 --- a/spec/system/embeddings/ai_embedding_definition_spec.rb +++ b/spec/system/embeddings/ai_embedding_definition_spec.rb @@ -5,7 +5,10 @@ RSpec.describe "Managing Embeddings configurations", type: :system, js: true do let(:page_header) { PageObjects::Components::DPageHeader.new } let(:form) { PageObjects::Components::FormKit.new("form") } - before { sign_in(admin) } + before do + enable_current_plugin + sign_in(admin) + end it "correctly sets defaults" do preset = "text-embedding-3-small" diff --git a/spec/system/embeddings/semantic_search_spec.rb b/spec/system/embeddings/semantic_search_spec.rb index 4805989e..15370897 100644 --- a/spec/system/embeddings/semantic_search_spec.rb +++ b/spec/system/embeddings/semantic_search_spec.rb @@ -10,6 +10,8 @@ RSpec.describe "AI Composer helper", type: :system, js: true do fab!(:post) { Fabricate(:post, topic: topic, raw: "Apple pie is a delicious dessert to eat") } before do + enable_current_plugin + prompt = DiscourseAi::Embeddings::HydeGenerators::OpenAi.new.prompt(query) OpenAiCompletionsInferenceStubs.stub_response( prompt, diff --git a/spec/system/llms/ai_llm_spec.rb b/spec/system/llms/ai_llm_spec.rb index 2fdb0339..57d36642 100644 --- a/spec/system/llms/ai_llm_spec.rb +++ b/spec/system/llms/ai_llm_spec.rb @@ -7,6 +7,7 @@ RSpec.describe "Managing LLM configurations", type: :system, js: true do let(:form) { PageObjects::Components::FormKit.new("form") } before do + enable_current_plugin SiteSetting.ai_bot_enabled = true sign_in(admin) end diff --git a/spec/system/summarization/chat_summarization_spec.rb b/spec/system/summarization/chat_summarization_spec.rb index dbb78417..8f9f340a 100644 --- a/spec/system/summarization/chat_summarization_spec.rb +++ b/spec/system/summarization/chat_summarization_spec.rb @@ -9,6 +9,8 @@ RSpec.describe "Summarize a channel since your last visit", type: :system do let(:summarization_result) { "This is a summary" } before do + enable_current_plugin + group.add(current_user) assign_fake_provider_to(:ai_summarization_model) diff --git a/spec/system/summarization/topic_summarization_spec.rb b/spec/system/summarization/topic_summarization_spec.rb index 30b147a0..b3d75880 100644 --- a/spec/system/summarization/topic_summarization_spec.rb +++ b/spec/system/summarization/topic_summarization_spec.rb @@ -21,6 +21,8 @@ RSpec.describe "Summarize a topic ", type: :system do fab!(:ai_summary) { Fabricate(:ai_summary, target: topic, summarized_text: "This is a summary") } before do + enable_current_plugin + group.add(current_user) assign_fake_provider_to(:ai_summarization_model) diff --git a/spec/tasks/backfill_spec.rb b/spec/tasks/backfill_spec.rb index b9b68846..aa002b8b 100644 --- a/spec/tasks/backfill_spec.rb +++ b/spec/tasks/backfill_spec.rb @@ -4,6 +4,7 @@ require_relative "../support/sentiment_inference_stubs" RSpec.describe "ai:sentiment:backfill" do before do + enable_current_plugin Rake::Task.clear Discourse::Application.load_tasks end diff --git a/spec/tasks/scan_spec.rb b/spec/tasks/scan_spec.rb index 53187392..a6876419 100644 --- a/spec/tasks/scan_spec.rb +++ b/spec/tasks/scan_spec.rb @@ -6,6 +6,8 @@ RSpec.describe "ai:spam rake tasks" do let!(:topic2) { Fabricate(:topic, created_at: 1.hour.ago) } let!(:post2) { Fabricate(:post, topic: topic2, created_at: 1.hour.ago) } + before { enable_current_plugin } + describe "ai:spam:scan_posts" do it "enqueues posts within date range" do freeze_time do