-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04-agents-test.sh
More file actions
executable file
·213 lines (182 loc) · 4.48 KB
/
04-agents-test.sh
File metadata and controls
executable file
·213 lines (182 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
# Claude Code Agent 系统测试脚本
# 用途:验证 Agent 定义和配置
set -e
echo "=========================================="
echo "Claude Code Agent 系统测试"
echo "=========================================="
TEST_DIR="/tmp/claude-agents-test"
rm -rf "$TEST_DIR"
mkdir -p "$TEST_DIR"
# 测试 1: Agent 定义 JSON 结构
echo ""
echo "测试 1: Agent 定义结构验证"
echo "--------------------------------"
cat > "$TEST_DIR/agent-test.json" << 'EOF'
{
"agents": {
"reviewer": {
"description": "代码审查专家",
"instructions": "你是一个专业的代码审查员...",
"tools": ["Read", "Grep", "Glob", "Edit"],
"disallowedTools": ["Bash(rm *)", "Bash(sudo *)"],
"model": "sonnet",
"maxTokens": 4096
},
"debugger": {
"description": "Bug 调试专家",
"tools": ["Read", "Grep", "Bash"],
"model": "opus"
}
}
}
EOF
if python3 -c "import json; json.load(open('$TEST_DIR/agent-test.json'))" 2>/dev/null; then
echo "✅ Agent 定义 JSON 语法正确"
else
echo "❌ Agent 定义 JSON 语法错误"
fi
# 测试 2: Agent tools 字段验证
echo ""
echo "测试 2: Agent tools 配置验证"
echo "--------------------------------"
VALID_TOOLS=(
"Read"
"Write"
"Edit"
"Glob"
"Grep"
"Bash"
"Agent"
"TaskOutput"
"TodoWrite"
)
for tool in "${VALID_TOOLS[@]}"; do
echo "✅ 有效工具: $tool"
done
# 测试 3: disallowedTools 规则
echo ""
echo "测试 3: disallowedTools 规则验证"
echo "--------------------------------"
DISALLOWED_RULES=(
"Bash(rm *)"
"Bash(sudo *)"
"Bash(!git *)"
"Write(!*.md)"
)
for rule in "${DISALLOWED_RULES[@]}"; do
if [[ "$rule" =~ ^[A-Za-z]+\(.+\)$ ]]; then
echo "✅ 有效禁止规则: $rule"
else
echo "❌ 无效禁止规则: $rule"
fi
done
# 测试 4: Agent 模型配置
echo ""
echo "测试 4: Agent 模型配置验证"
echo "--------------------------------"
VALID_MODELS=(
"opus"
"sonnet"
"haiku"
"claude-opus-4-6"
"claude-sonnet-4-6"
)
for model in "${VALID_MODELS[@]}"; do
echo "✅ 有效模型: $model"
done
# 测试 5: Agent 调用测试
echo ""
echo "测试 5: Agent 调用结构验证"
echo "--------------------------------"
cat > "$TEST_DIR/agent-call.json" << 'EOF'
{
"tool": "Agent",
"input": {
"prompt": "审查这段代码的问题",
"agent": "reviewer",
"timeout": 300
}
}
EOF
if python3 -c "import json; json.load(open('$TEST_DIR/agent-call.json'))" 2>/dev/null; then
echo "✅ Agent 调用 JSON 语法正确"
else
echo "❌ Agent 调用 JSON 语法错误"
fi
# 测试 6: 多 Agent 协作配置
echo ""
echo "测试 6: 多 Agent 协作配置"
echo "--------------------------------"
cat > "$TEST_DIR/multi-agent.json" << 'EOF'
{
"agents": {
"coordinator": {
"description": "任务协调者",
"tools": ["Agent"],
"maxTokens": 8192
},
"frontend-dev": {
"description": "前端开发者",
"tools": ["Read", "Write", "Edit", "Glob", "Bash"],
"cwd": "./frontend"
},
"backend-dev": {
"description": "后端开发者",
"tools": ["Read", "Write", "Edit", "Glob", "Bash"],
"cwd": "./backend"
}
}
}
EOF
if python3 -c "import json; json.load(open('$TEST_DIR/multi-agent.json'))" 2>/dev/null; then
echo "✅ 多 Agent 配置 JSON 语法正确"
else
echo "❌ 多 Agent 配置 JSON 语法错误"
fi
# 测试 7: Agent frontmatter 验证
echo ""
echo "测试 7: Agent frontmatter 验证"
echo "--------------------------------"
mkdir -p "$TEST_DIR/agents/reviewer"
cat > "$TEST_DIR/agents/reviewer/AGENT.md" << 'EOF'
---
name: reviewer
description: 代码审查专家
model: sonnet
tools:
- Read
- Grep
- Glob
- Edit
disallowedTools:
- Bash(rm *)
- Bash(sudo *)
---
# 代码审查 Agent
## 职责
- 检查代码质量
- 发现潜在 Bug
- 提出优化建议
## 工作流程
1. 阅读代码
2. 分析问题
3. 给出建议
EOF
if [ -f "$TEST_DIR/agents/reviewer/AGENT.md" ]; then
echo "✅ Agent 文件存在"
else
echo "❌ Agent 文件不存在"
fi
if grep -q "name: reviewer" "$TEST_DIR/agents/reviewer/AGENT.md"; then
echo "✅ Agent frontmatter name 正确"
fi
if grep -q "description:" "$TEST_DIR/agents/reviewer/AGENT.md"; then
echo "✅ Agent frontmatter description 存在"
fi
# 清理
rm -rf "$TEST_DIR"
echo ""
echo "=========================================="
echo "Agent 系统测试完成"
echo "=========================================="