Skip to content
Rehearsev1.2.0

Use Rehearse at a gate

The following script gates a change on its comparison, and exits 1 when the change slipped or broke something.

gate.sh
set -u
out=$(mktemp)
rehearse compare --base main --json > "$out"
rehearse down --all
jq -r '.line' "$out"
jq -r '.scenarios[]
| select(.verdict == "unsaid" or (.verdict == "fails" and (.failsOnBase | not)))
| "\(.verdict)\t\(.scenario.id)"' "$out"
jq -e '.base.ok and .head.ok and .counts.notRun == 0
and ([.scenarios[] | select(.verdict == "unsaid" or (.verdict == "fails" and (.failsOnBase | not)))] | length == 0)' \
"$out" > /dev/null

Run on a change to the shop, it prints the comparison’s line and each scenario that sends the change back.

Terminal
$ bash gate.sh; echo "exit $?"
7 base observations read from the cache (c68f00d9431f).
Nothing Rehearse brought up is running.
2 as on the base · 1 new · 2 changed and said so (2 edited) · 2 changed without saying so · 1 fails on the head · 1 gone
unsaid packages/api/items.hurl#The owner sees every item
fails packages/api/items.hurl#The count is right
unsaid packages/report/weekly.rehearse.yaml
exit 1

A gate asks one question of a change: does it do only what it says? rehearse compare answers with an exit code for the machine, a line for the person, and JSON for whatever decides. Other tools read Rehearse only through its JSON commands.

  1. Make the base reachable. The base is a git ref, checked out as a worktree, so the clone needs it: fetch main (or clone with full history) before comparing.

  2. Give the base its dependencies. A fresh worktree has no node_modules. Set prepare in rehearse.yaml, such as pnpm install --frozen-lockfile --offline. It runs once per base commit.

  3. Compare, as JSON. rehearse compare --base main --json. Add --announce <file> if the change keeps its announcement in the repository. Write the JSON outside the checkout: an untracked file makes the head dirty, and a dirty head is never cached.

  4. Stop what was started. rehearse down --all at the end, whatever happened. A comparison stops its own services, and Ctrl-C does too; this catches anything left from an earlier step.

Exit Means
0 ok: both sides came up, every scenario ran, nothing fails on the head, nothing changed without saying so
1 Not ok, or Rehearse couldn’t do what was asked (the JSON says which)
2 A usage mistake: an unknown flag, a missing value

A refusal prints one object with ok: false and an error.

Terminal
{
"v": 1,
"ok": false,
"error": {
"code": "usage",
"says": "rehearse compare takes no `--bogus`. It takes --base, --head, --announce, --said, --world, --as, --real, --manifest, --affected, --fresh, --json, --help."
}
}

ok in a comparison is exactly the following condition.

The ok condition
base.ok and head.ok and counts.notRun == 0 and counts.fails == 0 and counts.unsaid == 0
Verdict or part What a gate does
unsaid, changed without saying so Send it back: fix the slip, or announce it if it was meant
fails, with failsOnBase: false Send it back: the change broke it
fails, with failsOnBase: true Not the change’s doing: it failed on the base too. Don’t block on it; track it apart
new Let it through; a reviewer checks it tries the right thing. A new scenario that fails is fails
said, changed and said so Let it through; a reviewer reads the differences against the why
same Nothing
gone Ask whether it was meant: a scenario was deleted or renamed
notRun Infrastructure, not the change: its service, world or sign-in broke. Run again, or fix the manifest
base.ok: false The base didn’t come up: no verdicts at all. Fix the base or the manifest, then run again

When the base doesn’t come up, the comparison says where, once.

comparison.json
{
"ok": false,
"base": { "ok": false, "step": "checkout", "says": "nope isn't a commit Rehearse can find in …/shop." },
"line": "The base didn't come up (checkout): nope isn't a commit Rehearse can find in …/shop."
}

What to send back to the author (a person or an agent), in order:

  1. line: the whole picture in one sentence.
  2. Each unsaid and each fails that isn’t failsOnBase, with its differences or failures.
  3. byChange: the unannounced changes grouped by path. One cause often shows in many scenarios.
  4. announcedUnchanged: what the change said it would change and didn’t.

With a link to the stage for a scenario (rehearse open <id> --json), the reviewer tries it.

Add --affected to compare only the scenarios the change reaches.

Terminal
rehearse compare --base main --affected --json

--affected compares only the scenarios the files changed between the base and the head reach, through an import graph when there is one, else through packages. It is faster, and it misses nothing the covering rule can see; a scenario that tries something no rule connects to its files is skipped. Run the full comparison before a release, or on a schedule. See affected scenarios.

The base’s observations are cached by commit in .rehearse/cache/. A gate that runs many changes against the same main runs the base once, and says so.

Terminal
7 base observations came from the cache (c68f00d9431f).

To keep that across CI runs, keep .rehearse/cache/ between them (your CI’s cache, keyed by the base commit). A clean head commit is cached too. A head with uncommitted changes, a run where services broke, and a call that didn’t answer are never cached. --fresh ignores the cache. See the cache.

Comparisons are heavy: services, browsers, Vite servers. Rehearse keeps to a budget:

Setting Default Means
budget.services 1 Sets of services up at once. Bringing one up stops another checkout’s.
budget.checkouts 3 Base worktrees kept in .rehearse/checkouts/. Older ones are removed.

A comparison runs the base, then the head, never both at once. On a shared machine, run one comparison at a time. rehearse clean removes base checkouts beyond the budget, and runs and comparisons older than a week; --all also removes every base checkout and the cache.

A gate reads the announcement the change carries. Commit it in the repository (for example announce.yaml at the root, or beside the manifest) and pass --announce. See announcing what a change changes.