@@ -398,6 +398,65 @@ func TestComputeSummary(t *testing.T) {
398398 assert .Equal (t , 1 , s .ThreadCount ) // still counts threads
399399 })
400400
401+ t .Run ("note after reply — still shows reply" , func (t * testing.T ) {
402+ c := types.Conversation {CreatedAt : "2025-01-01T10:00:00Z" }
403+ threads := []types.Thread {
404+ {Type : "customer" , CreatedAt : "2025-01-01T10:00:00Z" },
405+ {Type : "reply" , CreatedAt : "2025-01-01T11:00:00Z" },
406+ {Type : "note" , CreatedAt : "2025-01-01T12:00:00Z" },
407+ }
408+ s := computeSummary (c , threads )
409+ assert .Equal (t , "reply" , s .LastBy )
410+ assert .False (t , s .AwaitingReply )
411+ })
412+
413+ t .Run ("note after customer — still awaiting" , func (t * testing.T ) {
414+ c := types.Conversation {CreatedAt : "2025-01-01T10:00:00Z" }
415+ threads := []types.Thread {
416+ {Type : "customer" , CreatedAt : "2025-01-01T10:00:00Z" },
417+ {Type : "note" , CreatedAt : "2025-01-01T11:00:00Z" },
418+ }
419+ s := computeSummary (c , threads )
420+ assert .Equal (t , "customer" , s .LastBy )
421+ assert .True (t , s .AwaitingReply )
422+ })
423+
424+ t .Run ("lineitem after customer — still awaiting" , func (t * testing.T ) {
425+ c := types.Conversation {CreatedAt : "2025-01-01T10:00:00Z" }
426+ threads := []types.Thread {
427+ {Type : "customer" , CreatedAt : "2025-01-01T10:00:00Z" },
428+ {Type : "reply" , CreatedAt : "2025-01-01T11:00:00Z" },
429+ {Type : "customer" , CreatedAt : "2025-01-01T12:00:00Z" },
430+ {Type : "lineitem" , CreatedAt : "2025-01-01T13:00:00Z" },
431+ }
432+ s := computeSummary (c , threads )
433+ assert .Equal (t , "customer" , s .LastBy )
434+ assert .True (t , s .AwaitingReply )
435+ })
436+
437+ t .Run ("forward types ignored" , func (t * testing.T ) {
438+ c := types.Conversation {CreatedAt : "2025-01-01T10:00:00Z" }
439+ threads := []types.Thread {
440+ {Type : "customer" , CreatedAt : "2025-01-01T10:00:00Z" },
441+ {Type : "forwardparent" , CreatedAt : "2025-01-01T11:00:00Z" },
442+ {Type : "forwardchild" , CreatedAt : "2025-01-01T12:00:00Z" },
443+ }
444+ s := computeSummary (c , threads )
445+ assert .Equal (t , "customer" , s .LastBy )
446+ assert .True (t , s .AwaitingReply )
447+ })
448+
449+ t .Run ("message type counts as agent reply" , func (t * testing.T ) {
450+ c := types.Conversation {CreatedAt : "2025-01-01T10:00:00Z" }
451+ threads := []types.Thread {
452+ {Type : "customer" , CreatedAt : "2025-01-01T10:00:00Z" },
453+ {Type : "message" , CreatedAt : "2025-01-01T11:00:00Z" },
454+ }
455+ s := computeSummary (c , threads )
456+ assert .Equal (t , "message" , s .LastBy )
457+ assert .False (t , s .AwaitingReply )
458+ })
459+
401460 t .Run ("attachments counted" , func (t * testing.T ) {
402461 c := types.Conversation {CreatedAt : "2025-01-01T10:00:00Z" }
403462 threads := []types.Thread {
0 commit comments