Screenshots and approvals
A criterion that is about what a user sees is better shown than asserted. A @shows scene runs in the app’s browser
tests once per language and saves one screenshot each. The owner approves the images, and everything that changes
afterwards (an image, a flow, a criterion, a case, a proving test) shows as “changed, not approved” until the owner
accepts or refuses it.
Settings
Section titled “Settings”grimoire/settings.md (written files) names the languages and
the screenshot mode. Without a languages key the Warlock adapter reads app.localeCodes from src/config/app.ts
without booting the app. An app with no languages has one unnamed language, and its files drop the .<language> part.
| Mode | What runs |
|---|---|
changed | the scenes of the features the change touches (the default) |
all | every scene; use it before a release: GRIMOIRE_SHOTS=all npx warlock e2e |
off | no scene runs and nothing is captured |
GRIMOIRE_SHOTS overrides the setting for one run. In changed mode the touched features are the owners of the files
that differ from the base (committed since the base, staged, unstaged and untracked) plus the features whose
grimoire/features/<id>/ files changed. When git or the book cannot answer, every scene runs: nothing is skipped
silently. A flow whose front matter says screenshots: false is never captured.
Show a criterion
Section titled “Show a criterion”import { defineE2E } from "@warlock.js/core/e2e";import { shows } from "@warlock.js/grimoire/warlock";
export default defineE2E({ app: {/* … */}, run: async (context) => { // @shows contact/send-message AC-3 await shows(context, "contact/send-message AC-3", async ({ page, language, path }) => { await page.mockRequests([{ url: "/api/contact", fail: "unreachable" }]); await page.goto(path("/")); await page.waitFor({ selector: ".warlock-form-status.is-error" }); }); },});The comment is the source of truth, like @proves. It must be on its own line directly above a shows( call whose
second argument is the same <feature>/<flow> AC-<n> (GR4013 otherwise); a flow or criterion that does not exist is
GR4014.
shows(context, ref, scene, options?) runs scene({ page, language, path, step }) once per language:
- it sends the language with every request (the
localeheader, which the app resolves like any request locale) andpath(p)gives the URL path ofpin that language (/ar/aboutunder theprefixlocale routing strategy); - a scene that throws fails that language only; every language still runs, the capture index is written, and then
shows()throws one error naming each failed language, sowarlock e2efails; - after a passing scene it saves the screenshot to
grimoire/screenshots/captured/<feature>/<flow>/<AC-n>.<language>.png(in the project root, never in the disposable copy of the app) and records it incaptured/index.jsonwith its sha256, viewport and time; options.maskis a list of selectors hidden just before the capture, for text that changes on every run;options.viewportsets a viewport first.
A run replaces the entries of the scenes and languages it ran and keeps the others, so a changed run never forgets
the rest. A mocked failure counts as a failed request in the run’s evidence: list the URL under allowNetworkFailures.
Core’s page.mockRequests(rules) answers a matching request with { status, body, headers } or fails it with
{ fail: "unreachable" }; page.clearMocks() stops it (shows() clears the mocks after each language).
page.setExtraHeaders(headers) sends headers with every request.
The approved baseline
Section titled “The approved baseline”grimoire/approved/baseline.json holds the approved flows, criteria, cases, proving tests and images. Until it
exists there is no drift and the Bird view shows “not approved yet” with one “Approve all” action;
warlock grimoire approve --all creates it. It is written only by approve and reject (and the tab’s buttons),
never by an agent.
| Change | Id |
|---|---|
shot-changed | shot-changed:<feature>/<flow>:<AC-n>:<language> |
shot-added, shot-removed | the same, with their type |
flow-added, flow-removed | flow-added:<feature>/<flow> |
criterion-added, criterion-removed, criterion-changed, proof-removed | <type>:<feature>/<flow>:<AC-n> |
case-added, case-removed | <type>:<feature>/<flow>:<case question> |
An image is changed when its size differs, or when more than 0.1% of its pixels differ by more than 16 in any colour
channel. proof-removed is a criterion that no @proves line names any more.
Approve and reject
Section titled “Approve and reject”npx warlock grimoire approve <id> # one changenpx warlock grimoire approve contact/send-message # every change of a flownpx warlock grimoire approve --all # everythingnpx warlock grimoire reject <id> --note "why"In the tab, the buttons call POST /approve and POST /reject with { ids, language?, note? } (ids are change ids,
<feature>/<flow> targets, or "all"; "--all" is read the same). Both routes work only in development and never
through a share link. A failure stays in the open panel with what failed, the status and, for a server failure, a
reference that is also in the dev server’s log.
Approving updates the baseline and copies the capture into grimoire/screenshots/approved/ (or deletes the approved
image of a removed shot) and clears any rejection of the same change. Rejecting records the change and the note; while
the change is still there it stays an error.
| Code | Severity | Meaning |
|---|---|---|
GR4013 | error | a @shows line is not directly above a matching shows() call |
GR4014 | error | a @shows line names a flow or criterion that does not exist |
GR4015 | warning | a shown criterion has no capture in a language (not when the mode is off or the flow opted out) |
GR4016 | error | a shown criterion failed in a language |
GR4017 | warning | a capture differs from the approved image, or has none yet |
GR4018 | warning | a flow, criterion, case or proving test changed since the approval |
GR4019 | error | a change the owner rejected is still there |
An app with no @shows line pays nothing: no scene, no capture and no finding. Images you attach by hand to a
written file () are unrelated and keep working.