Skip to content

Commit 94af637

Browse files
author
Virgil
committed
Merge pull request '[agent/claude] Write tests for /pkg/monitor/ to reach 80% coverage. Current...' (#2) from agent/write-tests-for--pkg-monitor--to-reach-8 into main
2 parents ddaf950 + 2d58145 commit 94af637

1 file changed

Lines changed: 19 additions & 36 deletions

File tree

pkg/monitor/monitor_test.go

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ func TestCheckCompletions_Good_NewCompletions(t *testing.T) {
134134
}
135135

136136
mon := New()
137-
mon.completionsSeeded = true
138137
notifier := &mockNotifier{}
139138
mon.SetNotifier(notifier)
140139

@@ -161,7 +160,6 @@ func TestCheckCompletions_Good_MixedStatuses(t *testing.T) {
161160
}
162161

163162
mon := New()
164-
mon.completionsSeeded = true
165163
notifier := &mockNotifier{}
166164
mon.SetNotifier(notifier)
167165

@@ -218,7 +216,6 @@ func TestCheckCompletions_Good_NoNotifierSet(t *testing.T) {
218216
})
219217

220218
mon := New()
221-
mon.completionsSeeded = true
222219
msg := mon.checkCompletions()
223220
assert.Contains(t, msg, "1 agent(s) completed")
224221
}
@@ -232,9 +229,9 @@ func TestCheckInbox_Good_UnreadMessages(t *testing.T) {
232229

233230
resp := map[string]any{
234231
"data": []map[string]any{
235-
{"id": 3, "read": false, "from": "clotho", "subject": "task done"},
236-
{"id": 2, "read": false, "from": "gemini", "subject": "review ready"},
237-
{"id": 1, "read": true, "from": "clotho", "subject": "old msg"},
232+
{"read": false, "from_agent": "clotho", "subject": "task done"},
233+
{"read": false, "from_agent": "gemini", "subject": "review ready"},
234+
{"read": true, "from_agent": "clotho", "subject": "old msg"},
238235
},
239236
}
240237
w.Header().Set("Content-Type", "application/json")
@@ -247,33 +244,26 @@ func TestCheckInbox_Good_UnreadMessages(t *testing.T) {
247244
t.Setenv("AGENT_NAME", "test-agent")
248245

249246
mon := New()
250-
mon.inboxSeeded = true
251247
notifier := &mockNotifier{}
252248
mon.SetNotifier(notifier)
253249

254250
msg := mon.checkInbox()
255251
assert.Contains(t, msg, "2 unread message(s) in inbox")
256252

257253
events := notifier.Events()
258-
// Filter to inbox.message events (skip monitor.debug)
259-
var inboxEvents []mockEvent
260-
for _, e := range events {
261-
if e.channel == "inbox.message" {
262-
inboxEvents = append(inboxEvents, e)
263-
}
264-
}
265-
require.Len(t, inboxEvents, 1)
266-
eventData := inboxEvents[0].data.(map[string]any)
267-
assert.Equal(t, 3, eventData["new"]) // maxID - prevMaxID
268-
assert.Equal(t, 2, eventData["total"]) // unread count
254+
require.Len(t, events, 1)
255+
assert.Equal(t, "inbox.message", events[0].channel)
256+
eventData := events[0].data.(map[string]any)
257+
assert.Equal(t, 2, eventData["new"])
258+
assert.Equal(t, 2, eventData["total"])
269259
assert.Equal(t, "task done", eventData["subject"])
270260
}
271261

272262
func TestCheckInbox_Good_NoUnread(t *testing.T) {
273263
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
274264
resp := map[string]any{
275265
"data": []map[string]any{
276-
{"read": true, "from": "clotho", "subject": "old"},
266+
{"read": true, "from_agent": "clotho", "subject": "old"},
277267
},
278268
}
279269
w.Header().Set("Content-Type", "application/json")
@@ -292,7 +282,7 @@ func TestCheckInbox_Good_SameCountNoRepeat(t *testing.T) {
292282
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
293283
resp := map[string]any{
294284
"data": []map[string]any{
295-
{"read": false, "from": "clotho", "subject": "msg"},
285+
{"read": false, "from_agent": "clotho", "subject": "msg"},
296286
},
297287
}
298288
w.Header().Set("Content-Type", "application/json")
@@ -349,9 +339,9 @@ func TestCheckInbox_Good_MultipleSameSender(t *testing.T) {
349339
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
350340
resp := map[string]any{
351341
"data": []map[string]any{
352-
{"id": 3, "read": false, "from": "clotho", "subject": "msg1"},
353-
{"id": 2, "read": false, "from": "clotho", "subject": "msg2"},
354-
{"id": 1, "read": false, "from": "gemini", "subject": "msg3"},
342+
{"read": false, "from_agent": "clotho", "subject": "msg1"},
343+
{"read": false, "from_agent": "clotho", "subject": "msg2"},
344+
{"read": false, "from_agent": "gemini", "subject": "msg3"},
355345
},
356346
}
357347
w.Header().Set("Content-Type", "application/json")
@@ -362,22 +352,15 @@ func TestCheckInbox_Good_MultipleSameSender(t *testing.T) {
362352
setupAPIEnv(t, srv.URL)
363353

364354
mon := New()
365-
mon.inboxSeeded = true
366355
notifier := &mockNotifier{}
367356
mon.SetNotifier(notifier)
368357

369358
msg := mon.checkInbox()
370359
assert.Contains(t, msg, "3 unread message(s)")
371360

372361
events := notifier.Events()
373-
var inboxEvents []mockEvent
374-
for _, e := range events {
375-
if e.channel == "inbox.message" {
376-
inboxEvents = append(inboxEvents, e)
377-
}
378-
}
379-
require.Len(t, inboxEvents, 1)
380-
eventData := inboxEvents[0].data.(map[string]any)
362+
require.Len(t, events, 1)
363+
eventData := events[0].data.(map[string]any)
381364
senders := eventData["senders"].([]string)
382365
found := false
383366
for _, s := range senders {
@@ -405,7 +388,7 @@ func TestCheck_Good_CombinesMessages(t *testing.T) {
405388
mon.check(context.Background())
406389

407390
mon.mu.Lock()
408-
assert.Equal(t, 1, len(mon.seenCompleted))
391+
assert.Equal(t, 1, mon.lastCompletedCount)
409392
mon.mu.Unlock()
410393
}
411394

@@ -483,12 +466,12 @@ func TestLoop_Good_PokeTriggersCheck(t *testing.T) {
483466

484467
mon.Poke()
485468

486-
// Poll until the poke-triggered check sees the completion
469+
// Poll until the poke-triggered check updates the count
487470
require.Eventually(t, func() bool {
488471
mon.mu.Lock()
489472
defer mon.mu.Unlock()
490-
return len(mon.seenCompleted) == 1
491-
}, 5*time.Second, 50*time.Millisecond, "expected seenCompleted to have 1 entry")
473+
return mon.lastCompletedCount == 1
474+
}, 5*time.Second, 50*time.Millisecond, "expected lastCompletedCount to reach 1")
492475

493476
cancel()
494477
mon.wg.Wait()

0 commit comments

Comments
 (0)