# The verification ladder

> What to run before a change leaves your machine, in order: rmp fmt, rmp lint, every stage of rmp test, the slower stages and when each is worth its time, the same run inside the build image, and the seen-red-first protocol.

Source: https://omardev29.github.io/rmp-docs/framework/contributing/ladder.html

A change is proved by running it, not by reading it: almost every bug this framework has had was found by looking at pixels, dumping a file or writing an assert. The ladder is what to run before a change leaves your machine, cheapest first, so that CI confirms what you already know instead of telling you something new twenty minutes later.

## Every time

```shell
rmp fmt
rmp lint
rmp test
```

All three run on your laptop, and all three have to end clean. Not mostly clean: a warning left for later is the one the next change hides behind.

### rmp fmt

Formats every C and C++ file under `include/`, `src/`, `tests/` and `examples/` with the clang-format the framework pins. `rmp fmt check` only reports the files it would change, which is what `rmp test` and CI do. Do not format by hand, and do not reformat a file you are not otherwise changing.

### rmp lint

Runs clang-tidy over `src/`, `tests/` and `examples/`, and over the C the tools and the build compile, with the framework's `.clang-tidy`. What the tree still owes the style guide is written down in `tools/lint_debt.txt`, a count per check and file, and the run is held to it: a warning nobody owes fails, and so does a count that grew. After a change that pays some of it off, lower the file to what is left:

```shell
bash tools/lint.sh debt
```

Nothing is ever added to it. A new warning is fixed, or silenced on its line with `// NOLINT(check)` and the reason beside it. `rmp lint fix` applies what clang-tidy is sure of and formats the result; read every change it makes, because some of its fixes are wrong. [What checks what](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html) lists every check and where it holds.

Two of the checks are the framework's own, and clang-tidy runs them only with `--experimental-custom-checks`; `rmp lint` passes it. A clang-tidy run by hand without the flag registers neither and says nothing about it.

### rmp test

Runs every stage below in this order and stops at the first that fails. Name a stage to run only that one; the first failure is usually all you need to run again.

| Stage | What it checks |
|---|---|
| `rmp test fmt` | every file is clang-format clean |
| `rmp test config` | the `.toml`, the pinned versions — your clang tools among them — and every licence |
| `rmp test repo` | git tracks sources, not build output |
| `rmp test seam` | nothing in `src/rmp` reads the clock, the input or the random state by itself |
| `rmp test workflows` | every reusable workflow gets what it asks for |
| `rmp test portable` | the scripts run on macOS's bash 3.2 and on the BSDs |
| `rmp test shell` | no `A && B \|\| C` in a script |
| `rmp test naming` | the names, in every branch of every `#if` |
| `rmp test style` | the rules of the style guide clang-tidy cannot see, in every branch |
| `rmp test ownership` | nothing allocated or freed by hand, raylib's loads only in their owners |
| `rmp test pointers` | no raw pointer and no C string a game can name |
| `rmp test cppcheck` | cppcheck finds nothing in `src/rmp`, and each suppression says why |
| `rmp test headers` | every public header compiles on its own |
| `rmp test cost` | what each public header costs to include |
| `rmp test gates` | each gate above, seen red on a mistake planted in a copy of the tree |
| `rmp test configure` | `tools/configure.py`, every refusal |
| `rmp test rmp` | the `rmp` command itself, and `rmp new`'s manifest |
| `rmp test binaries` | the readers that judge a shipped `.exe` and Mac binary |
| `rmp test size` | every shipped binary has a size budget, and its reader works |
| `rmp test unit` | the unit tests, in order and then shuffled, and `tests/game/` |
| `rmp test layout` | the UI laid out at four resolutions, with no window |
| `rmp test property` | the test campaign's own checks, RapidCheck at its fixed seed, Hypothesis derandomized |
| `rmp test ui-render` | the UI on a real GPU: a hidden window, read back |
| `rmp test render` | a frame drawn in software, checked and hashed |
| `rmp test smoke` | the game built, booted and seen to draw, with no mistake reported |

