---
name: rehearse
description: Use in a repository with a rehearse.yaml, or when asked to try, compare, prove or check a change before it ships, write piece/flow/call/file scenarios, or drive a running product step by step. Teaches Rehearse's commands, its scenario formats and how to read a comparison's verdicts.
---

# Rehearse

Rehearse sits beside a repository. It brings the product up, signs in as named people, starts from named worlds, runs
scenarios on a base and on the head, and compares them. Every command takes `--json` and prints one object whose
schema is in Rehearse's `schema/v1/`. Read JSON, not the words: the words are for people.

## 1. Look before you change anything

```bash
rehearse check --json      # the manifest reads; how many scenarios of each kind; files it couldn't read
rehearse list --json       # every scenario: id, kind, name, file, area
rehearse services --json   # what can come up
rehearse people --json     # who you can sign in as (people holds tokens: never print or store them)
rehearse worlds --json     # the named starting states
```

A scenario's id is its file, then `#` and its name when the file holds more than one:
`apps/api/members.hurl#A member isn't told the directory exists`, `src/Badge.stories.tsx#Primary`,
`flows/sign-in.flow.yaml`.

## 2. Find what your change reaches

```bash
rehearse list --affected <file>… --json     # or --since main
```

Each scenario comes with `reachedBy`: why the change reaches it.

## 3. Write a scenario beside what it tries

| Kind  | Write                                   | Rehearse compares                                     |
| ----- | --------------------------------------- | ----------------------------------------------------- |
| piece | a CSF story beside the component        | the accessibility tree, logged errors, axe violations |
| flow  | `*.flow.yaml`: steps by accessible name | the tree after each step                              |
| call  | Hurl's plain part, beside the handler   | status, content type, body (ids and times set aside)  |
| file  | `*.rehearse.yaml`: input, run, output   | the output, by column or by line                      |

**A call**, one per thing a person would check, named by the comment above it, sent as a person:

```hurl
# A member isn't told the directory exists
GET {{api}}/v1/organizations/{{organization}}/members
Authorization: Bearer {{member}}
HTTP 404
[Asserts]
jsonpath "$.error.code" == "not_found"
```

`{{api}}` is the calls service's URL; `{{member}}` is that person's token; no `Authorization` means nobody. Only Hurl's
plain part is read: `[Query]`, `[Options]` (retry, retry-interval), `[Captures]`, `[Asserts]` with status, header, body,
duration and jsonpath queries. Anything more is refused by name.

**A flow**: steps by the names a screen reader says.

```yaml
name: The owner adds two things to the basket
service: web # or piece: src/Counter.stories.tsx#Default
person: owner
steps:
  - fill: Search
    with: pens
  - click: Add to basket
    role: button
  - snapshot: Basket
    role: status
```

**A file scenario**:

```yaml
name: The weekly stock report lists every item with its price
input: { file: stock.json }
run: node report.mjs {{input}} {{output}}/weekly.csv
output: { file: weekly.csv, layout: csv }
```

Layouts: csv, tsv, json, lines, fixed (named columns by position), zip (entries by glob: csv, tsv, json, lines, zip,
skip).

**A piece** is a Storybook story. `play` functions are not run; Storybook's hooks (`useArgs`) and `storybook/test` are
answered by shims.

## 4. Run one, then compare

```bash
rehearse run '<id>' --json                        # one observation on this checkout
rehearse compare --base main --json               # every scenario, base against head
rehearse compare --base main --affected --json    # only what the change reaches
```

Read `line`, then each entry of `scenarios`:

| verdict  | Meaning                                                                | What you do                              |
| -------- | ---------------------------------------------------------------------- | ---------------------------------------- |
| `same`   | as on the base                                                         | nothing                                  |
| `said`   | changed and said so (`said`: announced or edited)                      | check `differences` match what you meant |
| `unsaid` | changed without saying so                                              | fix it, or announce it if you meant it   |
| `new`    | not on the base                                                        | check it passes                          |
| `fails`  | fails on the head (`failures`); `failsOnBase` means the base fails too | fix it unless `failsOnBase` is true      |

`byChange` groups unannounced changes by what changed. `notRun` lists scenarios that couldn't run, and `base.ok: false`
means the base didn't come up. The command exits 0 only when nothing fails on the head and nothing changed unsaid.

## 5. Announce what you meant to change

Write `.rehearse/announce.yaml` beside `rehearse.yaml` (or pass `--announce <file>`, or `--said <id>`):

```yaml
changes:
  - scenario: "apps/api/members.hurl#A creator isn't told the directory exists"
    why: A non-administrator now gets 403 instead of the concealed 404.
  - scenario: 'src/Badge.stories.tsx#*'
    why: Badges use the new colour tokens.
```

Editing a scenario's own definition also counts as saying so. Announce only what you changed on purpose.

## 6. Drive the product step by step

```bash
rehearse drive start --json                         # --service, --piece, --world, --as, --scheme dark
rehearse drive snapshot --json                      # the accessibility tree
rehearse drive click --name "Add to basket" --role button --json
rehearse drive fill --name Search --with pens --json
rehearse drive key Enter --json
rehearse drive screenshot shot.png --json
rehearse drive stop --json
```

A result is `{ok, command, ms, file, tree}` or `{ok: false, failure, says}`. On `not_found`, `says` lists the names
close to the one you asked for. Exit 0 done, 1 failed, 2 usage.

## 7. Show a person

```bash
rehearse open '<id>' --json      # the stage's address for it, for a PR or a message
```

## Rules

- Never print, log or commit a token from `rehearse people --json`. Rehearse scrubs them from what it keeps.
- Run one comparison at a time: services, browsers and builds are heavy.
- `rehearse down --all` and `rehearse drive stop` stop what you started.
