Unit 1: Compare a change
In this unit you write a tiny service and one call to it, then change the service on a branch and compare the branch
with main. By the end, Rehearse tells you the change altered an answer without saying so, then that it said so.
The comparison you reach at the end of the unit reads as follows.
$ rehearse compare --said "greeting.hurl#The greeting says hello"0 as on the base · 1 changed and said so (1 announced)
changed and said so: The greeting says hello (greeting.hurl:2) — announced: Said on the command line. $.text: "Hello" → "Hello, friend"
1 id, time or opaque value was set aside before comparing.1 base observation came from the cache (63e7527b08a5).Before you begin
Section titled “Before you begin”You need Node 22.18 or later and git. Install Rehearse once for your
user, so the rehearse command works in the empty folder this unit starts from.
pnpm add -g https://github.com/kurvball/rehearse/releases/download/v1.2.0/kurvball-rehearse-1.2.0.tgznpm install -g https://github.com/kurvball/rehearse/releases/download/v1.2.0/kurvball-rehearse-1.2.0.tgzyarn global add https://github.com/kurvball/rehearse/releases/download/v1.2.0/kurvball-rehearse-1.2.0.tgzThis unit uses calls only, so it needs no browser. Piece and flow scenarios need Chromium for Playwright.
Write the service and its call
Section titled “Write the service and its call”-
Make a service. In an empty folder, such as
~/hello, writeserver.mjs: a server that answers a health check and a greeting.server.mjs import { createServer } from 'node:http';const port = Number(process.argv[2]);createServer((req, res) => {res.setHeader('content-type', 'application/json');if (req.url === '/health') return res.end(JSON.stringify({ ok: true }));if (req.url === '/greeting')return res.end(JSON.stringify({ text: 'Hello', at: new Date().toISOString() }));res.statusCode = 404;res.end(JSON.stringify({ error: 'not_found' }));}).listen(port, '127.0.0.1'); -
Say what the repository has. Write
rehearse.yaml.{{port}}is a free port Rehearse picks, and the service is ready when the health check answers.rehearse.yaml base: mainservices:api:up: node server.mjs {{port}}port: autoready: http://127.0.0.1:{{port}}/healthscenarios:calls: ['**/*.hurl']In a real repository,
rehearse initwrites a starter with every block, commented. -
Write a call. A call is Hurl’s plain part. The comment above it is its name, and
{{api}}is the service’s address.greeting.hurl # The greeting says helloGET {{api}}/greetingHTTP 200[Asserts]jsonpath "$.text" startsWith "Hello" -
Commit it on
main. The base of a comparison is a commit, and.rehearse/holds Rehearse’s own state, which stays out of git.Terminal printf '.rehearse\n' > .gitignoregit init -b main && git add -A && git commit -m "Hello" -
Run the call. Rehearse brings the service up, sends the call, and takes the service down.
Terminal $ rehearse run "greeting.hurl#The greeting says hello"✓ The greeting says hello (greeting.hurl#The greeting says hello)on ~/hello at 63e7527b08a5GET /greeting as nobody → 200No one signed in, so the call went as nobody. People say who else it can go as.
Check: rehearse run printed a ✓ and exited 0. If it printed ✗ instead, its last lines say which assert failed.
Compare a change with its base
Section titled “Compare a change with its base”-
Make a change. On a branch, warm the greeting up.
Terminal git checkout -b warmersed -i "s/text: 'Hello'/text: 'Hello, friend'/" server.mjsgit commit -am "A warmer greeting" -
Compare it with
main. Rehearse runs the call onmainand on the branch, and compares the two answers.Terminal $ rehearse compare0 as on the base · 1 changed without saying sochanged without saying so:The greeting says hello (greeting.hurl:2)$.text: "Hello" → "Hello, friend"unannounced, by what changed:$.text — in 1 scenario1 id, time or opaque value was set aside before comparing.1 base observation came from the cache (63e7527b08a5).The greeting’s time differs on every run, so Rehearse set it aside. The text changed, the assert still holds, and nothing said it would change: that is a slip. The command exits 1.
-
Say so. Announce the change on the command line, and compare again.
Terminal $ rehearse compare --said "greeting.hurl#The greeting says hello"0 as on the base · 1 changed and said so (1 announced)changed and said so:The greeting says hello (greeting.hurl:2) — announced: Said on the command line.$.text: "Hello" → "Hello, friend"1 id, time or opaque value was set aside before comparing.1 base observation came from the cache (63e7527b08a5).Now it exits 0. The base came from the cache: each base commit runs once.
-
Try it on the stage. The stage shows every scenario on one page.
Terminal rehearse stageOpen the address it prints,
http://127.0.0.1:4400/, choose the greeting, and switch between Base, Head and Diff. Edit the call and send it to either side, then say whether it works. Ctrl-C stops the stage and what it brought up.
Check: the second comparison exited 0 and counted the greeting as changed and said so. Every command also takes
--json and prints one object: rehearse compare --json is what an agent or a gate reads, and its schema is
comparison.
What you built
Section titled “What you built”You have a repository Rehearse can compare: one service, one call, and a branch whose change it caught, then read as announced. To go further, write flows and piece scenarios, or announce a change in a file a pull request carries.