Skip to main content

Contract testing and CI gates

Apiome sorts every change between two versions of an API as breaking, non-breaking or docs-only. That one sorting drives every gate on this page: a pull-request check that fails on a breaking change, the changelog written at each publish, the webhook sent with it, a warning before a breaking change ships without a major version, and checks that a live deployment still matches what it publishes.

When to use it​

  • A pull request must not break a published API. Run apiome diff or the GitHub Action in CI, so the build fails before a removed path or a newly required field is merged.
  • Consumers need to know what changed. Every publish writes a classified changelog that shows in the dashboard and on the browse app, and is sent to your webhooks.
  • A breaking change needs a major version. The breaking-publish guardrail warns about, or blocks, a breaking change published as 1.4.1 instead of 2.0.0.
  • The deployment drifts from the spec. Provider verification calls the live API and reports every response that does not match the published version.
  • A deployment must not break a consumer. pact-broker can-i-deploy asks whether a version is compatible with what runs in the environment, from recorded Pact results.

What counts as breaking​

A change is breaking when an existing client of the older version can fail against the newer one: a removed path, operation or property, a narrowed type, a new required field or parameter, a removed enum value, or tighter authentication. Adding an optional field or a new operation is non-breaking. A changed description, summary or example is docs-only, and never fails a gate.

Avro, JSON Schema, Protobuf and AsyncAPI changes are graded by their own formats' rules, under a compatibility mode. See Breaking changes across formats.

Gate a pull request​

Compare the OpenAPI file in a branch with a published version, and fail the build when it breaks it:

apiome diff openapi.yaml --against payments-api@latest --fail-on breaking

The exit code is 0 when the gate passes, 1 when it fails, and 2 when the check could not run (a bad key, the network, a file that does not parse). --format md prints the changelog as Markdown, ready for a pull-request comment.

WhereUseDetails
GitHubapiome/diff-action, with a sticky pull-request commentCI contract gate on GitHub, diff-action
GitLab, Bitbucket and other CIThe container imageCI contract gate on GitLab and Bitbucket
Any shellapiome diffapiome diff
Two versions already in Apiomeapiome versions compatibilityVersion compatibility gate in CI

Give the pipeline a key with the CI: classified diff preset (diff:read) and nothing else — see Scopes.

See what changed at each publish​

When you publish a version, Apiome compares it with the previous published version and writes its classified changelog.

  • In the dashboard: the Changes tab on Versions lists every published version with a pill for its worst change — Breaking, Non-breaking or Docs-only — and its changelog. See Changes.
  • On the browse app: a published version's Changes tab shows the same changelog, and the project offers it as an RSS and a JSON feed.
  • In a webhook: the version.published event carries the changelog, with its counts and worst change, to every push-webhook subscription.
The Changes tab: published versions on the left, the selected version's classified changelog on the rightThe Changes tab: published versions on the left, the selected version's classified changelog on the right
Route/ade/dashboard/versions

Stop a breaking publish without a major version​

The breaking-publish guardrail checks a publish before it happens: does this version break the previous published one without bumping the major version? Its level is a style-guide setting:

LevelWhat happens
offThe guardrail does not run.
warn (default)The Publish dialog warns and lists the breaking changes; the publish goes ahead.
blockThe publish is refused unless it is force-published with a reason.

A version label that is not semver gets a warning but is never blocked. Set the level with Breaking-change publishes on a guide's Policy tab (breakingPublishPolicy on the style-guide policy over the REST API).

Check a live deployment (v2)​

These checks go past the spec to the people and services that use it. They are available over the REST API and the CLI, and a project's Consumers page registers consumers and imports Pact files.

