Show agent liveness, stuck/zombie detection and parse errors in admin
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package claude
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestBadLines(t *testing.T) {
|
||||
bad := []string{}
|
||||
s := &Session{
|
||||
events: make(chan Event, 16),
|
||||
done: make(chan struct{}),
|
||||
onBadLine: func(line []byte, reason string) {
|
||||
bad = append(bad, string(line)+" | "+reason)
|
||||
},
|
||||
}
|
||||
|
||||
input := strings.Join([]string{
|
||||
`{"type":"assistant","message":{"content":[]}}`,
|
||||
``,
|
||||
`warning: something on stdout`,
|
||||
`{"type":"assistant",`,
|
||||
`{"type":"mystery","x":1}`,
|
||||
`{"type":"keep_alive"}`,
|
||||
`{"type":"tool_progress","heartbeat":true}`,
|
||||
}, "\n")
|
||||
|
||||
before := time.Now()
|
||||
s.readLoop(strings.NewReader(input))
|
||||
|
||||
want := []string{
|
||||
`warning: something on stdout | not a JSON object`,
|
||||
`{"type":"assistant", | unexpected end of JSON input`,
|
||||
`{"type":"mystery","x":1} | unrecognised type "mystery"`,
|
||||
}
|
||||
if strings.Join(bad, "\n") != strings.Join(want, "\n") {
|
||||
t.Errorf("bad lines:\n%s\nwant:\n%s", strings.Join(bad, "\n"), strings.Join(want, "\n"))
|
||||
}
|
||||
|
||||
types := []string{}
|
||||
for ev := range s.events {
|
||||
types = append(types, ev.Type)
|
||||
}
|
||||
if strings.Join(types, ",") != "assistant,mystery,tool_progress" {
|
||||
t.Errorf("events = %v", types)
|
||||
}
|
||||
|
||||
if s.LastLine().Before(before) {
|
||||
t.Errorf("last line time %v not updated", s.LastLine())
|
||||
}
|
||||
if !s.Exited() {
|
||||
t.Errorf("session not exited after stdout closed")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user