Skip to content
Rehearsev1.2.0

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.

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).

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.

Terminal
pnpm add -g https://github.com/kurvball/rehearse/releases/download/v1.2.0/kurvball-rehearse-1.2.0.tgz

This unit uses calls only, so it needs no browser. Piece and flow scenarios need Chromium for Playwright.

  1. Make a service. In an empty folder, such as ~/hello, write server.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');
  2. 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: main
    services:
    api:
    up: node server.mjs {{port}}
    port: auto
    ready: http://127.0.0.1:{{port}}/health
    scenarios:
    calls: ['**/*.hurl']

    In a real repository, rehearse init writes a starter with every block, commented.

  3. 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 hello
    GET {{api}}/greeting
    HTTP 200
    [Asserts]
    jsonpath "$.text" startsWith "Hello"
  4. 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' > .gitignore
    git init -b main && git add -A && git commit -m "Hello"
  5. 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 63e7527b08a5
    GET /greeting as nobody → 200

    No 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.

  1. Make a change. On a branch, warm the greeting up.

    Terminal
    git checkout -b warmer
    sed -i "s/text: 'Hello'/text: 'Hello, friend'/" server.mjs
    git commit -am "A warmer greeting"
  2. Compare it with main. Rehearse runs the call on main and on the branch, and compares the two answers.

    Terminal
    $ rehearse compare
    0 as on the base · 1 changed without saying so
    changed without saying so:
    The greeting says hello (greeting.hurl:2)
    $.text: "Hello" → "Hello, friend"
    unannounced, by what changed:
    $.text — in 1 scenario
    1 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.

  3. 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.

  4. Try it on the stage. The stage shows every scenario on one page.

    Terminal
    rehearse stage

    Open 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.

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.