You want to…UseDetails
Record what each consumer uses, or import its Pact fileConsumer contractsConsumer contracts API
Know whose build a change breaks ("breaks billing-service")apiome diff --consumersapiome diff
Call a live deployment and report every response that does not match the specProvider verification, apiome verify contractapiome verify, Contract assurance API
Re-check a deployment on a schedule, and hear when it drifts or recoversVerification schedules, with verification.drift.detected and verification.drift.resolved webhooksContract assurance API
Run an Arazzo workflow's steps, in order, against a deployment or a mockapiome arazzo runRun a workflow against a target
Ask "can I promote this version?" in one callThe deploy gateDeploy gate API

Provider verification and Arazzo workflow runs send only GET, HEAD and OPTIONS requests unless the target allows changes, the run asks for them, and a fixture names the operation.

The deploy gate combines the lint grade, the breaking-change status, broken consumers, how recently the deployment was verified and the version's maturity level, and the Pact can-i-deploy verdict for the pacticipant bound to the project. It always answers 200 with the verdict in the body, so a pipeline can tell a failing gate from a network error. A signal that nothing has produced yet is reported as not_configured and left out of the verdict.

The same contract verdict can also stop a publish: under the block policy a version whose contracts fail is refused unless it is force-published with a reason. See Block a publish on failing contracts.

Security probes check that a deployment enforces what its contract says about authentication. They send requests a normal client would not, so a verification target needs your written consent before a probe may run against it. Consent and probe reports are available over the REST API now; there is no screen for them yet, and the probe run itself (apiome verify probe) is still to come.

  1. Grant consent. POST /v1/tenants/{tenant}/verification-targets/{target}/probe-consent with:
    • ownership_declared: true — you own the target or are allowed to test it;
    • expires_at — when the consent ends (required, with a timezone);
    • profiles_allowed — any of passive, safe-active and payload;
    • optionally identity_a and identity_b — the test accounts a probe signs in as, given as a credential reference like a target's auth ({"kind": "env", "scheme": "bearer", "ref": "PROBE_TOKEN_A"}). A pasted token is rejected.
  2. Check it. GET …/probe-consent returns the consent with its status: active, or expired once expires_at has passed.
  3. Revoke it when testing ends: DELETE …/probe-consent. Probes against the target are refused from then on.

A target has one consent at a time: granting a new one replaces the old one. Granting and revoking need the verification_evidence:create permission; a production target also needs a tenant administrator signed in (an API key cannot grant it). Every grant, revocation and refused probe run is written to the access audit.

TargetConsent neededStrongest result a probe can report
Environment mock on the Apiome-hosted mock's addressNoObserved — the mock serves the contract, so it cannot prove the real deployment enforces it
Any other targetYes, active and listing the profileExploited in test

Two more rules apply to every run:

  • The payload profile sends hostile payloads, so each run must also carry its own approval flag, even when the consent lists payload.
  • The kill switch. Security probing is off until an operator sets APIOME_SECURITY_PROBE_ENABLED=true. While it is off, every probe against a target other than the hosted mock is refused, whatever consent exists. Each workspace is also limited to APIOME_SECURITY_PROBE_MAX_CONCURRENT_PER_TENANT runs at once (default 2) and APIOME_SECURITY_PROBE_MAX_RUNS_PER_HOUR_PER_TENANT per hour (default 20), the hosted mock included.

Each run leaves a report you cannot edit afterwards: GET /v1/tenants/{tenant}/security-probe-reports lists them newest first, with the target as it was, the profile, the consent, the limits, the strongest result allowed and the number of findings at each level. See the Contract assurance API.

Contract test a GraphQL API​

