hf.validate-tests-before-commit

A commit check that runs before Git saves staged changes as a commit. It checks for forbidden ways of skipping hooks, required tests for changed Python files, and passing tests for affected services.

In plain words
What is it for?
Use it to enforce test checks before commits, require tests for staged Python code, and block commits when affected service tests fail.
Why use it?
It prevents commits from bypassing the project's checks or recording source changes without the related tests passing.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/t-rav/hydraflow/hf.validate-tests-before-commit
Any agent
npx skills add T-rav/hydraflow --skill hf.validate-tests-before-commit
Clone the repo
git clone --depth 1 https://github.com/T-rav/hydraflow

Made for: Claude Code, Codex.

Per session 13 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,364 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 2 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00013 $0.01364
Opus 5 $0.00006 $0.00682
Sonnet 5 $0.00003 $0.00273
Haiku 4.5 $0.00001 $0.00136

Measured 2d ago against content hash a906ab14c80d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade C, and why

hf.validate-tests-before-commit scanned grade C with 2 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Downloads and executes remote codehighSupply chain

curl | sh runs whatever the server returns today, which is not necessarily what it returned when this was reviewed.

echo "BLOCKED: uv is not installed. Install it: curl -LsSf https://astral.sh/uv/install.sh | sh" >&2

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

echo "BLOCKED: uv is not installed. Install it: curl -LsSf https://astral.sh/uv/install.sh | sh" >&2
.codex/skills/hf.validate-tests-before-commit/SKILL.md · 141 lines

How it starts

The opening of the file, as written. The whole thing — 141 lines — stays where its author put it; the contents beside it link to each section on GitHub.

hf.validate-tests-before-commit

#!/bin/bash
# Hook: Validate tests exist for staged changes and pass before allowing commit.
# Fires on PreToolUse for Bash commands matching git commit.
# Blocks commit if:
#   1. --no-verify or --no-hooks flags are used
#   2. Python source files are staged without corresponding test files
#   3. Tests for affected services fail

set -euo pipefail

INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
CWD=$(echo "$INPUT" | jq -r '.cwd // empty')

# Only intercept git commit commands
if ! echo "$COMMAND" | grep -qE '(^|\s|&&\s*|;\s*)git commit'; then
  exit 0
fi

# Block --no-verify / --no-hooks (forbidden per CLAUDE.md)
if echo "$COMMAND" | grep -qE '\-\-no-verify|\-\-no-hooks'; then
  echo "BLOCKED: --no-verify and --no-hooks are forbidden per CLAUDE.md." >&2
  echo "Fix code issues first, then commit cleanly." >&2
  exit 2
fi

# Resolve project root from git toplevel (CWD may be a subdirectory)
PROJECT_ROOT=$(git -C "$CWD" rev-parse --show-toplevel 2>/dev/null || echo "$CWD")
cd "$PROJECT_ROOT"

# Get staged files early — skip expensive checks for non-source commits
STAGED_FILES=$(git diff --cached --name-only 2>/dev/null || true)

if [ -z "$STAGED_FILES" ]; then
  exit 0  # Nothing staged, let git handle it
fi

# Fast exit: if no source code is staged, skip lint and tests entirely
HAS_SOURCE=$(echo "$STAGED_FILES" | grep -E '\.(py|ts|tsx|js|jsx)$' || true)
if [ -z "$HAS_SOURCE" ]; then
  exit 0  # Config/docs/YAML/Dockerfile-only commit, no lint or test needed
fi

# Require uv for running Python
if ! command -v uv &>/dev/null; then
  echo "BLOCKED: uv is not installed. Install it: curl -LsSf https://astral.sh/uv/install.sh | sh" >&2
  exit 2
fi

# Run lint checks (only reached for commits with source code)
echo "Running lint checks..." >&2
if ! make -C "$PROJECT_ROOT" lint-check > /dev/null 2>&1; then
  echo "BLOCKED: Lint check failed." >&2
  echo "Run 'make lint' to auto-fix formatting and import issues, then re-stage." >&2
  exit 2
fi
echo "Lint checks passed." >&2

# Get staged Python source files (excluding tests, configs, migrations, __init__)
SOURCE_FILES=$(echo "$STAGED_FILES" | grep '\.py$' \
  | grep -vE '(test_|_test\.py|conftest\.py|/tests/|__init__\.py|migrations?/|setup\.py|manage\.py)' \
  || true)

# Get staged test files
TEST_FILES=$(echo "$STAGED_FILES" | grep -E '(test_[^/]*\.py$|_test\.py$)' || true)

