Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit baaa3d1

Browse files
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 <[email protected]>
1 parent 6a33e51 commit baaa3d1

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

assets/javascripts/discourse/components/modal/diff-modal.gjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,18 @@ export default class ModalDiffModal extends Component {
8585

8686
@bind
8787
subscribe() {
88-
this.messageBus.subscribe(CHANNEL, this.updateResult);
88+
this.messageBus.subscribe(
89+
CHANNEL,
90+
this.updateResult,
91+
this.currentUser
92+
?.discourse_ai_helper_stream_composer_suggestion_last_message_bus_id
93+
);
8994
}
9095

9196
@bind
9297
cleanup() {
9398
// stop all callbacks so it does not end up streaming pointlessly
94-
this.smoothStreamer.resetStreaming();
95-
this.diffStreamer.reset();
99+
this.#resetState();
96100
this.messageBus.unsubscribe(CHANNEL, this.updateResult);
97101
}
98102

lib/ai_helper/entry_point.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ def inject_into(plugin)
7979
:discourse_ai_helper_stream_suggestion_last_message_bus_id,
8080
include_condition: -> { SiteSetting.ai_helper_enabled && scope.authenticated? },
8181
) { MessageBus.last_id("/discourse-ai/ai-helper/stream_suggestion/#{object.id}") }
82+
83+
plugin.add_to_serializer(
84+
:current_user,
85+
:discourse_ai_helper_stream_composer_suggestion_last_message_bus_id,
86+
include_condition: -> { SiteSetting.ai_helper_enabled && scope.authenticated? },
87+
) { MessageBus.last_id("/discourse-ai/ai-helper/stream_composer_suggestion") }
8288
end
8389
end
8490
end

spec/system/ai_helper/ai_composer_helper_spec.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)
1010
assign_fake_provider_to(:ai_helper_model)
1111
SiteSetting.ai_helper_enabled = true
12+
Jobs.run_immediately!
1213
sign_in(user)
1314
end
1415

@@ -80,7 +81,6 @@ def trigger_composer_helper(content)
8081
end
8182

8283
it "replaces the composed message with AI generated content" do
83-
skip("Message bus updates not appearing in tests")
8484
trigger_composer_helper(input)
8585
ai_helper_menu.fill_custom_prompt(custom_prompt_input)
8686

@@ -109,7 +109,6 @@ def trigger_composer_helper(content)
109109
let(:spanish_input) { "La lluvia en España se queda principalmente en el avión." }
110110

111111
it "replaces the composed message with AI generated content" do
112-
skip("Message bus updates not appearing in tests")
113112
trigger_composer_helper(spanish_input)
114113

115114
DiscourseAi::Completions::Llm.with_prepared_responses([input]) do
@@ -121,7 +120,6 @@ def trigger_composer_helper(content)
121120
end
122121

123122
it "reverts results when Ctrl/Cmd + Z is pressed on the keyboard" do
124-
skip("Message bus updates not appearing in tests")
125123
trigger_composer_helper(spanish_input)
126124

127125
DiscourseAi::Completions::Llm.with_prepared_responses([input]) do
@@ -134,7 +132,6 @@ def trigger_composer_helper(content)
134132
end
135133

136134
it "shows the changes in a modal" do
137-
skip("Message bus updates not appearing in tests")
138135
trigger_composer_helper(spanish_input)
139136

140137
DiscourseAi::Completions::Llm.with_prepared_responses([input]) do
@@ -168,7 +165,6 @@ def trigger_composer_helper(content)
168165
let(:proofread_text) { "The rain in Spain, stays mainly in the Plane." }
169166

170167
it "replaces the composed message with AI generated content" do
171-
skip("Message bus updates not appearing in tests")
172168
trigger_composer_helper(input)
173169

174170
DiscourseAi::Completions::Llm.with_prepared_responses([proofread_text]) do

spec/system/ai_helper/ai_proofreading_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
context "when triggering via keyboard shortcut" do
2525
it "proofreads selected text" do
26-
skip("Animation causing diff not to appear correctly in specs")
2726
visit "/new-topic"
2827
composer.fill_content("hello worldd !")
2928

@@ -38,7 +37,6 @@
3837
end
3938

4039
it "proofreads all text when nothing is selected" do
41-
skip("Animation causing diff not to appear correctly in specs")
4240
visit "/new-topic"
4341
composer.fill_content("hello worrld")
4442

@@ -65,7 +63,6 @@
6563
before { SiteSetting.rich_editor = true }
6664

6765
it "proofreads selected text and replaces it" do
68-
skip("Animation causing diff not to appear correctly in specs")
6966
visit "/new-topic"
7067
expect(composer).to be_opened
7168
composer.toggle_rich_editor

0 commit comments

Comments
 (0)