55describe DiscourseAi ::Automation ::LlmTriage do
66 fab! ( :category )
77 fab! ( :reply_user ) { Fabricate ( :user ) }
8+ fab! ( :personal_message ) { Fabricate ( :private_message_topic ) }
9+ let ( :canned_reply_text ) { "Hello, this is a reply" }
810
911 let ( :automation ) { Fabricate ( :automation , script : "llm_triage" , enabled : true ) }
1012
@@ -30,7 +32,7 @@ def add_automation_field(name, value, type: "text")
3032 add_automation_field ( "tags" , %w[ aaa bbb ] , type : "tags" )
3133 add_automation_field ( "hide_topic" , true , type : "boolean" )
3234 add_automation_field ( "flag_post" , true , type : "boolean" )
33- add_automation_field ( "canned_reply" , "Yo this is a reply" )
35+ add_automation_field ( "canned_reply" , canned_reply_text )
3436 add_automation_field ( "canned_reply_user" , reply_user . username , type : "user" )
3537 add_automation_field ( "max_post_tokens" , 100 )
3638 end
@@ -63,7 +65,7 @@ def add_automation_field(name, value, type: "text")
6365 expect ( topic . tags . pluck ( :name ) ) . to contain_exactly ( "aaa" , "bbb" )
6466 expect ( topic . visible ) . to eq ( false )
6567 reply = topic . posts . order ( :post_number ) . last
66- expect ( reply . raw ) . to eq ( "Yo this is a reply" )
68+ expect ( reply . raw ) . to eq ( canned_reply_text )
6769 expect ( reply . user . id ) . to eq ( reply_user . id )
6870
6971 ai_log = AiApiAuditLog . order ( "id desc" ) . first
@@ -79,6 +81,30 @@ def add_automation_field(name, value, type: "text")
7981 expect ( count ) . to be > ( 50 )
8082 end
8183
84+ it "does not triage PMs by default" do
85+ post = Fabricate ( :post , topic : personal_message )
86+ automation . running_in_background!
87+ automation . trigger! ( { "post" => post } )
88+
89+ # nothing should happen, no classification, its a PM
90+ end
91+
92+ it "will triage PMs if automation allows it" do
93+ # needs to be admin or it will not be able to just step in to
94+ # PM
95+ reply_user . update! ( admin : true )
96+ add_automation_field ( "include_personal_messages" , true , type : :boolean )
97+ post = Fabricate ( :post , topic : personal_message )
98+
99+ DiscourseAi ::Completions ::Llm . with_prepared_responses ( [ "bad" ] ) do
100+ automation . running_in_background!
101+ automation . trigger! ( { "post" => post } )
102+ end
103+
104+ last_post = post . topic . reload . posts . order ( :post_number ) . last
105+ expect ( last_post . raw ) . to eq ( canned_reply_text )
106+ end
107+
82108 it "does not reply to the canned_reply_user" do
83109 post = Fabricate ( :post , user : reply_user )
84110
0 commit comments