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

Function TestUnixSocketClientToolMethods

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

Source from the content-addressed store, hash-verified

555}
556
557func TestUnixSocketClientToolMethods(t *testing.T) {
558 t.Parallel()
559
560 client := &unixSocketClient{
561 socketPath: "/tmp/agh.sock",
562 httpClient: &http.Client{
563 Transport: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
564 switch {
565 case req.Method == http.MethodGet && req.URL.Path == "/api/tools":
566 if req.URL.Query().Get("workspace_id") != "ws-1" ||
567 req.URL.Query().Get("session_id") != "sess-1" ||
568 req.URL.Query().Get("agent_name") != "coder" {
569 t.Fatalf("tool list query = %s, want scoped query", req.URL.RawQuery)
570 }
571 return newHTTPResponse(http.StatusOK, string(mustJSON(t, sampleToolsResponse()))), nil
572 case req.Method == http.MethodPost && req.URL.Path == "/api/tools/search":
573 var request ToolSearchRequest
574 if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
575 t.Fatalf("decode search body: %v", err)
576 }
577 if request.Query != "skill" || request.Limit != 2 || request.WorkspaceID != "ws-1" {
578 t.Fatalf("tool search request = %#v, want scoped search", request)
579 }
580 return newHTTPResponse(http.StatusOK, string(mustJSON(t, sampleToolsResponse()))), nil
581 case req.Method == http.MethodGet && req.URL.Path == "/api/tools/agh__skill_view":
582 if req.URL.Query().Get("workspace_id") != "ws-1" {
583 t.Fatalf("tool info query = %s, want workspace_id=ws-1", req.URL.RawQuery)
584 }
585 return newHTTPResponse(
586 http.StatusOK,
587 string(mustJSON(t, ToolResponseRecord{Tool: sampleToolsResponse().Tools[0]})),
588 ), nil
589 case req.Method == http.MethodPost && req.URL.Path == "/api/tools/agh__tool_info/invoke":
590 var request ToolInvokeRequest
591 if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
592 t.Fatalf("decode invoke body: %v", err)
593 }
594 if string(request.Input) != `{"tool_id":"agh__skill_view"}` ||
595 request.SessionID != "sess-1" ||
596 len(request.SensitiveInputFields) != 1 ||
597 request.SensitiveInputFields[0] != "token" {
598 t.Fatalf("invoke request = %#v, want scoped tool input", request)
599 }
600 response := sampleInvokeResponse()
601 response.Result.Preview = "token=agh_claim_secret"
602 response.Result.Structured = json.RawMessage(
603 `{"access_token":"super-secret","completion_tokens":9}`,
604 )
605 return newHTTPResponse(http.StatusOK, string(mustJSON(t, response))), nil
606 case req.Method == http.MethodGet && req.URL.Path == "/api/toolsets":
607 if req.URL.Query().Get("agent_name") != "coder" {
608 t.Fatalf("toolsets query = %s, want agent_name=coder", req.URL.RawQuery)
609 }
610 return newHTTPResponse(http.StatusOK, string(mustJSON(t, sampleToolsetsResponse()))), nil
611 case req.Method == http.MethodGet && req.URL.Path == "/api/toolsets/agh__catalog":
612 if req.URL.Query().Get("session_id") != "sess-1" {
613 t.Fatalf("toolset info query = %s, want session_id=sess-1", req.URL.RawQuery)
614 }

Callers

nothing calls this directly

Calls 15

ListToolsMethod · 0.95
SearchToolsMethod · 0.95
GetToolMethod · 0.95
InvokeToolMethod · 0.95
ListToolsetsMethod · 0.95
GetToolsetMethod · 0.95
roundTripperFuncFuncType · 0.85
sampleToolsResponseFunction · 0.85
sampleInvokeResponseFunction · 0.85
sampleToolsetsResponseFunction · 0.85
ContainsMethod · 0.80
newHTTPResponseFunction · 0.70

Tested by

no test coverage detected