MCPcopy Create free account
hub / github.com/compozy/agh / TestUnixSocketClientStreamsSessionEvents

Function TestUnixSocketClientStreamsSessionEvents

internal/cli/client_test.go:969–1025  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

967}
968
969func TestUnixSocketClientStreamsSessionEvents(t *testing.T) {
970 t.Parallel()
971
972 t.Run("Should stream session events", func(t *testing.T) {
973 t.Parallel()
974
975 client := &unixSocketClient{
976 socketPath: "/tmp/agh.sock",
977 httpClient: &http.Client{
978 Transport: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
979 if req.Method == http.MethodGet && req.URL.Path == "/api/sessions" {
980 return newHTTPResponse(
981 http.StatusOK,
982 `{"sessions":[{"id":"sess-1","agent_name":"coder","workspace_id":"ws-1","workspace_path":"/tmp","state":"active","created_at":"2026-04-03T12:00:00Z","updated_at":"2026-04-03T12:00:00Z"}]}`,
983 ), nil
984 }
985 if req.Method != http.MethodGet || req.URL.Path != "/api/workspaces/ws-1/sessions/sess-1/stream" {
986 t.Fatalf("request = %s %s, want GET session stream", req.Method, req.URL.Path)
987 }
988 if req.Header.Get("Last-Event-ID") != "evt-0" {
989 t.Fatalf("Last-Event-ID = %q, want evt-0", req.Header.Get("Last-Event-ID"))
990 }
991 if req.URL.Query().Get("type") != "tool_call" ||
992 req.URL.Query().Get("agent_name") != "coder" ||
993 req.URL.Query().Get("limit") != "2" {
994 t.Fatalf("stream query = %s, want filters", req.URL.RawQuery)
995 }
996 return newHTTPResponse(
997 http.StatusOK,
998 "id: evt-1\n"+
999 "event: tool_call\n"+
1000 `data: {"id":"evt-1","session_id":"sess-1","sequence":1,"type":"tool_call","agent_name":"coder","timestamp":"2026-04-03T12:00:00Z"}`+
1001 "\n\n",
1002 ), nil
1003 }),
1004 },
1005 }
1006
1007 var events []SSEEvent
1008 err := client.StreamSessionEvents(
1009 context.Background(),
1010 " sess-1 ",
1011 SessionEventQuery{Type: "tool_call", AgentName: "coder", Last: 2},
1012 "evt-0",
1013 func(event SSEEvent) error {
1014 events = append(events, event)
1015 return nil
1016 },
1017 )
1018 if err != nil {
1019 t.Fatalf("StreamSessionEvents() error = %v", err)
1020 }
1021 if len(events) != 1 || events[0].ID != "evt-1" || events[0].Event != "tool_call" {
1022 t.Fatalf("events = %#v, want one tool_call event", events)
1023 }
1024 })
1025}
1026

Callers

nothing calls this directly

Calls 7

StreamSessionEventsMethod · 0.95
roundTripperFuncFuncType · 0.85
appendFunction · 0.85
newHTTPResponseFunction · 0.70
RunMethod · 0.65
GetMethod · 0.65
QueryMethod · 0.65

Tested by

no test coverage detected