From rnd-framework
Use when writing or modifying tests for rnd-framework hook scripts — covers the test-helpers.sh framework, run_hook pattern, assertions, environment mocking, and test organization
How this skill is triggered — by the user, by Claude, or both
Slash command
/rnd-framework:bash-hook-testingThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Every hook script in `hooks/` has a corresponding test file in `tests/`. Tests use a custom framework (`test-helpers.sh`) that provides stdin-driven hook invocation, assertion helpers, and a pass/fail report. No external test runners are needed — each test file is a standalone bash script.
Every hook script in hooks/ has a corresponding test file in tests/. Tests use a custom framework (test-helpers.sh) that provides stdin-driven hook invocation, assertion helpers, and a pass/fail report. No external test runners are needed — each test file is a standalone bash script.
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/test-helpers.sh"
HOOK="${SCRIPT_DIR}/../hooks/<hook-name>.sh"
printf '%s\n' '--- Section Name ---'
# Test: description
run_hook "$HOOK" '{"tool_name":"Read","tool_input":{"file_path":"/some/path"}}'
assert_exit_code "description of expected exit code" 0
assert_eq "description of expected stdout" '{"hookSpecificOutput":...}' "$HOOK_STDOUT"
# ... more tests ...
report
Key points:
<hook-name>.test.sh (e.g., read-gate.test.sh)report at the end — it prints summary and exits 1 if any test failedprintf '%s\n' '--- Section Name ---' headersrun_hook "$HOOK" '{"tool_name":"Read","tool_input":{"file_path":"/foo"}}'
Feeds the JSON string as stdin to the hook script. After execution, three variables are set:
| Variable | Content |
|---|---|
HOOK_STDOUT | Everything the hook printed to stdout |
HOOK_STDERR | Everything the hook printed to stderr |
HOOK_EXIT | The exit code (0, 2, etc.) |
assert_eq "description" "expected" "$actual"
assert_contains "description" "needle" "$haystack"
assert_exit_code "description" 0
assert_eq — exact string matchassert_contains — substring match (useful for JSON or error messages)assert_exit_code — checks $HOOK_EXIT against expected codereport
Prints N pass, M fail (T total) and returns exit code 1 if any test failed. Must be the last call in every test file.
Every PreToolUse hook should be tested for all three outcomes:
run_hook "$HOOK" '{"tool_name":"Read","tool_input":{"file_path":"/home/user/.claude/.rnd/session/plan.md"}}'
assert_exit_code "auto-allows .rnd/ path" 0
assert_contains "auto-allows .rnd/ path stdout" "allow" "$HOOK_STDOUT"
run_hook "$HOOK" '{"tool_name":"Read","tool_input":{"file_path":"/path/to/self-assessment.md"},"agent_type":"verifier"}'
assert_exit_code "blocks self-assessment read" 2
assert_contains "block message" "INFORMATION BARRIER" "$HOOK_STDERR"
run_hook "$HOOK" '{"tool_name":"Read","tool_input":{"file_path":"/some/regular/file.ts"}}'
assert_exit_code "no opinion for regular file" 0
assert_eq "no opinion produces no stdout" "" "$HOOK_STDOUT"
Some hooks use CLAUDE_PLUGIN_ROOT to locate resources:
export CLAUDE_PLUGIN_ROOT="${SCRIPT_DIR}/.."
For hooks that check active_session_dir:
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
export CLAUDE_CONFIG_DIR="$TMP_DIR"
mkdir -p "$TMP_DIR/.rnd/test-project/sessions/20260101-120000-abcd1234"
printf '%s' "20260101-120000-abcd1234" > "$TMP_DIR/.rnd/test-project/.current-session"
Hooks with active_session_dir fast-path should be tested without a session:
unset CLAUDE_CONFIG_DIR
run_hook "$HOOK" '{"tool_name":"Bash","tool_input":{"command":"echo hi"}}'
assert_exit_code "exits cleanly without active session" 0
assert_eq "no output without active session" "" "$HOOK_STDOUT"
For lib.sh utility functions, source lib.sh directly instead of using run_hook:
source "${SCRIPT_DIR}/../hooks/lib.sh"
result="$(jq_extract '{"key":"val"}' '.key')"
assert_eq "jq_extract extracts field" "val" "$result"
See tests/lib-fp.test.sh for the canonical pattern.
cd plugins/rnd-framework
bash tests/run-tests.sh
This runs all *.test.sh files in tests/ and reports any failures. Individual tests can be run directly:
bash tests/read-gate.test.sh
hooks/ should have a corresponding tests/<name>.test.shWrite vs Create vs write)rnd-framework:hook-authoring — how hooks work and how to write themrnd-framework:lib-sh-patterns — the shared functions being testedProvides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
npx claudepluginhub oleksify/rnd-framework --plugin rnd-framework