Skip to content

Commit e60b341

Browse files
committed
Extract follow-up test helper; remove unused wrappers
Add getFollowUpMessagesForTest in agent_loop_steering_test.go and update tests to call it instead of the AIClient method. Remove the oc.getFollowUpMessages implementation from pending_queue.go and delete the unused registerRoomRunPendingItem wrapper in room_runs.go (keep the locked registerRoomRunPendingItemLocked). These changes reduce API surface on AIClient and consolidate test-only logic into the test file.
1 parent 712e442 commit e60b341

3 files changed

Lines changed: 33 additions & 46 deletions

File tree

bridges/ai/agent_loop_steering_test.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1235
func 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.\nSummary:\n- older one\n- older two\n\n---\nQueued #1\nfirst\n\n---\nQueued #2\nsecond" {
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.\nSummary:\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
}

bridges/ai/pending_queue.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -351,32 +351,6 @@ func buildSteeringPromptMessages(prompts []string) []PromptMessage {
351351
return messages
352352
}
353353

354-
func (oc *AIClient) getFollowUpMessages(roomID id.RoomID) []PromptMessage {
355-
if oc == nil || roomID == "" {
356-
return nil
357-
}
358-
snapshot := oc.getQueueSnapshot(roomID)
359-
if snapshot == nil {
360-
return nil
361-
}
362-
behavior := airuntime.ResolveQueueBehavior(snapshot.mode)
363-
if !behavior.Followup {
364-
return nil
365-
}
366-
candidate, _ := oc.takePendingQueueDispatchCandidate(roomID, true)
367-
if candidate == nil || len(candidate.items) == 0 {
368-
return nil
369-
}
370-
for _, item := range candidate.items {
371-
oc.registerRoomRunPendingItem(roomID, item)
372-
}
373-
_, prompt, ok := preparePendingQueueDispatchCandidate(candidate)
374-
if !ok {
375-
return nil
376-
}
377-
return buildSteeringPromptMessages([]string{prompt})
378-
}
379-
380354
func (oc *AIClient) markQueueDraining(roomID id.RoomID) bool {
381355
oc.pendingQueuesMu.Lock()
382356
defer oc.pendingQueuesMu.Unlock()

bridges/ai/room_runs.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,6 @@ func (oc *AIClient) enqueueSteerQueue(roomID id.RoomID, item pendingQueueItem) b
117117
return true
118118
}
119119

120-
func (oc *AIClient) registerRoomRunPendingItem(roomID id.RoomID, item pendingQueueItem) {
121-
run := oc.getRoomRun(roomID)
122-
if run == nil {
123-
return
124-
}
125-
run.mu.Lock()
126-
defer run.mu.Unlock()
127-
oc.registerRoomRunPendingItemLocked(run, item)
128-
}
129-
130120
func (oc *AIClient) registerRoomRunPendingItemLocked(run *roomRunState, item pendingQueueItem) {
131121
if run == nil {
132122
return

0 commit comments

Comments
 (0)