0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/plugins/automation/spec/integration/infinite_loop_protection_spec.rb
Sam 43cd7ecee7
DEV: Make automation recursion depth configurable (#40778)
- Replace the hardcoded automation recursion limit with a hidden site
setting so deployments can tune nested trigger behavior.

discourse_automation_max_recursion_depth

- Stop raising exceptions on recursion guard (to match old behavior)
2026-06-11 09:41:00 +10:00

51 lines
1.5 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Infinite loop protection" do
fab!(:automation_1) do
Fabricate(:automation, script: "auto_responder", trigger: "post_created_edited", enabled: true)
end
fab!(:automation_2) do
Fabricate(:automation, script: "auto_responder", trigger: "post_created_edited", enabled: true)
end
before do
SiteSetting.discourse_automation_enabled = true
automation_1.upsert_field!(
"word_answer_list",
"key-value",
{ value: [{ key: "", value: "this is the reply" }].to_json },
)
automation_2.upsert_field!(
"word_answer_list",
"key-value",
{ value: [{ key: "", value: "this is the reply" }].to_json },
)
automation_1.upsert_field!(
"answering_user",
"user",
{ value: Fabricate(:user).username },
target: "script",
)
automation_2.upsert_field!(
"answering_user",
"user",
{ value: Fabricate(:user).username },
target: "script",
)
end
it "silently stops recursive replies at the configured limit" do
expected_post_count = 1 + (2 * SiteSetting.discourse_automation_max_recursion_depth)
expect do
PostCreator.create!(Fabricate(:user), raw: "post", title: "topic", skip_validations: true)
end.to change { Post.count }.by(expected_post_count).and change {
DiscourseAutomation::Stat.where(automation_id: [automation_1.id, automation_2.id]).sum(
:total_errors,
)
}.by(0)
end
end