Run Pre Commit Checks
Testing & Qualityrun-pre-commit-checksRun Pre Commit Checks is an Agent Skill for testing & quality published in the torrust/torrust-tracker repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Run all mandatory pre-commit verification steps for the torrust-tracker project. Covers the pre-commit script (automated checks), manual review steps, and individual linter commands for debugging. Use before any commit or PR to ensure all quality gates pass. Triggers on "pre-commit checks", "run all checks", "verify before commit", or "check everything".
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/torrust/torrust-tracker/blob/HEAD/.github/skills/dev/git-workflow/run-pre-commit-checks/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/run-pre-commit-checks, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
Run Pre-commit Checks
Git Hook (Recommended Setup)
The repository ships a pre-commit Git hook that runs ./contrib/dev-tools/git/hooks/pre-commit.sh
automatically on every git commit. Install it once after cloning:
./contrib/dev-tools/git/install-git-hooks.sh
After installation the hook fires automatically; you do not need to invoke the script manually before each commit.
For AI agents: before invoking the script manually, check whether the hook is installed:
./contrib/dev-tools/git/check-git-hooks.shIf installed, skip the manual run —
git commitwill trigger it automatically. Running both would execute every check twice.
Automated Checks
⏱️ Expected runtime: ~1 minute on a modern developer machine with warm caches. AI agents should set a command timeout of at least 3 minutes before invoking
./contrib/dev-tools/git/hooks/pre-commit.sh.
Run the pre-commit script. It must exit with code 0 before every commit.
For AI agents: set TORRUST_GIT_HOOKS_LOG_DIR=.tmp so per-step log files are
written inside the workspace (git-ignored) instead of /tmp (outside workspace,
requiring permission prompts):
TORRUST_GIT_HOOKS_LOG_DIR=.tmp ./contrib/dev-tools/git/hooks/pre-commit.sh
The script runs these steps in order:
cargo machete- unused dependency checklinter all- all linters (markdown, YAML, TOML, clippy, rustfmt, shellcheck, cspell)cargo test --doc --workspace- documentation tests
Output Modes
The pre-commit script supports concise human output, verbose human output, and JSON output for automation.
# Default: text + concise
./contrib/dev-tools/git/hooks/pre-commit.sh
# Explicit text + concise
./contrib/dev-tools/git/hooks/pre-commit.sh --format=text --verbosity=concise
# Text + verbose streaming command output
./contrib/dev-tools/git/hooks/pre-commit.sh --format=text --verbosity=verbose
# Compatibility alias
./contrib/dev-tools/git/hooks/pre-commit.sh --format=text --verbose
# Structured output (single JSON document to stdout)
./contrib/dev-tools/git/hooks/pre-commit.sh --format=json
Flag behavior:
--format=<text|json>defaults totext--verbosity=<concise|verbose>defaults toconcise--verboseis an alias for--verbosity=verbose- Duplicate
--format/--verbosityflags: last value wins - Invalid values or unknown flags exit with code
2and print usage guidance to stderr - In
--format=json, structured output remains JSON regardless of verbosity value - Per-step logs are written to
TORRUST_GIT_HOOKS_LOG_DIR(default:/tmp)
For restricted agent environments that cannot write outside the workspace, run with:
TORRUST_GIT_HOOKS_LOG_DIR=.tmp ./contrib/dev-tools/git/hooks/pre-commit.sh
The .tmp/ directory is git-ignored.
Because .tmp/ is workspace-local, clean stale pre-commit-*.log files periodically.
Check Tier Ownership
Check ownership is intentionally split by gate:
- Pre-commit: fast local gate (
cargo machete,linter all,cargo test --doc --workspace) - Pre-push: nightly toolchain checks + full stable test suite (no duplicates of pre-commit; no E2E)
- CI: merge authority with full validation and E2E matrix jobs
E2E tests are intentionally excluded from both pre-commit and pre-push. They run only in CI.
MySQL tests: MySQL-specific tests require a running instance and a feature flag:
TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST=true cargo test --package bittorrent-tracker-coreThese are not run by the pre-commit script.
Manual Checks (Cannot Be Automated)
Verify these by hand before committing:
- Self-review the diff: read through
git diff --stagedfor debug artifacts or unintended changes - Documentation updated: if public API or behaviour changed, doc comments and
docs/pages reflect it AGENTS.mdupdated: if architecture or key workflows changed, the relevantAGENTS.mdis updated- New technical terms in
project-words.txt: new jargon added alphabetically - Branch name validation: if the branch uses an issue-number prefix (e.g.
42-some-description), verify thatdocs/issues/open/contains a matching spec file or directory. This prevents committing under a non-existent, closed, or wrong issue number.- Future: a
TODOis recorded incontrib/dev-tools/git/hooks/pre-commit.shto automate this check. Until then, AI agents must verify branch names manually (see the committer agent spec).
- Future: a
Before Opening a PR (Recommended)
cargo +nightly doc --no-deps --bins --examples --workspace --all-features
Troubleshooting Output Modes
- Concise mode shows high-signal per-step summaries only. On failure, it prints the log path and a short failure tail.
- Verbose mode streams full command output to the terminal. Use this for deep local debugging.
- JSON mode emits one structured document to stdout; diagnostics and usage errors go to stderr.
- If concise output is too short for debugging, re-run the same command with
--format=text --verbosity=verbose.
Debugging Individual Linters
Run individual linters to isolate a failure:
linter markdown # Markdown
linter yaml # YAML
linter toml # TOML
linter clippy # Rust code analysis
linter rustfmt # Rust formatting
linter shellcheck # Shell scripts
linter cspell # Spell checking
| Failure | Fix |
|---|---|
| Unused dependency | Remove from Cargo.toml |
| Clippy warning | Fix the underlying issue |
| rustfmt error | Run cargo fmt |
| Markdown lint error | Fix formatting per .markdownlint.json |
| Spell check error | Add term to project-words.txt |
| Test failure | Fix the failing test or code |
| Doc build error | Fix Rust doc comment |