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

Function TestToolCommandsRenderJSON

internal/cli/tool_test.go:16–136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestToolCommandsRenderJSON(t *testing.T) {
17 t.Parallel()
18
19 t.Run("Should render tool list json with scoped query", func(t *testing.T) {
20 t.Parallel()
21
22 client := &stubClient{
23 listToolsFn: func(_ context.Context, query ToolQuery) (ToolsResponseRecord, error) {
24 if query.WorkspaceID != "ws-1" || query.SessionID != "sess-1" || query.AgentName != "coder" {
25 t.Fatalf("ListTools query = %#v, want scoped query", query)
26 }
27 return sampleToolsResponse(), nil
28 },
29 }
30 stdout, _, err := executeRootCommand(
31 t,
32 newTestDeps(t, client),
33 "tool",
34 "list",
35 "--workspace",
36 "ws-1",
37 "--session",
38 "sess-1",
39 "--agent",
40 "coder",
41 "-o",
42 "json",
43 )
44 if err != nil {
45 t.Fatalf("tool list error = %v", err)
46 }
47
48 var response ToolsResponseRecord
49 decodeJSONOutput(t, stdout, &response)
50 if got, want := len(response.Tools), 2; got != want {
51 t.Fatalf("tool count = %d, want %d", got, want)
52 }
53 if got, want := response.Tools[0].Descriptor.ToolID, toolspkg.ToolIDSkillView; got != want {
54 t.Fatalf("tool id = %q, want %q", got, want)
55 }
56 if got, want := response.Tools[1].Availability.ReasonCodes[0], toolspkg.ReasonMCPAuthRequired; got != want {
57 t.Fatalf("reason = %q, want %q", got, want)
58 }
59 })
60
61 t.Run("Should render tool search json with request body", func(t *testing.T) {
62 t.Parallel()
63
64 client := &stubClient{
65 searchToolsFn: func(_ context.Context, request ToolSearchRequest) (ToolsResponseRecord, error) {
66 if request.Query != "skill" ||
67 request.Limit != 1 ||
68 request.WorkspaceID != "ws-1" ||
69 request.SessionID != "sess-1" ||
70 request.AgentName != "coder" {
71 t.Fatalf("SearchTools request = %#v, want scoped search", request)
72 }
73 return ToolsResponseRecord{Tools: sampleToolsResponse().Tools[:1]}, nil

Callers

nothing calls this directly

Calls 6

sampleToolsResponseFunction · 0.85
executeRootCommandFunction · 0.85
newTestDepsFunction · 0.85
decodeJSONOutputFunction · 0.85
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected