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
| 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 |
| 7 | set -uo pipefail |
| 8 | |
| 9 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 10 | VALIDATOR="$SCRIPT_DIR/validate-agent.sh" |
| 11 | PLUGIN_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)" |
| 12 | TMP_DIR="$(mktemp -d)" || exit 1 |
| 13 | trap 'rm -rf "$TMP_DIR"' EXIT |
| 14 | |
| 15 | failures=0 |
| 16 | |
| 17 | check() { |
| 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. |
| 31 | for agent in "$PLUGIN_ROOT"/agents/*.md; do |
| 32 | check "own agent $(basename "$agent")" 0 "$agent" |
| 33 | done |
| 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. |
| 37 | cat > "$TMP_DIR/warning-agent.md" <<'EOF' |
| 38 | --- |
| 39 | name: warning-agent |
| 40 | description: A valid description that has no example blocks and no trigger phrase |
| 41 | model: sonnet |
| 42 | color: blue |
| 43 | --- |
| 44 | |
| 45 | You are a test agent. Your job is to exist so the validator has something to warn about. |
| 46 | EOF |
| 47 | check "valid agent with warnings" 0 "$TMP_DIR/warning-agent.md" |
| 48 | if ! grep -q "Validation passed" "$TMP_DIR/out.txt"; then |
| 49 | echo "FAIL: summary line missing (script aborted before finishing)" |
| 50 | failures=$((failures + 1)) |
| 51 | fi |
| 52 | |
| 53 | # An invalid agent (bad name, missing color) must still fail with exit 1. |
| 54 | cat > "$TMP_DIR/invalid-agent.md" <<'EOF' |
| 55 | --- |
| 56 | name: x |
| 57 | description: A valid description for an otherwise invalid agent file |
| 58 | model: sonnet |
| 59 | --- |
| 60 | |
| 61 | You are a test agent with an invalid name and no color field. |
| 62 | EOF |
| 63 | check "invalid agent" 1 "$TMP_DIR/invalid-agent.md" |
| 64 | |
| 65 | echo "" |
| 66 | if [ "$failures" -gt 0 ]; then |
| 67 | echo "$failures test(s) failed" |
| 68 | exit 1 |
| 69 | fi |
| 70 | echo "All tests passed" |