DEV: Fix new Rubocop offenses

This commit is contained in:
Loïc Guitaut 2024-03-05 16:48:28 +01:00 committed by Loïc Guitaut
parent 8b382d6098
commit 6ae4218a96
43 changed files with 88 additions and 66 deletions

View File

@ -1,11 +1,30 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.3.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.6)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
drb (2.2.1)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
minitest (5.22.2)
mutex_m (0.2.0)
parallel (1.24.0)
parser (3.3.0.3)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
@ -13,33 +32,38 @@ GEM
rainbow (3.1.1)
regexp_parser (2.9.0)
rexml (3.2.6)
rubocop (1.59.0)
rubocop (1.61.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-ast (1.31.1)
parser (>= 3.3.0.4)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
rubocop-discourse (3.6.0)
rubocop-discourse (3.7.1)
activesupport (>= 6.1)
rubocop (>= 1.59.0)
rubocop-capybara (>= 2.0.0)
rubocop-factory_bot (>= 2.0.0)
rubocop-rspec (>= 2.25.0)
rubocop-factory_bot (2.25.1)
rubocop (~> 1.41)
rubocop-rspec (2.26.1)
rubocop-rspec (2.27.1)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
PLATFORMS

View File

@ -3,6 +3,8 @@
module DiscourseAi
module Admin
class AiPersonasController < ::Admin::AdminController
requires_plugin ::DiscourseAi::PLUGIN_NAME
before_action :find_ai_persona, only: %i[show update destroy create_user]
def index

View File

@ -4,9 +4,7 @@ if defined?(DiscourseAutomation)
module DiscourseAutomation::LlmReport
end
DiscourseAutomation::Scriptable::LLM_REPORT = "llm_report"
DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scriptable::LLM_REPORT) do
DiscourseAutomation::Scriptable.add("llm_report") do
version 1
triggerables %i[recurring]

View File

@ -1,9 +1,7 @@
# frozen_string_literal: true
if defined?(DiscourseAutomation)
DiscourseAutomation::Scriptable::LLM_TRIAGE = "llm_triage"
DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scriptable::LLM_TRIAGE) do
DiscourseAutomation::Scriptable.add("llm_triage") do
version 1
run_in_background
@ -17,7 +15,7 @@ if defined?(DiscourseAutomation)
validator: ->(input) do
if !input.include?("%%POST%%")
I18n.t(
"discourse_automation.scriptables.#{DiscourseAutomation::Scriptable::LLM_TRIAGE}.system_prompt_missing_post_placeholder",
"discourse_automation.scriptables.llm_triage.system_prompt_missing_post_placeholder",
)
end
end,

View File

@ -6,7 +6,7 @@ RSpec.describe Jobs::StreamPostHelper do
before { SiteSetting.ai_helper_model = "fake:fake" }
describe "#execute" do
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:post) do
Fabricate(
:post,

View File

@ -56,7 +56,7 @@ end
RSpec.describe DiscourseAi::Completions::Endpoints::Anthropic do
subject(:endpoint) { described_class.new("claude-2", DiscourseAi::Tokenizer::AnthropicTokenizer) }
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:anthropic_mock) { AnthropicMock.new(endpoint) }

View File

@ -75,7 +75,7 @@ end
RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do
subject(:endpoint) { described_class.new("claude-2", DiscourseAi::Tokenizer::AnthropicTokenizer) }
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:bedrock_mock) { BedrockMock.new(endpoint) }

View File

@ -130,7 +130,7 @@ end
RSpec.describe DiscourseAi::Completions::Endpoints::Gemini do
subject(:endpoint) { described_class.new("gemini-pro", DiscourseAi::Tokenizer::OpenAiTokenizer) }
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:bedrock_mock) { GeminiMock.new(endpoint) }

View File

@ -65,7 +65,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::HuggingFace do
before { SiteSetting.ai_hugging_face_api_url = "https://test.dev" }
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:hf_mock) { HuggingFaceMock.new(endpoint) }

View File

@ -62,7 +62,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Vllm do
)
end
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:anthropic_mock) { VllmMock.new(endpoint) }

View File

