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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ uv.lock linguist-generated
**/package-lock.json linguist-generated
CHANGELOG.md linguist-generated
.release-please-manifest.json linguist-generated
tests/module_durations.json linguist-generated
docs/CLI_REFERENCE.md linguist-generated
docs/commands/*.md linguist-generated
20 changes: 12 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ 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, 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).
# recorded test time (tests/module_durations.json, #5247), 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.
Expand Down Expand Up @@ -190,7 +191,7 @@ jobs:
run: uv run devops ci test tests/invariants

# The combined data file of the shard, which the gate keeps (#1743), and the JUnit XML report
# with the time of each test of the shard, for the split by measured time (#4673). The
# with the time of each test of the shard, which `devops ci durations` reads (#4673). The
# coverage path starts with a dot, so the action needs `include-hidden-files`.
- name: Upload Coverage Data and Test Report
if: steps.changes.outputs.outside_plan != 'false'
Expand Down Expand Up @@ -359,16 +360,18 @@ jobs:
exit 1
fi

# AGENTS.md rule 5: a check that averages more than 5 minutes is a P0 bug. The run of one pull
# request is one sample, so this job reads the last twenty completed pushes to main from the
# Actions API and fails when the mean of the `Tests & Coverage` check is over 300 s (#2699). The
# AGENTS.md rule 5: a check that averages more than 5 minutes is a P0 bug, with 1 minute of
# tolerance for the variation of the runners. The run of one pull request is one sample, so
# this job reads the last twenty completed pushes to main from the Actions API and fails when
# the mean of the `Tests & Coverage` check is over 360 s (#2699, #5247). Then it comments on the
# open P0 issue of the check, or files one when none is open, so one breach has one issue. The
# time of a run is the run time of the slowest shard job plus that of the job `Tests & Coverage`,
# which joins the shards (#3050). The time the jobs waited for a runner is shown on its own line
# and is not counted (#4634). The job runs only on the daily schedule and on a manual run: a
# merge does not change the window of twenty runs much, and a red alarm on each push to main hid
# the result of the tests of that push (#4634). No pull request waits for it. It reads the
# conclusion of the test job, not of the run, so a failed run still gives its test time to the
# window. It needs `actions: read` only.
# window. It needs `actions: read`, and `issues: write` for the P0 issue.
job-time:
name: Test Job Duration
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
Expand All @@ -377,6 +380,7 @@ jobs:
permissions:
contents: read
actions: read
issues: write

steps:
- name: Check out repository
Expand All @@ -393,7 +397,7 @@ jobs:
- name: Check the duration of Tests & Coverage
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: uv run devops ci job-time --repo "$GITHUB_REPOSITORY"
run: uv run devops ci job-time --repo "$GITHUB_REPOSITORY" --file-issue

# Builds, smoke-tests and scans the Service image of every pull request but the release pull
# request, without pushing it; release.yml publishes it when a release is created (#1486).
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ devops-cli is a Python command-line tool, `devops`, that automates workstation,
2. **Check the premise first.** Confirm it against the real system: upstream documents, source or command output. Record how in the proposal `## Feasibility` section. If the item cannot be built as written, write no compensating code. Return it to `New` with the evidence (`devops roadmap return`) and stop. Close issues as rejected if their functionality has been superseded by newer issues or code changes. Stop also when you swallow an error, make product code detect tests, or put a second fix on a fix.
3. **Use an open tool before you build.** Name the tool or library that covers the need. To build instead, write the cost in the issue or pull request: tokens to build, keep and fix it, and elapsed time. This rule outranks every other convention.
4. **Test new behavior first** ([docs/TESTING.md](docs/TESTING.md)). Prove other changes with a command. A fix pull request cites its `fail-to-pass` run (`devops ci fail-to-pass --base <ref>`).
5. **Pass the checks.** The pre-push hook runs the fast static checks. Never use `--no-verify`. The required CI checks gate the merge. Never lower a security or quality threshold; only the owner can allow it ([SECURITY.md](SECURITY.md#a-finding-with-no-fix)). A check that averages more than 5 minutes is a P0 bug.
5. **Pass the checks.** The pre-push hook runs the fast static checks. Never use `--no-verify`. The required CI checks gate the merge. Never lower a security or quality threshold; only the owner can allow it ([SECURITY.md](SECURITY.md#a-finding-with-no-fix)). A check that averages over 5 min + 1 min tolerance is a P0 bug.
6. **Open every pull request as a draft** with `devops pr create`, watch it with `devops pr monitor <pr_number>`, and mark it ready (`devops pr ready <pr_number>`) only after the checks pass. Reply in each review thread (`devops pr threads reply`). Advance your pull requests oldest first. Never request a Copilot review.
7. **Use `devops gh` and `devops pr`.** Never run bare `gh`: `devops` paces each request against the rate limit.
8. **Write as merged.** Write code and documents as they will read after the merge. Make no commit or pull request that only updates tracking. If a change makes a document wrong, fix it in the same pull request.
Expand Down
1 change: 1 addition & 0 deletions docs/CLI_REFERENCE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/SDLC.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ CI is the authoritative gate ([ADR 0004](adr/0004-ci-is-the-authoritative-gate.m
- The release pull request starts only the jobs of the checks that the `main` ruleset reads: `Static Analysis`, `Tests on Main` and `Tests & Coverage`, `Semantic PR title` and the CodeQL analysis. It changes `pyproject.toml` and `uv.lock`, which are image inputs, and `release.yml` builds, starts and scans each image before it publishes it. So each other job that a push to it starts skips a branch of this repository whose name starts with `release-please--`, and takes no runner (#4637). The branch of a fork with such a name runs these jobs. A new job that no rule of `main` reads gets the same condition: an invariant test in `tests/invariants/test_workflow_contracts.py` fails without it.

#### 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 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. Its log gives the reason of each skipped test (`-rfEs`). It uploads its coverage data and a JUnit XML report with the time of each of its tests (`.data/junit.xml`) as one artifact, for the split by measured time (#4250).
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 to pytest the paths of the test files that hold about one quarter of the recorded test time (`tests/module_durations.json`), so a shard collects only its own files. A shard checks no coverage floor, since it measures a part of the tree. Its log gives the reason of each skipped test (`-rfEs`). It uploads its coverage data and a JUnit XML report with the time of each of its tests (`.data/junit.xml`) as one artifact. `devops ci durations` reads these reports and writes the record that the split reads (#5247).

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 lines and branches of the whole tree (`[tool.coverage.run]` sets `branch = true`), and then runs the step `Changed-Line Coverage`. Beside the step that writes it, the job keeps `.data/coverage.xml` as an artifact with a 7-day retention. 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
7 changes: 4 additions & 3 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ 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 run time of the slowest shard job `Tests & Coverage (shard <n> of <total>)` plus the run time of the job `Tests & Coverage`, which joins the shards. The time that the jobs waited for a runner is shown on its own line and is not counted, because the queue depends on the other runs of the account, not on the tests. It counts a job that passed, failed or timed out, whatever the run concluded, so a slow run that failed stays in the mean. The `Test Job Duration` job of `ci.yml` runs it every day and on a manual run, not on a push, so a push to `main` is green when its tests pass. A pull request cannot show the mean, so the check reads the history of `main`, not the pull request. A mean over the limit is a P0 bug: find the change that made the check slow, and fix it or revert it. Do not narrow or skip a needed check to hide the time.
- The `Tests & Coverage` check must average under 300 s (AGENTS.md, rule 5). The owner allows 60 s of tolerance for the variation of the runners (2026-10-23), so the limit of the alarm is 360 s. `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 run time of the slowest shard job `Tests & Coverage (shard <n> of <total>)` plus the run time of the job `Tests & Coverage`, which joins the shards. The time that the jobs waited for a runner is shown on its own line and is not counted, because the queue depends on the other runs of the account, not on the tests. It counts a job that passed, failed or timed out, whatever the run concluded, so a slow run that failed stays in the mean. The `Test Job Duration` job of `ci.yml` runs it every day and on a manual run, not on a push, so a push to `main` is green when its tests pass. A pull request cannot show the mean, so the check reads the history of `main`, not the pull request. A mean over the limit is a P0 bug: find the change that made the check slow, and fix it or revert it. Do not narrow or skip a needed check to hide the time. The job runs the check with `--file-issue`: over the limit, it comments on the open issue whose body holds the alarm line of the check, or files one with the labels `type/bug`, `scope/ci`, `status/new` and `priority/p0-critical` when none is open. The issue holds a Priority, so intake does not place it, and the Status New lets refine read it. So one breach has one issue, also after a person changes its title or labels, and the next breach after the issue closes files a new one.
- The budget measures the mean of the `Tests & Coverage` check on `main`, not the test step of one local run. A local `uv run devops ci` runs the whole suite on every logical CPU of a host, and the gates of other agents share that host, so a local full gate can pass the budget on a shared host. When the test step of a local run goes above `CONST_CI_TEST_BUDGET_SECONDS` (300 s), the gate prints the time of the step and the slowest tests against the budget. It fails no test on the time.
- 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.
- 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 recorded test time on each runner (`devops ci --only test --shard <n> --shards 4`). When `Test Job Duration` nears the bound, write the record again first (`uv run devops ci durations`, below), then 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.
- 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. 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.
- The split weighs each test module by its recorded seconds in `tests/module_durations.json` (#5247). It deals the modules, heaviest first, to the shard with the least weight so far. A module that the record does not hold weighs its lines at the recorded seconds per line, so a new test module joins a shard with no other step. A module that the record holds and the tree does not is in no shard. A stale record only unbalances the shards and drops no test, and every runner reads the same record from the same commit. The split by lines put a short module with slow tests in one shard, and each change of the tree moved modules between shards: in one run of 2026-11-13 the four shards took 160 s to 341 s, and the mean of the check over 20 runs was 316 s. A replay of the last 20 runs of `main` with weights from the other 19 runs gives a mean of 284 s. `uv run devops ci durations` writes the record: it reads the JUnit report of each shard of the last 20 push runs of `main`, which `ci.yml` uploads in the artifact `coverage-shard-<n>` and keeps for 7 days, and writes the mean seconds of each module over the runs that ran it. Write it again when `Test Job Duration` nears the bound, or after a change moves much test time, and commit the file.
- 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
Loading