Skip to content

Adopt engineering quality gates #43

Closed

Description

@openbotgit

Weekly architecture run 2026-11-04, quality-gate rollout. The standard covers every active repo and works as a ratchet: it gates changed code only, so existing debt never blocks a PR.

Today (farzai/github-runner-railway at 68e3e6d)

Stack: Go controller and runner images.
CI: ci.yml on ubuntu-latest: go vet, go test -race, then image builds and smoke tests. No format check and no coverage.

Gate In CI today To add
Lint and format go vet only gofmt -l (and golangci-lint if wanted)
Typecheck yes: go vet and build nothing
Tests, coverage must not drop tests yes, coverage no -coverprofile compared with the baseline
CRAP under 10 on changed functions no crapper (Go)
No new duplicate at 0.8 or above no dryer --threshold 0.8
Mutation on changed files no mutator --changed
.quality/baseline.json no add

Tools, checked on this repo on 2026-11-04

Baseline measured on 2026-11-04 (static run, tests excluded)

  • Functions: 49. Over cyclomatic complexity 10: 11. Worst: reconcile.Make (33), config.Load (25), ghapp.Client.call (19).
  • Duplicate pairs at 0.8 or above: 0.
  • Coverage and mutation score were not measured here (they need a test run). Record them from the first green run of the new job.

Acceptance

  • A quality job in .github/workflows/ci.yml runs on every pull request on ubuntu-latest and adds at most about 5 minutes.
  • gofmt -l is clean on the PR's changed files.
  • CRAP: the job fails when a function the PR adds or changes scores 10 or more. Functions the PR does not touch are not gated.
  • Duplication: the job fails when the PR adds a pair at 0.8 similarity or above.
  • Mutation: runs on the PR's changed files only (mutator --changed). A surviving mutant fails the job unless the PR body says why it is equivalent.
  • Coverage is reported on every PR, and the job fails when repo coverage drops below the baseline.
  • .quality/baseline.json is committed with coverage, functions over CRAP 10, duplicate pairs and mutation score measured on the default branch. A PR that improves a number updates the file.
  • No threshold is lowered or gate removed to get a PR through.

