protect-tests — плагин для Claude Code: блокирует отключение тестов
Плагин protect-tests останавливает «липовый зелёный» результат: не даёт агенту удалять, переименовывать или отключать тесты через skip/xfail вместо того, чтобы чинить код. Работает с pytest, jest, Go, JUnit, RSpec и другими фреймворками.
MIT ★ 586 обновлён 2026-10-26
/plugin marketplace add karanb192/claude-code-hooks
/plugin install protect-tests@claude-code-hooksЧто делает protect-tests
Плагин ставит блокировку перед каждым вызовом Bash, Edit, MultiEdit и Write. Если агент пытается удалить тестовый файл или папку (через rm, git rm), переименовать тест в отключённое имя (.bak, .disabled, .skip), добавить маркер пропуска в существующий тест или написать уже заскипленный файл, хук отклоняет операцию и возвращает сообщение: «Чини код, не отключай тест».
Уровень защиты настраивается переменной HOOK_SAFETY_LEVEL: critical (блокирует только удаление), high (по умолчанию, добавляет блокировку переименований и skip-маркеров) или strict (плюс запрет писать уже заскипленные новые тесты). Хук узнаёт тесты в pytest, unittest, jest, mocha, vitest, Go, JUnit, TestNG, NUnit, MSTest, RSpec и Rust.
Плагин не мешает писать новые реальные тесты, переименовывать тесты на другие имена или редактировать тело теста. Логи блокировок записываются в ~/.claude/hooks-logs/YYYY-MM-DD.jsonl без содержимого команд.
Какие задачи решает
- остановить агента от удаления тестовых файлов вместо исправления кода
- помешать переименованию тестов в отключённые имена
- заблокировать добавление skip и xfail маркеров в существующие тесты
- предотвратить написание уже заскипленных новых тестов
Примеры запросов агенту
- Установи плагин, и Claude Code перестанет игнорить падающие тесты
- Измени уровень защиты:
HOOK_SAFETY_LEVEL=strictв конфиге для максимального контроля - Проверь логи в
~/.claude/hooks-logs, если агент наткнулся на блокировку
Как установить protect-tests
Через маркетплейс плагинов
/plugin marketplace add karanb192/claude-code-hooks/plugin install protect-tests@claude-code-hooksПо шагам, с командами для каждой платформы: Плагины Claude Code: маркетплейсы, установка и как собрать свой
Вопросы о protect-tests
Как установить protect-tests в Claude Code?
Выполни /plugin marketplace add karanb192/claude-code-hooks, затем /plugin install protect-tests@claude-code-hooks. Перезагрузи Claude Code.
Что делает protect-tests?
Блокирует попытки агента обойти падающие тесты удалением файлов, переименованием тестов в отключённые имена или добавлением skip/xfail маркеров. Заставляет его чинить код вместо этого.
Какие фреймворки поддерживаются?
pytest, unittest, jest, mocha, vitest, Go, JUnit, TestNG, NUnit, MSTest, RSpec и Rust. Хук определяет тесты по расширениям и структуре файлов.
Исходный текст
protect-tests · MIT
# protect-tests
> Stops "fake green": blocks an agent from making a suite pass by deleting, renaming-away, or skip-disabling tests instead of fixing the code.
A `PreToolUse` hook fires before every `Bash`, `Edit`, `MultiEdit`, and `Write` call and denies the ones that remove or disable tests: `rm` / `git rm` of a test file or test directory, `mv` of a test file to a disabled name (`.bak`, `.disabled`, ...), an edit that introduces a skip/xfail/ignore marker into an existing test, and (at the `strict` level) writing a brand-new test file that is already skipped. Test paths and skip markers are matched across pytest, unittest, jest/mocha/vitest, Go, JUnit/TestNG, NUnit/MSTest, RSpec, and Rust. It does NOT block writing new, real tests, refactor-renaming a test to another test name, or editing test bodies: only removal and disabling.
## Install
```
/plugin marketplace add karanb192/claude-code-hooks # once per machine
/plugin install protect-tests@claude-code-hooks
```
Restart Claude Code, done. (Or from a shell: `claude plugin install protect-tests@claude-code-hooks`.)
## What it does
| Tool | Blocked when | Level | Deny id |
|------|--------------|-------|---------|
| `Bash` | `rm` / `unlink` / `shred` / `trash` / `git rm` targets a test file or test directory | `critical` | `delete-test` |
| `Bash` | `mv` renames a test file to a disabled name (`.bak`, `.old`, `.orig`, `.disabled`, `.skip`, `.ignore`, `.tmp`, `~`) | `high` | `rename-test` |
| `Edit` / `MultiEdit` | the edit adds a skip/xfail/ignore marker to an existing test file | `high` | `skip-test` |
| `Write` | the new test file's content is already skipped/ignored | `strict` | `write-skipped-test` |
Anything at or below the active safety level is denied with a reason Claude sees ("Fix the code, don't disable the test"); everything else passes through. On malformed input the hook fails open (emits `{}`), so it can never wedge a session.
## Safety levels
| Level | Blocks |
|-------|--------|
| `critical` | deleting test files or whole test directories (rm / git rm) |
| `high` (default) | + renaming a test file to a disabled name, + adding a skip/xfail/ignore marker to an existing test |
| `strict` | + writing a whole test file that is already skipped |
## Configuration
One optional environment variable:
| Variable | Default | Purpose |
|----------|---------|---------|
| `HOOK_SAFETY_LEVEL` | `high` | Safety level: `critical`, `high`, or `strict`. Any other value falls back to `high`. Set it via env (shell profile, or inline in a hook command), not by editing the installed script: plugin updates overwrite plugin files. |
## How it registers
`hooks/hooks.json` registers one `PreToolUse` hook with matcher `Bash|Edit|MultiEdit|Write`, running synchronously (a deny decision has to land before the tool executes).
## Data & privacy
Blocked calls and parse errors are logged as JSONL to `~/.claude/hooks-logs/YYYY-MM-DD.jsonl` (deny id, level, tool name, session id, cwd, permission mode; no commands or file contents, though a parse error's message can quote the first few characters of a malformed payload). The script only uses `fs` and `path`, so nothing leaves your machine.
## Uninstall
```
/plugin uninstall protect-tests@claude-code-hooks
```
Part of [claude-code-hooks](https://github.com/karanb192/claude-code-hooks), a marketplace of production-ready Claude Code hooks.
© Karan Bansal · MIT · karanb192/claude-code-hooks