@@ -9,6 +9,29 @@ import (
99 airuntime "github.com/beeper/agentremote/pkg/runtime"
1010)
1111
12+ func getFollowUpMessagesForTest (oc * AIClient , roomID id.RoomID ) []PromptMessage {
13+ if oc == nil || roomID == "" {
14+ return nil
15+ }
16+ snapshot := oc .getQueueSnapshot (roomID )
17+ if snapshot == nil {
18+ return nil
19+ }
20+ behavior := airuntime .ResolveQueueBehavior (snapshot .mode )
21+ if ! behavior .Followup {
22+ return nil
23+ }
24+ candidate , _ := oc .takePendingQueueDispatchCandidate (roomID , true )
25+ if candidate == nil || len (candidate .items ) == 0 {
26+ return nil
27+ }
28+ _ , prompt , ok := preparePendingQueueDispatchCandidate (candidate )
29+ if ! ok {
30+ return nil
31+ }
32+ return buildSteeringPromptMessages ([]string {prompt })
33+ }
34+
1235func TestGetSteeringMessages_FiltersAndDrainsQueue (t * testing.T ) {
1336 roomID := id .RoomID ("!room:example.com" )
1437 oc := & AIClient {
@@ -78,7 +101,7 @@ func TestGetFollowUpMessages_ConsumesSingleQueuedTextMessage(t *testing.T) {
78101 },
79102 }
80103
81- messages := oc . getFollowUpMessages ( roomID )
104+ messages := getFollowUpMessagesForTest ( oc , roomID )
82105 if len (messages ) != 1 || messages [0 ].Role != PromptRoleUser || messages [0 ].Text () != "follow up" {
83106 t .Fatalf ("unexpected follow-up messages: %#v" , messages )
84107 }
@@ -101,7 +124,7 @@ func TestGetFollowUpMessages_CollectsQueuedTextMessages(t *testing.T) {
101124 },
102125 }
103126
104- messages := oc . getFollowUpMessages ( roomID )
127+ messages := getFollowUpMessagesForTest ( oc , roomID )
105128 if len (messages ) != 1 || messages [0 ].Role != PromptRoleUser {
106129 t .Fatalf ("expected one combined follow-up message, got %#v" , messages )
107130 }
@@ -127,15 +150,15 @@ func TestGetFollowUpMessages_CollectSummaryIsConsumed(t *testing.T) {
127150 },
128151 }
129152
130- messages := oc . getFollowUpMessages ( roomID )
153+ messages := getFollowUpMessagesForTest ( oc , roomID )
131154 if len (messages ) != 1 || messages [0 ].Role != PromptRoleUser {
132155 t .Fatalf ("expected one combined follow-up message, got %#v" , messages )
133156 }
134157 if messages [0 ].Text () != "[Queued messages while agent was busy]\n \n [Queue overflow] Dropped 2 messages due to cap.\n Summary:\n - older one\n - older two\n \n ---\n Queued #1\n first\n \n ---\n Queued #2\n second" {
135158 t .Fatalf ("unexpected combined follow-up prompt with summary: %q" , messages [0 ].Text ())
136159 }
137160
138- if again := oc . getFollowUpMessages ( roomID ); len (again ) != 0 {
161+ if again := getFollowUpMessagesForTest ( oc , roomID ); len (again ) != 0 {
139162 t .Fatalf ("expected collect summary to be consumed, got %#v" , again )
140163 }
141164 if snapshot := oc .getQueueSnapshot (roomID ); snapshot != nil {
@@ -159,7 +182,7 @@ func TestGetFollowUpMessages_UsesSyntheticSummaryPrompt(t *testing.T) {
159182 },
160183 }
161184
162- messages := oc . getFollowUpMessages ( roomID )
185+ messages := getFollowUpMessagesForTest ( oc , roomID )
163186 if len (messages ) != 1 || messages [0 ].Role != PromptRoleUser {
164187 t .Fatalf ("expected one synthetic follow-up message, got %#v" , messages )
165188 }
@@ -184,23 +207,23 @@ func TestGetFollowUpMessages_SyntheticSummaryIsConsumedBeforeLatestMessage(t *te
184207 },
185208 }
186209
187- first := oc . getFollowUpMessages ( roomID )
210+ first := getFollowUpMessagesForTest ( oc , roomID )
188211 if len (first ) != 1 || first [0 ].Role != PromptRoleUser {
189212 t .Fatalf ("expected one synthetic follow-up message, got %#v" , first )
190213 }
191214 if first [0 ].Text () != "[Queue overflow] Dropped 2 messages due to cap.\n Summary:\n - older one\n - older two" {
192215 t .Fatalf ("unexpected first synthetic follow-up prompt: %q" , first [0 ].Text ())
193216 }
194217
195- second := oc . getFollowUpMessages ( roomID )
218+ second := getFollowUpMessagesForTest ( oc , roomID )
196219 if len (second ) != 1 || second [0 ].Role != PromptRoleUser {
197220 t .Fatalf ("expected queued latest message after summary, got %#v" , second )
198221 }
199222 if second [0 ].Text () != "latest" {
200223 t .Fatalf ("expected latest queued message after consuming summary, got %q" , second [0 ].Text ())
201224 }
202225
203- if third := oc . getFollowUpMessages ( roomID ); len (third ) != 0 {
226+ if third := getFollowUpMessagesForTest ( oc , roomID ); len (third ) != 0 {
204227 t .Fatalf ("expected queue to be drained after latest message, got %#v" , third )
205228 }
206229}
@@ -218,7 +241,7 @@ func TestGetFollowUpMessages_LeavesNonTextQueueItemsForBacklogProcessing(t *test
218241 },
219242 }
220243
221- messages := oc . getFollowUpMessages ( roomID )
244+ messages := getFollowUpMessagesForTest ( oc , roomID )
222245 if len (messages ) != 0 {
223246 t .Fatalf ("expected non-text follow-up to stay queued, got %#v" , messages )
224247 }
@@ -240,7 +263,7 @@ func TestGetFollowUpMessages_LeavesNonFollowupQueueUntouched(t *testing.T) {
240263 },
241264 }
242265
243- messages := oc . getFollowUpMessages ( roomID )
266+ messages := getFollowUpMessagesForTest ( oc , roomID )
244267 if len (messages ) != 0 {
245268 t .Fatalf ("expected no follow-up messages for non-followup mode, got %#v" , messages )
246269 }
0 commit comments