RedMachine Buy

ยท Blog

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.

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.

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

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.

Buy RedMachine

Related

Back to the blog