spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / plugins / plugin-dev / skills / agent-development / scripts / validate-agent.test.sh
70 lines · 2.1 KBRaw
1#!/bin/bash
2# Regression tests for validate-agent.sh (anthropics/claude-code#83803):
3# - warnings must not abort the run: under `set -e`, `((x++))` returns nonzero
4# when x was 0, so the first warning killed the script with exit 1
5# - multi-line descriptions (prose plus <example> blocks) must not be
6# false-flagged as missing examples
7set -uo pipefail
8
9SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10VALIDATOR="$SCRIPT_DIR/validate-agent.sh"
11PLUGIN_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
12TMP_DIR="$(mktemp -d)" || exit 1
13trap 'rm -rf "$TMP_DIR"' EXIT
14
15failures=0
16
17check() {
18 local label="$1" expected="$2" file="$3"
19 local actual=0
20 bash "$VALIDATOR" "$file" > "$TMP_DIR/out.txt" 2>&1 || actual=$?
21 if [ "$actual" -eq "$expected" ]; then
22 echo "PASS: $label (exit $actual)"
23 else
24 echo "FAIL: $label (expected exit $expected, got $actual)"
25 cat "$TMP_DIR/out.txt"
26 failures=$((failures + 1))
27 fi
28}
29
30# The plugin's own agents are valid and must pass.
31for agent in "$PLUGIN_ROOT"/agents/*.md; do
32 check "own agent $(basename "$agent")" 0 "$agent"
33done
34
35# A valid agent whose fields only trigger warnings must still exit 0,
36# and must reach the summary line instead of aborting at the first warning.
37cat > "$TMP_DIR/warning-agent.md" <<'EOF'
38---
39name: warning-agent
40description: A valid description that has no example blocks and no trigger phrase
41model: sonnet
42color: blue
43---
44
45You are a test agent. Your job is to exist so the validator has something to warn about.
46EOF
47check "valid agent with warnings" 0 "$TMP_DIR/warning-agent.md"
48if ! grep -q "Validation passed" "$TMP_DIR/out.txt"; then
49 echo "FAIL: summary line missing (script aborted before finishing)"
50 failures=$((failures + 1))
51fi
52
53# An invalid agent (bad name, missing color) must still fail with exit 1.
54cat > "$TMP_DIR/invalid-agent.md" <<'EOF'
55---
56name: x
57description: A valid description for an otherwise invalid agent file
58model: sonnet
59---
60
61You are a test agent with an invalid name and no color field.
62EOF
63check "invalid agent" 1 "$TMP_DIR/invalid-agent.md"
64
65echo ""
66if [ "$failures" -gt 0 ]; then
67 echo "$failures test(s) failed"
68 exit 1
69fi
70echo "All tests passed"