Files
bambuddy/.pre-commit-config.yaml
maziggy e0a2398783 ci: balance the backend test shards by measured time, not test count
Backend Tests (shard 1/4) timed out after 10 minutes on e8b901f54
("Updated BACKERS"), a docs-only commit. The step was not hung: it
reached 98%, every test passing, and was killed about 12 seconds short
of finishing.

pytest-split balances by duration only when it has a durations file,
and there was none. Without one it splits by test COUNT -- 2926 / 2926
/ 2926 / 2925, exactly 25% each, which is what the comment here claimed
was good enough. Count is not time. Measured over the full suite
(11703 tests, 1045.6s):

    shard 1   2926 tests   658.2s
    shard 2   2926 tests   173.1s
    shard 3   2926 tests   113.3s
    shard 4   2925 tests   101.1s

Shard 1 was carrying 63% of the suite's runtime -- a 6.5x spread -- and
had been walking toward the cap for weeks: 475s, 404s, 445s, then 587s
on 08-30, thirteen seconds under it, and 613s here. CI printed the
reason in its own log on every run: "[pytest-split] No test durations
found."

Commit tests/.test_durations and pass --durations-path explicitly:

    shard 1   1273 tests   261.6s
    shard 2   1070 tests   261.5s
    shard 3   1522 tests   262.0s
    shard 4   7838 tests   260.6s

A 1.01x spread. The lopsided test counts are the point: shard 4 takes
thousands of fast unit tests, shard 1 keeps the slow integration ones.
The four groups still partition the suite exactly -- union is 11703
with nothing dropped or duplicated, and all four pass.

--durations-path has to be explicit because pytest-split defaults it to
$CWD/.test_durations, and the two matrices run from different
directories: the native job from backend/, the Docker job from the
image root. Left implicit, the Docker one finds nothing and silently
falls back to the count split. Node IDs match across both because
backend/tests/pytest.ini pins rootdir to backend/tests either way, so a
single file serves them both; verified the file clears .dockerignore
and lands at /app/backend/tests/.test_durations at full size.

timeout-minutes 10 -> 15 for headroom, since the file goes stale as
tests are added. Staleness degrades slowly rather than breaking --
unknown tests are treated as average.
2026-08-31 17:13:09 +02:00

66 lines
2.5 KiB
YAML

# Pre-commit hooks for BamBuddy
# Install with: pip install pre-commit && pre-commit install
repos:
# Ruff - Fast Python linter and formatter
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.11
hooks:
# Linter
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
types_or: [python, pyi]
# Formatter
- id: ruff-format
types_or: [python, pyi]
# Standard pre-commit hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
# Exclude static/ (build output) so whitespace normalisation
# doesn't drift the files away from upstream.
exclude: ^static/
- id: end-of-file-fixer
exclude: ^static/
- id: check-yaml
- id: check-json
exclude: ^(static/|frontend/tsconfig\.)
- id: check-added-large-files
args: ['--maxkb=1000']
# CHANGELOG.md is intentionally large (detailed per-release entries over
# many versions); exempt it while keeping the 1 MB guard for everything else.
#
# backend/tests/.test_durations is ~1.5 MB and cannot be made smaller:
# its 11703 pytest node IDs are 1160 kB of keys before a single duration
# value is written, so no encoding fits under the guard (compact JSON
# with 3-decimal values still measures 1263 kB). Pruning fast tests is
# worse than useless -- pytest-split gives a test missing from the file
# the AVERAGE of the entries that remain, so dropped 1 ms tests come back
# weighted at ~89 ms and the balance it exists to provide degrades.
# It compresses to ~314 kB in the object store. Regenerate with
# --store-durations; see the backend test job in .github/workflows/ci.yml.
exclude: ^(static/assets/|CHANGELOG\.md$|backend/tests/\.test_durations$)
- id: check-merge-conflict
- id: debug-statements
- id: detect-private-key
# Check for import shadowing (custom)
- repo: local
hooks:
- id: check-import-shadowing
name: Check for dangerous import shadowing
entry: python -m pytest backend/tests/unit/test_code_quality.py::TestImportShadowing -v --tb=short
language: system
pass_filenames: false
types: [python]
files: ^backend/app/
- id: frontend-typecheck
name: TypeScript type check
entry: bash -c 'cd frontend && npx tsc --noEmit'
language: system
pass_filenames: false
files: ^frontend/src/
types_or: [ts, tsx]