You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.0 KiB
58 lines
2.0 KiB
package console
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"yunyan/comm"
|
|
)
|
|
|
|
// normalizeAgent 是落库前最后一道清洗:解绑过的 MCP 服务不能把工具白名单留在库里,
|
|
// 否则重新勾上该服务时会冒出上一轮的选择,运营看不见、客户端却会照着执行。
|
|
func TestNormalizeAgentMcpTools(t *testing.T) {
|
|
a := &AgentConfig{
|
|
McpSvcIds: []string{" mcp_map ", "mcp_music", "mcp_map", ""},
|
|
McpTools: map[string][]string{
|
|
"mcp_map": {"geocode", " geocode ", "", "route"},
|
|
"mcp_music": {}, // 空列表 = 全放开,不该留在库里
|
|
"mcp_gone": {"search"}, // 已解绑的服务,残留必须清掉
|
|
},
|
|
}
|
|
normalizeAgent(a)
|
|
|
|
if len(a.McpSvcIds) != 2 || a.McpSvcIds[0] != "mcp_map" || a.McpSvcIds[1] != "mcp_music" {
|
|
t.Fatalf("MCP 引用清洗错:%v", a.McpSvcIds)
|
|
}
|
|
if _, ok := a.McpTools["mcp_gone"]; ok {
|
|
t.Fatalf("解绑服务的工具白名单没清掉:%v", a.McpTools)
|
|
}
|
|
if _, ok := a.McpTools["mcp_music"]; ok {
|
|
t.Fatalf("空白名单应整条删掉(空=全放开):%v", a.McpTools)
|
|
}
|
|
got := a.McpTools["mcp_map"]
|
|
if len(got) != 2 || got[0] != "geocode" || got[1] != "route" {
|
|
t.Fatalf("工具名去空白/去重错:%v", got)
|
|
}
|
|
}
|
|
|
|
// 没配过工具白名单的老 agent(mcp_tools 为 nil)不能因为清洗炸掉,也不该凭空长出条目。
|
|
func TestNormalizeAgentMcpToolsNil(t *testing.T) {
|
|
a := &AgentConfig{McpSvcIds: []string{"mcp_map"}}
|
|
normalizeAgent(a)
|
|
if a.McpTools == nil || len(a.McpTools) != 0 {
|
|
t.Fatalf("nil 白名单应清洗成空 map:%v", a.McpTools)
|
|
}
|
|
}
|
|
|
|
// id 前缀按类型走,肉眼能看出这是哪类 agent;未知类型兜底成 agent。
|
|
func TestAgentIdPrefix(t *testing.T) {
|
|
for typ, want := range map[string]string{
|
|
comm.AgentTypeChat: "chat",
|
|
comm.AgentTypeStsChat: "sts",
|
|
"": "agent",
|
|
"whatever": "agent",
|
|
} {
|
|
if got := agentIdPrefix(typ); got != want {
|
|
t.Fatalf("type=%q 前缀应为 %s,实际 %s", typ, want, got)
|
|
}
|
|
}
|
|
}
|
|
|