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

The Shop API example

The example service in the repository, every difference seeded into its candidate build, and the scenario that finds each one.

examples/shop-api is a small, dependency-free Node.js service used throughout this documentation, by the end-to-end tests and by the interactive demo. It is demonstration software: one file, state in memory, not something to deploy.

One codebase starts in two behaviours:

bash
node examples/shop-api/server.mjs --variant baseline --port 8080
node examples/shop-api/server.mjs --variant candidate --port 8081

baseline is the reference implementation. candidate is "the next release": the same service with nine seeded differences switched on. Each difference is a flag, so you can also start a baseline with only some of them:

bash
node examples/shop-api/server.mjs --variant baseline --port 8081 --flags duplicate_payments,discount_not_persisted

#What is in the directory

FilePurpose
server.mjsThe service. The CHANGES table at the top lists every seeded difference.
openapi.yamlOpenAPI 3 description; Parity generates 82 single-request scenarios from it.
parity.yamlThe Parity configuration: three sources, ignore rules, seed 42.
tests/parity/*.yamlFive stateful workflows.
tests/requests.yamlTwo manually defined requests.

Follow the Quickstart to run it.

#The seeded differences

Seven are regressions, one is an intentional change, and one is an internal change that should not be reported at all.

FlagWhat the candidate doesFound byReported as
price_as_stringGET /products/{sku} returns price as a string instead of a numberGET /products/{sku} · valid request (OpenAPI)$.price changed type from number to string
cancel_returns_200DELETE /orders/{id} returns 200 with a body instead of 204Cancel an order (workflow), step 2Status changed from 204 to 200; body and content-type appeared
omit_null_phoneCustomers without a phone omit phone instead of returning nullCustomer without a phone number (workflow)$.phone is null in the baseline but absent from the candidate
accept_zero_quantityPOST /orders accepts quantity 0POST /orders · items[0].quantity below its minimum (0) (OpenAPI)Status changed from 422 to 201
float_taxInvoice tax is no longer rounded to centsInvoice totals (workflow), step 2$.tax changed from 27.7 to 27.70008403361345
duplicate_paymentsPOST /payments ignores Idempotency-Key and charges twicePayment retried with the same idempotency key (workflow), steps 4 and 5Retry returns 201 instead of 200; a second payment appears in the list
discount_not_persistedPOST /orders/{id}/discount answers the same but never saves the discountOrder lifecycle with discount (workflow), step 4$.discount changed to null; $.total changed
product_currencyProducts gain a currency field (intended)The GET /products scenarios and Books, first two$.items[*].currency was added
random_idsIdentifiers are random instead of sequential—Not reported

Three of these are worth a closer look.

discount_not_persisted is invisible to single requests. The discount endpoint returns an identical response in both versions. The difference only exists in state, and only a workflow that reads the order back can observe it. This is why Parity warns when a workflow ends on a mutation that is never read back.

product_currency is a real difference that is not a regression. Parity reports what changed; whether a change was intended is a judgement for a person. Locally you would add $..currency to comparison.ignore once the change is accepted, or update the baseline. In the hosted workspace you would classify it as intentional.

random_ids is not reported, for two different reasons. In workflows, IDs captured with extract are correlated: ord_1014 in the baseline and ord_af278cf8fa in the candidate are understood to be the same order. Single requests generated from OpenAPI have nothing to correlate with, so the example's configuration ignores $.id for that source:

yaml
sources:
  - openapi: ./openapi.yaml
    compare:
      ignore: [$.id]
    exclude: ["GET /admin/stats"]
  - workflows: ./tests/parity/
  - requests: ./tests/requests.yaml

#Two endpoints that are noisy on purpose

GET /health returns an uptime counter and GET /recommendations returns items in a random order with random scores — in both variants. Parity reports them as inconclusive, not as changed:

  ? GET /recommendations · valid request
      Every difference also appears between two runs of the baseline, so it cannot be attributed to
      the candidate. Add ignore rules for: $.items[*].score, $.items[*].sku.

See nondeterminism detection.

#The result of a full run

Against freshly started servers:

  89 scenarios  ·  73 unchanged  ·  14 changed  ·  2 inconclusive
  42 differences · 209 requests · 0.0s · seed 42

  ✗ Behaviour changed in 14 of 89 scenarios
    policy: 14 scenarios with behavioural changes → exit 1
    warning: 2 scenarios were inconclusive

Fourteen scenarios changed because several scenarios observe the same seeded difference (five GET /products variations all see the new currency field, for example).

    Loading the index…