R250 Keep only checks that take seconds, and no tests, in the commit hooks

On by default

Put into a repository’s commit hooks only checks that finish in seconds, such as formatting, lint, a secret scan and validating or building the repository’s own sources, aiming at no more than 5 seconds for all of them; never run tests in the hooks, whether unit, integration or end-to-end, nor checks that need a heavy toolchain or outside state, and leave those to the checks before a push and to CI.

Reason

The hooks run at every commit: slow ones hold up each commit and tempt the author to skip them (Art. III §1(2)). Tests are the checks that grow with the code: a suite that takes a second today takes a minute a year later, so a hook that runs them leaves the budget sooner or later, and drawing the line at tests keeps the decision from being made again for each suite. The tests and the heavy checks still run before the push and in CI, so none is lost.

Verification

What counts is what the hooks run, read from their configuration, and the total time of all the hooks on a commit of ordinary size, in a checkout where they are installed. A test is any run of a test suite or test runner, however fast, unit, integration and end-to-end tests alike; validating or building the repository’s own sources, or checking that a generated file is current, is not a test. The credential scan goes into the hooks before other checks, and scans the staged changes (rule 50). Hooks that pass do not clear a push: the checks the change touches still run before it (rule 53).

Violated when a repository’s commit hooks run any test, hold a check that needs a toolchain installed on the spot (downloading dependencies, for example) or needs the network or an outside service, or when all the hooks on an ordinary commit take more than 5 seconds time after time.

Provisions of the constitution it cites

Relations

Parent
R77 Git
Requires
none
Conflicts with
none

Metadata

ID
250
Revision
1
Kind
rule
Status
trial
Slug
hook-seconds-no-tests
Default level
project
Constitution revisions
>=1
Check
none
Default
on
Uses
Instructions instructions
Original language
English en
Translations
Chinese zh