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:
node examples/shop-api/server.mjs --variant baseline --port 8080
node examples/shop-api/server.mjs --variant candidate --port 8081baseline 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:
node examples/shop-api/server.mjs --variant baseline --port 8081 --flags duplicate_payments,discount_not_persisted#What is in the directory
| File | Purpose |
|---|---|
server.mjs | The service. The CHANGES table at the top lists every seeded difference. |
openapi.yaml | OpenAPI 3 description; Parity generates 82 single-request scenarios from it. |
parity.yaml | The Parity configuration: three sources, ignore rules, seed 42. |
tests/parity/*.yaml | Five stateful workflows. |
tests/requests.yaml | Two 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.
| Flag | What the candidate does | Found by | Reported as |
|---|---|---|---|
price_as_string | GET /products/{sku} returns price as a string instead of a number | GET /products/{sku} · valid request (OpenAPI) | $.price changed type from number to string |
cancel_returns_200 | DELETE /orders/{id} returns 200 with a body instead of 204 | Cancel an order (workflow), step 2 | Status changed from 204 to 200; body and content-type appeared |
omit_null_phone | Customers without a phone omit phone instead of returning null | Customer without a phone number (workflow) | $.phone is null in the baseline but absent from the candidate |
accept_zero_quantity | POST /orders accepts quantity 0 | POST /orders · items[0].quantity below its minimum (0) (OpenAPI) | Status changed from 422 to 201 |
float_tax | Invoice tax is no longer rounded to cents | Invoice totals (workflow), step 2 | $.tax changed from 27.7 to 27.70008403361345 |
duplicate_payments | POST /payments ignores Idempotency-Key and charges twice | Payment retried with the same idempotency key (workflow), steps 4 and 5 | Retry returns 201 instead of 200; a second payment appears in the list |
discount_not_persisted | POST /orders/{id}/discount answers the same but never saves the discount | Order lifecycle with discount (workflow), step 4 | $.discount changed to null; $.total changed |
product_currency | Products gain a currency field (intended) | The GET /products scenarios and Books, first two | $.items[*].currency was added |
random_ids | Identifiers 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:
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.#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 inconclusiveFourteen scenarios changed because several scenarios observe the same seeded difference (five GET /products variations all see the new currency field, for example).