MCPcopy Create free account
hub / github.com/coder/coder / TestInjectTools

Function TestInjectTools

aibridge/intercept/responses/reqpayload_internal_test.go:260–333  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

258}
259
260func TestInjectTools(t *testing.T) {
261 t.Parallel()
262
263 tests := []struct {
264 name string
265 raw []byte
266 injected []responses.ToolUnionParam
267 wantNames []string
268 wantErr string
269 wantSame bool
270 }{
271 {
272 name: "appends to existing tools",
273 raw: []byte(`{"model":"gpt-4o","input":"hello","tools":[{"type":"function","name":"existing"}]}`),
274 injected: []responses.ToolUnionParam{injectedFunctionTool("injected")},
275 wantNames: []string{"existing", "injected"},
276 },
277 {
278 name: "adds tools when none exist",
279 raw: []byte(`{"model":"gpt-4o","input":"hello"}`),
280 injected: []responses.ToolUnionParam{injectedFunctionTool("injected")},
281 wantNames: []string{"injected"},
282 },
283 {
284 name: "adds to empty tools array",
285 raw: []byte(`{"model":"gpt-4o","input":"hello","tools":[]}`),
286 injected: []responses.ToolUnionParam{injectedFunctionTool("injected")},
287 wantNames: []string{"injected"},
288 },
289 {
290 name: "appends multiple injected tools",
291 raw: []byte(`{"model":"gpt-4o","input":"hello","tools":[{"type":"function","name":"existing"}]}`),
292 injected: []responses.ToolUnionParam{
293 injectedFunctionTool("injected-one"),
294 injectedFunctionTool("injected-two"),
295 },
296 wantNames: []string{"existing", "injected-one", "injected-two"},
297 },
298 {
299 name: "empty injected tools is no op",
300 raw: []byte(`{"model":"gpt-4o","input":"hello","tools":[{"type":"function","name":"existing"}]}`),
301 wantSame: true,
302 },
303 {
304 name: "errors on unsupported tools shape",
305 raw: []byte(`{"model":"gpt-4o","input":"hello","tools":"bad"}`),
306 injected: []responses.ToolUnionParam{injectedFunctionTool("injected")},
307 wantErr: "failed to get existing tools: unsupported 'tools' type: String",
308 wantSame: true,
309 },
310 }
311
312 for _, tc := range tests {
313 t.Run(tc.name, func(t *testing.T) {
314 t.Parallel()
315
316 p := mustPayload(t, tc.raw)
317 updated, err := p.injectTools(tc.injected)

Callers

nothing calls this directly

Calls 6

injectedFunctionToolFunction · 0.85
mustPayloadFunction · 0.85
RunMethod · 0.65
injectToolsMethod · 0.45
EqualMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected