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
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ jobs:
# The test row runs in four shards on four runners (#3050). On one runner the suite took 355 s
# to 528 s for the same tests, depending on the speed of the runner that GitHub gave: more than
# the 300 s of AGENTS.md rule 5, and growing with the suite. Each shard runs a quarter of the
# tests with `pytest-split`, keeps its coverage data, and checks no floor, since it measures a
# part of the tree. The job `Tests & Coverage` below joins the data and checks the floor. The
# matrix lists the shards and `strategy.job-total` gives their number, so a fifth shard is one
# more entry. The shard jobs are no required check: ADR 0004 binds the ruleset to the aggregate.
# tests, keeps its coverage data, and checks no floor, since it measures a part of the tree. It
# passes the paths of its own test files to pytest, so no worker collects the whole suite (#2371).
# The job `Tests & Coverage` below joins the data and checks the floor. The matrix lists the
# shards and `strategy.job-total` gives their number, so a fifth shard is one more entry. The
# shard jobs are no required check: ADR 0004 binds the ruleset to the aggregate.
#
# A pull request that only adds a plan under openspec/changes/<issue>-<slug>/ changes no line the
# suite tests, so shard 1 runs tests/invariants, which read the change folders, and no shard
Expand Down
2 changes: 1 addition & 1 deletion docs/SDLC.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ CI is the authoritative gate ([ADR 0004](adr/0004-ci-is-the-authoritative-gate.m
14. `openspec`: Runs `devops openspec check`, the OpenSpec gate: `openspec validate --all --strict` and `--archived`, a regeneration of the committed skills under the isolated profile compared with the tree, the instructions of a probe change with nothing on standard error, and a check that no requirement is rewritten by two active changes. It needs Node and the pinned `openspec` (`uv run devops install-tools --tool openspec --only-missing`), runs in every `devops ci` and in the `static` job with no path filter and no exemption, and runs alone in a commit hook when a commit touches `openspec/` or the generated skills ([ADR 0010](adr/0010-openspec-is-the-spec-and-change-proposal-layer.md)).

#### The Test Shards (`ci.yml`, `test-shard` and `test`)
The suite has about 18,000 tests, and on one runner it took 355 s to 528 s, depending on the speed of the runner that GitHub gave. AGENTS.md rule 5 sets the bound at 300 s. The test row therefore runs in four shards on four runners, the jobs `Tests & Coverage (shard <n> of 4)`. Each runs `uv run devops ci --check --no-cache --only test --shard <n> --shards 4`, which gives one quarter of the tests to `pytest-split`. A shard checks no coverage floor, since it measures a part of the tree. It uploads its coverage data as an artifact.
The suite has about 18,000 tests, and on one runner it took 355 s to 528 s, depending on the speed of the runner that GitHub gave. AGENTS.md rule 5 sets the bound at 300 s. The test row therefore runs in four shards on four runners, the jobs `Tests & Coverage (shard <n> of 4)`. Each runs `uv run devops ci --check --no-cache --only test --shard <n> --shards 4`, which passes the paths of about one quarter of the test files to pytest, so a shard collects only its own files. A shard checks no coverage floor, since it measures a part of the tree. It uploads its coverage data as an artifact.

The required check `Tests & Coverage` is the job that waits for the shards. It fails when a shard did not succeed, because a skipped job would pass a required check. It downloads the data, runs `coverage combine` and `coverage report`, which applies `fail_under` of `pyproject.toml` to the whole tree, and then runs the step `Changed-Line Coverage`. The ruleset binds to this job, never to a shard ([ADR 0004](adr/0004-ci-is-the-authoritative-gate.md)). To add a shard, add a number to the matrix `shard` of `test-shard`: the name, `--shards` and the split follow the count.

Expand Down
3 changes: 2 additions & 1 deletion docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ Every new test follows these rules. Some of them name a path, fixture or check t
### Run time

- The `Tests & Coverage` check must average under 300 s (AGENTS.md, rule 5). `devops ci job-time` reads the time of the check in the last 20 completed pushes to `main` from the Actions API and fails when their mean is over the limit. The time of a run is the time from the first start of a shard job `Tests & Coverage (shard <n> of <total>)` to the end of the job `Tests & Coverage`, which joins the shards, so the short join does not hide the wait. It counts a job that passed, failed or timed out, whatever the run concluded, so a slow run that failed, and a run that this check turned red, stay in the mean. The `Test Job Duration` job of `ci.yml` runs it after every push to `main` and every day. A pull request cannot show the mean, so the check reads the history of `main`, not the pull request.
- The same suite took 355 s on a fast runner and 528 s on a slow one (2026-11-04), so no cut of constant work holds the bound on every runner. The test row runs in four shards, one quarter of the tests on each runner (`devops ci --only test --shard <n> --shards 4`, split by `pytest-split`). When `Test Job Duration` nears the bound, add a number to the matrix of the job `test-shard`. A test must not depend on a test that runs before it in the same process, since a shard holds only some of the tests.
- The same suite took 355 s on a fast runner and 528 s on a slow one (2026-11-04), so no cut of constant work holds the bound on every runner. The test row runs in four shards, one quarter of the tests on each runner (`devops ci --only test --shard <n> --shards 4`, split by lines of test code). When `Test Job Duration` nears the bound, add a number to the matrix of the job `test-shard`. A test must not depend on a test that runs before it in the same process, since a shard holds only some of the tests.
- A shard measures a part of the tree, so it checks no coverage floor and prints no report. The job `Tests & Coverage` combines the coverage data of the shards and checks `fail_under` on the whole.
- A shard collects only its own test files. Pytest collects every file it gets, in every xdist worker. A split plugin that deselects tests after collection makes each worker collect the whole suite. That cost 31.8 s of CPU in each of 16 workers, which is 13.5% of the CPU of a run (2026-11-05, 16-CPU host, 19,074 tests). Now `devops ci --shard <n> --shards <total>` passes the paths of the test modules of the shard to pytest. The split is by lines of test code, heaviest file first, and it stores no data. A new test module joins a shard with no other step. A quarter of the files collects in about two thirds of the CPU time of the whole suite, not a quarter. The imports of shared modules stay. In the same run, worker start was 2.8% of the CPU and the controller was 1.4%. A preload fixture gave no saving. A test must not depend on a test of another file, because a shard holds only some of the files. For the same reason a `conftest.py` below `tests/` imports no devops-cli module at its top: a run that names a file below its directory loads it before the root conftest isolates HOME, and devops-cli binds its paths under HOME when it is first imported.
- An autouse fixture runs before each of the 14,000 tests, so it does no work that most tests do not need. A fixture that loads settings, opens a database or lists a directory belongs to the tests that ask for it. A numbered directory made for every test, such as `tmp_path_factory.mktemp("run")`, is slow: pytest lists every entry of the base directory to find the next number.
- `tmp_path_retention_policy = "failed"` in `pyproject.toml` deletes the directory of a test that passed, so the base directory stays small. A later test can therefore get the path of an earlier one. A cache that is keyed by a path and holds the content of a file is wrong in such a run: key it by the content.
- The root conftest raises the young threshold of the garbage collector to `GC_YOUNG_THRESHOLD`. The default made the collector a tenth of the run time. A test that needs the collector calls `gc.collect()`.
Expand Down
24 changes: 0 additions & 24 deletions openspec/changes/2371-measure-and-cut-what-each-of/design.md

This file was deleted.

49 changes: 0 additions & 49 deletions openspec/changes/2371-measure-and-cut-what-each-of/proposal.md

This file was deleted.

Loading
Loading