-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·295 lines (241 loc) · 8.13 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·295 lines (241 loc) · 8.13 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
# test.sh — craft test suite for claude-code-craft
# Pure bash, no frameworks, no dependencies
# Run: bash test.sh
# Exit 0 if all pass, exit 1 if any fail
set -uo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$REPO_DIR"
passed=0
failed=0
total=0
pass() {
echo "[PASS] $1"
passed=$((passed + 1))
total=$((total + 1))
}
fail() {
echo "[FAIL] $1"
failed=$((failed + 1))
total=$((total + 1))
}
echo "craft test suite"
echo "================"
echo ""
# ============================================================
# 1. Consistency checks
# ============================================================
echo "--- Consistency ---"
# Count skill directories
skill_dirs=( skills/*/ )
skill_count=${#skill_dirs[@]}
# README badge number
badge_count=$(grep -oE 'skills-[0-9]+' README.md | head -1 | sed 's/skills-//')
if [[ "$skill_count" -eq "$badge_count" ]]; then
pass "skill count matches README badge ($skill_count)"
else
fail "skill count ($skill_count) does not match README badge ($badge_count)"
fi
# install.sh SKILLS array vs directories
install_skills=()
in_array=false
while IFS= read -r line; do
if [[ "$line" =~ ^SKILLS=\( ]]; then
in_array=true
continue
fi
if $in_array; then
[[ "$line" =~ ^\) ]] && break
skill=$(echo "$line" | xargs)
[[ -n "$skill" ]] && install_skills+=("$skill")
fi
done < install.sh
dir_skills=()
for d in skills/*/; do
dir_skills+=("$(basename "$d")")
done
# Sort both arrays for comparison
install_sorted=$(printf '%s\n' "${install_skills[@]}" | sort)
dir_sorted=$(printf '%s\n' "${dir_skills[@]}" | sort)
if [[ "$install_sorted" == "$dir_sorted" ]]; then
pass "install.sh SKILLS array matches skill directories"
else
fail "install.sh SKILLS array does not match skill directories"
diff <(echo "$install_sorted") <(echo "$dir_sorted") | head -10 || true
fi
# craft-update-self SKILLS array must match install.sh
update_skills=()
in_array=false
while IFS= read -r line; do
if [[ "$line" =~ ^SKILLS=\( ]]; then
in_array=true
continue
fi
if $in_array; then
[[ "$line" =~ ^\) ]] && break
skill=$(echo "$line" | xargs)
[[ -n "$skill" ]] && update_skills+=("$skill")
fi
done < skills/craft-update-self/SKILL.md
update_sorted=$(printf '%s\n' "${update_skills[@]}" | sort)
if [[ "$update_sorted" == "$install_sorted" ]]; then
pass "craft-update-self SKILLS array matches install.sh"
else
fail "craft-update-self SKILLS array does not match install.sh"
diff <(echo "$install_sorted") <(echo "$update_sorted") | head -10 || true
fi
# craft-global-audit "all N present" must match skill count
global_audit_count=$(grep -oE 'all [0-9]+ present' skills/craft-global-audit/SKILL.md | head -1 | sed 's/all \([0-9]*\) present/\1/')
if [[ "$global_audit_count" -eq "$skill_count" ]]; then
pass "craft-global-audit 'all $global_audit_count present' matches skill count"
else
fail "craft-global-audit says 'all $global_audit_count present' but there are $skill_count skills"
fi
# craft-project-audit "N/N installed" must match skill count
# Pattern is "[N/10 installed...]" where 10 is the hardcoded total
audit_count=$(grep -oE 'N/[0-9]+ installed' skills/craft-project-audit/SKILL.md | head -1 | sed 's|N/||; s| installed||')
if [[ "$audit_count" -eq "$skill_count" ]]; then
pass "craft-project-audit 'N/$audit_count installed' matches skill count"
else
fail "craft-project-audit says 'N/$audit_count installed' but there are $skill_count skills"
fi
echo ""
# ============================================================
# 2. Stale reference checks
# ============================================================
echo "--- Stale references ---"
# craft-project-learn (exclude this test script)
learn_hits=$(grep -rl "craft-project-learn" --include='*.md' --include='*.sh' --include='*.json' . | grep -v "test.sh" | grep -v ".craft/" || true)
if [[ -z "$learn_hits" ]]; then
pass "no stale references to craft-project-learn"
else
fail "stale reference: craft-project-learn found in: $learn_hits"
fi
# craft-project-update (exclude CHANGELOG.md historical entries and this test script)
update_hits=$(grep -rl "craft-project-update" --include='*.md' --include='*.sh' --include='*.json' . | grep -v "test.sh" | grep -v "CHANGELOG.md" | grep -v ".craft/" || true)
if [[ -z "$update_hits" ]]; then
pass "no stale references to craft-project-update"
else
fail "stale reference: craft-project-update found in: $update_hits"
fi
# craft-project-new (exclude this test script)
new_hits=$(grep -rl "craft-project-new" --include='*.md' --include='*.sh' --include='*.json' . | grep -v "test.sh" | grep -v ".craft/" || true)
if [[ -z "$new_hits" ]]; then
pass "no stale references to craft-project-new"
else
fail "stale reference: craft-project-new found in: $new_hits"
fi
echo ""
# ============================================================
# 3. Frontmatter checks
# ============================================================
echo "--- Frontmatter ---"
for skill_dir in skills/*/; do
skill_name=$(basename "$skill_dir")
skill_file="$skill_dir/SKILL.md"
if [[ ! -f "$skill_file" ]]; then
fail "$skill_name: SKILL.md missing"
continue
fi
# Check frontmatter block exists (starts with ---)
first_line=$(head -1 "$skill_file")
if [[ "$first_line" != "---" ]]; then
fail "$skill_name: no frontmatter block"
continue
fi
# Extract frontmatter (between first and second ---)
frontmatter=$(awk 'NR==1{next} /^---$/{exit} {print}' "$skill_file")
fm_ok=true
for field in name version description allowed-tools; do
if ! echo "$frontmatter" | grep -q "^${field}:"; then
fail "$skill_name: frontmatter missing '$field'"
fm_ok=false
fi
done
if $fm_ok; then
pass "$skill_name: frontmatter valid"
fi
done
echo ""
# ============================================================
# 4. File existence checks
# ============================================================
echo "--- File existence ---"
expected_files=(
README.md
LICENSE
CONTRIBUTING.md
install.sh
templates/quality.md
)
for f in "${expected_files[@]}"; do
if [[ -f "$f" ]]; then
pass "$f exists"
else
fail "$f missing"
fi
done
echo ""
# ============================================================
# 5. install.sh checks
# ============================================================
echo "--- install.sh ---"
# Executable or has bash shebang
if [[ -x install.sh ]]; then
pass "install.sh is executable"
elif head -1 install.sh | grep -q "^#!/bin/bash"; then
pass "install.sh has bash shebang"
else
fail "install.sh is neither executable nor has bash shebang"
fi
# No hardcoded absolute paths
if grep -qE '/Users/|/home/' install.sh; then
fail "install.sh contains hardcoded absolute paths"
else
pass "install.sh has no hardcoded absolute paths"
fi
# No sudo usage
if grep -q "sudo" install.sh; then
fail "install.sh uses sudo"
else
pass "install.sh does not use sudo"
fi
echo ""
# ============================================================
# 6. Security checks
# ============================================================
echo "--- Security ---"
# Check for API keys, tokens, secrets
secret_patterns='(sk-[a-zA-Z0-9]{20,}|ghp_[a-zA-Z0-9]{36}|ANTHROPIC_API_KEY=.+|OPENAI_API_KEY=.+|password\s*=\s*["\x27][^"\x27]+["\x27])'
secret_hits=$(grep -rEI "$secret_patterns" --include='*.md' --include='*.sh' --include='*.json' . | grep -v "test.sh" | grep -v ".craft/" || true)
if [[ -z "$secret_hits" ]]; then
pass "no API keys, tokens, or secrets found"
else
fail "possible secrets found: $secret_hits"
fi
# .gitignore exists and has required exclusions
if [[ -f .gitignore ]]; then
gitignore_ok=true
for pattern in ".env" ".craft/"; do
if ! grep -q "$pattern" .gitignore; then
fail ".gitignore missing pattern: $pattern"
gitignore_ok=false
fi
done
if $gitignore_ok; then
pass ".gitignore exists and excludes .env and .craft/"
fi
else
fail ".gitignore missing"
fi
echo ""
# ============================================================
# Results
# ============================================================
echo "================"
echo "Results: $passed passed, $failed failed"
if [[ "$failed" -gt 0 ]]; then
exit 1
else
exit 0
fi