package agents import "testing" func one(t *testing.T, line string) Act { t.Helper() acts := Translate([]byte(line)) if len(acts) != 1 { t.Fatalf("Translate(%s) = %+v, want one act", line, acts) } return acts[0] } func TestTranslateInit(t *testing.T) { a := one(t, `{"type":"system","subtype":"init","session_id":"cs-123","model":"x"}`) if a.Kind != "init" || a.ClaudeSessionID != "cs-123" { t.Errorf("init: %+v", a) } } func TestTranslateToolUse(t *testing.T) { a := one(t, `{"type":"assistant","message":{"content":[{"type":"text","text":"Let me check."},{"type":"tool_use","name":"Bash","input":{"command":"go test ./internal/bot"}}]}}`) if a.Kind != "tool" || a.Tool != "Ran go test ./internal/bot" { t.Errorf("tool: %+v", a) } a = one(t, `{"type":"assistant","message":{"content":[{"type":"tool_use","name":"Read","input":{"file_path":"/x/y.go"}}]}}`) if a.Kind != "tool" || a.Tool != "Read /x/y.go" { t.Errorf("tool: %+v", a) } } func TestTranslateResultTurn(t *testing.T) { a := one(t, `{"type":"result","subtype":"success","result":"Fixed — the ticker fired early.","is_error":false,"session_id":"cs-123"}`) if a.Kind != "turn" || a.Text != "Fixed — the ticker fired early." { t.Errorf("turn: %+v", a) } a = one(t, `{"type":"result","subtype":"error_during_execution","result":"boom","is_error":true}`) if a.Kind != "error" || a.Text != "boom" { t.Errorf("error: %+v", a) } } func TestTranslateIgnoresNoise(t *testing.T) { for _, line := range []string{ "not json", `{"type":"user","message":{"content":[{"type":"tool_result"}]}}`, `{"type":"stream_event","event":{"type":"content_block_delta"}}`, `{"type":"result","result":"","is_error":false}`, `{"type":"system","subtype":"compact"}`, } { if acts := Translate([]byte(line)); len(acts) != 0 { t.Errorf("Translate(%s) = %+v, want none", line, acts) } } } func TestClampLineFlattens(t *testing.T) { if got := clampLine("a\n b\tc", 100); got != "a b c" { t.Errorf("clampLine: %q", got) } }