Skip to content

Commit 02497ca

Browse files
committed
test(test) add cmd path to tool name conv
1 parent 88a6116 commit 02497ca

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

test/test.go renamed to test/tools.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"os"
66
"slices"
7+
"strings"
78
"testing"
89

910
"github.com/google/jsonschema-go/jsonschema"
@@ -72,6 +73,16 @@ func ToolNames(t *testing.T, tools []*mcp.Tool, expectedNames ...string) {
7273
}
7374
}
7475

76+
// CmdPathsToToolNames converts command names with spaces to tool names with underscores
77+
func CmdPathsToToolNames(paths []string) []string {
78+
names := make([]string, 0, len(paths))
79+
for _, path := range paths {
80+
names = append(names, strings.ReplaceAll(path, " ", "_"))
81+
}
82+
83+
return names
84+
}
85+
7586
// Tools runs `mcp tools` and checks the output tool names against expectedNames
7687
// It fails if ophis.Command is not a root level subcommand
7788
func Tools(t *testing.T, cmd *cobra.Command, expectedNames ...string) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,11 @@ func TestGetTools(t *testing.T) {
6060
assert.Equal(t, "object", schema.Type, "Schema type should be object")
6161
}
6262
}
63+
64+
func TestCmdNamesToToolNames(t *testing.T) {
65+
cmdNames := []string{"get", "list all", "create this item"}
66+
expectedToolNames := []string{"get", "list_all", "create_this_item"}
67+
68+
toolNames := CmdPathsToToolNames(cmdNames)
69+
assert.Equal(t, expectedToolNames, toolNames, "Tool names should match expected format")
70+
}

0 commit comments

Comments
 (0)