Skip to content
Rehearsev1.2.0

Affected scenarios

In the shop fixture, a change to the API’s server reaches every scenario, and Rehearse says why for each one.

Terminal
$ rehearse list --affected packages/api/server.mjs
8 of 8 scenarios are reached by 1 file.
No import graph is here (no Ashlar, no affected.graph), so Rehearse took the touched packages and the packages that depend on them. v1 reads workspace links for JavaScript packages only: other languages’ packages count as folders.
call packages/api/items.hurl#The shop says it is up
it is in @shop/api, which the change touches
…
file packages/report/weekly.rehearse.yaml
it is in @shop/report, which depends on @shop/api

A change touches some files. rehearse list --affected lists the scenarios those files reach, each with why, so you run what matters and skip the rest. Name the files, or let git find them.

Terminal
rehearse list --affected src/x.ts src/y.ts # the files you name
rehearse list --since main # the files changed since main
rehearse compare --base main --affected # compare only what the change between base and head reaches

--since <ref> and compare --affected take every file that differs: committed, staged, unstaged and untracked. With --json, each scenario has reachedBy, and the result says how it decided (by: graph or packages) and anything it couldn’t do (said).

Nothing imports a .hurl file or a .flow.yaml. So whatever else Rehearse knows, it starts from where a scenario sits. A touched file reaches a scenario when:

Rule reachedBy says
It is the scenario’s own file its own file changed
It is in the scenario’s package it is in @shop/api, which the change touches
It is in the package of the scenario’s service (its cwd) its service is in …, which the change touches
It matches the scenario’s covers globs it covers <file>

A package is the nearest folder above a file that holds a package.json, pyproject.toml, Cargo.toml or go.mod.

covers names what a scenario tries when its folder doesn’t say it. Put it on a path in the manifest, in a flow (a *.flow.yaml, or a flow module’s default export), or in a file scenario:

rehearse.yaml
scenarios:
calls:
paths: [{ path: 'apps/web/stage/**/*.hurl', covers: ['packages/ui/src/**'] }]
files: [{ path: 'packages/**/*.rehearse.yaml', covers: ['apps/web/features/**'] }]

A file scenario names its own covers beside its name.

report.rehearse.yaml
name: The weekly report lists every item
covers: ['packages/pricing/**']
run: node report.mjs {{output}}/weekly.csv
output: { file: weekly.csv, layout: csv }

An import graph knows which files reach a file through imports. When one is here, Rehearse asks it for the dependents of each touched file, then applies the covering rule to the touched file and to each of its dependents. A call beside a handler that imports the touched file is reached, though nothing imports the call.

The graph is, in order:

  1. the command in affected.graph, when the manifest names one;
  2. Ashlar’s, when the checkout has an ashlar.config.* (ts, mts, js, mjs or json) and Ashlar is installed: node_modules/.bin/ashlar in the checkout, else ashlar on PATH.

Rehearse runs <command> <files…> --json in the checkout and reads what it prints against schema/v1/dependents.schema.json. See Rehearse with Ashlar for the contract.

With a graph, the result names the command that gave it, and each touched file the graph doesn’t hold.

Terminal
8 of 8 scenarios are reached by 2 files (import graph: node ../graph.mjs).
The graph doesn't hold README.md: for it, Rehearse took the package and the packages that depend on it.

A file the graph lists as unknown, or doesn’t list, falls back to packages, for that file only.

Without a graph, or when the graph fails, Rehearse takes the touched packages and every package that depends on them, directly or not. It reads the links between packages from a pnpm workspace (pnpm-workspace.yaml) or npm and yarn workspaces (workspaces in the root package.json), from each package’s dependencies, dev, peer and optional dependencies. A change to the shop’s report script reaches only the report’s scenario.

Terminal
$ rehearse list --affected packages/report/report.mjs
1 of 8 scenarios are reached by 1 file.
No import graph is here (no Ashlar, no affected.graph), so Rehearse took the touched packages and the packages that depend on them. v1 reads workspace links for JavaScript packages only: other languages’ packages count as folders.
file packages/report/weekly.rehearse.yaml
it is in @shop/report, which the change touches

@shop/report depends on @shop/api, so a change in @shop/api reaches the report, and a change in the report reaches only the report.

v1 reads links between JavaScript packages only. A Python, Rust or Go package still counts as a package (its own scenarios are reached), but packages that depend on it aren’t found.

When the graph fails, the result says why and falls back to packages.

Terminal
`node ../missing-graph.mjs` failed (exit 1: …), so Rehearse took the touched packages and the packages that depend on them.

A touched file in no package (a lockfile, rehearse.yaml, a root config, a script at the root) can change anything. It reaches every scenario.

Terminal
$ rehearse list --affected seed.mjs
8 of 8 scenarios are reached by 1 file.
…
call packages/api/items.hurl#The shop says it is up
seed.mjs is outside every package, so it reaches every scenario

A file in the root package, beside the root package.json, counts as outside every package. With an import graph that holds the file, the graph says what it reaches instead: in a repository that is one package, every file is outside every package, and the graph is what keeps a change from reaching everything.

A scenario read beside the manifest (a path starting with ./) sits in no package of the product. Without covers, Rehearse can’t tell what it tries, so every change reaches it, with it is read beside the manifest and says nothing of what it covers. Give it covers to narrow it.