mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-24 16:26:17 +01:00
Compare commits
3 Commits
1351a1460f
...
f4535b6bfb
| Author | SHA1 | Date | |
|---|---|---|---|
| f4535b6bfb | |||
| 83c8c9deb3 | |||
| e4b8ad0cfe |
11
.github/workflows/pre-commit.yml
vendored
11
.github/workflows/pre-commit.yml
vendored
@ -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
|
||||
|
||||
9
.github/workflows/python-tests.yml
vendored
9
.github/workflows/python-tests.yml
vendored
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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."
|
||||
]
|
||||
}
|
||||
@ -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."
|
||||
]
|
||||
}
|
||||
@ -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."
|
||||
]
|
||||
}
|
||||
40
meta/requirements-test.txt
Normal file
40
meta/requirements-test.txt
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user