Activity

  1. parsilver commented on Nov 20, 2026

    @parsilver
    Contributor

    Moved to Ready and work has started: the quality job per the acceptance above, ratcheting changed code only. The controller images are not redeployed by this change.

  2. parsilver commented on Nov 20, 2026

    @parsilver
    Contributor

    Plan

    A quality job in ci.yml (ubuntu-latest, every pull request, forks included since the repo is public and the job only reads) that runs one script, .quality/gate.py. The script follows the shape the other repos on the standard already use (crapper, dryer and mutator pinned to commits in .quality/requirements.txt), adapted to Go. It judges only what the PR adds or changes.

    Scope. Go source under cmd/ and internal/, minus *_test.go and testdata/. Changed lines come from git diff -U0 --numstat -z between the PR's base (HEAD^1 of the merge checkout) and HEAD. Pure-deletion hunks add no line. An unsafe path name, a binary file, a symlink, or hunks that do not add up to git's count stop the gate rather than pass it.

    Checks

    Check Fails when
    Format gofmt -l lists a changed .go file (tests included)
    Coverage an executable line the PR adds or changes has no hit in the coverage profile. A changed file missing from the profile fails unless it holds no function body. The repo total is printed next to the baseline
    CRAP a function the PR adds or changes scores 10 or more, unless it was already 10 or more on base and scores no higher (owner rule of 2026-11-05). Base is measured in a throwaway worktree only when that case comes up
    Duplication the PR adds a pair at 0.8 or above that touches a changed line and no base pair still holds
    Mutation a mutant on a changed line survives or gets no verdict, unless the PR body has an Equivalent mutant: <file>:<line> <reason> paragraph. Budget sized to the change, 5 to 30 minutes, failing cleanly with a partial report

    Go specifics found while checking the tools

    • go test -coverprofile writes module paths (github.com/farzai/github-runner-railway/internal/...). At the pinned commit mutator matches a profile entry only when the checkout path ends with the module path, so on CI it marks every site UNCOVERED and mutates nothing. The gate therefore reads the raw profile and writes a repo-relative copy to target/coverage/coverage.out, which both crapper and mutator read. Checked: with it, internal/webhook/webhook.go goes from 15 uncovered sites to 15 killed.
    • Each mutant runs go test -count=1 on its own package (mutator's default for Go) through a small mutant-tests.sh that also logs each verdict, so a run stopped at the budget still reports what it finished. Mutants run in parallel, one worker per CPU from the cgroup quota when there is one.
    • Functions are keyed by file, receiver plus name, and order, so a moved or renamed function counts as new.

    Coverage rule. The issue asks for a failure when repo coverage drops below the baseline. The engineering quality standard (2026-11-04) reads that as "no new uncovered code": a drop caused only by deleting covered code does not fail a PR. I follow the standard: changed lines must be covered, the repo total is reported and ratcheted in baseline.json. Flagging it here in case you want the stricter reading.

    Baseline measured on main and committed in .quality/baseline.json: line coverage of the scope, functions measured and over CRAP 10, duplicate pairs at 0.8, and a full mutation run (sites, killed, survived, score).

    Invariants not to break

    • The existing test, images, example and variant jobs stay as they are. images does not depend on quality.
    • The token is used only by the first step that renders the PR description, before any code from the PR runs; its sha256 is a step output the gate checks.
    • Nothing deploys or publishes from this change; the controller and runner images are untouched.

    Tests

    • Gate self-tests (python -m unittest) run in the job before the gate: changed-line parsing incl. pure deletions and unsafe names, Go profile parsing and line hits, the CRAP ratchet (new, under on base, over and no worse, over and worse), duplicate matching, waiver parsing from rendered HTML, mutation budget and scan parsing.
    • End to end: the gate run locally against this branch, and a throwaway branch with a deliberately untested and a deliberately complex function to watch Coverage, CRAP and Mutation fail.
    • The quality job green on the PR itself.
  3. parsilver commented on Nov 20, 2026

    @parsilver
    Contributor

    In progress. The gate's self-tests are pushed on feat/43-quality-gates with draft PR #54; next come the gate, the quality job and the measured baseline.

    Plan review changes, on top of the plan above:

    • Deviations from the acceptance text, each from the standard: mutation is sized to the change with a 5-30 minute budget (the 2026-11-12 time amendment; GitHub-hosted runners are not metered on a public repo), so the job's timeout sits above 30 minutes plus setup. Mutation gets the PR's own changed files and lines instead of mutator --changed, which reads git status and so finds nothing on a clean CI checkout. Coverage follows the standard's "Coverage on deletions" section; review, not the gate, keeps baseline.json from getting worse.
    • An Equivalent mutant: paragraph also waives one uncovered line, so a change to func main (no test runs it) can pass with a stated reason.
    • Blank, comment-only and brace-only lines inside a block that never ran are not judged.
    • The job runs only on pull requests, checks out with persist-credentials: false, gives setup-go and setup-python no token, and sets its permissions explicitly. A PR runs its own copy of the gate, so review of .quality/ and .github/ stays the control.
    • Considered: a smaller Go-only gate on go-mutesting (the standard's fallback). Rejected because the pinned unclebob tools work on this repo once the profile is rewritten, and they keep one toolset across the repos on the standard.
    • Size: about 900 lines of gate plus its tests, ported from the gate already reviewed on other repos. Splitting it would leave the standard half applied in CI, so it stays one PR.
    • Docs: .quality/README.md and the CI line in CONTRIBUTING.md.
    • Changing ci.yml makes the images job rebuild all six images, and a merge pushes their sha tags to GHCR. Nothing deploys.
  4. parsilver commented on Nov 20, 2026

    @parsilver
    Contributor

    Ready for review: #54. The quality job is green on the PR (59 s, all checks passing), baseline.json is measured on main, and the PR body lists each acceptance criterion with its evidence. It waits on review and merge.

    Notes:

    • At the pinned commit, mutator cannot match a Go coverage profile that uses module paths unless the checkout path ends with the module path, so it would silently mutate nothing. Any other Go repo adopting these tools needs the same rewrite to repository paths (relative_profile in .quality/gate.py).
    • func main has no test, so a PR that changes it needs a waiver line or a refactor to pass Coverage.
    • 10 functions are over CRAP 10 on main (listed in baseline.json). Each is worth its own refactor issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions