-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_agents.sh
More file actions
executable file
·218 lines (192 loc) · 8.1 KB
/
validate_agents.sh
File metadata and controls
executable file
·218 lines (192 loc) · 8.1 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
214
215
216
217
218
#!/bin/bash
# validate_agents.sh
# Validation script for Agent Factory
# This script runs all MUST requirement tests
# Note: Do not use 'set -e' here; tests are expected to fail without aborting the script.
echo "======================================"
echo "Agent Factory Validation Suite"
echo "======================================"
echo ""
PASSED=0
FAILED=0
TOTAL=0
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if agents/ directory exists when agents are defined in agents.yaml
if [ -f "agents.yaml" ]; then
agent_count=$(grep -c ' - id:' agents.yaml 2>/dev/null || echo "0")
if [ "$agent_count" -gt 0 ] && [ ! -d "agents" ]; then
echo -e "${YELLOW}Warning: agents.yaml defines $agent_count agent(s) but agents/ directory does not exist.${NC}"
echo "Create the directory with: mkdir -p agents"
echo ""
fi
fi
# Test function
run_test() {
local test_id=$1
local test_name=$2
local test_command=$3
TOTAL=$((TOTAL + 1))
echo "Running ${test_id}: ${test_name}"
if eval "$test_command"; then
echo -e "${GREEN}✓ PASS${NC}: ${test_id}"
PASSED=$((PASSED + 1))
else
echo -e "${RED}✗ FAIL${NC}: ${test_id}"
FAILED=$((FAILED + 1))
fi
echo ""
}
# Helper: verify all agent files referenced in agents.yaml exist
check_agent_files_exist() {
if [ ! -f "agents.yaml" ]; then
return 0 # No agents.yaml, nothing to check
fi
# Extract file_path entries from agents.yaml and check they exist
local missing_files=0
while IFS= read -r filepath; do
if [ -n "$filepath" ] && [ ! -f "$filepath" ]; then
echo "Missing file: $filepath"
missing_files=$((missing_files + 1))
fi
done < <(grep 'file_path:' agents.yaml | awk '{print $2}' | tr -d '"')
[ $missing_files -eq 0 ]
}
# TEST-007-1: Verify agent files exist (replaces flat structure test)
echo "=== SPEC-007: Flexible Directory Structure ==="
if [ -d "agents" ]; then
run_test "TEST-007-1" \
"Verify all agent files referenced in agents.yaml exist" \
"check_agent_files_exist"
else
echo "Note: agents/ directory does not exist yet - skipping TEST-007-1"
echo ""
fi
# TEST-002-1: Verify required headings in agent files (presence and order)
echo "=== SPEC-002: Agent File Format ==="
if [ -d "agents" ] && [ "$(find agents/ -name '*.md' -type f 2>/dev/null | wc -l)" -gt 0 ]; then
# Find all .md files in agents/ directory (including nested)
while IFS= read -r file; do
[ -f "$file" ] || continue
# Check both presence and order of headings
run_test "TEST-002-1" \
"Verify required headings in $(basename $file)" \
"grep -n '^## Purpose' '$file' > /dev/null && \
grep -n '^## Inputs' '$file' > /dev/null && \
grep -n '^## Outputs' '$file' > /dev/null && \
grep -n '^## Behavior' '$file' > /dev/null && \
grep -n '^## Constraints' '$file' > /dev/null && \
[ \$(grep -n '^## Purpose' '$file' | cut -d: -f1) -lt \$(grep -n '^## Inputs' '$file' | cut -d: -f1) ] && \
[ \$(grep -n '^## Inputs' '$file' | cut -d: -f1) -lt \$(grep -n '^## Outputs' '$file' | cut -d: -f1) ] && \
[ \$(grep -n '^## Outputs' '$file' | cut -d: -f1) -lt \$(grep -n '^## Behavior' '$file' | cut -d: -f1) ] && \
[ \$(grep -n '^## Behavior' '$file' | cut -d: -f1) -lt \$(grep -n '^## Constraints' '$file' | cut -d: -f1) ]"
done < <(find agents/ -name '*.md' -type f)
# TEST-002-2: Verify heading format follows markdown H2 convention
while IFS= read -r file; do
[ -f "$file" ] || continue
run_test "TEST-002-2" \
"Verify H2 heading format in $(basename $file)" \
"grep -E '^## (Purpose|Inputs|Outputs|Behavior|Constraints)$' '$file' > /dev/null"
done < <(find agents/ -name '*.md' -type f)
else
echo "Note: No agent markdown files found yet - skipping TEST-002-1 and TEST-002-2"
echo ""
fi
# TEST-003-1: Verify each agent has at least one tag
# TEST-003-2: Verify agent IDs are unique
# TEST-003-3: Verify tags are from allowed list
echo "=== SPEC-003: Tags and Metadata ==="
if [ -f "agents.yaml" ]; then
# TEST-003-1: Check each agent has at least one tag
run_test "TEST-003-1" \
"Verify each agent has at least one tag" \
"[ -z \"\$(awk '/ - id:/{flag=1; next} flag && /tags:/{flag=2; next} flag==2 && /^[[:space:]]*-/{flag=0; next} flag==2 && /^ - id:/{print \"no_tags\"; flag=0}' agents.yaml | grep no_tags)\" ]"
# TEST-003-2: Check agent IDs are unique
run_test "TEST-003-2" \
"Verify agent IDs are unique in agents.yaml" \
"! grep 'id:' agents.yaml | awk '{print \$3}' | sed 's/\"//g' | sort | uniq -d | grep -q ."
# TEST-003-3: Verify tags are from allowed list
if grep -q 'allowed_tags:' agents.yaml; then
# Extract allowed tags and agent tags, then compare
allowed_tags=$(awk '/^allowed_tags:/,/^# / {if (/^ - /) print $2}' agents.yaml | tr '\n' '|' | sed 's/|$//')
if [ -n "$allowed_tags" ]; then
run_test "TEST-003-3" \
"Verify all tags are from allowed list" \
"! awk '/^agents:/,/^# Validation/ {if (/^ tags:/) {flag=1; next} if (flag && /^ - /) {print \$2} if (flag && /^ [a-z_]/) flag=0}' agents.yaml | grep -vE \"^($allowed_tags)\$\" | grep -q ."
else
echo "Note: No allowed_tags found - skipping TEST-003-3"
fi
else
echo "Note: No allowed_tags defined in agents.yaml - skipping TEST-003-3"
fi
else
echo "Error: agents.yaml not found"
FAILED=$((FAILED + 3))
TOTAL=$((TOTAL + 3))
echo ""
fi
# TEST-004-1: Verify append-only files are only appended to
echo "=== SPEC-004: Append-Only Files ==="
echo "Note: TEST-004-1 requires git history - checking files exist"
run_test "TEST-004-1" \
"Verify append-only files exist" \
"[ -f specs.md ] && [ -f agent_runs.md ] && [ -f decisions.md ]"
# TEST-005-1: Citations verification (manual review required)
echo "=== SPEC-005: No Fabrication ==="
echo "Note: TEST-005-1 (Citation verification) requires manual review"
echo ""
# TEST-006-1: Verify documentation uses .md extension
echo "=== SPEC-006: Markdown Output ==="
run_test "TEST-006-1" \
"Verify key documentation files use .md extension" \
"[ -f agents.md ] && [ -f specs.md ] && [ -f agent_runs.md ] && [ -f decisions.md ]"
# TEST-008-1: Enforce script references for repeatable task docs
echo "=== SPEC-008: Script-First Automation ==="
if [ -f "scripts/check_repeatable_script_refs.py" ]; then
run_test "TEST-008-1" \
"Verify repeatable task docs include script references" \
"python3 scripts/check_repeatable_script_refs.py --root ."
else
echo "Note: scripts/check_repeatable_script_refs.py not found - skipping TEST-008-1"
echo ""
fi
# TEST-008-2: Validate registry schema
if [ -f "scripts/validate_registry.py" ]; then
run_test "TEST-008-2" \
"Validate scripts registry schema" \
"python3 scripts/validate_registry.py --registry scripts/registry.yaml"
else
echo "Note: scripts/validate_registry.py not found - skipping TEST-008-2"
echo ""
fi
# TEST-008-3: Validate dry-run conventions for executable scripts
if [ -f "scripts/check_dry_run_conventions.py" ]; then
run_test "TEST-008-3" \
"Verify execute-intent scripts use dry-run gating" \
"python3 scripts/check_dry_run_conventions.py --registry scripts/registry.yaml"
else
echo "Note: scripts/check_dry_run_conventions.py not found - skipping TEST-008-3"
echo ""
fi
# Summary
echo "======================================"
echo "Validation Summary"
echo "======================================"
if [ $TOTAL -eq 0 ]; then
echo -e "${YELLOW}Warning: No tests were executed!${NC}"
exit 1
fi
echo "Total tests run: $TOTAL"
echo -e "${GREEN}Passed: $PASSED${NC}"
if [ $FAILED -gt 0 ]; then
echo -e "${RED}Failed: $FAILED${NC}"
echo ""
echo "Please fix the failing tests before proceeding."
exit 1
else
echo -e "${GREEN}All tests passed!${NC}"
exit 0
fi