@ -9,7 +9,7 @@ RSpec.describe DiscourseAi::Completions::Llm do
)
end
fab!(:user) { Fabricate(:user) }
fab!(:user)
describe ".proxy" do
it "raises an exception when we can't proxy the model" do

View File

@ -3,7 +3,7 @@
return if !defined?(DiscourseAutomation)
describe DiscourseAi::Automation::LlmTriage do
fab!(:post) { Fabricate(:post) }
fab!(:post)
let(:automation) { Fabricate(:automation, script: "llm_triage", enabled: true) }

View File

@ -3,7 +3,7 @@
RSpec.describe DiscourseAi::AiBot::Bot do
subject(:bot) { described_class.as(bot_user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:admin)
before do
SiteSetting.ai_bot_enabled_chat_bots = "gpt-4"

View File

@ -3,7 +3,7 @@
RSpec.describe DiscourseAi::AiBot::EntryPoint do
describe "#inject_into" do
describe "subscribes to the post_created event" do
fab!(:admin) { Fabricate(:admin) }
fab!(:admin)
let(:gpt_bot) { User.find(described_class::GPT4_ID) }
fab!(:bot_allowed_group) { Fabricate(:group) }

View File

@ -4,7 +4,7 @@ RSpec.describe Jobs::CreateAiReply do
before { SiteSetting.ai_bot_enabled = true }
describe "#execute" do
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
let(:expected_response) do

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe DiscourseAi::AiHelper::Assistant do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:prompt) { CompletionPrompt.find_by(id: mode) }
before { SiteSetting.ai_helper_model = "fake:fake" }

View File

@ -7,7 +7,7 @@ RSpec.describe DiscourseAi::AiHelper::ChatThreadTitler do
fab!(:thread) { Fabricate(:chat_thread) }
fab!(:chat_message) { Fabricate(:chat_message, thread: thread) }
fab!(:user) { Fabricate(:user) }
fab!(:user)
describe "#cleanup" do
it "picks the first when there are multiple" do

View File

@ -3,7 +3,7 @@
RSpec.describe DiscourseAi::AiHelper::Painter do
subject(:painter) { described_class.new }
fab!(:user) { Fabricate(:user) }
fab!(:user)
before do
SiteSetting.ai_helper_model = "fake:fake"

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
describe DiscourseAi::Automation::LlmTriage do
fab!(:post) { Fabricate(:post) }
fab!(:post)
def triage(**args)
DiscourseAi::Automation::LlmTriage.handle(**args)

View File

@ -13,13 +13,13 @@ module DiscourseAi
fab!(:secure_topic) { Fabricate(:topic, category: secure_category) }
fab!(:secure_post) { Fabricate(:post, raw: "Top secret date !!!!", topic: secure_topic) }
fab!(:category) { Fabricate(:category) }
fab!(:category)
fab!(:topic_in_category) { Fabricate(:topic, category: category) }
fab!(:post_in_category) do
Fabricate(:post, raw: "I am in a category", topic: topic_in_category)
end
fab!(:tag) { Fabricate(:tag) }
fab!(:tag)
fab!(:topic_with_tag) { Fabricate(:topic, tags: [tag]) }
fab!(:post_with_tag) { Fabricate(:post, raw: "I am in a tag", topic: topic_with_tag) }

View File

@ -9,7 +9,7 @@ RSpec.describe Jobs::GenerateEmbeddings do
SiteSetting.ai_embeddings_enabled = true
end
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:post) { Fabricate(:post, post_number: 1, topic: topic) }
let(:truncation) { DiscourseAi::Embeddings::Strategies::Truncation.new }

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true
RSpec.describe DiscourseAi::Embeddings::SemanticSearch do
fab!(:post) { Fabricate(:post) }
fab!(:user) { Fabricate(:user) }
fab!(:post)
fab!(:user)
let(:query) { "test_query" }
let(:subject) { described_class.new(Guardian.new(user)) }
@ -104,7 +104,7 @@ RSpec.describe DiscourseAi::Embeddings::SemanticSearch do
end
context "when the post belongs to a secured category" do
fab!(:group) { Fabricate(:group) }
fab!(:group)
fab!(:private_category) { Fabricate(:private_category, group: group) }
before do

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
describe DiscourseAi::Embeddings::EntryPoint do
fab!(:user) { Fabricate(:user) }
fab!(:user)
describe "SemanticTopicQuery extension" do
describe "#list_semantic_related_topics" do
@ -39,7 +39,7 @@ describe DiscourseAi::Embeddings::EntryPoint do
end
context "when the semantic search returns a topic from a restricted category" do
fab!(:group) { Fabricate(:group) }
fab!(:group)
fab!(:category) { Fabricate(:private_category, group: group) }
fab!(:secured_category_topic) { Fabricate(:topic, category: category) }

