5
5
describe DiscourseAi ::Automation ::LlmTriage do
6
6
fab! ( :category )
7
7
fab! ( :reply_user ) { Fabricate ( :user ) }
8
+ fab! ( :personal_message ) { Fabricate ( :private_message_topic ) }
9
+ let ( :canned_reply_text ) { "Hello, this is a reply" }
8
10
9
11
let ( :automation ) { Fabricate ( :automation , script : "llm_triage" , enabled : true ) }
10
12
@@ -30,7 +32,7 @@ def add_automation_field(name, value, type: "text")
30
32
add_automation_field ( "tags" , %w[ aaa bbb ] , type : "tags" )
31
33
add_automation_field ( "hide_topic" , true , type : "boolean" )
32
34
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 )
34
36
add_automation_field ( "canned_reply_user" , reply_user . username , type : "user" )
35
37
add_automation_field ( "max_post_tokens" , 100 )
36
38
end
@@ -63,7 +65,7 @@ def add_automation_field(name, value, type: "text")
63
65
expect ( topic . tags . pluck ( :name ) ) . to contain_exactly ( "aaa" , "bbb" )
64
66
expect ( topic . visible ) . to eq ( false )
65
67
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 )
67
69
expect ( reply . user . id ) . to eq ( reply_user . id )
68
70
69
71
ai_log = AiApiAuditLog . order ( "id desc" ) . first
@@ -79,6 +81,30 @@ def add_automation_field(name, value, type: "text")
79
81
expect ( count ) . to be > ( 50 )
80
82
end
81
83
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
+
82
108
it "does not reply to the canned_reply_user" do
83
109
post = Fabricate ( :post , user : reply_user )
84
110
0 commit comments