[Commands](https://omardev29.github.io/rmp-docs/reference/commands.html#test) has the list as `rmp help test` prints it, and [Testing](https://omardev29.github.io/rmp-docs/framework/testing.html) what each stage does in detail. Every stage is also a step of CI, in the `lint` job or in a job of its own, and a test holds the two lists to each other.

## When the change calls for more

Some stages are left out of `rmp test` because they take minutes or hours, and run only when named. The examples are the clearest case: building all of them on every check would keep a laptop compiling a folder that only grows. Run each of these when the change is the kind it is for:

| Run | When the change touches | What it does |
|---|---|---|
| `rmp test examples` | the public API, objects, collision, maps, scenes, input, the UI, or an example | builds every example for the software renderer, boots each one and saves a screenshot, plays the platformer to the flag at 60 and 240 Hz, and plays every e2e script |
| `rmp test sanitize` | anything that parses, casts, indexes or frees | the unit and layout tests again, built by GCC under its AddressSanitizer and UndefinedBehaviorSanitizer, every warning an error: a second compiler finds what the first passed over |
| `rmp test fuzz` | a reader of files: saves, `rmp::Value`, LDtk, Tiled, Aseprite, the resource pack, the loader | every fuzz target built in `build/fuzz`, and every committed input replayed under the sanitizers; it fails unless every file ran |
| `rmp test coverage` | any code in `src/rmp/`, and any test of it | the tests built with Clang's coverage, every file held to its floor and every public function to having a test that calls it — a gate in the build image only |
| `rmp test mutation` | rarely by hand: it takes hours, in the build image | Mull and mutmut over every module, each against its floor; `bash tools/mutation.sh run MODULE` does one |
| `rmp test render-update` | the demo's frame, on purpose | records the frame's hash as the new golden |
| `rmp test e2e-update` | an e2e shot, on purpose | records every shot as its golden, inside the build image only |

Outside the image, `rmp test examples` plays every script and reports a shot that differs from its golden without failing: `outside the pinned build image: a difference is reported, not
enforced`. The goldens are drawn by the image's compiler and renderer, and a pixel of difference anywhere else proves nothing either way. A golden recorded on purpose is looked at, picture by picture, before it is committed.

The [tests](https://omardev29.github.io/rmp-docs/framework/contributing/tests.html), [examples and e2e](https://omardev29.github.io/rmp-docs/framework/contributing/examples-and-e2e.html), [properties, fuzzing and mutation](https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html) and [coverage and gates](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html) pages say how to write what each of these runs, and how to update a floor that a change has earned.

## The same, inside the image

Your laptop is not CI. Before a pull request that changes C++, the build, or anything the image-only checks hold, run the ladder again in the pinned build image, on a checkout of its own, as [Setting up](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html#the-image) shows:

```shell
IMAGE=ghcr.io/omardev29/raylib-build@$(sed -nE 's/^build_image_digest +//p' thirdparty/FROZEN_VERSIONS.md)
repo_git=$(git rev-parse --path-format=absolute --git-common-dir)
podman run --rm --init --network=none \
    -v "$PWD":/work -v "$repo_git":"$repo_git":ro -w /work "$IMAGE" \
    bash -c 'python3 tools/configure.py >/dev/null && xvfb-run -a ./rmp test'
```

Replace `./rmp test` with `./rmp test examples` or `./rmp test coverage` for the stages that are exact only there. The display `xvfb-run` provides is what the UI render test and the smoke boot open their window on; without one, the boot fails inside raylib's window code under the sanitizers instead of saying what is wrong.

## Seen red first

A test you have not seen fail is a hope with a name. Every test and every gate is seen red on the mistake it exists for before its green counts:

1. Write the test, or the gate.
2. Put the mistake back: revert the fix, or plant the error by hand. Check that the text you changed was found exactly once, because a plant that did not apply proves nothing.
3. Run it. It has to fail, and its message has to name the mistake: a `FAIL` line that says what it found, not a crash somewhere near it.
4. Take the mistake out again, and see it pass.
5. Write down what you saw: the command, and the line it failed with. It goes in the commit message and in the pull request.

`rmp test gates` does this for every `tools/*_check.sh` on every run: each gate is copied with what it reads into a scratch tree, a mistake of its kind is planted, and the gate has to say `FAIL` and name it. A new gate fails that stage until it has a planted mistake of its own.

## When the change is visual, look at it

An assert proves the boxes are where you said; it does not prove the screen looks right. `rmp test examples` leaves a screenshot of every example in `build/examples-check/screenshots/`, and, for every e2e shot that differs, the expected picture, the actual one and their difference in `build/examples-check/e2e/`. Open them.

```shell
rmp example 01_pong
```

builds one example and runs it in a window, by name or by its path under `examples/`; `rmp example` alone lists them.

## Say what ran

Report what actually happened: which stages ran, where — the laptop or the image — and what was skipped and why. A stage that skipped for a missing tool did not pass. For CI, name the run: a run number and its result is a fact, "CI passes" is a claim. The pull request template asks for exactly this, and [Pull requests](https://omardev29.github.io/rmp-docs/framework/contributing/pull-requests.html) says how it is filled in.

Next: [CI](https://omardev29.github.io/rmp-docs/framework/contributing/ci.html).
