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

Function TestToolInvokeCommandInputs

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

Source from the content-addressed store, hash-verified

136}
137
138func TestToolInvokeCommandInputs(t *testing.T) {
139 t.Parallel()
140
141 t.Run("Should invoke with inline json and redact sensitive result fields", func(t *testing.T) {
142 t.Parallel()
143
144 client := &stubClient{
145 invokeToolFn: func(_ context.Context, id string, request ToolInvokeRequest) (ToolInvokeResponseRecord, error) {
146 if id != toolspkg.ToolIDToolInfo.String() {
147 t.Fatalf("InvokeTool id = %q, want %q", id, toolspkg.ToolIDToolInfo)
148 }
149 if got, want := string(request.Input), `{"tool_id":"agh__skill_view"}`; got != want {
150 t.Fatalf("InvokeTool input = %s, want %s", got, want)
151 }
152 if len(request.SensitiveInputFields) != 1 || request.SensitiveInputFields[0] != "token" {
153 t.Fatalf("SensitiveInputFields = %#v, want token", request.SensitiveInputFields)
154 }
155 return ToolInvokeResponseRecord{
156 ToolID: toolspkg.ToolIDToolInfo,
157 Status: "completed",
158 DurationMS: 9,
159 Result: toolspkg.ToolResult{
160 Preview: "token=super-secret",
161 Structured: json.RawMessage(`{"token":"super-secret","visible":"ok"}`),
162 DurationMS: 9,
163 },
164 Events: []contract.ToolCallEventPayload{},
165 }, nil
166 },
167 }
168 stdout, _, err := executeRootCommand(
169 t,
170 newTestDeps(t, client),
171 "tool",
172 "invoke",
173 toolspkg.ToolIDToolInfo.String(),
174 "--input",
175 `{"tool_id":"agh__skill_view"}`,
176 "--sensitive-input-field",
177 "token",
178 "-o",
179 "json",
180 )
181 if err != nil {
182 t.Fatalf("tool invoke inline error = %v", err)
183 }
184 if strings.Contains(stdout, "super-secret") {
185 t.Fatalf("tool invoke output leaked secret: %s", stdout)
186 }
187
188 var response ToolInvokeResponseRecord
189 decodeJSONOutput(t, stdout, &response)
190 if got, want := compactJSON(response.Result.Structured), `{"token":"[REDACTED]","visible":"ok"}`; got != want {
191 t.Fatalf("structured result = %s, want %s", got, want)
192 }
193 })
194
195 t.Run("Should invoke with json input file", func(t *testing.T) {

Callers

nothing calls this directly

Calls 11

executeRootCommandFunction · 0.85
newTestDepsFunction · 0.85
decodeJSONOutputFunction · 0.85
sampleInvokeResponseFunction · 0.85
assertToolErrorFunction · 0.85
ContainsMethod · 0.80
compactJSONFunction · 0.70
RunMethod · 0.65
WriteFileMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected