Use Rehearse at a gate
The following script gates a change on its comparison, and exits 1 when the change slipped or broke something.
set -uout=$(mktemp)rehearse compare --base main --json > "$out"rehearse down --alljq -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/nullRun on a change to the shop, it prints the comparison’s line and each scenario that sends the change back.
$ 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 goneunsaid packages/api/items.hurl#The owner sees every itemfails packages/api/items.hurl#The count is rightunsaid packages/report/weekly.rehearse.yamlexit 1A 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.
Run it
Section titled “Run it”-
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. -
Give the base its dependencies. A fresh worktree has no
node_modules. Setprepareinrehearse.yaml, such aspnpm install --frozen-lockfile --offline. It runs once per base commit. -
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. -
Stop what was started.
rehearse down --allat the end, whatever happened. A comparison stops its own services, and Ctrl-C does too; this catches anything left from an earlier step.
Read the exit code
Section titled “Read the exit code”| 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.
{ "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.
base.ok and head.ok and counts.notRun == 0 and counts.fails == 0 and counts.unsaid == 0Read the comparison as a gate
Section titled “Read the comparison as a gate”| 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.
{ "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:
line: the whole picture in one sentence.- Each
unsaidand eachfailsthat isn’tfailsOnBase, with itsdifferencesorfailures. byChange: the unannounced changes grouped by path. One cause often shows in many scenarios.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.
Compare only what the change reaches
Section titled “Compare only what the change reaches”Add --affected to compare only the scenarios the change reaches.
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.
Keep the cache between runs
Section titled “Keep the cache between runs”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.
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.
Keep to the machine’s budget
Section titled “Keep to the machine’s budget”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.
Read announcements at a gate
Section titled “Read announcements at a gate”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.