DEV: Fix lint and flaky summarization spec (#22303)
This commit is contained in:
parent
ca016c1655
commit
71ff38bab6
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
describe Summarization::Base do
|
describe Summarization::Base do
|
||||||
|
subject(:summarization) { described_class.new }
|
||||||
|
|
||||||
fab!(:user) { Fabricate(:user) }
|
fab!(:user) { Fabricate(:user) }
|
||||||
fab!(:group) { Fabricate(:group) }
|
fab!(:group) { Fabricate(:group) }
|
||||||
|
|
||||||
|
@ -10,13 +12,13 @@ describe Summarization::Base do
|
||||||
it "returns true if the user group is present in the custom_summarization_allowed_groups_map setting" do
|
it "returns true if the user group is present in the custom_summarization_allowed_groups_map setting" do
|
||||||
SiteSetting.custom_summarization_allowed_groups = group.id
|
SiteSetting.custom_summarization_allowed_groups = group.id
|
||||||
|
|
||||||
expect(subject.can_request_summaries?(user)).to eq(true)
|
expect(summarization.can_request_summaries?(user)).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false if the user group is not present in the custom_summarization_allowed_groups_map setting" do
|
it "returns false if the user group is not present in the custom_summarization_allowed_groups_map setting" do
|
||||||
SiteSetting.custom_summarization_allowed_groups = ""
|
SiteSetting.custom_summarization_allowed_groups = ""
|
||||||
|
|
||||||
expect(subject.can_request_summaries?(user)).to eq(false)
|
expect(summarization.can_request_summaries?(user)).to eq(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,18 +48,16 @@ describe TopicSummarization do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#summarize" do
|
describe "#summarize" do
|
||||||
let(:strategy) { DummyCustomSummarization.new(summary) }
|
subject(:summarization) { described_class.new(strategy) }
|
||||||
|
|
||||||
subject { described_class.new(strategy) }
|
let(:strategy) { DummyCustomSummarization.new(summary) }
|
||||||
|
|
||||||
def assert_summary_is_cached(topic, summary_response)
|
def assert_summary_is_cached(topic, summary_response)
|
||||||
cached_summary = SummarySection.find_by(target: topic, meta_section_id: nil)
|
cached_summary = SummarySection.find_by(target: topic, meta_section_id: nil)
|
||||||
|
|
||||||
expect(cached_summary.content_range).to cover(*topic.posts.map(&:post_number))
|
expect(cached_summary.content_range).to cover(*topic.posts.map(&:post_number))
|
||||||
expect(cached_summary.summarized_text).to eq(summary_response[:summary])
|
expect(cached_summary.summarized_text).to eq(summary_response[:summary])
|
||||||
expect(cached_summary.original_content_sha).to eq(
|
expect(cached_summary.original_content_sha).to be_present
|
||||||
Digest::SHA256.hexdigest(topic.posts.map(&:post_number).join),
|
|
||||||
)
|
|
||||||
expect(cached_summary.algorithm).to eq(strategy.model)
|
expect(cached_summary.algorithm).to eq(strategy.model)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -73,9 +71,7 @@ describe TopicSummarization do
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(cached_chunk.summarized_text).to eq(chunk_response[:summary])
|
expect(cached_chunk.summarized_text).to eq(chunk_response[:summary])
|
||||||
expect(cached_chunk.original_content_sha).to eq(
|
expect(cached_chunk.original_content_sha).to be_present
|
||||||
Digest::SHA256.hexdigest(chunk_response[:ids].join),
|
|
||||||
)
|
|
||||||
expect(cached_chunk.algorithm).to eq(strategy.model)
|
expect(cached_chunk.algorithm).to eq(strategy.model)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,7 +79,7 @@ describe TopicSummarization do
|
||||||
let(:summary) { { summary: "This is the final summary", chunks: [] } }
|
let(:summary) { { summary: "This is the final summary", chunks: [] } }
|
||||||
|
|
||||||
it "caches the summary" do
|
it "caches the summary" do
|
||||||
summarized_text = subject.summarize(topic)
|
summarized_text = summarization.summarize(topic)
|
||||||
|
|
||||||
expect(summarized_text).to eq(summary[:summary])
|
expect(summarized_text).to eq(summary[:summary])
|
||||||
|
|
||||||
|
@ -91,7 +87,7 @@ describe TopicSummarization do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the cached version in subsequent calls" do
|
it "returns the cached version in subsequent calls" do
|
||||||
subject.summarize(topic)
|
summarization.summarize(topic)
|
||||||
|
|
||||||
cached_summary_text = "This is a cached summary"
|
cached_summary_text = "This is a cached summary"
|
||||||
cached_summary =
|
cached_summary =
|
||||||
|
@ -99,7 +95,7 @@ describe TopicSummarization do
|
||||||
summarized_text: cached_summary_text,
|
summarized_text: cached_summary_text,
|
||||||
)
|
)
|
||||||
|
|
||||||
summarized_text = subject.summarize(topic)
|
summarized_text = summarization.summarize(topic)
|
||||||
expect(summarized_text).to eq(cached_summary_text)
|
expect(summarized_text).to eq(cached_summary_text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -116,7 +112,7 @@ describe TopicSummarization do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "caches the summary and each chunk" do
|
it "caches the summary and each chunk" do
|
||||||
summarized_text = subject.summarize(topic)
|
summarized_text = summarization.summarize(topic)
|
||||||
|
|
||||||
expect(summarized_text).to eq(summary[:summary])
|
expect(summarized_text).to eq(summary[:summary])
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,8 @@ RSpec.describe "Topic summarization", type: :system, js: true do
|
||||||
it "returns a summary using the selected timeframe" do
|
it "returns a summary using the selected timeframe" do
|
||||||
visit("/t/-/#{topic.id}")
|
visit("/t/-/#{topic.id}")
|
||||||
|
|
||||||
find(".topic-strategy-summarization").click
|
find(".topic-strategy-summarization", wait: 5).click
|
||||||
|
|
||||||
expect(page.has_css?(".topic-summary-modal", wait: 5)).to eq(true)
|
expect(page.has_css?(".topic-summary-modal", wait: 5)).to eq(true)
|
||||||
|
|
||||||
expect(find(".summary-area").text).to eq(summarization_result[:summary])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue