Files
ai_academy/internal/mcpserver/tools_annotations_test.go
T
runny 7ec21f35b0 chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
2026-11-16 18:12:23 +08:00

54 lines
1.4 KiB
Go

package mcpserver
import (
"testing"
"github.com/mark3labs/mcp-go/mcp"
)
func TestReadOnlyEndpointToolsAreNotDestructive(t *testing.T) {
for _, tool := range []mcp.Tool{
listKnowledgeBasesTool(),
searchKnowledgeTool(),
grepChunksTool(),
listDocumentsTool(),
readDocumentTool(),
wikiSearchTool(),
wikiReadPageTool(),
wikiIndexTool(),
} {
ann := tool.Annotations
if ann.ReadOnlyHint == nil || !*ann.ReadOnlyHint {
t.Fatalf("%s must be read-only", tool.Name)
}
if ann.DestructiveHint == nil || *ann.DestructiveHint {
t.Fatalf("%s must not be destructive", tool.Name)
}
if ann.IdempotentHint == nil || !*ann.IdempotentHint {
t.Fatalf("%s must be idempotent", tool.Name)
}
if ann.OpenWorldHint == nil || *ann.OpenWorldHint {
t.Fatalf("%s must not be open-world", tool.Name)
}
}
}
func TestMutatingEndpointToolsStayDestructive(t *testing.T) {
ask := askTool()
if ask.Annotations.ReadOnlyHint == nil || *ask.Annotations.ReadOnlyHint {
t.Fatal("ask must not be read-only")
}
if ask.Annotations.DestructiveHint == nil || !*ask.Annotations.DestructiveHint {
t.Fatal("ask keeps the default destructive hint")
}
for _, tool := range []mcp.Tool{
addDocumentTool(),
updateDocumentTool(),
deleteDocumentTool(),
} {
if tool.Annotations.DestructiveHint == nil || !*tool.Annotations.DestructiveHint {
t.Fatalf("%s must stay destructive", tool.Name)
}
}
}