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

Function TestUnixSocketClientMethods

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

Source from the content-addressed store, hash-verified

1162}
1163
1164func TestUnixSocketClientMethods(t *testing.T) {
1165 t.Parallel()
1166
1167 client := &unixSocketClient{
1168 socketPath: "/tmp/agh.sock",
1169 httpClient: &http.Client{
1170 Transport: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
1171 switch {
1172 case req.Method == http.MethodGet && req.URL.Path == "/api/sessions":
1173 if got := req.URL.Query().Get("workspace"); got != "" && got != "ws-1" {
1174 t.Fatalf("session workspace query = %q, want empty or ws-1", got)
1175 }
1176 return newHTTPResponse(
1177 http.StatusOK,
1178 `{"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"}]}`,
1179 ), nil
1180 case req.Method == http.MethodPost && req.URL.Path == "/api/sessions":
1181 body, err := io.ReadAll(req.Body)
1182 if err != nil {
1183 t.Fatalf("io.ReadAll(session create body) error = %v", err)
1184 }
1185 if !strings.Contains(string(body), `"agent_name":"coder"`) {
1186 t.Fatalf("session create body = %s, want agent_name", body)
1187 }
1188 return newHTTPResponse(
1189 http.StatusCreated,
1190 `{"session":{"id":"sess-new","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"}}`,
1191 ), nil
1192 case req.Method == http.MethodGet && req.URL.Path == "/api/workspaces/ws-1/sessions/sess-1":
1193 return newHTTPResponse(
1194 http.StatusOK,
1195 `{"session":{"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"}}`,
1196 ), nil
1197 case req.Method == http.MethodPost && req.URL.Path == "/api/workspaces/ws-1/sessions/sess-1/stop":
1198 return newHTTPResponse(http.StatusNoContent, ``), nil
1199 case req.Method == http.MethodPost && req.URL.Path == "/api/workspaces/ws-1/sessions/sess-1/attach":
1200 return newHTTPResponse(
1201 http.StatusOK,
1202 `{"session":{"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"}}`,
1203 ), nil
1204 case req.Method == http.MethodPost && req.URL.Path == "/api/workspaces/ws-1/sessions/sess-1/repair":
1205 if got := req.URL.Query().Get("dry_run"); got != "true" {
1206 t.Fatalf("repair dry_run query = %q, want true", got)
1207 }
1208 if got := req.URL.Query().Get("force"); got != "true" {
1209 t.Fatalf("repair force query = %q, want true", got)
1210 }
1211 return newHTTPResponse(
1212 http.StatusOK,
1213 `{"repair":{"session_id":"sess-1","persisted":false,"issues":[],"actions":[{"code":"append_terminal_error","turn_id":"turn-1","persisted":false}]}}`,
1214 ), nil
1215 case req.Method == http.MethodPost && req.URL.Path == "/api/workspaces/ws-1/sessions/sess-1/prompt":
1216 body, err := io.ReadAll(req.Body)
1217 if err != nil {
1218 t.Fatalf("io.ReadAll(prompt body) error = %v", err)
1219 }
1220 if got := req.URL.Query().Get("format"); got != "raw" {
1221 t.Fatalf("prompt format query = %q, want raw", got)

Callers

nothing calls this directly

Calls 15

DaemonStatusMethod · 0.95
ListSessionsMethod · 0.95
CreateSessionMethod · 0.95
GetSessionMethod · 0.95
StopSessionMethod · 0.95
ResumeSessionMethod · 0.95
PromptSessionMethod · 0.95
SessionEventsMethod · 0.95
SessionHistoryMethod · 0.95
ListAgentsMethod · 0.95
GetAgentMethod · 0.95
ListSkillsMethod · 0.95

Tested by

no test coverage detected