Write file scenarios
A file scenario names an input, the command to run, and the output that command writes.
name: The weekly stock report lists every item with its priceinput: file: stock.jsonrun: node packages/report/report.mjs {{input}} {{output}}/weekly.csvoutput: file: weekly.csv layout: csvIts input is a file beside it.
[ { "sku": "P-1", "name": "Pen", "price": 3.5, "quantity": 40 }, { "sku": "N-2", "name": "Notebook", "price": 12, "quantity": 15 }, { "sku": "I-3", "name": "Ink", "price": 7.25, "quantity": 8 }]A comparison groups what changed in the output by column.
$ rehearse compare --base main…changed without saying so: The weekly stock report lists every item with its price (packages/report/weekly.rehearse.yaml) weekly.csv column 3 "price": "3.5" → "3.50" (2 places)
unannounced, by what changed: weekly.csv column 3 "price" — in 1 scenarioA file scenario tries a command that reads an input and writes an output: a report, an export, a rendered document, a
generated map. Rehearse runs it on the base and on the head and compares the outputs by their layout. A CSV is
compared cell by cell and grouped by column, so one change in a column reads as one line, however many rows it
touches. Above, the head writes prices with two decimals: 3.5 became 3.50 and 12 became 12.00, and 7.25 stayed
as it was.
Write a file scenario
Section titled “Write a file scenario”-
Point the manifest at your file scenarios. List them under
scenarios.files.rehearse.yaml scenarios:files: ['**/*.rehearse.yaml'] -
Name it with what it tries, in plain words. Its id is its path:
packages/report/weekly.rehearse.yaml. -
Give it an input, or none:
Input Is file: stock.jsona file beside the scenario. Its contents are part of the scenario’s definition. command: node make-input.mjs {{input}}a command that writes {{input}}, a file in a scratch folder (namedinput, orname:) -
Give it the command to run. It runs in the checkout (or in
cwd, relative to the checkout), and writes into{{output}}, a scratch folder of its own. -
Say what it writes, and how to read it:
output: { file: weekly.csv, layout: csv }.fileis relative to{{output}}. A command that always writes to the same place can name any absolute path instead, such as'{{checkout}}/out/report.csv'. -
Run it by its path, which is its id.
Terminal $ rehearse run packages/report/weekly.rehearse.yaml✓ The weekly stock report lists every item with its price (packages/report/weekly.rehearse.yaml)on …/shop at dc928d1a5199 · world stocked · as ownerexit 0 · weekly.csv (csv, 3 rows)
Use placeholders in the command
Section titled “Use placeholders in the command”| Placeholder | Environment | Is |
|---|---|---|
{{input}} |
REHEARSE_INPUT |
the input file |
{{output}} |
REHEARSE_OUTPUT |
the folder to write the output in |
{{here}} |
the scenario file’s folder | |
{{checkout}}, {{manifest}} |
the checkout, and the manifest’s folder | |
{{world}}, {{person}} |
the world and the person it runs as | |
{{token}} |
REHEARSE_TOKEN |
that person’s token |
{{api_url}} |
each running service’s URL, by its name |
env: sets more variables. timeout: is in seconds (default 120).
A file scenario that calls a service names it: services: [api] brings it up first. A file scenario starts from its
world:, else the default world, like any other scenario. If that world adds anything, every service comes up before
it runs.
Tell a failure from a difference
Section titled “Tell a failure from a difference”A file scenario fails when input or run exits with anything but 0, takes longer than its timeout, or an output file
is missing. The log’s last lines are in the failure. Everything else is a difference, not a failure.
Choose a layout
Section titled “Choose a layout”| Layout | Reads | Compared |
|---|---|---|
csv, tsv |
rows, the first one naming the columns (header: false and columns: [...] when it doesn’t) |
the columns, the number of rows, then each cell, grouped by column |
json |
a JSON document | by path, as a call’s body, with ids and times set aside |
lines |
text, line by line | line by line |
fixed |
fixed-width rows: columns: [{ name, start, width }], start counted from 1 |
each cell, grouped by column |
zip |
each entry, by the layout its glob gives in entries |
entry by entry |
A scenario can write more than one file: give output a list. An output that isn’t text (a PNG, a PDF) is compared by
its size and hash.
unordered: true on an output compares its rows (or a JSON output’s arrays) without their order.
Set aside
Section titled “Set aside”A file scenario’s setAside names what never counts as a difference.
setAside: columns: [generated_at, batch_id] # never compared values: ['RUN-[0-9]+'] # set aside wherever they appear keep: [sku] # never set asideA cell is text, so Rehearse sets aside what it finds inside text: UUIDs, ISO date-times, relative times, and the
manifest’s and the scenario’s values. columns are never compared at all. See
what is set aside.
Compare zip outputs
Section titled “Compare zip outputs”A package of files (a handoff, an export, a .docx) is a zip. Compare it entry by entry, each by its own layout.
name: An order renders into its handoff packageinput: file: order.jsonrun: python3 render/render.py {{input}} {{output}}/handoff.zipoutput: file: handoff.zip layout: zip entries: '*.pdf': skip '*.csv': csv '*.json': jsonA comparison names the entry inside the zip that changed.
$ rehearse compare --base main0 as on the base · 1 changed without saying so
changed without saying so: An order renders into its handoff package (render/handoff.rehearse.yaml) handoff.zip!lines.csv column 3 "price": "3.5" → "3.50" (2 places)entries maps a glob to a layout: csv, tsv, json, lines, zip or skip. The first glob that matches an entry
wins; an entry no glob matches is read as lines. A difference names the entry after !.
zip reads an archive inside the archive with the same entries. A Word file is one: read it as zip, and its parts
are compared one by one, with the times inside them set aside. Kurvball’s handoff renderer is compared this way.
output: file: handoff.zip layout: zip entries: '**/*.md': lines '*.json': json '**/*.docx': zip '**/*.pdf': skipAn entry inside an inner archive is named with both, such as handoff.zip!brief.docx!word/document.xml.
See it on the stage
Section titled “See it on the stage”The stage shows a file scenario’s input and its output: a table of rows, a JSON document, or lines, and a zip entry by entry. In Diff, each cell that changed is marked with what it was on the base. See the stage.
Read next
Section titled “Read next”- Comparing base and head
- Scenario files reference: every field of
*.rehearse.yaml.