Skip to content
Rehearsev1.2.0

rehearse.yaml

rehearse.yaml says what a repository has: the branch production runs, its services, people, worlds, stand-ins and scenarios. Every block is optional. A repository declares what it has. The following example declares every block.

rehearse.yaml
version: 1
base: main
prepare: pnpm install --frozen-lockfile --offline
services:
api:
describe: The API, on its in-memory runtime
up: pnpm --filter @acme/api exec tsx test/serve.ts --port {{port}}
port: auto
ready: http://127.0.0.1:{{port}}/health
env: { NODE_ENV: test }
isolate: { env: ACME_STATE_DIR }
app:
up: pnpm drive start --scenario {{world}}
ready: { command: pnpm drive snapshot --json }
down: pnpm drive stop
drive: pnpm drive
signIn:
command: node scripts/people.mjs --api {{api_url}}
service: api
people:
owner: { describe: The organisation's owner, default: true }
member: { describe: A member without administration, real: local }
nobody-in-particular:
real: stand-in
browser: { headers: { Authorization: 'Bearer {{token}}' } }
worlds:
empty: { describe: Nothing but the schema }
one-org:
extends: empty
add: node scripts/seed.mjs one-org --api {{api_url}}
default: true
standins:
ai:
replaces: The model provider
by: test/fixtures/ai-fake.ts
fidelity: fake
services: [api]
env: { AI_PROVIDER: fixture }
real: { env: { AI_PROVIDER: anthropic } }
scenarios:
pieces:
paths: ['packages/ui/src/**/*.stories.tsx']
preview: .storybook/preview.ts
schemes: [light, dark]
flows: ['apps/web/features/*/reach.ts', '**/*.flow.yaml']
calls:
paths: ['apps/api/src/**/*.hurl', { path: ./calls/*.hurl, covers: ['apps/api/src/routes/**'] }]
service: api
files: ['**/*.rehearse.yaml']
defaults: { world: one-org, person: owner }
setAside:
keys: ['^requestId$']
keep: ['$.expiresAt']
budget: { services: 1, checkouts: 3 }

This is schema/v1/samples/manifest.yaml. The schema is schema/v1/manifest.schema.json. rehearse init writes a starter with every block commented. The CLI page says how Rehearse finds the file.

Rehearse checks the file against the schema before it runs anything, then checks what the schema can’t: that every name points at something declared, that worlds don’t extend in a circle, that only one person and one world are the default, and that each setAside rule is a regular expression. It names the first problem with its line:

Terminal
$ rehearse check
rehearse.yaml:5: services.api has no field “readdy”.
Field Type Default What it is
version 1 none The manifest’s version. Only 1 exists.
base string main The branch production runs. compare and stage use it as the base.
checkout path the git repository holding this file The checkout to run in when none is given, relative to this file. For a manifest kept outside the product.
prepare command none Runs once in each fresh base checkout, before anything else: install, build.
overlay list none Files copied into each checkout before a run.
services map none What can come up.
signIn command or map none Prints the people you can sign in as, with their tokens.
people map none Who you can sign in as.
worlds map none Named starting states.
standins map none Fakes for what can’t run locally.
scenarios map none Where the scenarios are, by kind.
defaults map see below What a scenario runs with when it says nothing.
setAside map none More to set aside before comparing, and what never to.
affected map Ashlar, when present How list --affected finds what a change reaches.
budget map 1 set of services, 3 checkouts How much may run at once on this machine.

The following example installs the dependencies of each base checkout.

rehearse.yaml
prepare: pnpm install --frozen-lockfile --offline

prepare runs in a base checkout the first time Rehearse makes it (from a ref, under .rehearse/checkouts/), with up to 30 minutes. Rehearse marks the checkout prepared and doesn’t run it again there. It never runs in a folder you name, nor in your own checkout. When it fails, the comparison says the base didn’t come up, at the step prepare.

The following example copies one file into each checkout.

rehearse.yaml
overlay:
- { from: rehearse/serve.ts, to: apps/api/rehearse/serve.ts }
Field What it is
from A file or folder, relative to this file.
to Where it goes, relative to the checkout.

Rehearse copies each entry into the checkout before up, run and compare run anything, so after prepare. Files it copies there don’t count as a change to the checkout. Use it for a manifest kept outside the product: a stand-in server, a piece’s preview. In a repository that adopts Rehearse, commit those files instead.

The following example declares one service, on a free port, ready when its health check answers.

rehearse.yaml
services:
api:
up: pnpm --filter api serve --port {{port}}
port: auto
ready: http://127.0.0.1:{{port}}/health

A service is what can come up: a server, an app, a daemon. Its name matches [A-Za-z_][A-Za-z0-9_-]*.

Field Type Default What it does
describe string none One line about it.
up command, required Brings it up. It may keep running, or start a daemon and exit 0.
cwd path the checkout Where up, ready, down and drive run, relative to the checkout.
port 1–65535, or auto none The port it listens on. auto picks a free one on 127.0.0.1.
url string http://127.0.0.1:{{port}} when it has a port Where it answers.
ready URL, command, or one of http, command, log see below How Rehearse knows it is ready.
timeout seconds 60 How long to wait until it is ready.
down command end its process group Stops it.
env map of strings, numbers, booleans none Environment variables it gets. Values take placeholders.
isolate { env: NAME } none Gives each copy its own scratch folder, in the variable NAME, so base and head keep apart.
drive command none The service’s own driver, for flows and rehearse drive.

Each line of the following example is one form of ready.

rehearse.yaml
ready: http://127.0.0.1:{{port}}/health # a URL
ready: pnpm drive snapshot --json # a command
ready: { log: 'Listening on' } # a line in its output

A string that starts with http:// or https:// is a URL; any other string is a command. The map form names one of http, command or log.

Kind Ready when
http The URL answers with a status below 500. Redirects aren’t followed.
command The command exits 0. Each try may take up to 15 seconds.
log The service’s output matches this regular expression.
none At once; or, when it has a port, as soon as something listens on that port.

Rehearse asks every 250 ms. When the service exits non-zero first, or isn’t ready within timeout, Rehearse stops it and says what its log last said.

  • up runs in a shell in its own process group, in cwd.
  • It gets PORT (when it has a port), REHEARSE_SCRATCH (its scratch folder under .rehearse/scratch/), the isolate variable, its env, and the env of each stand-in that applies to it.
  • Its output goes to .rehearse/logs/<name>@<hash>.log.
  • To stop it, Rehearse runs down when there is one, then ends its process group (SIGTERM, then SIGKILL after 5 seconds), then removes its scratch folder.
  • A fixed port that something already answers on is refused: stop that, or use port: auto.

The default service is defaults.service, else the service named api, else the first with a URL, else the first. Its URL is {{url}} outside a service’s own commands. Flows open it when they name no service, calls are sent to it when scenarios.calls.service is unset, and rehearse drive start opens it.

The following example declares a service with its own driver.

rehearse.yaml
services:
app:
up: pnpm drive start --scenario {{world}}
ready: { command: pnpm drive snapshot --json }
down: pnpm drive stop
drive: pnpm drive

A service with drive has its own driver, such as pnpm drive. For each step, Rehearse runs <drive> <step> <flags> --json in the service’s folder, with its environment, and reads the last line it prints as a drive result: {ok, command, ms, file, tree}, or {ok: false, command, ms, failure, says}. Steps are click, type, key, snapshot, screenshot and record; fill isn’t passed. A flow through such a driver takes a nameless snapshot after each action. The driver can’t sign in as a person: the result says so. Placeholders in drive aren’t filled.

signIn is a command, or a map with the command and where it runs. The following example is the short form.

rehearse.yaml
signIn: node scripts/people.mjs --api {{api_url}}

The map form also names the service that must be up, and the folder the command runs in.

rehearse.yaml
signIn:
command: node scripts/people.mjs --api {{api_url}}
service: api
cwd: scripts
Field What it is
command Required. Prints the people and their tokens. Runs in the checkout, with up to 30 seconds, placeholders filled.
service The service that must be up for it to run. Runs bring it up; rehearse people asks you to.
cwd Where it runs, relative to the checkout.

The command prints one JSON object on stdout, in the sign-in shape:

Terminal
{
"people": {
"owner": { "token": "local-owner-0001", "role": "owner" },
"member": "local-member-0002"
},
"variables": { "shop": "main-street" }
}
  • Each person is a token, or an object with token and more fields.
  • Each more field becomes a variable <name>_<key>: here owner_role.
  • Each entry of variables becomes a variable as it is.
  • Names that aren’t [A-Za-z_][A-Za-z0-9_-]*, and the reserved names you, nobody and api, are skipped.

When the command fails, Rehearse says so with what it printed on stderr, never on stdout, since that is where the tokens are.

Tokens never leave Rehearse in the clear. Wherever a token of 6 characters or more would appear in an observation, the cache, the stage’s records or a printed line, Rehearse writes {{<name>}} instead. rehearse people --json is the one place that prints them.

The following example declares two people: one signed in by a header, one by steps on the service’s page.

rehearse.yaml
people:
owner:
describe: The organisation's owner
default: true
browser: { headers: { Authorization: 'Bearer {{token}}' } }
clerk:
token: { env: CLERK_TOKEN }
browser:
steps:
- click: Sign in
role: link
- fill: Name
with: the clerk
- click: Sign in
role: button

A person’s name matches [A-Za-z_][A-Za-z0-9_-]* and isn’t you, nobody or api.

Field Type Default What it is
describe string none Who they are.
real local, stand-in, real local How real they are: a sign-in the local services trust, a fake identity, or a real account.
default boolean false Scenarios run as this person when they name no one. Only one person can be the default.
token { command } or { env } none Where their token comes from when signIn doesn’t give one.
browser map none How a browser signs in as them.

token.command runs in the checkout with placeholders filled, and its trimmed stdout is the token. token.env reads the token from that environment variable of the Rehearse process.

How Rehearse’s browser signs in as this person, for flows and rehearse drive. Values take {{token}} (the person’s token) and {{person}} (their name).

Field What it does
headers Sent on every request.
storage Put in localStorage before each page loads.
cookies A list of { name, value, path }, set for the service’s origin.
steps Flow steps run on the service’s own page before the flow opens. Never observed, never kept.

A flow run as a person who has no browser entry runs signed in as no one, and its result says so.

--as <person>, else the scenario’s own person, else defaults.person, else the person marked default. A call’s person is the one its Authorization header names; a call with no Authorization is sent as nobody, whatever the defaults. Pieces run as no one.

The following example declares two worlds, the second built on the first.

rehearse.yaml
worlds:
empty: { describe: No items }
stocked:
describe: Three items in stock
extends: empty
add: node seed.mjs {{api_url}}
default: true

A world is a named starting state. It builds on the world it extends.

Field Type What it is
describe string What the world holds.
extends name The world this one builds on. Worlds can’t extend in a circle.
add command Adds this world on top of the one it extends, once services are up.
before command Adds this world before services come up.
default boolean Scenarios start from this world when they name none. Only one world can be the default.

To build a world, Rehearse takes its chain from the root (empty → stocked). It runs each before in that order, brings the services up, then runs each add in that order. Each command runs in the checkout, with up to 5 minutes; {{world}} is the world being built, the last of the chain.

before runs before any service is up, so {{port}}, {{url}} and {{scratch}} aren’t filled there. Rehearse builds a world this way for rehearse up, for runs and comparisons, for rehearse drive start, and for calls sent from the stage.

  • A world is built only on services Rehearse brings up for it. A service already up keeps the world it was built with, and a run that wants another world refuses to use it: stop it with rehearse down.
  • When any world in the chain has an add, every service comes up for it.
  • A scenario starts from --world, else its own world, else defaults.world, else the world marked default.

@kurvball/rehearse/worlds exports defineWorld and worldMain, to write worlds in TypeScript. The following file writes the worlds empty and stocked.

worlds.ts
import { defineWorld, worldMain } from '@kurvball/rehearse/worlds';
const empty = defineWorld({ name: 'empty', add: async () => {} });
const stocked = defineWorld({
name: 'stocked',
extends: 'empty',
add: async ({ url }) => {
await fetch(`${url}/items`, { method: 'POST', body: '{"name":"Pen"}' });
},
});
await worldMain([empty, stocked]);

The manifest then builds a world by running that file.

rehearse.yaml
worlds:
stocked: { extends: empty, add: 'node worlds.ts stocked --url {{api_url}}' }

worldMain builds the named world’s chain in order. Each add gets { world, url, args, shared }: world is the world being built, the last of the chain, in every add of the chain; url is --url, else $REHEARSE_URL; args holds every other --name value; shared starts empty, and holds whatever a world before this one left in it for the next.

Rehearse sets $REHEARSE_URL to the default service’s URL, once that service is up, for a world’s commands in runs, comparisons, rehearse up, drive start and the stage: every world is built the same way. --url, as above, names the URL outright.

The following example declares a fake payment provider, and how to use the real one instead.

rehearse.yaml
standins:
payments:
replaces: The payment provider
by: packages/api/server.mjs (its fake provider)
services: [api]
env: { PAYMENTS: fake }
real: { env: { PAYMENTS: sandbox } }

A stand-in is a fake for what can’t run locally. Every observation and comparison names the stand-ins it ran with.

Field Type Default What it is
replaces string, required What it stands in for.
by string none What plays it: a file, a package, a command.
fidelity fake, recorded, local fake Written by hand; replays real answers; the real thing, run locally.
services list of service names every service The services it applies to.
env map none Set on those services while the stand-in is used. Values take placeholders.
real { env } none How to use the real dependency instead. Without it, the real one can’t be chosen.

--real <name> on up, run and compare uses real.env in place of env for that stand-in. The service’s entry then shows <name>:real, and the observation marks the stand-in real: true.

The following example says where each kind of scenario lives.

rehearse.yaml
scenarios:
pieces: ['packages/ui/src/**/*.stories.tsx']
flows: ['**/*.flow.yaml']
calls:
paths: ['apps/api/src/**/*.hurl', { path: ./calls/*.hurl, covers: ['apps/api/src/routes/**'] }]
service: api
files: ['**/*.rehearse.yaml']

Each kind (pieces, flows, calls, files) takes a list of paths, or a map with paths and that kind’s settings. Scenario files describes each format.

Each path is a glob, or { path, covers }.

Glob Matches
* Any characters within one folder.
** Any folders, none included.
? One character within one folder.
{a,b} a or b.
[ab] One of the characters; [!ab], none of them.

Rehearse never walks into node_modules, .git, dist, out, build, target, .rehearse, coverage, .turbo, .next, .astro, __pycache__ or .venv.

The ./ rule. A path that starts with ./ or ../ is read beside rehearse.yaml: the same file runs on both sides of a comparison. Such a scenario is never new and never edited; only an announcement says it changed. Its id starts with ./. Any other path is read from each checkout, so each side runs its own definition.

covers. covers lists globs of files whose change reaches these scenarios, for list --affected and compare --affected. A scenario read beside the manifest with no covers is reached by every change.

Setting Default What it does
preview none A Storybook-style preview module (decorators, parameters, global styles), relative to the piece’s package.
styles a .css the package exports, else src/styles.css, else src/index.css A stylesheet every piece loads, relative to the piece’s package.
config vite.config.*, else vitest.config.* The Vite config to use, relative to the piece’s package.
schemes [light] The colour schemes each piece is observed in: light, dark.
compare [tree, errors, violations] What is compared: tree, errors, violations, screenshot.
viewport { width: 1024, height: 768 } The browser’s size, in pixels.
Setting Default What it does
service the default service The service a flow opens when it names none.
Setting Default What it does
service the default service The service whose URL is {{api}}.
variables none More variables every call file can use, as strings.
unordered false Compares arrays in answers without their order.

No settings beyond paths.

The following example sets every default.

rehearse.yaml
defaults: { service: api, world: one-org, person: owner }
Field Default
service The service named api, else the first with a URL, else the first.
world The world marked default, else none.
person The person marked default, else none.

Each must name something the manifest declares.

The following example adds a rule over keys and one over values, and keeps one field.

rehearse.yaml
setAside:
keys: ['^requestId$']
values: ['ord_[0-9]+']
keep: ['$.expiresAt']

Before comparing, Rehearse sets aside what differs on every run and means nothing. setAside adds rules, and names what never to set aside. Observations are kept raw, so a new rule applies to the next comparison without running anything again.

Field What it is
keys Regular expressions over JSON keys. Their values are set aside.
values Regular expressions over values, and over text such as accessibility trees and output lines.
keep JSON paths ($.expiresAt, $.items[*].at) or column names that are never set aside.

What Rehearse sets aside on its own:

Kind What
ids UUIDs and ULIDs anywhere. Under a key named id, ending in Id or _id, starting with correlation, or named requestId or traceId: integers, and strings that look generated (16 characters or more, letters and digits mixed, no spaces). So roleId: "owner" is still compared.
times ISO date-times. Integers over 10⁹ under a key ending in At, _at, Time or _time, or named at, timestamp or ts. In text, relative times: “3 days ago”, “in 5 minutes”, “just now”.
opaque Strings under a key ending in cursor, token, etag or nonce. Base64url strings of 32 characters or more that mix upper case, lower case and digits, so a hex checksum is still compared.
order Array or row order, only where a scenario or the manifest says unordered.
custom What your keys and values rules match.

In text (trees, output lines, cells), only UUIDs, date-times, relative times and your values are set aside. A value set aside reads ‹id›, ‹time›, ‹opaque› or ‹set aside›. Every comparison counts what it set aside, by kind.

The following example names another tool’s graph command.

rehearse.yaml
affected:
graph: npx depgraph dependents
Field What it is
graph A command that prints the dependents of the files appended to it. Default Ashlar’s, when present.

Rehearse appends each changed file, quoted, then --json, and runs the command in the checkout with up to 2 minutes. It must exit 0 and print one object as dependents describes. Otherwise Rehearse falls back to packages and says why.

Without graph, Rehearse uses Ashlar when the checkout has an ashlar.config.ts, .mts, .js, .mjs or .json, and Ashlar is installed in node_modules/.bin or on PATH: it runs ashlar dependents. Neither is required.

The following example sets both limits to their defaults.

rehearse.yaml
budget: { services: 1, checkouts: 3 }
Field Range Default What it is
services 1–4 1 Sets of services up at once, one set per checkout. To make room, Rehearse stops another checkout’s services.
checkouts 1 or more 3 Base checkouts kept under .rehearse/checkouts/. Older ones are removed when Rehearse checks out a ref, and by rehearse clean.

Commands and values in the manifest take placeholders in double braces. A placeholder with no value stays as written, for the command to see.

Placeholder Value Where
{{port}} The service’s port. A service’s up, url, ready, down, env; its stand-ins’ env.
{{url}} In a service’s own fields: its URL. Elsewhere: the default service’s URL, when it is up. Everywhere below, but not in a world’s before.
{{checkout}} The checkout’s folder. Services, worlds, signIn, token.command, calls, file scenarios.
{{manifest}} The folder that holds rehearse.yaml. The same.
{{scratch}} The service’s scratch folder. A service’s fields; its stand-ins’ env.
{{world}} The world being built, or run from. Services, worlds, signIn during a run, calls, file scenarios.
{{person}} The person a scenario runs as. A person’s browser entry; file scenarios.
{{<service>_url}} That service’s URL, once it is up in the checkout. Services that come up after it; worlds, signIn, calls, file scenarios.
{{<service>_port}} That service’s port, once it is up. The same.
{{token}} The person’s token. A person’s browser entry; a flow step’s with; file scenarios.
{{input}}, {{output}}, {{here}} A file scenario’s input file, output folder, and own folder. File scenarios.
{{api}}, {{<person>}} The calls service’s URL; a person’s token. Calls.

prepare, overlay and drive take no placeholders.

YAML reads { … } as a flow mapping. Inside one, an unquoted {{ starts another mapping, and a comma ends the value. Quote such values. In the following example, the first form is refused and the second reads.

rehearse.yaml
# Wrong: rehearse.yaml:3: Unexpected flow-map-start at node end
people:
owner:
browser: { headers: { Authorization: Bearer {{token}} } }
# Right
people:
owner:
browser: { headers: { Authorization: 'Bearer {{token}}' } }

A comma in an unquoted value inside a flow mapping is refused too.

rehearse.yaml
# Wrong: rehearse.yaml:4: services.api.env.world should be string or number or boolean.
services:
api:
up: node a.mjs
env: { GREETING: hello, world }
# Right
services:
api:
up: node a.mjs
env: { GREETING: 'hello, world' }

A value that starts with {{ needs quotes in block style too: up: '{{checkout}}/bin/serve'.