Skip to content

ADR-0026: Configs and baselines move forward between versions with one command

Status: Accepted Date: 2026-09-30

Context

The config and the baseline are committed, and both are public API (ADR-0011). A setting is deprecated with a warning for at least one minor release and removed only in a major (ADR-0011). A project on an older major needs a way to its successor’s config that does not mean reading a changelog key by key.

What exists to build on:

  • The config has no version marker. JSON’s $schema names the release line in its URL (…/php-mutation-gate/v0.1/resources/mutation-gate.schema.json, ADR-0002). The baseline has "format": 1 (ADR-0003).
  • Every format reads into one form. Each config file, in any of the four formats, is read through the same definition (ADR-0002), and an unknown key is an error that names the nearest known key (ADR-0002).
  • The formats differ in what a rewrite keeps.
    • config:show --format=… writes any format from the effective config, and writes no comments.
    • php-parser’s format-preserving printer keeps a PHP file’s layout and comments, and edits only the nodes that change.
    • symfony/yaml and nette/neon parse into plain PHP values, which hold no comments, so a file they write back has none.
  • The ledger needs no migration. A ledger of another format is not read, and the verdict warns so, which costs a run and never a verdict (ADR-0007).

Decision

  1. A file’s version is known by what it holds.

    • Every key the gate has ever renamed or removed stays known to the definition, with the version that changed it.
    • A file that holds one is read as that version’s file. The error for it names the change and the command, in the form <old key> became <new key> in : run vendor/bin/mutation-gate migrate, the gate named as it was started (ADR-0022).
    • No file carries a version key.

    This amends ADR-0002.

  2. A migration is data: typed steps in Core.

    • The steps are Rename(from, to), Move(from, to), MapValue(key, old, new), Split(from, {part => to}) and Remove(key, because), each tied to the version that made it.
      • Rename gives a key another name under the same parent, where it stands. Move takes a key and its value anywhere else.
      • Split moves each named part of the object at from to a key of its own. A part it does not name stays under from. A scalar cannot be split, so a from that holds one is left for a hand edit.
    • Each step may also name the builder spelling it retires and, for a rename or a move, the one that replaces it, such as Reach::everything becoming Reach::all with the same arguments. A PHP config is changed through these spellings alone.
    • The steps apply to the JSON form every format reads into (ADR-0002), before the definition reads it, so one step serves the JSON, YAML and NEON formats.
    • A step that still applies once every step has run, such as a rename whose new key is already written, is left for a hand edit.
    • Each step has a fixture per format, and a test that the migrated file reads with no problem.
  3. The file is written back keeping what its format can keep.

    • PHP: php-parser’s format-preserving printer edits only the builder calls a step touches, and keeps every comment and the layout.
      • It finds a step’s calls by the spelling the step retires, anywhere in the file, so a call held in a variable is found too. A rename or a move gives the call the new spelling and keeps its arguments. A removal takes the call out of the chain, or out of with().
      • A call it cannot rewrite is never guessed at, and is listed with its line for a hand edit. Such calls are a MapValue call whose argument is not a literal, a Split call, and, wherever a step names a spelling, a with() argument that is not a builder call, since nothing short of running it says which keys it writes.
    • JSON: each step is a key-level text edit, through a JSON tokenizer in Core that keeps the file’s whitespace and key order. JSON holds no comments. A $schema that names this package’s published schema of another release line is rewritten to the current line’s, on every JSON migration. A $schema that names a local path, such as the one init writes into vendor, is left as it is.
    • YAML and NEON: the file is written again from its migrated form. The diff says that its comments are not kept, and --write says so again, and then writes it.

    The PHP config is parsed, never included, so migrating it runs none of it. This needs nikic/php-parser in require, as ADR-0021 puts it. A PHP config that cannot load because it calls a spelling a step retired fails with that step’s error.

  4. The baseline migrates too. A change of the baseline’s format is migrated by the same command and the same kind of step. The ledger is not migrated (ADR-0007).

  5. mutation-gate migrate [--config=<path>] [--write] shows before it writes.

    • It prints a unified diff of every file it would change, and writes only with --write, as baseline --write does (ADR-0003).
    • Exit 0 when every file is current or has been written.
    • Exit 1 when a migration is pending and --write was not given, so CI can check that nothing is behind, and when a hand edit is left, with --write or without it.
    • Exit 2 when the named file is not a config the gate can read.
    • It writes only the config and the baseline, and nothing else.

    The command is public API. This amends ADR-0002 and ADR-0011.

  6. The machinery is tested with synthetic old keys. Its steps, the format-preserving PHP edit and the command are part of the first release, which has no older version to migrate from, and are tested with keys made up for the tests.

Alternatives considered

OptionWhy it lost
A version key in every config, written by initA key every file must carry, which a hand edit forgets to bump. The keys that make a file old already say how old it is.
A PHP class per version, with free codeFlexible, untestable in general, and it grows without limit. Typed steps are data.
Always writing the file again through config:show’s writerOne writer, and every comment and custom line of a PHP config, the canonical format, lost.
The config onlyThe first change of the baseline’s format would need a second tool.
Writing without being askedA migration is a change to a committed file, and a reviewer should see its diff first.

Consequences

Moving to a new major is one command, whose diff a reviewer reads before it is written.

A PHP config keeps its comments and layout through a migration. YAML and NEON say beforehand that theirs do not.

CI can check that a project’s config is current from the exit code.

  • ADR-0002: the one form every format reads into, and how an unknown key is reported
  • ADR-0003: the baseline and baseline --write
  • ADR-0007: why a ledger needs no migration
  • ADR-0011: what semver protects, and how a removal is deprecated
  • ADR-0021: php-parser in require