View File

@ -7,7 +7,7 @@ RSpec.describe DiscourseAi::Embeddings::Strategies::Truncation do
context "when using vector from OpenAI" do
before { SiteSetting.max_post_length = 100_000 }
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:post) do
Fabricate(:post, topic: topic, raw: "Baby, bird, bird, bird\nBird is the word\n" * 500)
end

View File

@ -53,7 +53,7 @@ describe DiscourseAi::Toxicity::EntryPoint do
context "when editing a chat message" do
# This fabricator trigger events because it uses the UpdateMessage service.
# Using let makes the test fail.
fab!(:chat_message) { Fabricate(:chat_message) }
fab!(:chat_message)
let(:updater) do
Chat::UpdateMessage.call(
guardian: Guardian.new(chat_message.user),

View File

@ -9,7 +9,7 @@ describe Jobs::ToxicityClassifyChatMessage do
SiteSetting.ai_toxicity_flag_automatically = true
end
fab!(:chat_message) { Fabricate(:chat_message) }
fab!(:chat_message)
describe "scenarios where we return early without doing anything" do
it "does nothing when ai_toxicity_enabled is disabled" do

View File

@ -10,7 +10,7 @@ describe Jobs::ToxicityClassifyPost do
SiteSetting.ai_toxicity_flag_automatically = true
end
fab!(:post) { Fabricate(:post) }
fab!(:post)
describe "scenarios where we return early without doing anything" do
it "does nothing when ai_toxicity_enabled is disabled" do

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
describe DiscourseAi::Toxicity::ScanQueue do
fab!(:group) { Fabricate(:group) }
fab!(:group)
before do
SiteSetting.ai_toxicity_enabled = true
@ -9,7 +9,7 @@ describe DiscourseAi::Toxicity::ScanQueue do
end
describe "#enqueue_post" do
fab!(:post) { Fabricate(:post) }
fab!(:post)
it "queues a job" do
expect { described_class.enqueue_post(post) }.to change(
@ -38,7 +38,7 @@ describe DiscourseAi::Toxicity::ScanQueue do
end
describe "#enqueue_chat_message" do
fab!(:chat_message) { Fabricate(:chat_message) }
fab!(:chat_message)
it "queues a job" do
expect { described_class.enqueue_chat_message(chat_message) }.to change(

View File

@ -1,9 +1,9 @@
# frozen_string_literal: true
RSpec.describe ReviewableAiChatMessage, type: :model do
fab!(:moderator) { Fabricate(:moderator) }
fab!(:user) { Fabricate(:user) }
fab!(:chat_channel) { Fabricate(:chat_channel) }
fab!(:moderator)
fab!(:user)
fab!(:chat_channel)
fab!(:chat_message) { Fabricate(:chat_message, chat_channel: chat_channel, user: user) }
fab!(:reviewable) { described_class.needs_review!(target: chat_message, created_by: moderator) }

View File

@ -121,7 +121,7 @@ describe ReviewableAiPost do
let(:reviewable) do
described_class.needs_review!(target: target, created_by: Discourse.system_user)
end
fab!(:admin) { Fabricate(:admin) }
fab!(:admin)
before do
reviewable.add_score(

View File

@ -6,8 +6,8 @@ describe Plugin::Instance do
before { SiteSetting.discourse_ai_enabled = true }
describe "on reviewable_transitioned_to event" do
fab!(:post) { Fabricate(:post) }
fab!(:admin) { Fabricate(:admin) }
fab!(:post)
fab!(:admin)
it "adjusts model accuracy" do
ToxicityInferenceStubs.stub_post_classification(post, toxic: true)

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe DiscourseAi::AiBot::BotController do
fab!(:user) { Fabricate(:user) }
fab!(:user)
before { sign_in(user) }
describe "#stop_streaming_response" do

View File

@ -32,7 +32,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
end
context "when logged in as an allowed user" do
fab!(:user) { Fabricate(:user) }
fab!(:user)
before do
sign_in(user)
@ -109,7 +109,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
end
describe "#caption_image" do
fab!(:upload) { Fabricate(:upload) }
fab!(:upload)
let(:image_url) { "#{Discourse.base_url}#{upload.url}" }
let(:caption) { "A picture of a cat sitting on a table" }
let(:caption_with_attrs) do
@ -161,7 +161,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
end
context "for secure uploads" do
fab!(:group) { Fabricate(:group) }
fab!(:group)
fab!(:private_category) { Fabricate(:private_category, group: group) }
fab!(:post_in_secure_context) do
Fabricate(:post, topic: Fabricate(:topic, category: private_category))

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
describe ::TopicsController do
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:topic1) { Fabricate(:topic) }
fab!(:topic2) { Fabricate(:topic) }
fab!(:topic3) { Fabricate(:topic) }

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe AiChatChannelSerializer do
fab!(:admin) { Fabricate(:admin) }
fab!(:admin)
describe "#title" do
context "when the channel is a DM" do

View File

@ -3,7 +3,7 @@
require_relative "../support/toxicity_inference_stubs"
describe DiscourseAi::ChatMessageClassificator do
fab!(:chat_message) { Fabricate(:chat_message) }
fab!(:chat_message)
let(:model) { DiscourseAi::Toxicity::ToxicityClassification.new }
let(:classification) { described_class.new(model) }

View File

@ -3,7 +3,7 @@
require_relative "../support/toxicity_inference_stubs"
describe DiscourseAi::PostClassificator do
fab!(:post) { Fabricate(:post) }
fab!(:post)
let(:model) { DiscourseAi::Toxicity::ToxicityClassification.new }
let(:classification) { described_class.new(model) }

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
RSpec.describe "AI chat channel summarization", type: :system, js: true do
fab!(:user) { Fabricate(:user) }
fab!(:user)
fab!(:group) { Fabricate(:group, visibility_level: Group.visibility_levels[:staff]) }
before do

View File

@ -17,7 +17,7 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
let(:ai_helper_context_menu) { PageObjects::Components::AIHelperContextMenu.new }
let(:diff_modal) { PageObjects::Modals::DiffModal.new }
let(:ai_suggestion_dropdown) { PageObjects::Components::AISuggestionDropdown.new }
fab!(:category) { Fabricate(:category) }
fab!(:category)
fab!(:category_2) { Fabricate(:category) }
fab!(:video) { Fabricate(:tag) }
fab!(:music) { Fabricate(:tag) }

View File

@ -3,7 +3,7 @@
RSpec.describe "AI Post helper", type: :system, js: true do
fab!(:user) { Fabricate(:admin) }
fab!(:non_member_group) { Fabricate(:group) }
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:post) do
Fabricate(
:post,

View File

@ -3,8 +3,8 @@
RSpec.describe "AI Post helper", type: :system, js: true do
fab!(:user) { Fabricate(:admin) }
fab!(:non_member_group) { Fabricate(:group) }
fab!(:topic) { Fabricate(:topic) }
fab!(:category) { Fabricate(:category) }
fab!(:topic)
fab!(:category)
fab!(:category_2) { Fabricate(:category) }
fab!(:post) do
Fabricate(

View File

@ -6,7 +6,7 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
let(:hypothetical_post) { "This is an hypothetical post generated from the keyword apple_pie" }
fab!(:user) { Fabricate(:admin) }
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic, raw: "Apple pie is a delicious dessert to eat") }
before do

View File

@ -3,8 +3,8 @@
require_relative "../../support/toxicity_inference_stubs"
RSpec.describe "Toxicity-flagged chat messages", type: :system, js: true do
fab!(:chat_message) { Fabricate(:chat_message) }
fab!(:admin) { Fabricate(:admin) }
fab!(:chat_message)
fab!(:admin)
before do
sign_in(admin)