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

Function TestUnixSocketClientTaskExecutionMethods

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

Source from the content-addressed store, hash-verified

1025}
1026
1027func TestUnixSocketClientTaskExecutionMethods(t *testing.T) {
1028 t.Parallel()
1029
1030 t.Run("Should execute task mutation methods", func(t *testing.T) {
1031 t.Parallel()
1032
1033 client := &unixSocketClient{
1034 socketPath: "/tmp/agh.sock",
1035 httpClient: &http.Client{
1036 Transport: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
1037 if req.Method != http.MethodPost {
1038 t.Fatalf("request method = %s, want POST", req.Method)
1039 }
1040 switch req.URL.Path {
1041 case "/api/tasks/task-1/publish", "/api/tasks/task-1/start", "/api/tasks/task-1/approve":
1042 var request TaskExecutionRequest
1043 if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
1044 t.Fatalf("decode task execution body: %v", err)
1045 }
1046 if request.IdempotencyKey != "idem-1" || request.NetworkChannel != "builders" {
1047 t.Fatalf("task execution request = %#v, want idempotency and channel", request)
1048 }
1049 return newHTTPResponse(http.StatusOK, string(mustJSON(t, sampleTaskExecutionRecord()))), nil
1050 default:
1051 t.Fatalf("unexpected request path = %s", req.URL.Path)
1052 return nil, nil
1053 }
1054 }),
1055 },
1056 }
1057 request := TaskExecutionRequest{
1058 IdempotencyKey: "idem-1",
1059 NetworkChannel: "builders",
1060 Metadata: json.RawMessage(`{"source":"cli-test"}`),
1061 }
1062
1063 published, err := client.PublishTask(context.Background(), " task-1 ", request)
1064 if err != nil {
1065 t.Fatalf("PublishTask() error = %v", err)
1066 }
1067 if published.Task.ID == "" || published.Run.ID == "" {
1068 t.Fatalf("PublishTask() = %#v, want task and run", published)
1069 }
1070 started, err := client.StartTask(context.Background(), " task-1 ", request)
1071 if err != nil {
1072 t.Fatalf("StartTask() error = %v", err)
1073 }
1074 if started.Task.ID != published.Task.ID {
1075 t.Fatalf("StartTask() task id = %q, want %q", started.Task.ID, published.Task.ID)
1076 }
1077 approved, err := client.ApproveTask(context.Background(), " task-1 ", request)
1078 if err != nil {
1079 t.Fatalf("ApproveTask() error = %v", err)
1080 }
1081 if approved.Run.ID != published.Run.ID {
1082 t.Fatalf("ApproveTask() run id = %q, want %q", approved.Run.ID, published.Run.ID)
1083 }
1084 })

Callers

nothing calls this directly

Calls 8

PublishTaskMethod · 0.95
StartTaskMethod · 0.95
ApproveTaskMethod · 0.95
roundTripperFuncFuncType · 0.85
newHTTPResponseFunction · 0.70
mustJSONFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected