FIX: streaming related specs (#1448)

## 🔍 Overview
This update fixes an issue where message bus streaming related specs
were not working correctly. To do so we pass the `last_id` when
subscribing to `MessageBus` which allows us to unskip those broken
tests.

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
Keegan George 2025-06-19 07:41:18 -07:00 committed by GitHub
parent 6a33e5154d
commit baaa3d199a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 11 deletions

View File

@ -85,14 +85,18 @@ export default class ModalDiffModal extends Component {
@bind @bind
subscribe() { subscribe() {
this.messageBus.subscribe(CHANNEL, this.updateResult); this.messageBus.subscribe(
CHANNEL,
this.updateResult,
this.currentUser
?.discourse_ai_helper_stream_composer_suggestion_last_message_bus_id
);
} }
@bind @bind
cleanup() { cleanup() {
// stop all callbacks so it does not end up streaming pointlessly // stop all callbacks so it does not end up streaming pointlessly
this.smoothStreamer.resetStreaming(); this.#resetState();
this.diffStreamer.reset();
this.messageBus.unsubscribe(CHANNEL, this.updateResult); this.messageBus.unsubscribe(CHANNEL, this.updateResult);
} }

View File

@ -79,6 +79,12 @@ module DiscourseAi
:discourse_ai_helper_stream_suggestion_last_message_bus_id, :discourse_ai_helper_stream_suggestion_last_message_bus_id,
include_condition: -> { SiteSetting.ai_helper_enabled && scope.authenticated? }, include_condition: -> { SiteSetting.ai_helper_enabled && scope.authenticated? },
) { MessageBus.last_id("/discourse-ai/ai-helper/stream_suggestion/#{object.id}") } ) { MessageBus.last_id("/discourse-ai/ai-helper/stream_suggestion/#{object.id}") }
plugin.add_to_serializer(
:current_user,
:discourse_ai_helper_stream_composer_suggestion_last_message_bus_id,
include_condition: -> { SiteSetting.ai_helper_enabled && scope.authenticated? },
) { MessageBus.last_id("/discourse-ai/ai-helper/stream_composer_suggestion") }
end end
end end
end end

View File

@ -9,6 +9,7 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user) Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)
assign_fake_provider_to(:ai_helper_model) assign_fake_provider_to(:ai_helper_model)
SiteSetting.ai_helper_enabled = true SiteSetting.ai_helper_enabled = true
Jobs.run_immediately!
sign_in(user) sign_in(user)
end end
@ -80,7 +81,6 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
end end
it "replaces the composed message with AI generated content" do it "replaces the composed message with AI generated content" do
skip("Message bus updates not appearing in tests")
trigger_composer_helper(input) trigger_composer_helper(input)
ai_helper_menu.fill_custom_prompt(custom_prompt_input) ai_helper_menu.fill_custom_prompt(custom_prompt_input)
@ -109,7 +109,6 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
let(:spanish_input) { "La lluvia en España se queda principalmente en el avión." } let(:spanish_input) { "La lluvia en España se queda principalmente en el avión." }
it "replaces the composed message with AI generated content" do it "replaces the composed message with AI generated content" do
skip("Message bus updates not appearing in tests")
trigger_composer_helper(spanish_input) trigger_composer_helper(spanish_input)
DiscourseAi::Completions::Llm.with_prepared_responses([input]) do DiscourseAi::Completions::Llm.with_prepared_responses([input]) do
@ -121,7 +120,6 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
end end
it "reverts results when Ctrl/Cmd + Z is pressed on the keyboard" do it "reverts results when Ctrl/Cmd + Z is pressed on the keyboard" do
skip("Message bus updates not appearing in tests")
trigger_composer_helper(spanish_input) trigger_composer_helper(spanish_input)
DiscourseAi::Completions::Llm.with_prepared_responses([input]) do DiscourseAi::Completions::Llm.with_prepared_responses([input]) do
@ -134,7 +132,6 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
end end
it "shows the changes in a modal" do it "shows the changes in a modal" do
skip("Message bus updates not appearing in tests")
trigger_composer_helper(spanish_input) trigger_composer_helper(spanish_input)
DiscourseAi::Completions::Llm.with_prepared_responses([input]) do DiscourseAi::Completions::Llm.with_prepared_responses([input]) do
@ -168,7 +165,6 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
let(:proofread_text) { "The rain in Spain, stays mainly in the Plane." } let(:proofread_text) { "The rain in Spain, stays mainly in the Plane." }
it "replaces the composed message with AI generated content" do it "replaces the composed message with AI generated content" do
skip("Message bus updates not appearing in tests")
trigger_composer_helper(input) trigger_composer_helper(input)
DiscourseAi::Completions::Llm.with_prepared_responses([proofread_text]) do DiscourseAi::Completions::Llm.with_prepared_responses([proofread_text]) do

View File

@ -23,7 +23,6 @@ RSpec.describe "AI Composer Proofreading Features", type: :system, js: true do
context "when triggering via keyboard shortcut" do context "when triggering via keyboard shortcut" do
it "proofreads selected text" do it "proofreads selected text" do
skip("Animation causing diff not to appear correctly in specs")
visit "/new-topic" visit "/new-topic"
composer.fill_content("hello worldd !") composer.fill_content("hello worldd !")
@ -38,7 +37,6 @@ RSpec.describe "AI Composer Proofreading Features", type: :system, js: true do
end end
it "proofreads all text when nothing is selected" do it "proofreads all text when nothing is selected" do
skip("Animation causing diff not to appear correctly in specs")
visit "/new-topic" visit "/new-topic"
composer.fill_content("hello worrld") composer.fill_content("hello worrld")
@ -65,7 +63,6 @@ RSpec.describe "AI Composer Proofreading Features", type: :system, js: true do
before { SiteSetting.rich_editor = true } before { SiteSetting.rich_editor = true }
it "proofreads selected text and replaces it" do it "proofreads selected text and replaces it" do
skip("Animation causing diff not to appear correctly in specs")
visit "/new-topic" visit "/new-topic"
expect(composer).to be_opened expect(composer).to be_opened
composer.toggle_rich_editor composer.toggle_rich_editor