Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ repos:
types: [python]
require_serial: true

# Runs only the tests covering the staged sources, so committing stays fast while
# still verifying the change. Falls back to the full suite when a staged source has
# no covering test, rather than passing without running anything.
- id: devops-ci-test-changed
name: devops ci test (covering tests for staged files)
entry: uv run devops ci test
language: system
stages: [pre-commit]
types: [python]
require_serial: true

- id: ast-grep-scan
name: ast-grep scan (network constructs in src, elapsed-time bounds in tests)
entry: uv run ast-grep scan --error=unused-suppression --error=no-suppress-all src tests
Expand Down Expand Up @@ -104,6 +93,9 @@ repos:
pass_filenames: false
require_serial: true

# A commit runs no tests: the tests that cover a change of a shared module such as
# config/constants.py are a large part of the suite, and this hook runs the full suite
# before each push (#2086).
- id: devops-ci-pre-push
name: devops ci (pre-push quality gate)
entry: uv run devops ci
Expand Down
7 changes: 5 additions & 2 deletions docs/SDLC.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ flowchart TD
H5[check-yaml / toml / json]
H6[ruff check & format]
H7[structural-invariants]
H8[devops-ci-test-changed]
H8[ast-grep scan & test]
H9[openspec gate]
end

subgraph CIQualityGate["Primary Quality Gate (devops ci / uv run devops ci)"]
Expand Down Expand Up @@ -183,7 +184,9 @@ The `.pre-commit-config.yaml` suite intercepts flawed commits before they enter
- `check-yaml`, `check-toml`, `check-json`: Validates configuration syntax across all structured files.
- `ruff`: Enforces lint rules and code formatting.
- `structural-invariants`: Enforces max nesting depth $\le 5$ (< 6 indentation levels) across source files.
- `devops-ci-test-changed`: Runs targeted test suite covering staged files.
- `ast-grep-scan` and `ast-grep-test`: Run the ast-grep rules over `src` and `tests`, and the tests of the rules.
- `openspec-gate`: Runs `devops ci --only openspec` when a commit changes `openspec/` or the committed skills.
- A commit runs no tests. The pre-push gate and CI run the full suite (#2086).
- Pre-push `devops ci` gate: Runs every check of `devops ci` (including `actionlint` and `zizmor`) before a push, as the next section describes.

#### The Primary CI Verification Gate (`devops ci`)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: spec-driven
created: 2026-10-24
skip_specs: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Proposal

## Why

Issue #2086 shows that a commit in devops-cli waits minutes for the pre-commit hook `devops-ci-test-changed`, which runs `uv run devops ci test` on the staged Python files. The other pre-commit hooks take less than 1 second each. The pre-push gate (`uv run devops ci`) runs the full suite again, and CI runs it a third time. The owner decided on 2026-10-24 to remove the hook.

## What Changes

- Remove the hook `devops-ci-test-changed` from `.pre-commit-config.yaml`. A commit runs only the fast hooks: pre-commit-hooks, ruff, the AST structural invariants, ast-grep and the openspec gate.
- The pre-push gate and CI still run the full suite before code gets to GitHub, so no threshold changes.
- Add a test that fails when a pre-commit-stage hook runs the test suite.
- Remove the hook from the pre-commit diagram and list in `docs/SDLC.md`, and add the hooks that the list did not name.
- Change the module docstring of `src/devops_cli/core/test_selection.py`, which said that pre-commit uses the selector.
- `devops ci test <paths>` does not change, and its help text stays correct. The change alters a development hook and documents only, so it has no spec delta and sets `skip_specs: true`.
- This change fits in one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

None.

## Impact

- `.pre-commit-config.yaml`: the hook is removed, and a comment on the pre-push hook gives the reason.
- `docs/SDLC.md`: the pre-commit diagram and list.
- `src/devops_cli/core/test_selection.py`: the module docstring.
- `tests/test_workflow_contracts.py`: the new test.

## Feasibility

Measured on 2026-10-24, on a host with 16 CPUs:

- `uv run pre-commit run --verbose --files <the 26 files of the #2031 commit>`: each hook before `devops-ci-test-changed` took 0.16 to 0.74 s. The covering-tests hook ran for more than 10 minutes under that day's load (load average 65 to 106 from parallel test suites), and then the run was stopped.
- `load_index(resolve_coverage_index_path(root))` gives an empty index: only `devops ci coverage --build-index` builds one, and no hook or workflow runs it. So the hook uses the text-based selector.
- `select_tests_for_sources` picks 109 of the 484 test modules for `src/devops_cli/config/constants.py`, 76 for `src/devops_cli/config/defaults.py`, and 0 for `src/devops_cli/lang/en/help.py`. When no staged source maps to a test, the hook runs the full suite.
- The pre-push hook `devops-ci-pre-push` runs `uv run devops ci`, which holds the `test` check over the full suite.

## Existing Tool Considered

pre-commit is the open tool, and its documentation recommends fast hooks at commit time. The tests stay in the pre-push gate and in CI. This change deletes a hook and builds nothing.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Tasks

## 1. Remove the test hook from pre-commit

- [x] 1.1 Add a failing test that no pre-commit-stage hook runs the test suite (`uv run pytest tests/test_workflow_contracts.py -k no_pre_commit_hook_runs_the_test_suite`)
- [x] 1.2 Remove `devops-ci-test-changed` from `.pre-commit-config.yaml` (`uv run pytest tests/test_workflow_contracts.py tests/test_code_metrics.py tests/test_openspec_scaffold.py tests/test_ruff_complexity_cap.py tests/test_architectural_invariants.py`)
- [x] 1.3 Update the pre-commit diagram and list in `docs/SDLC.md` and the docstring of `src/devops_cli/core/test_selection.py` (`uv run devops docs check`)
- [x] 1.4 Run the gate (`uv run devops ci`)

## Workflow follow-up

- Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).
5 changes: 2 additions & 3 deletions src/devops_cli/core/test_selection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Map changed source files to the test modules that exercise them.

Pre-commit hands a hook the list of staged files. Running the whole suite for a one-line
change is the reason people start passing `--no-verify`, so this narrows the run to the
tests that actually cover the changed sources.
`devops ci test <paths>` narrows a run to the tests that cover the given files, so a person
or an agent checks a change quickly before the full gate runs.

Selection deliberately errs toward running too much: an extra test module costs seconds,
whereas missing the one test that covers a change gives a false green.
Expand Down
18 changes: 18 additions & 0 deletions tests/test_workflow_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,24 @@ def test_every_devops_command_the_workflows_actions_and_hooks_run_resolves() ->
assert (bool(workflow_commands), bool(hook_commands), unresolved) == (True, True, [])


def test_no_pre_commit_hook_runs_the_test_suite() -> None:
"""A commit runs only the fast hooks. The pre-push gate and CI run the tests (#2086)."""
config = yaml.safe_load(PRE_COMMIT_PATH.read_text(encoding="utf-8"))
default_stages = config.get("default_stages", ["pre-commit"])
commit_entries = [
str(hook.get("entry", ""))
for repo in config["repos"]
for hook in repo.get("hooks", [])
if "pre-commit" in hook.get("stages", default_stages)
]
runs_tests = [
entry
for entry in commit_entries
if "pytest" in entry.split() or re.search(r"\bdevops ci( test\b|$)", entry)
]
assert (bool(commit_entries), runs_tests) == (True, [])


def test_a_misspelled_command_in_a_workflow_is_reported() -> None:
"""The negative control: extraction and resolution together report a command that does not
exist, inside a command substitution and a compound line."""
Expand Down