A contract run works on a GraphQL version too. Apiome turns every root query and mutation field into test cases and calls a GraphQL endpoint with them. Each case passes or fails on what the endpoint answers. It is available over the REST API.

  1. Define a GraphQL target. Create a verification target whose base_url is the GraphQL endpoint itself and whose protocol is graphql. For the hosted mock, that is the mock's /graphql URL:

    curl -X POST "$APIOME/v1/tenants/acme/verification-targets" \
    -H "X-API-Key: $APIOME_API_KEY" -H "Content-Type: application/json" \
    -d '{"slug": "pets-graphql-mock", "name": "Pets GraphQL mock",
    "environment": "mock", "protocol": "graphql",
    "base_url": "https://mock.apiome.dev/acme/pets-graph/1.0.0/graphql"}'
  2. Look at the suite (optional). POST …/contracts/project/pets-graph/1.0.0/suite returns the cases. Each one has protocol: graphql and a graphql block holding the query, its variables and its operationName.

  3. Run it. POST …/contracts/project/pets-graph/1.0.0/run with {"target_ref": "pets-graphql-mock"}. The evidence records protocol: graphql, one result per case, and the exact field that disagreed (for example /pet/name).

Each root field gets…It passes when the endpoint answers…
A call with the arguments the schema declares through @example, then with generated onesNo errors, and data matching the field's type — every selected field present, null only where the schema allows it
A call with a required argument left out, one with an argument of the wrong type, and one that selects a field the type does not haveA non-empty errors array
  • Mutations are held back unless the target allows changes (allow_mutating_methods). Queries always run.
  • Subscriptions are not run. They are listed under unsupported in the suite, with the reason.
  • The protocols must match. A run that names an http target for a GraphQL version is refused with 422 target-protocol-mismatch, and the reverse is refused too.
  • The selection goes three levels of objects deep by default. Change it with options.max_selection_depth (1–8).

Contract test a gRPC API​

A version imported from Protobuf (.proto files, a descriptor set or gRPC reflection) gets a contract suite too. Apiome turns every unary method into test cases and calls a deployment with them, either over the Connect protocol (plain JSON over HTTP, no proxy) or over native gRPC. The cases are the same either way; the target decides how they are sent. It is available over the REST API and apiome verify contract.

  1. Define a target. Create a verification target whose protocol says how to reach the service:

    • connect — each case is a POST of JSON to {base_url}/{package.Service}/{Method}, with Connect-Protocol-Version: 1. Any server built with a Connect library (connect-go, connect-es, connect-kotlin, …) answers it; a grpc-gateway REST mapping does not.
    • grpc — a native gRPC channel to the base_url's host and port: https:// uses TLS, http:// does not. The server must have server reflection turned on, because Apiome reads the server's message types from it to encode each call.
    curl -X POST "$APIOME/v1/tenants/acme/verification-targets" \
    -H "X-API-Key: $APIOME_API_KEY" -H "Content-Type: application/json" \
    -d '{"slug": "grpc-dev", "name": "Orders gRPC (dev)",
    "environment": "development", "protocol": "grpc",
    "base_url": "https://orders.dev.example.com:443"}'
  2. Look at the suite (optional). POST …/contracts/project/orders/1.0.0/suite returns the cases. Each one has protocol: grpc and an rpc block holding the procedure (/acme.orders.v1.Orders/GetOrder), the request message in protobuf JSON (orderId, not order_id) and the status it expects back.

  3. Run it. apiome verify contract --project orders --version 1.0.0 --target grpc-dev. The evidence records the target's protocol (grpc or connect), one result per case, and the exact field that disagreed (for example /items/0/quantity). Add --format sarif --out contract.sarif to upload the failures to code scanning.

Each unary method gets…It passes when the service answers…
A call with a declared example message (when the import recorded one), then generated messages: required fields only, then every fieldStatus ok, and a message that matches the method's output type — every field it sends is declared and has the right type, and every required field is present
A call with a required field left out, one with a field of the wrong JSON type, and one with a field the message does not haveStatus invalid_argument (HTTP 400 over Connect)
  • Only methods marked safe run by default. A method runs against a target that does not allow changes (allow_mutating_methods: false) only when the .proto declares option idempotency_level = NO_SIDE_EFFECTS; on it. Every other method is held back as mutating-method-blocked.
  • Streaming methods are not run. They are listed under unsupported in the suite with the reason unsupported: streaming. A deploy gate reading that evidence reports the verification as partial (warn, reason verification-partial), never as a plain pass.
  • Two negatives need JSON. A wrong-typed field and an unknown field cannot be written in binary protobuf, so a grpc run records them as skipped (rpc-negative-json-only). Use a connect target to run them.
  • The protocols must match. A Protobuf version runs on a grpc or a connect target; an http or graphql target is refused with 422 target-protocol-mismatch.
  • A grpc server without reflection fails every case with rpc-reflection-unavailable; use its Connect endpoint instead.

