Workflows
Stateful multi-step scenarios in YAML — variables, extraction, expectations, assertions, setup and teardown — plus manual request files and Postman import.
A workflow is a sequence of requests that share state: create something, capture its identifier, use it in the next request, read the result back. Each step is sent to both environments and compared.
Workflows are where most real regressions are found, because the behaviour that matters is usually spread over several calls.
#A complete workflow
name: Order lifecycle with discount
description: Create a customer and an order, apply a discount, then read the order back.
tags: [orders, stateful]
variables:
email: "ada+{{$run}}@example.test"
steps:
- id: create_customer
name: Create a customer
request:
method: POST
path: /customers
body: { name: Ada Lovelace, email: "{{email}}" }
extract:
customer_id: $.id
expect: { status: 201 }
- id: create_order
name: Create an order for that customer
request:
method: POST
path: /orders
body:
customer_id: "{{customer_id}}"
items:
- { sku: BOOK-001, quantity: 1 }
extract:
order_id: $.id
expect: { status: 201 }
- id: apply_discount
name: Apply a discount
request:
method: POST
path: /orders/{{order_id}}/discount
body: { code: WELCOME10 }
expect: { status: 200 }
- id: read_order
name: Retrieve the order
request: GET /orders/{{order_id}}
assert:
- path: $.discount.code
equals: WELCOME10Point a source at a file or a directory; directories are searched recursively for .yaml and .yml files.
sources:
- workflows: ./tests/parity/#Separate contexts
Each environment has its own variable context. When create_order runs, the baseline's response sets order_id in the baseline context and the candidate's response sets order_id in the candidate context. The next step renders /orders/{{order_id}} twice, once from each context.
An identifier generated by one environment is therefore never sent to the other. Nothing in a workflow can read the other side's variables.
The two values are also remembered as a pair, so later responses that echo them are not reported as different; see identifier correlation.
#Why read state back
Matching responses do not prove matching state. In the Shop API example the candidate answers POST /orders/{id}/discount with exactly the same response as the baseline and never saves the discount. Only the GET that follows reveals it.
End every workflow that mutates with a read. Parity warns when one does not:
warning: workflow `Example` ends on a mutation that is never read back. Matching responses do not prove matching state — add a follow-up GET.The report records this per scenario as state_verified.
#Workflow reference
| Key | Type | Meaning |
|---|---|---|
name | string, required | Shown in output and reports. |
id | string | Explicit scenario id. See ids. |
description | string | Free text, shown in reports. |
tags | list of strings | For --tag and for grouping. |
variables | map | Initial variables. Values may use {{…}}; they are rendered separately for each environment. |
serial | boolean, default false | Run this workflow alone, before the concurrent ones. |
setup | list of steps | Run first; not compared by default. |
steps | list of steps, required | The workflow itself. |
teardown | list of steps | Always run last, even after a failure; never compared. |
compare | object | Comparison rules for every step of this workflow. |
A file contains either one workflow, as above, or several under a workflows: list.
#Steps
| Key | Type | Meaning |
|---|---|---|
id | string | Unique within the workflow. Defaults to step-1, step-2, … Used in difference fingerprints, so set it if you care about stable history. |
name | string | Defaults to METHOD /path. |
request | string or object, required | GET /path, or the full form below. |
extract | map | Variables to capture from the response. |
expect | { status } | The status this step is supposed to produce: one code or a list. |
assert | list | Checks on the response body. |
compare | boolean or object | false to send without comparing; an object of comparison rules for this step only. Defaults to true in steps, false in setup. |
#Requests
request:
method: POST # GET (default), POST, PUT, PATCH, DELETE, HEAD, OPTIONS
path: /orders/{{order_id}}/items
query: { expand: [customer, items], limit: 10 }
headers: { Idempotency-Key: "{{key}}" }
body: { sku: BOOK-001, quantity: 2 }pathmust start with/; it is appended to each environment'surl. Values substituted into a path are percent-encoded.queryvalues may be scalars or lists (a list repeats the parameter);nullomits it.bodyis sent as JSON withContent-Type: application/json. Usebody_textinstead for a non-JSON body and set the content type inheaders.- Every request carries
Accept: application/jsonunless you override it, plus the environment'sheaders,queryandauth.
#Variables
{{name}} is replaced with a variable from the current environment's context. Dotted access reaches into objects and arrays: {{customer.address.city}}, {{items.0.sku}}.
A string that is exactly one expression keeps the variable's JSON type; anything else is interpolated as text:
body:
quantity: "{{count}}" # a number, if count is a number
note: "ordered {{count}} items" # a stringVariables come from, in order: the environment's variables in parity.yaml, the workflow's variables, and each step's extract. A variable that nothing defines is an error when the configuration is loaded, before any request is sent:
error: w/x.yaml: scenario `X`: step `step-1` uses `{{order_id}}`, which nothing defines
hint: add `order_id` to the scenario's `variables`, to both environments' `variables`, or `extract` it in an earlier step#Built-in variables
| Variable | Value |
|---|---|
{{$run}} | The run's nonce: eight hexadecimal characters, new for every run. Use it to make values unique per run. |
{{$seed}} | generation.seed. |
{{$now}} | The time the run started, RFC 3339, UTC. The same value for the whole run. |
{{$uuid}} | A UUID. |
{{$unique}} | Ten random alphanumeric characters. |
{{$env.NAME}} | The process environment variable NAME. The scenario is inconclusive if it is not set. |
Built-ins have the same value in both environments, so the two versions always receive the same input. $uuid and $unique are derived from the seed, the run nonce and the step they appear in: different in every run, identical for baseline and candidate.
To reproduce a run exactly, pass its nonce (from run.nonce in the report) back in:
parity compare --nonce d320cc44#Extract
extract captures values from a response into variables.
extract:
order_id: $.id # a JSONPath into the body
location: { header: location } # a response header
code: { status: true } # the status code
etag: { path: $.etag, correlate: false } # capture, but do not correlatePaths use the supported JSONPath subset; the first match is taken.
If a value cannot be extracted from either response (the path is missing or null), the rest of the workflow cannot run meaningfully. The remaining steps are skipped and the scenario is inconclusive with reason extraction_failed — unless a difference was already found, in which case it is changed and the reason says where the workflow stopped.
Extracted values are shown in the report per environment. A variable whose name looks sensitive (token, password, …) is shown as [REDACTED].
#Expect
expect declares the status a step is supposed to produce.
expect: { status: 201 }
expect: { status: [200, 204] }It answers the question "did this step do what the workflow needs?", which is different from "did the two versions agree?":
| Baseline | Candidate | Result |
|---|---|---|
| expected | expected | Compared as usual. |
| expected | not expected (or the reverse) | A difference. |
| not expected | not expected | Inconclusive (expectation_unmet): both versions agreed, but the intended behaviour was never exercised. |
expect also marks a status as intentional. A step that expects 401 is not treated as an authentication failure, one that expects 429 is not treated as rate limiting, and one that expects 503 is not treated as an environment error.
#Assert
assert checks the response body, in each environment independently.
assert:
- path: $.status
equals: cancelled
- path: $.discount
exists: true
- path: $.items
length: 1Each assertion has a path and exactly one of equals (any JSON value), exists (true or false) or length (of an array, string or object).
An assertion that holds in one environment and fails in the other is a difference (assertion_diverged). One that fails in both makes the scenario inconclusive. One that holds in both changes nothing.
Assertions are for facts that comparison alone cannot establish. Two versions that both return an empty list agree with each other; an assertion says that the list was supposed to have one element.
#Setup and teardown
name: Archive a project
serial: true
setup:
- request: POST /__reset
steps:
- id: create
request:
method: POST
path: /projects
body: { name: "Parity {{$run}}" }
extract: { project_id: $.id }
- id: archive
request: POST /projects/{{project_id}}/archive
- id: read
request: GET /projects/{{project_id}}
teardown:
- request: DELETE /projects/{{project_id}}setupsteps run first and are not compared. If one fails with a status of 400 or above that it did notexpect, the scenario is inconclusive and the main steps are skipped.teardownsteps run last, also when an earlier step failed or the run was cancelled. They are never compared and their failures are ignored.serial: trueruns the workflow by itself before any concurrent scenario starts. Use it for workflows that reset or depend on shared state.
Scenarios run concurrently (execution.concurrency, default 8), and both environments receive the same step at the same time. Write workflows so that they do not depend on each other: create what you need, and make created values unique with {{$run}}.
#Scenario ids
| File contains | Id |
|---|---|
One workflow, no id | workflow:<file name without extension> |
One workflow with id: foo | workflow:foo |
Several workflows under workflows: | workflow:<file name>/<slug of the name> |
Ids must be unique across all sources. They are how --filter, history and reviews refer to a scenario, so renaming a file changes the id.
parity compare --filter "workflow:order-*"#Manual requests
For single requests that are not worth a workflow, list them in a requests file:
requests:
- name: Admin statistics
path: /admin/stats
tags: [admin]
expect: { status: 200 }
compare:
body: ignore
- name: Books, first two
path: /products
query: { category: books, limit: 2 }
- name: Search rejects an empty query
method: POST
path: /search
body: { q: "" }
expect: { status: 422 }sources:
- requests: ./tests/requests.yamlEach request accepts name (required), id, description, tags, method (default GET), path, query, headers, body or body_text, compare, expect and assert, with the same meaning as in a workflow step. The id is request:<slug of the id or name>. Built-in variables work; there is nothing to extract into.
Requests can also be written inline in parity.yaml:
sources:
- requests:
- name: Health
path: /health
compare:
ignore: [$.uptime_ms]#Postman import
A Postman Collection (v2.0 or v2.1 export) can be used as a source:
sources:
- postman: ./collection.postman.jsonEvery request in the collection becomes a single-request scenario with the id postman:<folders>/<name>; folder names become tags.
What is translated:
- method, path, query parameters, headers and raw bodies (JSON bodies are parsed; other raw bodies are sent as text);
- path variables (
:id) from the request's URL variables; - collection variables, as scenario variables;
{{$guid}}and{{$randomUUID}}become{{$uuid}}, and{{$isoTimestamp}}becomes{{$now}}.
What is not:
- Scripts and tests are not executed. Pre-request scripts, test scripts and anything they set are ignored.
- Stored authentication is dropped.
Authorization,Cookie,HostandContent-Lengthheaders in the collection are removed, and Postman's auth helpers are not applied. Authentication comes from each environment'sauthblock. - The host is ignored. Only the path is used; the request goes to each environment's
url. - Only raw bodies are imported. Requests with form-data, urlencoded, file or GraphQL bodies are skipped with a warning.
- Requests are not chained. Each one is independent; variables set by one request's scripts are not available to the next. Rewrite chains as workflows.