MCPcopy Index your code
hub / github.com/coder/coder / TestDynamicToolsFromSDK

Function TestDynamicToolsFromSDK

coderd/x/chatd/dynamictool_internal_test.go:13–114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestDynamicToolsFromSDK(t *testing.T) {
14 t.Parallel()
15
16 t.Run("EmptySlice", func(t *testing.T) {
17 t.Parallel()
18 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
19 result := dynamicToolsFromSDK(logger, nil)
20 require.Nil(t, result)
21 })
22
23 t.Run("ValidToolWithSchema", func(t *testing.T) {
24 t.Parallel()
25 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
26 tools := []codersdk.DynamicTool{
27 {
28 Name: "my_tool",
29 Description: "A useful tool",
30 InputSchema: json.RawMessage(`{"type":"object","properties":{"input":{"type":"string"}},"required":["input"]}`),
31 },
32 }
33 result := dynamicToolsFromSDK(logger, tools)
34 require.Len(t, result, 1)
35
36 info := result[0].Info()
37 require.Equal(t, "my_tool", info.Name)
38 require.Equal(t, "A useful tool", info.Description)
39 require.NotNil(t, info.Parameters)
40 require.Contains(t, info.Parameters, "input")
41 require.Equal(t, []string{"input"}, info.Required)
42 })
43
44 t.Run("ToolWithoutSchema", func(t *testing.T) {
45 t.Parallel()
46 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
47 tools := []codersdk.DynamicTool{
48 {
49 Name: "no_schema",
50 Description: "Tool with no schema",
51 },
52 }
53 result := dynamicToolsFromSDK(logger, tools)
54 require.Len(t, result, 1)
55
56 info := result[0].Info()
57 require.Equal(t, "no_schema", info.Name)
58 require.Nil(t, info.Parameters)
59 require.Nil(t, info.Required)
60 })
61
62 t.Run("MalformedSchema", func(t *testing.T) {
63 t.Parallel()
64 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
65 tools := []codersdk.DynamicTool{
66 {
67 Name: "bad_schema",
68 Description: "Tool with malformed schema",
69 InputSchema: json.RawMessage("not-json"),
70 },

Callers

nothing calls this directly

Calls 6

dynamicToolsFromSDKFunction · 0.85
RunMethod · 0.65
LenMethod · 0.45
InfoMethod · 0.45
EqualMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected