discourse-ai/spec/system/summarization/topic_summarization_spec.rb
Roman Rizzi 46fcdb6ba5
FIX: Make summaries backfill job more resilient. (#1071)
To quickly select backfill candidates without comparing SHAs, we compare the last summarized post to the topic's highest_post_number. However, hiding or deleting a post and adding a small action will update this column, causing the job to stall and re-generate the same summary repeatedly until someone posts a regular reply. On top of this, this is not always true for topics with `best_replies`, as this last reply isn't necessarily included.

Since this is not evident at first glance and each summarization strategy picks its targets differently, I'm opting to simplify the backfill logic and how we track potential candidates.

The first step is dropping `content_range`, which serves no purpose and it's there because summary caching was supposed to work differently at the beginning. So instead, I'm replacing it with a column called `highest_target_number`, which tracks `highest_post_number` for topics and could track other things like channel's `message_count` in the future.

Now that we have this column when selecting every potential backfill candidate, we'll check if the summary is truly outdated by comparing the SHAs, and if it's not, we just update the column and move on
2025-01-16 09:42:53 -03:00

57 lines
1.6 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Summarize a topic ", type: :system do
fab!(:current_user) { Fabricate(:user) }
fab!(:group)
fab!(:topic)
fab!(:post) do
Fabricate(
:post,
topic: topic,
raw:
"I like to eat pie. It is a very good dessert. Some people are wasteful by throwing pie at others but I do not do that. I always eat the pie.",
)
end
let(:summarization_result) { "This is a summary" }
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:summary_box) { PageObjects::Components::AiSummaryTrigger.new }
fab!(:ai_summary) { Fabricate(:ai_summary, target: topic, summarized_text: "This is a summary") }
before do
group.add(current_user)
assign_fake_provider_to(:ai_summarization_model)
SiteSetting.ai_summarization_enabled = true
SiteSetting.ai_custom_summarization_allowed_groups = group.id.to_s
sign_in(current_user)
end
context "when a summary is cached" do
it "displays it" do
topic_page.visit_topic(topic)
summary_box.click_summarize
expect(summary_box).to have_summary(summarization_result)
end
end
context "when a summary is outdated" do
fab!(:new_post) do
Fabricate(
:post,
topic: topic,
raw:
"Idk, I think pie is overrated. I prefer cake. Cake is the best dessert. I always eat cake. I never throw it at people.",
)
end
it "displays the new summary instead of a cached one" do
topic_page.visit_topic(topic)
summary_box.click_summarize
summary_box.click_regenerate_summary
expect(summary_box).to have_generating_summary_indicator
end
end
end