Skip to content
Rehearsev1.2.0

Adopt Rehearse in a repository

Adopting Rehearse starts with rehearse init, and the first comparison after it finds every scenario new.

Terminal
$ rehearse init
Wrote …/shop/rehearse.yaml.
Keep the blocks this repository has, then run `rehearse check`.
$ rehearse compare --base main
0 as on the base · 8 new
new:
The shop says it is up (packages/api/items.hurl:4)
The shop names itself (packages/api/items.hurl:8)
The legacy ping answers (packages/api/items.hurl:14)
The owner sees every item (packages/api/items.hurl:18)
A member isn't told the admin page exists (packages/api/items.hurl:25)
The count is right (packages/api/items.hurl:30)
Nobody is let in without a token (packages/api/items.hurl:37)
The weekly stock report lists every item with its price (packages/report/weekly.rehearse.yaml)
Stand-ins: payments (fake, for The payment provider).

Adopting Rehearse means writing down what the repository has, and what it does today. The first comparison finds every scenario new: the base has never heard of them. Once they are merged, every change after is compared against them.

  1. Write a starter manifest. Run rehearse init in the repository’s root, where rehearse.yaml belongs.

    Terminal
    rehearse init

    It writes rehearse.yaml with every block, commented. --force replaces one that is there.

  2. Keep the blocks this repository has. Every block is optional. A component library may keep only scenarios; an API keeps services, signIn, people and worlds. The following manifest keeps the blocks of a small shop: one API, two people and one world.

    rehearse.yaml
    base: main
    services:
    api:
    up: node packages/api/server.mjs --port {{port}}
    port: auto
    ready: http://127.0.0.1:{{port}}/health
    signIn: { command: node people.mjs, service: api }
    people:
    owner: { describe: Runs the shop, default: true }
    member: { describe: A customer with an account }
    worlds:
    stocked:
    add: node seed.mjs {{api_url}}
    default: true
    scenarios:
    calls: ['packages/**/*.hurl']
    files: ['packages/**/*.rehearse.yaml']

    Services, people, worlds and stand-ins explains each block, and the rehearse.yaml reference lists every field.

  3. Check it. rehearse check names each mistake with its line.

    Terminal
    $ rehearse check
    rehearse.yaml:31: The world “emtpy” isn't declared: there is “empty”, “one-org”.
  4. Bring it up once by hand. rehearse up brings the services up and builds the default world; rehearse people says who signed in; rehearse down stops it all.

  5. Keep Rehearse’s state out of git. Add .rehearse/ to .gitignore. It holds base worktrees, the cache, logs and runs.

Write scenarios for what works today, beside what they try: a call beside each handler that matters, a story for each component, a flow for each path a person takes, a file scenario for each report. Start with what a reviewer would check by hand.

  1. Write a few, then rehearse run '<id>' each until it passes on the code as it is.

  2. Compare with the base. Every scenario is new: the base has no such file. New scenarios don’t fail a comparison, so it exits 0.

  3. Commit them, with the manifest, and merge. The base has them now. From the next change on, each scenario is compared, and gets a verdict.

A scenario read beside the manifest (a path starting with ./) is the same file on both sides: the base runs the head’s definition. So today’s behaviour on the base is recorded the day you write it.

rehearse.yaml
scenarios:
calls: ['./rehearse/*.hurl']
files: ['./rehearse/*.rehearse.yaml']

The first comparison then finds every scenario as on the base.

Terminal
$ rehearse compare --base main
8 as on the base
8 ids, times and opaque values were set aside before comparing.
Stand-ins: payments (fake, for The payment provider).

The base has no rehearse.yaml and no scenarios, and it doesn’t need any: the head’s manifest drives both sides. Such scenarios are never new and never edited, so only an announcement says one changed. Move them beside the code later, when you want each side to run its own.

Sometimes the manifest can’t live in the product yet: you are trying Rehearse before proposing it, or a team keeps a mirror. Keep it in its own folder and point it at a checkout.

outside/rehearse.yaml
# The shop's manifest, kept outside the shop. It runs over the clone at ../product.
base: main
checkout: ../product
overlay:
- { from: standin/serve.mjs, to: rehearse/serve.mjs }
services:
api:
up: node rehearse/serve.mjs --port {{port}}
port: auto
ready: http://127.0.0.1:{{port}}/health
signIn: { command: node people.mjs, service: api }
people:
owner: { default: true }
member: {}
worlds:
stocked:
add: node seed.mjs {{api_url}}
default: true
scenarios:
calls: ['./calls/*.hurl']
files: ['./files/*.rehearse.yaml']
Field Does
checkout The checkout to run in, relative to the manifest. The head is that checkout as it is; the base is a worktree of its base.
overlay Files copied into each checkout after prepare, before anything runs: here a stand-in entry point that runs the product’s own server module. from is relative to the manifest, to to the checkout.
./ paths The scenarios, kept beside the manifest, run on both sides.

Run Rehearse from the manifest’s folder, or give --manifest from anywhere else.

Terminal
$ rehearse compare --base main
2 as on the base · 2 changed without saying so · 4 fail on the head
changed without saying so:
The owner sees every item (./calls/items.hurl:18)
$.items[*].price: 3.5 → "3.50" (3 places)
…

The overlay’s files land in the checkout. Rehearse never counts them as a change, so the head stays clean for the cache, but git shows them as untracked. Use overlay for what supports a run (a stand-in server, a piece’s preview module), and ./ paths for scenarios.

The Kurvball example, in examples/kurvball/, runs Rehearse on a real product this way. Its manifest sits outside the product, with checkout: pointing at a scratch clone (.scratch/kurvball). The files Kurvball would commit to adopt Rehearse are kept in adopt/, at the paths they would take, such as its stand-in API and its handoff scenario. prove.sh clones Kurvball from KURVBALL_REPO, a clone you can read, commits adopt/ on the clone’s main (never pushed), makes a head with head.mjs, and compares, with announce.yaml.

Run the proof from Rehearse’s own repository.

Terminal
pnpm build # in Rehearse, once
export KURVBALL_REPO=<url or path> # a clone of Kurvball you can read
examples/kurvball/prove.sh # clones Kurvball, adopts Rehearse, makes a head, compares

When the product adopts Rehearse for real, adopt/ and the manifest are committed in it, and checkout: goes away.