Contributing
This page says what a contribution needs, how to check one before you push it, and where the design is written down. A vulnerability is reported privately, as SECURITY.md says, and everyone here keeps the code of conduct.
Setup
- PHP 8.4 or later, with pcov. The coverage gate runs under pcov.
composer install. It setscore.hooksPathto.githooksand runsbin/mutation-gate pest:patch.- Python 3 runs the scripts under
.github/scripts, the action’s scripts underresources/action, and their tests. - Node runs markdownlint, locked in
.github/bot/markdownlint, and builds the docs site, locked in.site(ADR-0038).
The hooks in .githooks say early what CI says later:
| Hook | Refuses |
|---|---|
pre-commit | a staged PHP file Pint would change |
commit-msg | a subject that is not conventional, and a Spec: number that is no decision |
pre-push | a push straight to main, and a push that would leave a branch with no commit of its own |
The local gates
Every CI job has an entry in .github/gates.json. Its
reproduce is the command that runs the job here, and its fix, where a fix
is mechanical, the command that makes it. This prints the one for checks:
jq -r '.gates.checks.reproduce' .github/gates.jsonA job that runs several tools, as hygiene/tools does, holds a line for each.
Before each push, run the entries for what you changed:
| You changed | Run |
|---|---|
| anything | typos and python3 .github/scripts/line_cap.py --root . |
PHP, composer.json, phpstan.neon, phpstan/layers.neon, rector.php or pint.json | checks and rules, and the tests of the code you changed: vendor/bin/pest <test files> |
| Markdown | the markdownlint line of hygiene/tools and lychee --config lychee.toml . |
ARCHITECTURE.md or .docs/using/ | the Markdown entries, and composer test, because tests read them |
.docs/, .site/, README.md, CONTRIBUTING.md, ARCHITECTURE.md, SECURITY.md or what prints a link into the docs | site/build |
| a workflow | actionlint and zizmor . |
.github/scripts or resources/action | scripts |
tests/Unit mirrors src, so the tests of src/Core/Plan/Cut.php are in
tests/Unit/Core/Plan/CutTest.php, and each plugin’s are under
plugins/<name>/tests. Where they would pass the line cap, they are split by
concern into tests/Unit/Core/Plan/Cut/, beside the first file, with what the
files share in a class of tests/Support. A test that starts a real process
goes in tests/Process instead, mirroring src the same way. Its file holds
the units its tests kill with a holds: group on each test, since the gate’s
own config lists Process in tests.holding
(holding tests).
The whole suite runs locally too, more slowly:
| Command | Runs |
|---|---|
composer test | every suite but Guards, in parallel |
composer test:coverage | the same, with every line of src and of each plugin’s src covered (tests) |
composer test:guards | a planted violation of every rule, which each rule must refuse (guards) |
composer ci | validate, normalize, audit, lint, analyse, refactor, deps, test:guards and test:report, in that order |
composer phar builds the gate’s PHAR into build/mutation-gate.phar as a
release builds it (ADR-0022), with Box at the release scripts/phar.sh pins.
Its smoke suite, which CI’s phar job runs, runs against it with
vendor/bin/pest --group=phar, once composer install --working-dir=tests/Fixtures/Archive has installed the project it judges.
Leave these to CI:
lowest dependencies, because it rewritescomposer.lockandvendor;runner contracts, because each of its legs installs a fixture library at one end of a supported range first. On a pull request, a runner’s legs run only where its adapter, its fixture, the test support its tests use or what every runner shares changed;end-to-end / warm workersruns only where the PHPUnit runner, its worker or what every runner shares changed (.github/scripts/scope.py). Each leg’s test support is listed in.github/scripts/legs.json, and the leg fails where a test of its uses support the list does not hold:python3 .github/scripts/leg_support.py writelists it again. Every leg runs onmainand every night;sonarcloudandgate, which ask SonarCloud;analyze, CodeQL’s analysis of the workflows.
The benchmark, bench.yml, runs on demand and monthly (ADR-0017).
composer bench -- <project> [cold|scenarios|sharded] runs one project of it
here, which takes hours and needs what the project’s suite needs, such as
MySQL for pinkary.
Commits and pull requests
- Conventional subjects. Every commit subject, and the pull request’s
title, is
type(scope): subject. The type is one offeat,fix,docs,refactor,test,chore,ci,perf,build,styleandrevert. The scope is optional and lowercase, and a!before the colon marks a breaking change.prchecks them. - The title and body become the commit on
main.maintakes only squash merges, whose subject is the pull request’s title and whose message is its body. Spec:in the body. A change that follows a decision names it on a line of its own,Spec: 0006, or several numbers,Spec: 0002, 0011. Each number must be a decision in.docs/decisions, whichdescriptionchecks. A commit may carry the same trailer, and thecommit-msghook checks its numbers.- A breaking change says how to move. A title with
!needs a## Migrationsection in the body, saying what a user changes. - Signing is not required, and there is no sign-off. Every commit on
mainis signed, becausemaintakes only squash commits and GitHub signs each one. Your own commits need not be signed, and need noSigned-off-byline. - Open the pull request as a draft, and mark it ready for review once its checks are green.
CI on a pull request from someone who is neither a member of the organisation nor a collaborator on this repository starts once a maintainer approves the run. The pull request template holds the checklist.
The bot’s comment
Each pull request gets one comment from the bot, which follows it. It says
which gates failed and why, at the file and line, in words from
.github/gates.json and .github/bot/, with the command that reproduces each
one and the one that fixes it where a fix is mechanical. A mechanical fix
inside the diff is also posted as suggested changes, which you can commit from
the pull request. The comment also holds a checklist, the line the changelog
will take from the title, and, where the title or the Spec: line is
missing, a suggestion for it.
Commands in comments
A comment whose first line is one of these runs it:
| Command | Does | Who |
|---|---|---|
/update | GitHub merges the base branch into the pull request’s branch, and signs the merge commit, which the squash leaves out of main | someone with write access, or the pull request’s author |
/rebase | the same as /update, because GitHub cannot sign rebased commits | someone with write access, or the pull request’s author |
/retest | re-runs the failed jobs of the latest CI run on the pull request’s head, at most three times per head | someone with write access, or the pull request’s author |
/fix | commits the fix the pull request’s own latest CI run computed (Pint, Rector, composer normalize, markdownlint) to its branch, where the branch is in this repository and neither its base nor a protected branch | someone with write access, or the pull request’s author |
/docs <words> | replies with at most three links to headings under .docs that match the words | anyone, on an issue or a pull request |
Finding your way
- ARCHITECTURE.md is the contract. It lays out the
layers,
Core,Attribute,Port,Mutator,Config,Extension,AdapterandCli, each naming only itself and those before it. Every rule in it names what enforces it, andtests/Guardsplants a violation of each one. - The decisions are the design. Each ADR
gives a decision, the alternatives and why they lost. A commit or pull
request that implements one names it in
Spec:. - The tests are laid out by kind.
tests/Unitmirrorssrc, and so doestests/Process, which holds the tests that start real processes.tests/Contractholds one suite per port, which runs against the port’s fake intests/Fakesand every adapter.tests/Archholds the rules the suite enforces, andtests/Docsholds the documentation to the code. The gate judges its own mutants byUnitandPlugins.ProcessandContractjudge only the units they hold. - CI, the docs and releases each have a page of their own: how CI works, the docs and releasing.
- The reusable workflow is generated. Edit its template,
scripts/workflows/mutation-gate/, and runpython3 scripts/workflows/generate.py, which writes.github/workflows/mutation-gate.ymlwith every download retried once (ADR-0072). Thescriptsjob fails where the two differ. Every filescripts/generated.pylists is written by its own recipe in the same way.
Adding an adapter, a preset or an extension
- An adapter implements one of the interfaces in
src/Port, in a directory of its own undersrc/Adapter, and names no other adapter.src/Cli/FirstParty.phpregisters it under the name a config chooses it by. Its port’s suite intests/Contractis run against it, and its unit tests mirror it undertests/Unit/Adapter. - A preset is a layer of config. The presets this package ships are in
src/Cli/Config/Presets.php, named byCore\Config\BuiltinPreset. An extension registers its own withExtensions::withPreset(). - An extension is a class implementing
NightWorksIO\MutationGate\Extension\Extension, constructed with no arguments and named in its package’scomposer.jsonunderextra.mutation-gate.extensions. Itsextend()answers the registry with its adapters, presets and mutator sets added. A first-party mutator set is a plugin, a package of its own underplugins/<name>, asplugins/defaultis (ADR-0021).
Extending the gate lists every extension point with its contract, and adapters says how a config names an adapter, and how an adapter reads its options.
Maintainers and decisions
- There is one maintainer, as
.github/CODEOWNERSsays. - Design is decided by ADR. Each decision is recorded in
.docs/decisions. An accepted decision changes only through a new ADR that supersedes it, linked both ways, as the decisions’ rules say. - A proposal becomes an ADR by pull request. It adds a decision record
under the next unused number, written as the others are. The docs site
builds the index from it, and
python3 .github/scripts/decisions_index.py validatesays whether it reads as one. The maintainer accepts it by merging it.