mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-10 16:13:29 +00:00
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:
parent
6a33e5154d
commit
baaa3d199a
@ -85,14 +85,18 @@ export default class ModalDiffModal extends Component {
|
||||
|
||||
@bind
|
||||
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
|
||||
cleanup() {
|
||||
// stop all callbacks so it does not end up streaming pointlessly
|
||||
this.smoothStreamer.resetStreaming();
|
||||
this.diffStreamer.reset();
|
||||
this.#resetState();
|
||||
this.messageBus.unsubscribe(CHANNEL, this.updateResult);
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,12 @@ module DiscourseAi
|
||||
:discourse_ai_helper_stream_suggestion_last_message_bus_id,
|
||||
include_condition: -> { SiteSetting.ai_helper_enabled && scope.authenticated? },
|
||||
) { 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
|
||||
|
@ -9,6 +9,7 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
|
||||
Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)
|
||||
assign_fake_provider_to(:ai_helper_model)
|
||||
SiteSetting.ai_helper_enabled = true
|
||||
Jobs.run_immediately!
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
@ -80,7 +81,6 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
|
||||
end
|
||||
|
||||
it "replaces the composed message with AI generated content" do
|
||||
skip("Message bus updates not appearing in tests")
|
||||
trigger_composer_helper(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." }
|
||||
|
||||
it "replaces the composed message with AI generated content" do
|
||||
skip("Message bus updates not appearing in tests")
|
||||
trigger_composer_helper(spanish_input)
|
||||
|
||||
DiscourseAi::Completions::Llm.with_prepared_responses([input]) do
|
||||
@ -121,7 +120,6 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
DiscourseAi::Completions::Llm.with_prepared_responses([input]) do
|
||||
@ -134,7 +132,6 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
|
||||
end
|
||||
|
||||
it "shows the changes in a modal" do
|
||||
skip("Message bus updates not appearing in tests")
|
||||
trigger_composer_helper(spanish_input)
|
||||
|
||||
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." }
|
||||
|
||||
it "replaces the composed message with AI generated content" do
|
||||
skip("Message bus updates not appearing in tests")
|
||||
trigger_composer_helper(input)
|
||||
|
||||
DiscourseAi::Completions::Llm.with_prepared_responses([proofread_text]) do
|
||||
|
@ -23,7 +23,6 @@ RSpec.describe "AI Composer Proofreading Features", type: :system, js: true do
|
||||
|
||||
context "when triggering via keyboard shortcut" do
|
||||
it "proofreads selected text" do
|
||||
skip("Animation causing diff not to appear correctly in specs")
|
||||
visit "/new-topic"
|
||||
composer.fill_content("hello worldd !")
|
||||
|
||||
@ -38,7 +37,6 @@ RSpec.describe "AI Composer Proofreading Features", type: :system, js: true do
|
||||
end
|
||||
|
||||
it "proofreads all text when nothing is selected" do
|
||||
skip("Animation causing diff not to appear correctly in specs")
|
||||
visit "/new-topic"
|
||||
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 }
|
||||
|
||||
it "proofreads selected text and replaces it" do
|
||||
skip("Animation causing diff not to appear correctly in specs")
|
||||
visit "/new-topic"
|
||||
expect(composer).to be_opened
|
||||
composer.toggle_rich_editor
|
||||
|
Loading…
x
Reference in New Issue
Block a user