Agent Wranglers

Integration and contract tests Required

Check the contract between services

When two services you own talk to each other, test the shape of their messages on both sides with a shared contract.

How to do it

Let the consumer write down the requests it sends and the answers it needs, with a tool such as Pact or a shared schema. Run that contract against the provider in its own build. A provider change that breaks a consumer fails before it ships. Skip this when both sides live in one codebase and always deploy together. To test one API against its OpenAPI file, see test the API against its contract.

Example

// Consumer side, Pact JS
await provider.addInteraction({
  states: [{ description: 'order 1042 exists' }],
  uponReceiving: 'a request for order 1042',
  withRequest: { method: 'GET', path: '/orders/1042' },
  willRespondWith: { status: 200, body: { id: 1042, total: 4200 } },
});
# Consumer side, pact-python 3 or later
pact = Pact("shop-web", "orders-api").with_specification("V4")
(pact.upon_receiving("a request for order 1042")
    .given("order 1042 exists")
    .with_request("GET", "/orders/1042")
    .will_respond_with(200)
    .with_body({"id": 1042, "total": 4200}, content_type="application/json"))

How to check

Remove a field that a consumer uses from the provider's answer. The provider's build fails on the contract test.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers testing playbook: https://agentwranglers.se/playbook/testing/integration-and-contract-tests/contract-tests.