Skip to content

Adopt engineering quality gates #20

Closed

Description

@parsilver

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

Today (farzai/tether at 41d3e6c)

Stack: Bun 1.4.2 and TypeScript (tsc), Biome, Vitest, Ajv: the protocol schemas, the CLI client and the conformance runner.
CI: ci.yml check on ubuntu-latest and macos-latest, push to main and every pull request: biome check, tsc --noEmit, Vitest (on macOS also the real launchd service test).

Gate In CI today To add
Lint and format yes: Biome nothing
Typecheck yes: tsc --noEmit nothing
Tests, coverage must not drop tests yes; no coverage in CI (bun run coverage exists) run Vitest --coverage in CI, compared with the baseline
CRAP under 10 on changed functions no crapper (TypeScript)
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-18

  • CRAP: unclebob/crapper ran on src with --no-coverage, exit 0, TypeScript detected. Coverage needs --coverage-command with the Vitest lcov output.
  • Duplication: unclebob/dryer --threshold 0.8 ran on src, exit 0.
  • Mutation: unclebob/mutator --scan parsed src/protocol/urls.ts (7 sites), exit 0.

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

  • Functions: 242 in src.
  • Over cyclomatic complexity 10: 0.
  • 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 (one OS is enough for the quality job) and adds at most about 5 minutes.
  • CRAP: the job fails when a function the PR adds or changes scores 10 or more. A function that already scored 10 or more on the base passes when its score is no higher than on the base; 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 --test-command "bun run test"), with a time budget that fails cleanly and still publishes the partial report. A surviving mutant, or a changed executable line no test runs, fails the job unless the PR body says why, line by line.
  • Coverage is reported on every PR; changed lines must be covered, and the repo total is compared with 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 (that needs an owner decision).

Activity

  1. parsilver commented on Nov 18, 2026

    @parsilver
    ContributorAuthor

    Moved to Ready and started: add the coverage, CRAP, duplication and mutation gates with a baseline.

  2. parsilver commented on Nov 18, 2026

    @parsilver
    ContributorAuthor

    Plan for the quality gates.

    Approach. Port the changed-line gate already running in buildboard (.quality/gate.py with its self-tests), adapted to Vitest, and add a quality job to ci.yml on ubuntu-latest for pull requests only. Everything lives in .quality/ plus that one job, so one revert removes it.

    • Coverage: the gate runs vitest run --coverage (v8, lcov) itself after deleting any old report. Every executable line the PR adds or changes under src/ must have a hit. The repo total (lines and functions, src/ only) is reported against .quality/baseline.json; a drop alone does not fail (deleting covered code can cause it), a rise asks for the baseline update.
    • CRAP (crapper, pinned): a touched function must score under 10, or, if it was already 10 or more on base, no higher than on base (base measured in a throwaway worktree with the same coverage run).
    • Duplication (dryer --threshold 0.8, pinned): fails when a pair touching a changed line is new compared with base.
    • Mutation (mutator, pinned): changed lines of changed files only, after the cheaper checks pass. Test command: materialize the worker's symlinks into copies (Vite resolves real paths, so a linked test would import the unmutated file), run vitest related --run --bail=1 for the file, then the whole suite only for a survivor (the CLI entry points are run as subprocesses, which related cannot see). Budget sized to the change, 5 to 30 minutes, fails cleanly and still prints the partial report. A changed executable line with 0 hits counts like a survivor.
    • Waivers: Equivalent mutant: <file>:<line> <reason> as its own paragraph in the PR description, read from GitHub's rendering fetched before any PR code runs (hash pinned), one line per waiver.
    • Baseline: coverage, functions measured, functions over CRAP 10, duplicate pairs and the full mutation score of src/, measured on main at 41d3e6c.

    Invariants. No threshold lowered. No token reaches a step that runs PR code. Tests under the gate never install a real launchd agent (TETHER_REAL_SERVICE is dropped). The existing check matrix is unchanged.

    Tests per criterion.

    1. Job on every PR, about 5 minutes: the workflow job itself; this PR's own run gives the timing.
    2. CRAP ratchet: self-tests for new, under-on-base, worse-than-base and no-worse-than-base functions.
    3. Duplication: self-tests for a new pair, an old pair and an untouched pair.
    4. Mutation: self-tests for survivor, waived survivor, budget exhaustion with partial report, budget sizing within 5 to 30 minutes; plus one real mutator run on a tether file locally.
    5. Coverage: self-tests for an uncovered changed line, a pure-deletion hunk, totals against baseline.
    6. Baseline committed with measured numbers.
    7. Self-test pins the thresholds.
  3. parsilver commented on Nov 18, 2026

    @parsilver
    ContributorAuthor

    Started. The gate, its self-tests and the Vitest mutant command are on the draft PR #21. Next: the quality job in ci.yml and the baseline measured on main. The plan above was reviewed with fresh eyes; the changes from that review: a file with no related tests or a broken test harness can never count as a killed mutant, the gate and every mutant run with the keychain off and the real launchd test dropped, and the CLI entry points (only run as child processes) are judged line by line with waivers.

  4. parsilver commented on Nov 18, 2026

    @parsilver
    ContributorAuthor

    PR #21 is ready for review. The quality job passes on its own PR (1m15s: self-tests, then coverage, CRAP, duplication, mutation), and check passes on both OSes at 73beec5. The baseline is recorded from main at 41d3e6c: lines 97.11%, functions 98.96%, 242 functions with none over CRAP 10, no duplicate pairs, mutation score 81.3% across all 636 sites. An end-to-end local run on a throwaway src change caught a real (equivalent) survivor. Not yet seen on CI: a PR that changes src/ lines, and a live waiver.

    Notes:

    • Vite resolves symbolic links to real paths, so mutator's linked workers need their links copied before Vitest runs, or every mutant survives.
    • test/service-real.test.ts:93 (launchctl print right after bootout) and test/cli.test.ts "kills the agent on timeout" are flaky; both failed once and passed on re-run while this was built.
    • Line coverage moves about 0.06 points between runs of the same code.
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