Upload verification failures to code scanning​

apiome verify contract --format sarif --out contract.sarif writes the run as SARIF 2.1.0: one result per failed case (level error) or case that could not run (level warning), with the rule apiome-contract/<failure code> and the field that disagreed in the message. Each result carries the case id as its fingerprint, so the same failure in the next run updates one alert instead of adding another. The same file is available from GET …/verification-runs/{run_id}/export?format=sarif.

- run: apiome verify contract --project orders --version 1.0.0 --target grpc-dev --format sarif --out contract.sarif
- uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: contract.sarif

Gate a deployment on pacts​

Teams that test with Pact can stop a deployment that would break a consumer or a provider already running in the environment. Ask before deploying:

pact-broker can-i-deploy --pacticipant "Billing Service" --version "$GIT_COMMIT" \
--to-environment production --retry-while-unknown 12 --retry-interval 10

The command exits 1 when a verification failed, or when a result is still missing after the retries, and prints the reason for each. Apiome answers from the pacts consumers published, the results providers published, and the deployments your deploy jobs recorded. See Can I deploy?.

The same verdict is a signal of the project's deploy gate: its contracts signal judges the pacticipant bound to the project and fails the gate when the version is not deployable (see In the deploy gate). It can also stop a version from being published at all: set contracts.publishPolicy in the gate policy to warn (the default) or block, and the Publish dialog shows a Contracts card listing the failing integrations (see Block a publish on failing contracts).

So that a consumer's new expectation does not fail the provider's build the moment it is published, turn on pending pacts (enablePending: true) in the provider's verifier, and work-in-progress pacts (includeWipPactsSince) to verify feature-branch pacts early. See Pending and work-in-progress pacts.

To start the provider's verification build when a pact needs verifying, and to report the result back to the consumer's commit, create contract webhooks: pact-broker create-webhook works unchanged, and a GitHub Actions workflow can be started directly. See Contract webhooks.

One consumer model​

Pact tooling and the registry's consumer contracts describe the same thing. When a consumer publishes a pact to the Pact Broker API, its declared surface in the provider's project is refreshed as the next contract revision, so consumer-aware breaking analysis sees the consumers that publish pacts without a second upload. Interactions that cannot be placed are kept with reason codes, and a provider that is not bound to a project is reported, never ignored.

Broker consumers in the diff and in CI​

apiome diff --consumers and the diff-action (its consumers input, on by default) end the changelog with a Consumer impact section. A consumer that a Pact Broker pacticipant is bound to is labelled with it, so a reviewer sees which pact the verdict rests on:

### `billing-service` — breaking

Pact Broker: pacticipant `billing-service` — surface from a published pact (version 1.4.0, a1b2c3d4e5f6)

A consumer registered by hand has no such line. In the JSON report each verdict gains a broker object (pacticipant, fromPact, consumerVersion, pactSha) and the counts gain consumers_from_broker. The gate threshold is unchanged: it still grades the whole specification.

Consumers on public pages​

A public project's page in Browse, and the portal page of an API product that lists it, show the project's pact badges and how many consumers depend on it.

How the pieces fit​

  • One classifier. The CLI, the GitHub Action, the changelog, the webhook, the guardrail and the deploy gate all use the same rules, so a change graded breaking in CI is graded breaking at publish.
  • Stored once, read everywhere. The changelog is written at publish and read back by the dashboard, the browse app, webhooks and the deploy gate, so they all show the same list of changes.
  • Read-only keys for CI. A contract gate needs only diff:read; it cannot change anything in your workspace.