Pact "Verification failed" provider/consumer mismatch in CI
Pact replayed the consumer's expected interactions against the running provider and one or more responses did not match the contract. It reports the mismatched interaction with the expected versus actual body, headers, or status.
What this error means
Provider verification fails with "Verification failed" and a mismatch list showing an expected field or status the provider did not return.
Verifying a pact between web-consumer and user-api
Given a user with id 1 exists
a request for user 1
returns a response which
has status code 200 (OK)
has a matching body (FAILED)
Failures:
1) Verifying a pact ... has a matching body
$.name -> Expected "Ada" but received "Ada Lovelace"Common causes
The provider changed its response shape
The provider now returns a different field, type, or status than the published contract expects, so verification fails.
Missing provider state setup
The "Given" provider state was not set up (data not seeded), so the provider returns a body that does not match the interaction.
How to fix it
Reconcile the provider with the contract
- Read the mismatch: expected versus actual for the named field or status.
- Either fix the provider to honor the contract, or update the consumer test and republish.
- Implement the provider state so the seeded data matches the interaction.
Wire up provider states
Register a state handler that seeds the exact data the "Given" clause names before the interaction is replayed.
stateHandlers.put("a user with id 1 exists",
() -> repository.save(new User(1, "Ada")));How to prevent it
- Run provider verification in CI on every provider change.
- Implement provider states so seeded data matches each interaction.
- Coordinate contract changes with the consumer before merging.