返回 DeepSeek-Reasonix
toolcard_test.go
根目录 / internal / cli / toolcard_test.go
1 package cli
2
3 import (
4 "strings"
5 "testing"
6 )
7
8 func TestToolCard(t *testing.T) {
9 cases := []struct {
10 name string
11 args string
12 want []string
13 deny []string
14 }{
15 {"bash", `{"command":"npm test"}`, []string{"Bash", "npm test"}, nil},
16 {"read_file", `{"path":"pkg/a.go"}`, []string{"Read", "pkg/a.go"}, nil},
17 {"grep", `{"pattern":"TODO","path":"."}`, []string{"Search", "TODO"}, nil},
18 {"wait", `{"job_ids":["bash-1","bash-2"],"timeout_seconds":300}`, []string{"Wait", "bash-1", "bash-2"}, []string{"timeout_seconds", "300", "job_ids"}},
19 {"web_fetch", `{"url":"https://x.dev"}`, []string{"Fetch", "https://x.dev"}, nil},
20 {"use_capability", `{"action":"call","capability_id":"mcp-tool:github/search_issues","arguments":{"query":"bug"}}`, []string{"MCP", "mcp-tool:github/search_issues"}, []string{`"arguments"`, `"query"`, "bug"}},
21 {"use_capability", `{"action":"list"}`, []string{"MCP", "list"}, []string{"action"}},
22 }
23 for _, c := range cases {
24 got := toolCard(c.name, c.args, 120)
25 for _, w := range c.want {
26 if !strings.Contains(got, w) {
27 t.Errorf("%s: %q missing %q", c.name, got, w)
28 }
29 }
30 for _, d := range c.deny {
31 if strings.Contains(got, d) {
32 t.Errorf("%s: %q should not contain raw arg %q", c.name, got, d)
33 }
34 }
35 }
36 }
37
38 func TestToolCardUnknownFallsBackToName(t *testing.T) {
39 if got := toolCard("frobnicate", `{}`, 80); !strings.Contains(got, "frobnicate") {
40 t.Errorf("unknown tool should show its raw name, got %q", got)
41 }
42 }
43
43 lines GO