Pre-release. Parity is not publicly available yet: the CLI, the GitHub Action and the hosted workspace open at launch. The demo runs on example data.

Skip to content

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

yaml
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: WELCOME10

Point a source at a file or a directory; directories are searched recursively for .yaml and .yml files.

yaml
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

KeyTypeMeaning
namestring, requiredShown in output and reports.
idstringExplicit scenario id. See ids.
descriptionstringFree text, shown in reports.
tagslist of stringsFor --tag and for grouping.
variablesmapInitial variables. Values may use {{…}}; they are rendered separately for each environment.
serialboolean, default falseRun this workflow alone, before the concurrent ones.
setuplist of stepsRun first; not compared by default.
stepslist of steps, requiredThe workflow itself.
teardownlist of stepsAlways run last, even after a failure; never compared.
compareobjectComparison rules for every step of this workflow.

A file contains either one workflow, as above, or several under a workflows: list.

#Steps

KeyTypeMeaning
idstringUnique within the workflow. Defaults to step-1, step-2, … Used in difference fingerprints, so set it if you care about stable history.
namestringDefaults to METHOD /path.
requeststring or object, requiredGET /path, or the full form below.
extractmapVariables to capture from the response.
expect{ status }The status this step is supposed to produce: one code or a list.
assertlistChecks on the response body.
compareboolean or objectfalse to send without comparing; an object of comparison rules for this step only. Defaults to true in steps, false in setup.

#Requests

yaml
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 }
  • path must start with /; it is appended to each environment's url. Values substituted into a path are percent-encoded.
  • query values may be scalars or lists (a list repeats the parameter); null omits it.
  • body is sent as JSON with Content-Type: application/json. Use body_text instead for a non-JSON body and set the content type in headers.
  • Every request carries Accept: application/json unless you override it, plus the environment's headers, query and auth.

#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:

yaml
body:
  quantity: "{{count}}"          # a number, if count is a number
  note: "ordered {{count}} items" # a string

Variables 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

VariableValue
{{$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:

bash
parity compare --nonce d320cc44

#Extract

extract captures values from a response into variables.

yaml
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 correlate

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

yaml
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?":

BaselineCandidateResult
expectedexpectedCompared as usual.
expectednot expected (or the reverse)A difference.
not expectednot expectedInconclusive (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.

yaml
assert:
  - path: $.status
    equals: cancelled
  - path: $.discount
    exists: true
  - path: $.items
    length: 1

Each 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

yaml
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}}
  • setup steps run first and are not compared. If one fails with a status of 400 or above that it did not expect, the scenario is inconclusive and the main steps are skipped.
  • teardown steps run last, also when an earlier step failed or the run was cancelled. They are never compared and their failures are ignored.
  • serial: true runs 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 containsId
One workflow, no idworkflow:<file name without extension>
One workflow with id: fooworkflow: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.

bash
parity compare --filter "workflow:order-*"

#Manual requests

For single requests that are not worth a workflow, list them in a requests file:

yaml
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 }
yaml
sources:
  - requests: ./tests/requests.yaml

Each 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:

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:

yaml
sources:
  - postman: ./collection.postman.json

Every 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, Host and Content-Length headers in the collection are removed, and Postman's auth helpers are not applied. Authentication comes from each environment's auth block.
  • 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.
    Loading the index…