Skip to content

ci: adopt the engineering quality gates - #54

Merged
parsilver merged 8 commits into
mainfrom
feat/43-quality-gates
Nov 20, 2026
Merged

parsilver merged 8 commits into
mainfrom
feat/43-quality-gates

Conversation

@parsilver

@parsilver parsilver commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #43

Adds a quality job to CI that runs .quality/gate.py on every pull request. The gate judges only what the PR adds or changes (the engineering quality standard's ratchet), so existing debt never blocks a PR. Rules, waivers and local use are in .quality/README.md.

Acceptance criteria

  • A quality job runs on every pull request on ubuntu-latest and adds at most about 5 minutes. The job is quality gate in ci.yml. It runs only on pull_request events, alongside the existing jobs, and images does not wait for it. On this PR, which changes no Go code, it took 59 s from start to finish: about 16 s to install the tools, 20 s of self-tests and 12 s of tests with coverage. Mutation scales with the change: the budget is sized from one timed mutant, with a floor of 5 and a cap of 30 minutes, per the standard's 2026-11-12 time amendment. A one-function change mutated in about 3 s locally. The timeout is 45 minutes, so the job can never time out before the gate reports. GitHub-hosted minutes are not metered on a public repo.

  • gofmt -l is clean on the PR's changed files. The Format check runs gofmt -l on every Go file the PR adds or changes, tests included. It fails on a file gofmt would change, or one gofmt cannot parse.

  • CRAP fails when an added or changed function scores 10 or more; untouched functions are not gated. Uses crapper with the owner's 2026-11-05 rule: a touched function already at 10 or more on base passes when it is no worse. The base is measured in a throwaway worktree only when that case comes up. Functions are keyed by file, receiver plus name, and order.

  • Duplication fails when the PR adds a pair at 0.8 or above. dryer runs on base and head. A head pair touching a changed line is new unless a base pair between the same two files still holds both sides.

  • Mutation runs on the PR's changed files only; a survivor fails unless the PR body says why it is equivalent. This differs from the literal mutator --changed: that flag reads git status, which is empty on a clean CI checkout, so it would mutate nothing. The gate gives mutator each changed file and its changed lines (--lines) instead. A site with no verdict also fails. A waiver is a paragraph of its own in the PR description, in the form Equivalent mutant: <file>:<line> <reason>. It is read from GitHub's own rendering of the description, so it counts only where a reviewer can see it.

  • Coverage is reported on every PR, and the job fails when repo coverage drops below the baseline. Implemented per the standard's "Coverage on deletions" section, as agreed in the plan on the issue. Every executable line the PR adds or changes must be run by a test, or carry a waiver. The repo total is printed next to the baseline on every PR and ratcheted in baseline.json, but a drop caused only by deleting covered code does not fail the PR. Review, not the gate, keeps baseline.json from getting worse.

  • .quality/baseline.json is committed with coverage, functions over CRAP 10, duplicate pairs and mutation score measured on the default branch. Measured on main at 08061db. The Go code on this branch is identical to it.

    • statement coverage 87.88%
    • 59 functions, 10 of them over CRAP 10 (listed in the file)
    • 0 duplicate pairs
    • full mutation run: 425 sites, 293 killed, 102 survived, 30 uncovered, score 74.18%, 707 s

    The gate asks for an update when coverage or the pair count improves.

  • No threshold is lowered or gate removed. Limits are CRAP under 10, similarity 0.8, and mutation 5 to 30 minutes, all as in the standard. No existing job changed.

Go specifics

  • go test -coverprofile writes module paths. At the pinned commit, mutator matches a profile entry only when the checkout path ends with the module path, so on CI it would mark every site UNCOVERED and mutate nothing. The gate writes a copy of the profile with repository paths to target/coverage/coverage.out, and both crapper and mutator read that copy. Checked on internal/webhook/webhook.go: 15 sites went from UNCOVERED to 15 killed.
  • Each mutant runs go test -count=1 on its own package, as mutator does for Go. The coverage profile is built without -coverpkg to match, so a line counts as covered only when its own package's tests run it. Mutants run in parallel, one per CPU of the cgroup quota.
  • These lines are not judged as untested: blank lines, comments, lines with only braces or parentheses, and empty functions (blocks of 0 statements).

CI security

The description render is the only step that holds the token, and it runs before any code from the PR. Its sha256 is passed on as a step output, and the gate checks it. Checkout uses persist-credentials: false, setup-go and setup-python get token: '', and permissions are explicit (contents: read, pull-requests: read). Untrusted values reach the shell only through env:. A PR runs its own copy of the gate, so review of .quality/ and .github/ stays the control.

Commands run

python -m unittest discover -s .quality -p 'test_*.py'   ->  Ran 108 tests ... OK
go test -count=1 -coverprofile=target/coverage/profile.out ./...  ->  99 passed in 7 packages
python .quality/gate.py --base origin/main               ->  every check pass, exit 0 (no Go change)

The gate was also run on throwaway branches:

  • One added an untested, complex, duplicated and unformatted file. Format, Coverage, CRAP and Duplication failed, and Mutation reported "Not run: an earlier check failed".
  • One added a weakly tested Abs. Mutation failed with > -> >= and 0 -> 1 surviving. With a rendered waiver paragraph and its hash, it passed and listed the reason.

The same cases are now self-tests (EndToEnd) using the real go, crapper, dryer and mutator.

Gate numbers on the gate's own code

The gate is Python, which is outside its own Go scope, so these were run by hand:

  • CRAP: highest 8.0 (main, held, coverage_verdict), with 96% line coverage from coverage.py.
  • dryer at 0.8 on .quality: no duplicate candidates.
  • mutator on the Go-specific functions (profile parsing, line rules, repo total, function names, workers, format check): 60 killed, 0 survived.

The waiver parser, duplicate matching and mutation plumbing are ported from the gate already reviewed on other repos. The waiver tests reuse its fixtures of GitHub renderings, with a Go path.

Risks

  • Changing ci.yml makes the changes job rebuild all six images. After merge, their sha tags are pushed to GHCR. Nothing deploys.
  • A PR touching func main will fail Coverage, since no test runs it. It passes only with a waiver line that gives the reason, or a refactor that makes main testable.
  • Stopping mutants at the budget relies on /proc, so it is Linux only, which is fine on ubuntu-latest.

Not verified

  • The full mutation baseline was measured locally (macOS, Go 1.27.1) rather than on the runner, one file at a time with 2 workers, because no shared heavy-job slot came free. The counts should not depend on the machine, but the 707 s figure does.
  • No real PR with a Go change has gone through the CI job yet. The closest evidence: on the runner, the job ran all 108 self-tests with none skipped. That includes the EndToEnd cases, which run the gate with the real go, crapper, dryer and mutator on a throwaway module, mutation and the CRAP base measurement included. The whole job took 59 s.
  • No generated Go files exist, so the gate has no special case for them.

The gate itself follows; these pin its behaviour first: changed-line
parsing, Go coverage profiles, the CRAP ratchet, duplicate matching,
waivers from the rendered PR description and the mutation budget.
They fail now because .quality/gate.py does not exist yet.
@parsilver parsilver mentioned this pull request Nov 20, 2026
8 tasks
Judges only the lines a pull request adds or changes, per the
engineering quality standard: gofmt, coverage of changed lines, CRAP
under 10 with the base ratchet, no new duplicate at 0.8 and no
surviving mutant within a budget sized to the change.

go test writes module paths into the coverage profile, which mutator
cannot match to a checkout, so the gate rewrites it with repository
paths before crapper and mutator read it.

All 93 self-tests pass locally.
A quality job on ubuntu-latest renders the PR description for waivers
(the only step with the token, before any PR code runs), installs the
pinned tools, runs the gate's self-tests and the Go tests with
coverage, then the gate. Checkout keeps no credentials and the setup
actions get no token. The timeout leaves room for the 30-minute
mutation cap; the repository is public, so the minutes are not
metered.
@parsilver
parsilver force-pushed the feat/43-quality-gates branch from b56f101 to 1f8bec2 Compare November 20, 2026 17:22
go test lists an empty function as a block of 0 statements, so its
line read as untested even though there is nothing in it to run. Also
keep __pycache__ out of the tree.

Found by running the gate on a throwaway branch; 94 self-tests pass.
The report printed the first 8 characters of the name it was given,
so a local run against origin/main showed "origin/m". 95 self-tests
pass.
Statement coverage 87.88%, 59 functions with 10 over CRAP 10, no
duplicate pair at 0.8, and a full mutation run of 425 sites: 293
killed, 102 survived, 30 uncovered (score 74.18%). Numbers may only
improve; a PR that improves one updates this file.
Runs gate.main on a throwaway Go module with the real tools: the CRAP
ratchet against a measured base, every check failing on a bad change,
a weak test failing mutation, and no Go change. Splits
uncovered_changed so its complexity stays under 10, drops a default
that could never be read in the repo total, and adds tests for the
mutants that survived (gofmt failing outright, an inert last line, a
namespace without a slash, cpu_count returning None, a quota under one
CPU).

Gate functions: highest CRAP 8.0, 96% line coverage under coverage.py.
Mutation on the Go-specific functions: 60 killed, 0 survived. 108
self-tests pass.
@parsilver
parsilver marked this pull request as ready for review November 20, 2026 18:19

@parsilver parsilver left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Blocker. The gate follows the standard:

  • Changed lines only. It gates only the lines the PR changes, and it takes the old CRAP debt rule from 2026-11-05.
  • Mutation. It runs on the changed files and lines through --lines rather than --changed; the PR explains why --changed would mutate nothing on a CI checkout. The budget is 5 to 30 minutes.
  • Coverage. It is judged on added lines, with the repo total ratcheted in baseline.json, measured on 08061db.

The job is safe on a public repo:

  • It runs on pull_request, not pull_request_target, with contents: read and pull-requests: read.
  • persist-credentials: false.
  • The token appears only in the description-render step, which runs before any code from the PR.
  • The setup actions get an empty token, and the rendered description is pinned by a sha256 output.

One thing from the same gate in another repo: a waiver paragraph with inline code (backticks) isn't counted, so write waivers as plain text. Merging.

@parsilver
parsilver merged commit 3434099 into main Nov 20, 2026
15 checks passed
@parsilver
parsilver deleted the feat/43-quality-gates branch November 20, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adopt engineering quality gates

1 participant