Skip to content

Skills for Claude Code CLI such as full stack dev Cloudflare, React, Tailwind v4, and AI integrations.

feat(testing-patterns): Add /create-tests and /run-tests commands

Jez737c60dabdc3
diff --git a/skills/testing-patterns/.claude-plugin/plugin.json b/skills/testing-patterns/.claude-plugin/plugin.json
index 715fc2a7..d16ca254 100644
--- a/skills/testing-patterns/.claude-plugin/plugin.json
+++ b/skills/testing-patterns/.claude-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "testing-patterns",
- "description": "What these tests validate",
+ "description": "Agent-based declarative testing with YAML test specs. Tests run in sub-agents to preserve main context while executing many tests. Supports MCP servers, APIs, and browser automation. Use when: testing MCP servers, running integration tests, validating tool behavior after changes, or creating regression test suites.",
"version": "1.0.0",
"author": {
"name": "Jeremy Dawes",
@@ -8,6 +8,6 @@
},
"license": "MIT",
"repository": "https://github.com/jezweb/claude-skills",
- "keywords": [],
+ "keywords": ["yaml tests", "agent testing", "mcp test", "integration tests", "test runner"],
"agents": []
}
diff --git a/skills/testing-patterns/SKILL.md b/skills/testing-patterns/SKILL.md
index 8b90e83d..27f9d6c9 100644
--- a/skills/testing-patterns/SKILL.md
+++ b/skills/testing-patterns/SKILL.md
@@ -35,6 +35,21 @@ Running 50 tests in the main conversation would consume your entire context wind
- Results come back as a summary
- Failed tests get detailed investigation
+## Commands
+
+| Command | Purpose |
+|---------|---------|
+| `/create-tests` | Discover project, generate test specs + testing agent |
+| `/run-tests` | Execute tests via agent(s), report results |
+
+**Quick workflow:**
+```
+/create-tests → Generates tests/specs/*.yaml + .claude/agents/test-runner.md
+/run-tests → Spawns agent, runs all tests, saves results
+/run-tests api → Run only specs matching "api"
+/run-tests --failed → Re-run only failed tests
+```
+
## Getting Started in a New Project
This skill provides the **pattern and format**. Claude designs the actual tests based on your project context.
diff --git a/skills/testing-patterns/commands/create-tests.md b/skills/testing-patterns/commands/create-tests.md
new file mode 100644
index 00000000..adc205a0
--- /dev/null
+++ b/skills/testing-patterns/commands/create-tests.md
@@ -0,0 +1,362 @@
+# Create Tests
+
+Generate test specs and a testing agent for the current project.
+
+---
+
+## Command Usage
+
+`/create-tests [test-type]`
+
+- With type: `/create-tests mcp` or `/create-tests api`
+- Without type: `/create-tests` (interactive discovery)
+
+---
+
+## Your Task
+
+Discover testable components in the project, generate YAML test specs, and create a testing agent.
+
+### Step 1: Discover Project Structure
+
+Search for testable components:
+
+```bash
+# MCP servers
+ls .mcp.json mcp.json 2>/dev/null
+
+# API routes (common patterns)
+find . -name "*.ts" -path "*/routes/*" 2>/dev/null | head -5
+grep -r "app\.\(get\|post\|put\|delete\)" --include="*.ts" -l 2>/dev/null | head -5
+
+# Existing test frameworks
+ls vitest.config.* jest.config.* pytest.ini pyproject.toml 2>/dev/null
+
+# CLI tools
+ls bin/ 2>/dev/null
+grep '"bin"' package.json 2>/dev/null
+
+# Browser/UI (playwright or browser MCP)
+ls playwright.config.* 2>/dev/null
+```
+
+**Categorise what you find:**
+
+| Found | Test Type | Tools Needed |
+|-------|-----------|--------------|
+| `.mcp.json` / `mcp.json` | MCP | Inherit (omit tools field) |
+| Route files / Hono/Express | API | `WebFetch` |
+| `playwright.config.*` | Browser | Inherit (Playwright MCP) |
+| `vitest.config.*` / `jest.config.*` | Framework | `Bash` |
+| `bin/` directory | CLI | `Bash`, `Read` |
+
+### Step 2: Ask Clarifying Questions
+
+If test type not provided as argument:
+
+```
+═══════════════════════════════════════════════
+ CREATE TESTS
+═══════════════════════════════════════════════
+
+I found these testable components:
+
+✅ MCP Server: web-scraper-mcp (3 tools)
+✅ API Routes: /api/users, /api/items (5 endpoints)
+⬜ Browser: No playwright config found
+⬜ CLI: No bin/ directory
+
+What would you like to test?
+
+1. MCP tools - Test MCP server tools directly
+2. API endpoints - Test HTTP endpoints with WebFetch
+3. Browser flows - Test UI interactions
+4. CLI commands - Test command-line tools
+5. All of above - Generate tests for everything found
+
+Your choice [1-5]:
+```
+
+Then ask:
+
+```
+Include edge cases and error scenarios? [Y/n]
+```
+
+### Step 3: Generate Test Specs
+
+Create `tests/specs/` directory and YAML files:
+
+```bash
+mkdir -p tests/specs tests/results
+```
+
+**For MCP tests** (`tests/specs/mcp-tools.yaml`):
+
+```yaml
+name: MCP Tool Tests
+description: Validate MCP server tool functionality
+
+defaults:
+ timeout: 10000
+
+tests:
+ - name: tool_basic_call
+ description: Verify basic tool invocation
+ tool: mcp__server__tool_name
+ params:
+ action: list
+ expect:
+ status: success
+
+ - name: tool_with_params
+ description: Verify tool with parameters
+ tool: mcp__server__tool_name
+ params:
+ action: search
+ query: "test"
+ expect:
+ contains: "results"
+ count_gte: 0
+```
+
+**For API tests** (`tests/specs/api-endpoints.yaml`):
+
+```yaml
+name: API Endpoint Tests
+description: Validate HTTP endpoint responses
+
+defaults:
+ base_url: http://localhost:8787
+ timeout: 5000
+
+tests:
+ - name: get_items_success
+ description: GET /api/items returns list
+ method: GET
+ path: /api/items
+ expect:
+ status: 200
+ type: array
+
+ - name: post_item_validation
+ description: POST /api/items validates input
+ method: POST
+ path: /api/items
+ body:
+ name: ""
+ expect:
+ status: 400
+ contains: "required"
+```
+
+**For CLI tests** (`tests/specs/cli-commands.yaml`):
+
+```yaml
+name: CLI Command Tests
+description: Validate CLI tool behavior
+
+defaults:
+ timeout: 30000
+
+tests:
+ - name: cli_help_flag
+ description: --help shows usage
+ command: node bin/cli.js --help
+ expect:
+ contains: "Usage:"
+ status: 0
+
+ - name: cli_version_flag
+ description: --version shows version
+ command: node bin/cli.js --version
+ expect:
+ matches: "\\d+\\.\\d+\\.\\d+"
+```
+
+**For Browser tests** (`tests/specs/browser-flows.yaml`):
+
+```yaml
+name: Browser Flow Tests
+description: Validate UI interactions
+
+defaults:
+ base_url: http://localhost:5173
+ timeout: 10000
+
+tests:
+ - name: homepage_loads
+ description: Homepage renders correctly
+ navigate: /
+ expect:
+ title_contains: "App"
+ element_exists: "[data-testid='main']"
+
+ - name: login_flow
+ description: User can log in
+ steps:
+ - navigate: /login
+ - fill: { selector: "#email", value: "[email protected]" }
+ - fill: { selector: "#password", value: "password" }
+ - click: "[type='submit']"
+ expect:
+ url_contains: /dashboard
+```
+
+### Step 4: Create Testing Agent
+
+Generate `.claude/agents/test-runner.md`:
+
+**For MCP tests** (omit tools field):
+
+```markdown
+---
+name: test-runner
+description: |
+ Tests project functionality. Reads YAML test specs and validates responses.
+
+ MUST BE USED when: testing after changes, running regression tests.
+ Use PROACTIVELY after deploying changes.
+
+ Keywords: test, run tests, validate, regression
+# tools field OMITTED - inherits ALL tools from parent session (including MCP)
+model: sonnet
+---
+
+# Test Runner Agent
+
+## CRITICAL: You HAVE Tool Access
+
+**DO NOT assume you can't call tools. You CAN and MUST call them directly.**
+
+[Include rest of test-agent.md template content, customised for project]
+```
+
+**For API/CLI tests** (include specific tools):
+
+```markdown
+---
+name: test-runner
+description: |
+ Tests project API endpoints and CLI commands.
+
+ MUST BE USED when: testing after changes, running regression tests.
+
+ Keywords: test, run tests, validate, regression
+tools: Read, Glob, Grep, Bash, WebFetch
+model: sonnet
+---
+
+# Test Runner Agent
+
+[Include test-agent.md template content, customised for project]
+```
+
+### Step 5: Output Summary
+
+```
+═══════════════════════════════════════════════
+ ✅ TESTS CREATED
+═══════════════════════════════════════════════
+
+Test Type: [MCP / API / CLI / Browser / Mixed]
+
+Created files:
+ tests/
+ ├── specs/
+ │ ├── mcp-tools.yaml (12 tests)
+ │ ├── api-endpoints.yaml (8 tests)
+ │ └── cli-commands.yaml (5 tests)
+ └── results/ (empty - results saved here)
+
+ .claude/agents/
+ └── test-runner.md (testing agent)
+
+Total: 25 tests across 3 spec files
+
+═══════════════════════════════════════════════
+ NEXT STEPS
+═══════════════════════════════════════════════
+
+1. Review generated test specs in tests/specs/
+2. Adjust params and expectations as needed
+3. Run tests with: /run-tests
+4. Commit test files when satisfied
+
+═══════════════════════════════════════════════
+
+Would you like me to run the tests now?
+```
+
+---
+
+## Error Handling
+
+**If no testable components found:**
+```
+⚠️ No testable components discovered.
+
+This project doesn't appear to have:
+• MCP server configs (.mcp.json)
+• API routes
+• Test framework configs
+• CLI tools
+
+Options:
+1. Specify what to test manually
+2. Create tests for a specific file/function
+3. Set up a test framework first (vitest, jest)
+
+Your choice:
+```
+
+**If tests/ directory already exists:**
+```
+⚠️ tests/ directory already exists.
+
+Options:
+1. Add new specs alongside existing
+2. Overwrite existing specs
+3. Cancel and review existing tests
+
+Your choice [1-3]:
+```
+
+**If .claude/agents/test-runner.md exists:**
+```
+⚠️ Testing agent already exists at .claude/agents/test-runner.md
+
+Options:
+1. Keep existing agent (recommended)
+2. Replace with new agent
+3. Create with different name (test-runner-v2.md)
+
+Your choice [1-3]:
+```
+
+---
+
+## Important Notes
+
+- **MCP tests**: MUST omit `tools` field to inherit MCP tools from parent
+- **API tests**: Include `WebFetch` in tools list
+- **CLI tests**: Include `Bash`, `Read` in tools list
+- **Browser tests**: Omit tools field if using Playwright MCP or claude-in-chrome
+- Test specs are YAML for human readability and version control
+- Results are saved as markdown for git history
+
+---
+
+## Quick Reference
+
+| Test Type | Spec Template | Agent Tools |
+|-----------|---------------|-------------|
+| MCP | `mcp-tools.yaml` | Inherit (omit field) |
+| API | `api-endpoints.yaml` | `WebFetch` |
+| CLI | `cli-commands.yaml` | `Bash`, `Read` |
+| Browser | `browser-flows.yaml` | Inherit |
+
+---
+
+**Version**: 1.0.0
+**Last Updated**: 2026-02-03
diff --git a/skills/testing-patterns/commands/run-tests.md b/skills/testing-patterns/commands/run-tests.md
new file mode 100644
index 00000000..dc216280
--- /dev/null
+++ b/skills/testing-patterns/commands/run-tests.md
@@ -0,0 +1,336 @@
+# Run Tests
+
+Execute test specs via testing agent(s) and report results.
+
+---
+
+## Command Usage
+
+`/run-tests [spec-file]`
+
+- All tests: `/run-tests`
+- Specific spec: `/run-tests tests/specs/mcp-tools.yaml`
+- Pattern: `/run-tests api` (runs all specs containing "api")
+
+---
+
+## Your Task
+
+Find test specs, spawn testing agent(s) to execute them, and report results.
+
+### Step 1: Find Test Specs
+
+```bash
+# Find all YAML test specs
+find tests -name "*.yaml" -o -name "*.yml" 2>/dev/null
+```
+
+If argument provided, filter:
+- Exact file: use that file only
+- Pattern: match against filenames
+
+### Step 2: Check Prerequisites
+
+**Test specs exist?**
+
+If no specs found:
+```
+⚠️ No test specs found in tests/
+
+Run /create-tests first to generate test specs.
+
+Or create tests manually at:
+ tests/specs/your-tests.yaml
+
+Would you like me to run /create-tests now?
+```
+
+**Testing agent exists?**
+
+Check for `.claude/agents/test-runner.md`:
+
+If missing:
+```
+⚠️ Testing agent not found at .claude/agents/test-runner.md
+
+Options:
+1. Create testing agent now (recommended)
+2. Run tests without dedicated agent (uses main context)
+
+Your choice [1-2]:
+```
+
+### Step 3: Count Tests and Plan Execution
+
+Parse YAML specs to count total tests:
+
+```
+Found test specs:
+ tests/specs/mcp-tools.yaml (12 tests)
+ tests/specs/api-endpoints.yaml (8 tests)
+ tests/specs/cli-commands.yaml (5 tests)
+ ─────────────────────────────────────────
+ Total: 25 tests
+```
+
+**Execution strategy:**
+
+| Test Count | Strategy | Rationale |
+|------------|----------|-----------|
+| 1-20 | Single agent | Efficient, minimal overhead |
+| 21-50 | 2 parallel agents | Split by spec file |
+| 51+ | 3+ parallel agents | 15-20 tests each |
+
+### Step 4: Spawn Testing Agent(s)
+
+**Single agent execution:**
+
+```
+Spawning test-runner agent...
+
+Agent task:
+ Read and execute all tests in:
+ - tests/specs/mcp-tools.yaml
+ - tests/specs/api-endpoints.yaml
+ - tests/specs/cli-commands.yaml
+
+ Save results to: tests/results/2026-02-03-143022.md
+```
+
+Use the Task tool:
+
+```
+Task(
+ subagent_type: "test-runner",
+ prompt: "Execute all tests in tests/specs/*.yaml. For each test:
+ 1. Read the spec
+ 2. Call the tool/endpoint with params
+ 3. Validate response against expectations
+ 4. Record PASS/FAIL with details
+
+ Save results to tests/results/[timestamp].md
+
+ Return summary: X passed, Y failed, Z skipped"
+)
+```
+
+**Parallel agent execution (20+ tests):**
+
+```
+Spawning 2 parallel test-runner agents...
+
+Agent 1:
+ - tests/specs/mcp-tools.yaml (12 tests)
+
+Agent 2:
+ - tests/specs/api-endpoints.yaml (8 tests)
+ - tests/specs/cli-commands.yaml (5 tests)
+```
+
+Launch in single message with multiple Task calls.
+
+### Step 5: Collect and Save Results
+
+Results format (`tests/results/YYYY-MM-DD-HHMMSS.md`):
+
+```markdown
+# Test Results
+
+**Date**: 2026-02-03 14:30:22
+**Duration**: 45 seconds
+**Summary**: 23/25 passed (92%)
+
+## Overview
+
+| Spec File | Passed | Failed | Skipped |
+|-----------|--------|--------|---------|
+| mcp-tools.yaml | 11 | 1 | 0 |
+| api-endpoints.yaml | 7 | 1 | 0 |
+| cli-commands.yaml | 5 | 0 | 0 |
+
+## Results by Spec
+
+### mcp-tools.yaml
+
+✅ tool_basic_call - PASSED (0.3s)
+✅ tool_with_params - PASSED (0.5s)
+✅ tool_search - PASSED (0.4s)
+❌ tool_error_handling - FAILED
+...
+
+### api-endpoints.yaml
+
+✅ get_items_success - PASSED (0.2s)
+❌ post_item_validation - FAILED
+...
+
+## Failed Test Details
+
+### tool_error_handling (mcp-tools.yaml)
+- **Expected**: `contains: "error"`
+- **Actual**: Response was `{"status": "success"}`
+- **Suggestion**: Check error handling for invalid input
+
+### post_item_validation (api-endpoints.yaml)
+- **Expected**: `status: 400`
+- **Actual**: `status: 200`
+- **Suggestion**: Validation middleware may not be applied
+
+## Environment
+
+- Node: v20.x
+- Platform: linux
+- Working Directory: /path/to/project
+```
+
+### Step 6: Report to User
+
+```
+═══════════════════════════════════════════════
+ TEST RESULTS
+═══════════════════════════════════════════════
+
+Summary: 23/25 passed (92%)
+
+✅ Passed: 23
+❌ Failed: 2
+⏭️ Skipped: 0
+
+Duration: 45 seconds
+
+Failed tests:
+ 1. tool_error_handling (mcp-tools.yaml)
+ Expected: contains "error"
+ Actual: {"status": "success"}
+
+ 2. post_item_validation (api-endpoints.yaml)
+ Expected: status 400
+ Actual: status 200
+
+Results saved to: tests/results/2026-02-03-143022.md
+
+═══════════════════════════════════════════════
+ NEXT STEPS
+═══════════════════════════════════════════════
+
+What would you like to do?
+
+1. Investigate failed tests
+2. Re-run failed tests only
+3. Commit results to git
+4. Fix issues and re-run all
+5. Done for now
+
+Your choice [1-5]:
+```
+
+**If all tests pass:**
+
+```
+═══════════════════════════════════════════════
+ ✅ ALL TESTS PASSED
+═══════════════════════════════════════════════
+
+Summary: 25/25 passed (100%)
+
+Duration: 42 seconds
+
+Results saved to: tests/results/2026-02-03-143022.md
+
+Would you like to commit the results? [Y/n]
+```
+
+---
+
+## Error Handling
+
+**If agent times out:**
+```
+⚠️ Test agent timed out after 5 minutes.
+
+Partial results may be available.
+Check: tests/results/
+
+Options:
+1. Review partial results
+2. Re-run remaining tests
+3. Increase timeout and retry
+
+Your choice:
+```
+
+**If tool access fails:**
+```
+❌ Agent reported: "Cannot access MCP tools"
+
+This usually means the testing agent has `tools:` specified.
+MCP tools require inheriting from parent (omit tools field).
+
+Fix: Edit .claude/agents/test-runner.md
+Remove or comment out the `tools:` line.
+
+Would you like me to fix this?
+```
+
+**If spec file has invalid YAML:**
+```
+❌ Invalid YAML in tests/specs/mcp-tools.yaml
+
+Error: unexpected end of stream at line 15
+
+Fix the syntax error and re-run.
+```
+
+---
+
+## Options
+
+### Re-run Failed Tests Only
+
+```bash
+/run-tests --failed
+```
+
+Reads previous results file, extracts failed test names, runs only those.
+
+### Verbose Output
+
+```bash
+/run-tests --verbose
+```
+
+Shows each test as it executes (useful for debugging).
+
+### Specific Spec File
+
+```bash
+/run-tests tests/specs/mcp-tools.yaml
+```
+
+Runs only tests in that file.
+
+---
+
+## Important Notes
+
+- **Agent context preservation**: Tests run in sub-agent, main context stays clean
+- **Results are git-friendly**: Markdown files with timestamps
+- **Parallel execution**: Enabled for 20+ tests automatically
+- **MCP tool inheritance**: Agent MUST omit `tools:` field for MCP access
+- **Timestamps**: Results use ISO format for sorting
+
+---
+
+## Quick Reference
+
+| Test Count | Agents | Approximate Time |
+|------------|--------|------------------|
+| 1-10 | 1 | ~30 seconds |
+| 11-20 | 1 | ~1 minute |
+| 21-50 | 2 parallel | ~1-2 minutes |
+| 51-100 | 3-5 parallel | ~2-3 minutes |
+
+---
+
+**Version**: 1.0.0
+**Last Updated**: 2026-02-03