How to read a RedMachine receipt
Two things come out of a run
A RedMachine run prints a report to the terminal and writes a receipt file, redmachine-receipt.jsonl, at the top of your repository. The report is for reading now. The receipt is the record you can keep and check later. A run removes the old receipt when it starts and writes a new one when it finishes, so add the file to .gitignore and copy it somewhere if you want to keep one.
The verdict on each line
Each changed line that RedMachine counts gets one verdict.
- KILLED: a test went red with the line broken. A test noticed the break. A break that makes the code crash or raise counts too. This does not fail the run.
- SURVIVED: every test passed with the line broken, so no test noticed the break. This fails the run. Under it,
line:shows the original text andbroken as:shows the wrong version that every test accepted. - UNVIABLE: no way of breaking the line still builds. It is listed with its text and does not fail the run. It is not proven either, so a person decides what to do.
- NOT_TRIED: no verdict. The
--maxlimit ran out, or a check ran past its time or memory limit, or the tests were already failing before anything was broken. This fails the run, and the report says why. - WAIVED: a person wrote down, in a file called
.redmachine-waive, why this line needs no test. The reason goes into the receipt.
A KILLED line can carry a note in brackets, and three of them mean no test failed. [timeout]: the tests ran past their time limit and then passed on unbroken code. [memory limit]: two runs with the line broken were stopped for memory. [before any test ran], only in Xcode runs: the app crashed before any test ran, twice, with the line broken. The summary and the RESULT line count the last kind apart.
The result line
The last line of the report is the verdict for the whole change.
RESULT: PASS. Every counted line is proven by a forced fail.
RESULT: FAIL. 2 changed lines are not proven by any test.
Exit code 0 means PASS and 1 means FAIL. Other codes mean RedMachine could not run or had to stop, and it prints a message saying why. There is also PASS, with nothing proven, which appears when every counted line was UNVIABLE or WAIVED. Read that one as "nothing was shown".
What is inside the receipt
The receipt is a text file with one JSON record per line: a header, one record per counted line, a result, and a few more. Each record except the final meta record carries the SHA-256 hash of the record before it, so the records form a chain. The hash of the result record is the proof id.
The receipt holds hashes, file names, line numbers, commit ids, commands, options and waiver reasons. It does not hold your source text. It also names the tests that ran with nothing broken and, for each KILLED line, the tests seen to fail with it broken. With Python's built-in test commands, which stop at the first failure, that is only the first one. Each name is labelled printed if it was read from your test runner's output, or record if it came from an Xcode result bundle. If you pass your own --test command, the receipt has no names.
What verify proves
redmachine verify RECEIPT reads a receipt and checks it. It needs no repository and runs nothing. It checks that every record links to the one before, that the first is a header and the last a result, that the counts equal the line records, and that PASS or FAIL agrees with the counts. It prints something like this (excerpt):
receipt: the chain and the counts are consistent
note: anyone can rebuild a consistent chain. To confirm this run, run redmachine on the same commit with --expect 6a82a286852415465e74c214d51410919f8a85c01136e4992bac91aa4976d2f1
recorded: base 9a6e18a68138 head 1b48c33897d5 profile rust
counted 9: killed 8, survived 0, unviable 1, not tried 0
tree restored: yes
proof id: 6a82a286852415465e74c214d51410919f8a85c01136e4992bac91aa4976d2f1
recorded result: PASS
If someone has changed a record, verify says the receipt is not valid and names the line where the chain breaks. It exits 0 for a receipt that records a pass, 1 for one that records a fail, and 2 for one that is not valid.
Two options go further.
--expect IDcompares the proof id with one you kept from the original run.--ran TESTsays whether a test of that name ran on the unbroken code, and which broken lines it was seen to fail for. It exits 0 for yes, 1 for no, and 4 when the receipt cannot tell, for example because it holds no test names.
What verify does not prove
A receipt is not a signature. It has no key. Changing one record breaks the chain, but anyone holding the file can rewrite every record, recompute every hash, and verify will accept the result. For that reason, trust a proof id only when you produced it, when your own CI printed it, or when a fresh run on the same commit with --expect ID gives the same id.
Printed test names can be imitated by a test that sets out to deceive, and verify says so in a note. The verdicts do not depend on the names. They come from the exit codes of the test runs.
What the tool does not check
- That the code is right. A line a test proves can still be wrong in a way the test agrees with.
- That a test checks a line's result. A break that makes the code crash is KILLED either way.
- That a test is a good one. One failing test is enough to prove a line.
- Every possible break. By default each line gets one, the first that builds.
- Flaky tests. A test that fails at random while a line is broken makes that line KILLED. The
--confirm-killsoption catches a failure that repeats, but not one that happens once. - Lines you removed, with the exception noted in the post on changed lines.
It also runs your tests against code it has broken on purpose. If your code deletes files or sends anything, run it in CI or a container. The questions page has more.