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

Commit 644141f

Browse files
authored
FIX: Regenerate summary button still shows cached summary (#903)
This PR fixes an issue where clicking to regenerate a summary was still showing the cached summary. To resolve this we call resetSummary() to reset all the summarization related properties before creating a new request.
1 parent fbc74c7 commit 644141f

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

assets/javascripts/discourse/connectors/topic-map-expanded-after/ai-summary-box.gjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ export default class AiSummaryBox extends Component {
123123
}
124124
}
125125

126+
// ensure summary is reset before requesting a new one:
127+
this.resetSummary();
126128
return this._requestSummary(fetchURL);
127129
}
128130

lib/summarization/fold_content.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def summarize(user, &on_partial_blk)
4848

4949
# @returns { AiSummary } - Resulting summary.
5050
#
51-
# Finds a summary matching the target and strategy. Marks it as outdates if the strategy found newer content
51+
# Finds a summary matching the target and strategy. Marks it as outdated if the strategy found newer content
5252
def existing_summary
5353
if !defined?(@existing_summary)
5454
summary = AiSummary.find_by(target: strategy.target, summary_type: strategy.type)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
module PageObjects
4+
module Components
5+
class AiSummaryBox < PageObjects::Components::Base
6+
SUMMARY_BUTTON_SELECTOR = ".ai-summarization-button button"
7+
SUMMARY_CONTAINER_SELECTOR = ".ai-summary-container"
8+
9+
def click_summarize
10+
find(SUMMARY_BUTTON_SELECTOR).click
11+
end
12+
13+
def click_regenerate_summary
14+
find("#{SUMMARY_CONTAINER_SELECTOR} .outdated-summary button").click
15+
end
16+
17+
def has_summary?(summary)
18+
find("#{SUMMARY_CONTAINER_SELECTOR} .generated-summary p").text == summary
19+
end
20+
21+
def has_generating_summary_indicator?
22+
find("#{SUMMARY_CONTAINER_SELECTOR} .ai-summary__generating-text").present?
23+
end
24+
end
25+
end
26+
end

spec/system/summarization/topic_summarization_spec.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
end
1515
let(:summarization_result) { "This is a summary" }
1616
let(:topic_page) { PageObjects::Pages::Topic.new }
17+
let(:summary_box) { PageObjects::Components::AiSummaryBox.new }
1718

1819
before do
1920
group.add(current_user)
@@ -38,10 +39,35 @@
3839

3940
it "displays it" do
4041
topic_page.visit_topic(topic)
42+
summary_box.click_summarize
43+
expect(summary_box).to have_summary(summarization_result)
44+
end
45+
end
4146

42-
find(".ai-summarization-button button").click
47+
context "when a summary is outdated" do
48+
before do
49+
AiSummary.create!(
50+
target: topic,
51+
summarized_text: summarization_result,
52+
algorithm: "test",
53+
original_content_sha: "test",
54+
summary_type: AiSummary.summary_types[:complete],
55+
)
56+
end
57+
fab!(:new_post) do
58+
Fabricate(
59+
:post,
60+
topic: topic,
61+
raw:
62+
"Idk, I think pie is overrated. I prefer cake. Cake is the best dessert. I always eat cake. I never throw it at people.",
63+
)
64+
end
4365

44-
expect(find(".generated-summary p").text).to eq(summarization_result)
66+
it "displays the new summary instead of a cached one" do
67+
topic_page.visit_topic(topic)
68+
summary_box.click_summarize
69+
summary_box.click_regenerate_summary
70+
expect(summary_box).to have_generating_summary_indicator
4571
end
4672
end
4773
end

0 commit comments

Comments
 (0)