# If there are source changes but no test files staged, block the commit
if [ -n "$SOURCE_FILES" ] && [ -z "$TEST_FILES" ]; then
  echo "BLOCKED: Python source files staged without corresponding test files." >&2
  echo "" >&2
  echo "Source files staged:" >&2
  echo "$SOURCE_FILES" | sed 's/^/  - /' >&2
  echo "" >&2
  echo "Per CLAUDE.md: Every new function/class/feature MUST include tests." >&2
  echo "Write tests for your changes and stage them before committing." >&2
  exit 2
fi

# Determine which services are affected and run their tests
SERVICES_TO_TEST=""

# Auto-discover affected top-level directories from staged files
TOP_DIRS=$(echo "$STAGED_FILES" | sed -n 's|^\([^/]*\)/.*|\1|p' | sort -u)
for dir in $TOP_DIRS; do
  # Skip non-testable directories
  case "$dir" in
    .github|.claude|.hydraflow|docs|ui|venv|node_modules) continue ;;
  esac
  if [ -d "$PROJECT_ROOT/$dir/tests" ]; then
    SERVICES_TO_TEST="$SERVICES_TO_TEST $dir"
  fi
done

# Also check root-level test directory
if echo "$STAGED_FILES" | grep -q "^tests/"; then
  SERVICES_TO_TEST="$SERVICES_TO_TEST root"
fi

if [ -z "$SERVICES_TO_TEST" ]; then
  exit 0  # No testable service changes (docs, configs, etc.)
fi

# Run tests for each affected service
FAILED_SERVICES=""

for service in $SERVICES_TO_TEST; do
  if [ "$service" = "root" ]; then
    TEST_DIR="$PROJECT_ROOT"
    TEST_PATH="tests/"
  else
    TEST_DIR="$PROJECT_ROOT/$service"
    TEST_PATH="tests/"
  fi

  if [ -d "$TEST_DIR/$TEST_PATH" ]; then
    echo "Running tests for $service..." >&2
    if ! (cd "$TEST_DIR" && PYTHONPATH=. VIRTUAL_ENV="$PROJECT_ROOT/venv" uv run --active pytest -m "not integration and not system_flow and not smoke" -q "$TEST_PATH" 2>&1); then
      FAILED_SERVICES="$FAILED_SERVICES $service"
    fi
  fi
done

if [ -n "$FAILED_SERVICES" ]; then
  echo "" >&2
  echo "BLOCKED: Tests failed for:$FAILED_SERVICES" >&2
  echo "Fix failing tests before committing." >&2
  exit 2
fi

echo "All tests passed for affected services." >&2
exit 0

Read the full file on GitHub · 141 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 141 lines · 13 tokens per session scan C a906ab14c80d

Subscribe to this mod's changes

hf.validate-tests-before-commit is a skill published in the GitHub repository T-rav/hydraflow (5 stars, last pushed 2d ago), licensed Apache-2.0. It adds 13 tokens to every session and 1,364 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it C with 2 findings (downloads and executes remote code, makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

develop

Run /develop to build a feature, UI or backend, from an approved design, a page, component, API, service, or data slice. If something load bearing is undecided and no spec records it, it stops and routes you to /architect; otherwise it reads the spec plus AGENTS.md, builds, and advances the scope.

jsmastery-pro/skills · 71 tokens

sync

Run /sync as the last step after a change is complete, around merge, to keep durable knowledge current. Updates root and nested AGENTS.md, reconciles the scope from repo evidence, and flags specs the change made stale. Surgical edits only: it adds lines, and rewrites single lines it owns. Never a whole section, never…

jsmastery-pro/skills · 73 tokens

test

Run /test to write a test suite for code you just built or changed, after implementing a feature, route, or fix. Targets uncommitted changes automatically, reads test preferences.json for your framework (asks and saves it if absent), and picks the right strategy per file: happy path, edge cases, error states…

jsmastery-pro/skills · 69 tokens

document

Run /document pr | changelog | release-note | postmortem (or let it ask) to write the human facing prose about a change. Drafts from the real commits and diff, writing to the right place. Does not write code, tests, or specs.

jsmastery-pro/skills · 65 tokens

debug

Run /debug to find and fix a bug's root cause: a test failing for an unclear reason, /check verify finding a failure, or behavior being wrong. Runs a reproduce, localize, hypothesize, test, fix, verify loop, makes the minimal fix, and hands a regression test to /test. No features, no extra refactors.

jsmastery-pro/skills · 74 tokens

check

Confirm a change before merge. /check verify drives the real app to prove behavior against the spec (every acceptance criterion met, every surface built). /check review runs a senior code review on a fresh model, one that did not write the code. Verify after /develop, review before a PR. Writes to docs/reviews/, never…

jsmastery-pro/skills · 74 tokens