Pact "Verification failed" request/response mismatch in CI
The provider replayed each recorded interaction and one response did not match the consumer's expectation. Pact prints "expected ... but received ..." for the exact field, so the contract, not the network, is the problem.
What this error means
Provider verification ends with "Pact verification failed" and a per-interaction diff listing the mismatched status code, header, or body path with "expected ... but received ...".
Verifying a pact between web-consumer and orders-provider
A request for order 42
returns a response which
has status code 200 (OK)
has a matching body (FAILED)
Failures:
1) Verifying a pact ... has a matching body
$.total -> Expected 19.99 but received 20.0Common causes
The provider response drifted from the contract
A field was renamed, retyped, or its value shape changed on the provider, so the recorded expectation no longer matches what the provider now returns.
An exact value was asserted instead of a matcher
The consumer pinned a literal value (a total, a timestamp) rather than a type matcher, so any differing but valid value fails verification.
How to fix it
Read the diff and align provider or contract
- Open the failing interaction and read the "Expected ... but received ..." line.
- If the provider change is intended, update the consumer expectation and republish the pact.
- If the provider drifted by mistake, fix the provider response to match the contract.
# run the provider verification locally against the same pact
./gradlew pactVerify
# or, for JS
npm run test:pact:providerUse type matchers for volatile values
Assert the shape, not the literal, so valid variation does not break verification.
// consumer test (@pact-foundation/pact)
body: {
total: Matchers.decimal(19.99),
createdAt: Matchers.iso8601DateTime(),
}How to prevent it
- Prefer type matchers over literal values for anything that varies.
- Republish the consumer pact whenever the expectation changes.
- Run provider verification in CI on every provider change.