Rehearse with Ashlar, or any import graph
Name an import graph in rehearse.yaml, and Rehearse asks it which files depend on what a change touches.
affected: graph: node ../graph.mjsThe graph prints who imports each file, and rehearse list --affected reaches only those.
$ node ../graph.mjs packages/api/server.mjs README.md --json{"v":1,"dependents":{"packages/api/server.mjs":["packages/api/routes.mjs"]},"unknown":["README.md"]}
$ rehearse list --affected packages/api/server.mjs7 of 8 scenarios are reached by 1 file (import graph: node ../graph.mjs). call packages/api/items.hurl#The shop says it is up it is in @shop/api, which the change touches; it is in @shop/api, which the change reaches (packages/api/routes.mjs, which depends on packages/api/server.mjs) …Without an import graph, rehearse list --affected reaches every scenario in a touched package and in every package
that depends on it. That is safe, and often too much. An import graph knows which files actually import the touched
one, so Rehearse can reach less and still miss nothing. Above, the graph says only routes.mjs imports server.mjs,
so the report in another package isn’t reached, where the package fallback reached it.
Ashlar is never required. When it is present, Rehearse uses its graph. Any other tool can print the same contract.
Use Ashlar
Section titled “Use Ashlar”Ashlar is the package @kurvball/ashlar; its command is ashlar. It isn’t on
npm, so install it from its release’s tarball, pinned to a version.
pnpm add -D "@kurvball/ashlar@https://github.com/kurvball/ashlar/releases/download/v1.1.0/kurvball-ashlar-1.1.0.tgz"Then follow Ashlar’s own guide to adopt it: a config, a baseline, and ashlar check in CI. Rehearse uses Ashlar’s graph
when the checkout has both:
- an Ashlar config:
ashlar.config.ts,.mts,.js,.mjsor.json; - Ashlar installed:
node_modules/.bin/ashlarin the checkout, elseashlaronPATH.
It then runs ashlar dependents in the checkout, with the touched files and --json.
ashlar dependents <file>… --jsonNothing to configure. A manifest’s affected.graph wins over Ashlar when both are there.
Rehearse does this on its own code. Its ashlar.config.ts names src, test and scripts, and its two file
scenarios cover the CLI’s entry and list command. A change to the stage’s command reaches only the scenario whose
covered file imports it.
$ rehearse list --affected src/commands/stage.ts1 of 2 scenarios are reached by 1 file (import graph: "…/node_modules/.bin/ashlar" dependents). file scenarios/help.rehearse.yaml it covers src/cli.ts, which depends on src/commands/stage.tsUse any import graph
Section titled “Use any import graph”-
Write a command that prints the dependents contract. Rehearse appends the touched files and
--json, and runs it at the checkout’s root. -
Name it in the manifest. Rehearse runs whatever
affected.graphsays.rehearse.yaml affected:graph: node scripts/dependents.mjs -
Check what it prints against the dependents schema, with
rehearse validate.Terminal $ node ../graph.mjs packages/api/server.mjs README.md --json | rehearse validate dependentsIt meets the dependents schema.
Print the dependents contract
Section titled “Print the dependents contract”schema/v1/dependents.schema.json describes what the command prints.
{ "v": 1, "dependents": { "packages/ui/src/Badge.tsx": ["packages/ui/src/Badge.stories.tsx", "apps/web/src/Header.tsx"] }, "unknown": ["README.md"]}| Rule | Says |
|---|---|
| Every file given | appears either as a key of dependents or in unknown |
| A key’s list | every file that reaches it through imports, directly or not; the file itself left out; [] when nothing does |
unknown |
files the graph doesn’t hold: not source, or outside what it reads |
| Paths | relative to the repository’s root, with forward slashes |
| Output | the command exits 0 and prints this one object on stdout |
v |
the version of Rehearse’s contract, not of the tool |
rehearse validate refuses a list that isn’t a list.
$ echo '{"v":1,"dependents":{"a.ts":"b.ts"}}' | rehearse validate dependents✗ dependents.a.ts should be array.Understand how Rehearse uses the graph
Section titled “Understand how Rehearse uses the graph”For each touched file the graph holds, Rehearse applies the covering rule to the file itself and to every file that reaches it:
| A scenario is reached when | reachedBy says |
|---|---|
| its own file is the touched file | its own file changed |
| its own file reaches the touched file | it depends on <file>, directly or not |
| it is in the package of a file that reaches the touched one | it is in @shop/api, which the change reaches (packages/api/routes.mjs, which depends on packages/api/server.mjs) |
its covers match such a file |
it covers <file>, which depends on <touched file> |
That is why the graph and the covering rule are joined, never one or the other: nothing imports a .hurl file or a
.flow.yaml, so the graph alone would reach no call and no flow. A call beside a handler that imports the touched file
is reached because it sits in the handler’s package.
With a graph, packages that depend on a touched package aren’t walked: the graph says what reaches what.
A file the graph lists in unknown, or doesn’t list at all, gets the package fallback, for that file only, and the
result says so.
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.README.md is outside every package here, so it reaches every scenario. A file the graph holds never reaches every
scenario only for being outside a package: in a repository that is one package, every file is, and the graph says what
each one reaches.
Expect a fallback when the graph fails
Section titled “Expect a fallback when the graph fails”If the command exits with anything but 0, prints something that isn’t JSON, or prints JSON that doesn’t meet the contract, Rehearse doesn’t guess. It takes the touched packages and the packages that depend on them, for every file, and says why.
$ rehearse list --affected packages/report/report.mjs1 of 8 scenarios are reached by 1 file.`node ../missing-graph.mjs` failed (exit 1: } Node.js v26.13.1), 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 touchesWith --json, by is packages, graph is null, and said holds the same words. With a graph that worked, by
is graph and graph is the command.