Compare commits

..

3 Commits

Author SHA1 Message Date
f4535b6bfb Allow Pre-commit checks to be run manually
Some checks are pending
Pre-commit checks / pre-commit (push) Waiting to run
Python tests / test (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
The run that added the hook-environment cache could not benefit from it:
its key is a hash of .pre-commit-config.yaml, which that same commit
changed, so it logged "Cache not found" and then saved. Six hook
environments were still built from scratch -- including pylint's, which
pulls a dozen extra packages -- and that is most of the 126s hook step.

Without a dispatch there is no way to re-run the job on an unchanged tree
to see the cached number, so the saving could only be asserted, not
measured. Now it can be measured.

Confirmed in the same log that the previous commit landed:
"pytest with coverage enforcement....Skipped".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 16:38:15 +02:00
83c8c9deb3 Stop running the Python suite twice per push in CI
Per-step timings showed the real cost was not the install I had just
cached:

  Pre-commit checks   Run pre-commit hooks   152s
                      Install dependencies    55s

The log explains it -- "pytest with coverage enforcement....Passed"
inside the Pre-commit checks job. `pre-commit run --all-files` fires the
pytest-coverage hook, which runs every python_pkg suite with
--cov-fail-under=100: precisely what the Python tests workflow had
already done on the same commit. Two full 2174-test runs per push.

SKIP=pytest-coverage in that job only. It is the one hook skipped, and it
is skipped for being DUPLICATED rather than for being slow -- noted in
the workflow so it gets dropped if Python tests ever goes away.

Also checked and deliberately left alone:
session-autopsy-hook-mutations costs ~50s locally, but self-skips when
~/.claude/hooks is absent, which is always true on a runner. It was never
a CI cost.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 16:30:27 +02:00
e4b8ad0cfe Install only the test deps in Python tests CI: 79 packages -> 17
python-tests.yml runs pytest and nothing else, but installed the full
requirements.txt -- 79 packages, of which ~62 are linters, formatters and
type checkers that job never invokes. Installing them was the workflow's
slowest step: 49s, against 35s actually running the tests.

meta/requirements-test.txt holds the 17 that matter. Derived by static
import analysis over python_pkg/ and linux_configuration/tests/, then
VERIFIED rather than assumed -- a clean Python 3.11 venv with only this
list runs the whole suite:

  2174 passed, TOTAL 100.00%, 7138 stmts / 1748 branches, 0 missing

identical to the full-requirements run. Install of the subset: 6.2s.

The pytest-* entries are in the list even though nothing imports them:
randomly reorders tests, timeout enforces a limit, sugar changes
reporting and xdist provides -n. Dropping one changes how the suite runs.

Drift is gated, not left to discipline: a new requirements-test-sync hook
reuses check_requirements_sync.py's existing --requirements flag, so a
new third-party import fails at commit time rather than as a bare
ModuleNotFoundError in CI. The new file is also in both path filters.

pre-commit.yml keeps the full list -- it needs every formatter.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 16:29:24 +02:00
7 changed files with 190 additions and 3 deletions

View File

@ -5,6 +5,10 @@ on:
branches: [main]
pull_request:
branches: [main]
# Manual runs: this job's cost is dominated by whether the pre-commit hook
# environments are cached, and without a dispatch there is no way to
# re-run it on an unchanged tree to confirm a cache actually helps.
workflow_dispatch: {}
jobs:
pre-commit:
@ -115,4 +119,9 @@ jobs:
pip install pre-commit
- name: Run pre-commit hooks
run: pre-commit run --all-files --show-diff-on-failure
# SKIP=pytest-coverage: the Python tests workflow already runs the
# whole suite with the same 100% coverage gate, so running it again
# here doubled the cost of this job for no extra signal. It is the
# only hook skipped, and it is skipped because it is DUPLICATED, not
# because it is slow -- if that workflow is ever removed, drop this.
run: SKIP=pytest-coverage pre-commit run --all-files --show-diff-on-failure

View File

@ -16,6 +16,7 @@ on:
# workflow and the red run stayed on an older commit.
- "requirements.txt"
- "meta/requirements.txt"
- "meta/requirements-test.txt"
- ".github/workflows/python-tests.yml"
pull_request:
branches: [main]
@ -32,6 +33,7 @@ on:
# workflow and the red run stayed on an older commit.
- "requirements.txt"
- "meta/requirements.txt"
- "meta/requirements-test.txt"
- ".github/workflows/python-tests.yml"
workflow_dispatch: {}
@ -50,7 +52,7 @@ jobs:
# hashed from the file at this path, and hashing a symlink is not
# the same as hashing its target.
cache: pip
cache-dependency-path: meta/requirements.txt
cache-dependency-path: meta/requirements-test.txt
- name: Install system dependencies
run: |
set -euo pipefail
@ -59,6 +61,9 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# The TEST subset, not the full requirements.txt. This job runs
# pytest and nothing else, so the ~62 linters and formatters in the
# full list were pure install time. See meta/requirements-test.txt.
pip install -r meta/requirements-test.txt
- name: Run pytest with coverage
run: pytest --cov=python_pkg --cov-branch --cov-report=term-missing --cov-fail-under=100

View File

@ -306,6 +306,16 @@ repos:
language: system
pass_filenames: false
files: ^(python_pkg/.*\.py|requirements\.txt)$
- id: requirements-test-sync
name: requirements-test.txt covers all python_pkg imports
# python-tests.yml installs this SUBSET rather than the full list, so
# it needs the same completeness guarantee. Without this hook a new
# third-party import would pass locally and fail in CI with a bare
# ModuleNotFoundError.
entry: python3 meta/scripts/check_requirements_sync.py --package python_pkg --requirements meta/requirements-test.txt
language: system
pass_filenames: false
files: ^(python_pkg/.*\.py|meta/requirements-test\.txt)$
- id: session-autopsy-hook-mutations
name: session_autopsy hook tests are non-vacuous (mutation)
entry: python3 meta/scripts/mutate_session_autopsy_hooks.py

View File

@ -0,0 +1,37 @@
{
"intent": "Allow the Pre-commit checks workflow to be re-run manually, so a caching change can be verified on an unchanged tree instead of being asserted.",
"scope": [
".github/workflows/pre-commit.yml (triggers only)",
"Non-goal: changing what the job runs"
],
"changes": ["Added workflow_dispatch to the Pre-commit checks triggers."],
"verification": [
{
"command": "gh run view 32645759168 --log | grep for cache keys",
"result": "pass",
"evidence": "'Cache not found for input keys: pre-commit-Linux-py3.12-...' then 'Cache saved with key: ...' -- the env cache missed because that commit changed .pre-commit-config.yaml, which is the key. It is populated now."
},
{
"command": "gh run view 32645759168 --log | grep -c 'Installing environment'",
"result": "pass",
"evidence": "6 hook environments built from scratch, including pylint's with a dozen extra packages -- the bulk of the 126s hook step"
},
{
"command": "gh run view 32645759168 --log | grep 'pytest with coverage enforcement'",
"result": "pass",
"evidence": "'....Skipped' -- the duplicate-suite skip from the previous commit took effect"
},
{
"command": "python3 -c \"import yaml; yaml.safe_load(...)\"",
"result": "pass",
"evidence": "workflow parses as valid YAML"
}
],
"risks": [
"A dispatch trigger lets anyone with write access run the job on demand; it runs the same read-only checks as a push, so there is no additional privilege."
],
"rollback": [
"Remove the workflow_dispatch line.",
"After rollback, confirm the workflow no longer offers a Run workflow button."
]
}

View File

@ -0,0 +1,45 @@
{
"intent": "Stop the Python tests workflow installing ~62 linters and formatters it never invokes, by giving it a requirements file scoped to what the suite actually needs.",
"scope": [
"meta/requirements-test.txt (new)",
".github/workflows/python-tests.yml",
".pre-commit-config.yaml (new requirements-test-sync hook)",
"Non-goal: changing pre-commit.yml, which genuinely needs every formatter"
],
"changes": [
"Added meta/requirements-test.txt: 17 packages, down from 79. Derived by static import analysis over python_pkg/ and linux_configuration/tests/, then verified by running the suite against only that list.",
"python-tests.yml installs the subset, caches on it, and lists it in both path filters so a change to it triggers the workflow.",
"Added a requirements-test-sync pre-commit hook reusing check_requirements_sync.py's existing --requirements flag, so a new third-party import cannot silently break CI with a ModuleNotFoundError.",
"The pytest-* plugins are included deliberately: randomly, timeout, sugar and xdist change how the suite runs even though nothing imports them."
],
"verification": [
{
"command": "python3.11 venv + pip install -r meta/requirements-test.txt + full pytest run with coverage",
"result": "pass",
"evidence": "2174 passed, TOTAL 100.00%, 7138 statements / 1748 branches, 0 missing -- identical to the full-requirements run"
},
{
"command": "pip install -r meta/requirements-test.txt (timed)",
"result": "pass",
"evidence": "6.2s for 17 packages against a warm local cache; the full 79-package list took 49-55s on the CI runner"
},
{
"command": "python3 meta/scripts/check_requirements_sync.py --package python_pkg --requirements meta/requirements-test.txt",
"result": "pass",
"evidence": "exit 0 -- every third-party import in python_pkg is declared in the subset"
},
{
"command": "pre-commit run requirements-test-sync --all-files",
"result": "pass",
"evidence": "Passed"
}
],
"risks": [
"A new runtime import that is not added here would fail CI. Mitigated by the new hook, which gates on the same analysis and runs on every python_pkg .py change.",
"The subset can drift from the full list's version bounds. Both are >= ranges on the same packages, so a divergence surfaces as a resolver conflict rather than a silent mismatch."
],
"rollback": [
"Point the Install dependencies step and cache-dependency-path back at requirements.txt and delete the hook.",
"After rollback, confirm the install step returns to ~50s."
]
}

View File

@ -0,0 +1,41 @@
{
"intent": "Stop the Pre-commit checks workflow running the entire Python test suite a second time, when the Python tests workflow already runs it with the same coverage gate.",
"scope": [
".github/workflows/pre-commit.yml",
"Non-goal: skipping any hook that is not duplicated elsewhere"
],
"changes": [
"Run the hooks with SKIP=pytest-coverage. That hook invokes pytest_changed_packages.py, which runs every python_pkg suite with --cov-fail-under=100 -- exactly what the Python tests workflow does.",
"Recorded in the workflow that this is skipped because it is DUPLICATED, not because it is slow, and that the skip must be dropped if the Python tests workflow ever goes away."
],
"verification": [
{
"command": "gh api .../runs/32645337532/jobs -- per-step timings for Pre-commit checks",
"result": "pass",
"evidence": "Run pre-commit hooks = 152s, the dominant step, against Install dependencies at 55s"
},
{
"command": "gh run view 32645337532 --log | grep for the heavy hooks",
"result": "pass",
"evidence": "'pytest with coverage enforcement....Passed' confirms the suite really was running inside this job as well as in Python tests"
},
{
"command": "Checked whether session-autopsy-hook-mutations (50s locally) also inflates CI",
"result": "pass",
"evidence": "It self-skips when ~/.claude/hooks is absent, which is the case on a runner, so it was not a CI cost and is left alone"
},
{
"command": "python3 -c \"import yaml; yaml.safe_load(...)\"",
"result": "pass",
"evidence": "workflow parses as valid YAML"
}
],
"risks": [
"If the Python tests workflow is deleted or its path filters stop matching, the suite would no longer run in CI at all. The comment in the workflow names this dependency explicitly.",
"A path-filter gap could mean a change runs Pre-commit checks but not Python tests. Both filters were widened earlier today to cover meta/requirements*.txt for exactly this reason."
],
"rollback": [
"Remove the SKIP=pytest-coverage prefix from the Run pre-commit hooks step.",
"After rollback, expect that step to return to roughly 150s."
]
}

View File

@ -0,0 +1,40 @@
# ==============================================================================
# testsAndMisc — the dependencies needed to RUN THE TEST SUITE, and no others.
#
# python-tests.yml runs pytest and nothing else, but installed the full
# meta/requirements.txt: ~79 packages, of which ~62 are linters, formatters and
# type checkers that job never invokes. That install was the workflow's slowest
# step (49s, against 35s actually running pytest).
#
# Derived by static import analysis over python_pkg/ and
# linux_configuration/tests/, then VERIFIED by running the whole suite against
# only this list: 2174 passed, 100.00% coverage, 0 missing lines or branches.
#
# The pytest-* entries are here because they are plugins that change behaviour,
# not because anything imports them: randomly reorders tests, timeout enforces
# a limit, sugar changes reporting, xdist provides -n. Dropping one silently
# changes how the suite runs.
#
# The linting job (pre-commit.yml) still installs the full requirements.txt --
# it needs every formatter. Keep this file in sync when python_pkg gains a new
# runtime import; check_requirements_sync.py gates the full list, and the
# suite itself fails loudly here on a missing import.
# ==============================================================================
anthropic>=0.25.0
beautifulsoup4>=4.0
coverage>=7.4.0
defusedxml>=0.7.1
markdownify>=1.2.0
numpy>=1.20
pillow>=10.0
pytest>=8.0.0
pytest-cov>=4.1.0
pytest-randomly>=3.15.0
pytest-sugar>=1.0.0
pytest-timeout>=2.2.0
pytest-xdist>=3.5.0
requests>=2.0
rich>=13.0
typer>=0.12.0
typing_extensions