Skip to main content

Choose pacts to verify with selectors

A provider's CI build does not name the pacts it verifies. Its Pact verifier sends consumer-version selectors — "the latest pact from each consumer's main branch", "whatever is tagged prod" — and Apiome answers with the pacts that match and the reason each was chosen. This is the Pact Broker's pacts for verification API, and the Pact verifiers call it unchanged.

This page also covers the latest reads: the latest pact of a consumer from a tag or a branch, and the latest pact of every consumer of a provider.

Environment selectors (deployed, released, environment) select what your deploy jobs record as deployed or released. Each pact can report whether it is pending, and the answer can include work-in-progress pacts no selector chose (see Pending and work-in-progress pacts).

Before you start​

  • Your consumers have published their pacts, with --branch (or tags) on each version.
  • For mainBranch selectors, each consumer has a main branch. The first version a consumer publishes on develop, main or master sets it for you, as on the Pact Broker. For any other branch, set it on the pacticipant with PATCH …/pacticipants/<consumer> and {"main_branch": "trunk"} (see Register a pacticipant). A main branch you set is never replaced. A consumer with no main branch is never selected by mainBranch.
  • The verifier's token is an API key from a member who holds Pacts → View. Every built-in role does.

Verify from CI​

Give the verifier the broker base URL, the token, and your selectors. With pact-js:

await new Verifier({
provider: 'Ledger API',
providerBaseUrl: 'http://localhost:8080',
pactBrokerUrl: 'https://api.apiome.dev/v1/tenants/acme/pact-broker',
pactBrokerToken: process.env.APIOME_API_KEY,
providerVersion: process.env.GIT_COMMIT,
providerVersionBranch: process.env.GIT_BRANCH,
consumerVersionSelectors: [{ mainBranch: true }, { matchingBranch: true }, { deployedOrReleased: true }],
enablePending: true,
}).verifyProvider();

The selectors above are the ones Pact recommends: the latest pact from each consumer's main branch, the pact from a consumer branch named like the provider's branch, and what is in an environment. The other Pact verifiers (pact-jvm, pact-go, pact-python, pact-ruby, pact-net) take the same values under their own option names.

Before it verifies, the verifier prints why each pact was chosen:

The pact at https://api.apiome.dev/v1/tenants/acme/pact-broker/pacts/provider/ledger-api/consumer/billing-service/pact-version/0e3369… is being verified because the pact content belongs to the consumer version matching the following criterion:
* latest version from the main branch 'main' (2f4c1a9)

Build selectors in the app​

On Run a verification (Contracts → Verification), Which pacts to verify writes each selector as a sentence, with the number of pacts it chooses on its own:

RuleSelector
Each consumer's latest pact on its main branch{"mainBranch": true}
Pacts of every consumer version deployed or released anywhere (or to an environment){"deployedOrReleased": true}, with environment
Pacts on a consumer branch named like this one{"matchingBranch": true}
The latest pact on branch …{"branch": "…"}
The latest pact tagged …{"tag": "…", "latest": true}
Pacts of every consumer version currently deployed, or released and supported{"deployed": true}, {"released": true}
Each consumer's latest pact, wherever it was published{"latest": true}

Any rule can be narrowed to one consumer, which adds consumer. Recommended is the first three rules, as in the example above. Everything adds the last one. Custom lets you add and remove rules. Two rules that are the same selector are sent once. The page's The same, from anywhere block prints the same rules as --consumer-version-selector options, for apiome pact verify and for the Pact verifier. See Verify a provider from Apiome.

Selectors​

Each selector is a JSON object. Add consumer to any of them to apply it to one consumer only ({"mainBranch": true, "consumer": "Billing Service"}); the name or the handle works.

SelectorSelects
{"mainBranch": true}The latest version of each consumer from its own main branch.
{"branch": "feat/new-invoice"}The latest version of each consumer from that branch.
{"branch": "feat/x", "fallbackBranch": "main"}As above; a consumer with no pact from feat/x gets its latest from main instead.
{"branch": "feat/x", "fallbackToMainBranch": true}As above, falling back to each consumer's main branch.
{"matchingBranch": true}The latest version from the branch named in the request's providerVersionBranch.
{"tag": "prod"}Every version tagged prod.
{"tag": "prod", "latest": true}The latest version of each consumer tagged prod.
{"tag": "rc", "latest": true, "fallbackTag": "prod"}As above; a consumer with nothing tagged rc gets its latest tagged prod.
{"latest": true}The latest version of each consumer that has a pact with the provider.
{"deployed": true}Every version currently deployed, in any environment and on every application instance. Add "environment": "production" for one environment.
{"released": true}Every version released and still supported. Add environment for one environment.
{"deployedOrReleased": true}Both of the above.
{"environment": "production"}Every version currently deployed or supported in production.
  • Latest means recorded last, not the highest version number.
  • A fallback applies per consumer: one consumer without a pact from the branch gets its fallback even when the others have one.
  • No selectors means the Pact Broker's defaults: for each consumer, its main branch if it has a pact from there, else the latest version tagged with the main branch's name, else its latest version; then whatever is deployed or released.
  • When several selectors choose the same pact content for one consumer, it is verified once. Its notice lists every selector, and it is named after the latest consumer version.

Other fields of the request​

FieldWhat it does
providerVersionBranchThe branch of the provider build that verifies. Needed by matchingBranch, and named in the pending notices.
providerVersionTagsThe tags of the provider build, for setups that use tags instead of branches.
includePendingStatustrue adds pending to each pact and the pending notices. Defaults to false. Pact verifiers send it when pending pacts are enabled.
includeWipPactsSinceA date (2026-01-31). Adds the work-in-progress pacts published on or after it. Needs providerVersionBranch or providerVersionTags.

Selectors that are refused​

A selector that is missing its criteria or combines criteria that contradict each other is refused with 400 pact-selector-invalid. pointer names the selector, and the message is the Pact Broker's:

{
"detail": {
"code": "pact-selector-invalid",
"message": "/consumerVersionSelectors/1: cannot specify both a tag and a branch",
"pointer": "/consumerVersionSelectors/1"
}
}
RefusedWhy
{} or {"consumer": "x"} aloneA selector must say what it selects.
tag with branchA version is chosen by one or the other.
mainBranch with anything but consumermainBranch already names the branch.
mainBranch or branch with "latest": falseA branch selector always means the latest version.
matchingBranch with other criteria, or without providerVersionBranchIt takes its branch from the request.
fallbackTag without tag and "latest": trueA fallback replaces a latest-tagged pact.
fallbackBranch or fallbackToMainBranch without branch, or both togetherA fallback replaces a branch pact.
A branch or tag field with an environment fieldChoose from branches or from environments, not both.
Two of deployed, released, deployedOrReleasedUse deployedOrReleased for either.
A field of the wrong type ("mainBranch": false, "latest": "true")pointer names the field.

What the answer contains​

One entry per pact to verify, under _embedded.pacts:

{
"_embedded": {
"pacts": [
{
"shortDescription": "latest from main branch",
"verificationProperties": {
"pending": true,
"notices": [
{ "when": "before_verification", "text": "The pact at … is being verified because …" },
{ "when": "before_verification", "text": "This pact is in pending state for this version of Ledger API …" }
]
},
"_links": {
"self": {
"href": "https://api.apiome.dev/v1/tenants/acme/pact-broker/pacts/provider/ledger-api/consumer/billing-service/pact-version/0e3369…/metadata/c1tdW2Jd…",
"name": "Pact between Billing Service (2f4c1a9) and Ledger API"
}
}
}
]
},
"_links": { "self": { "href": "…/pacts/provider/ledger-api/for-verification", "title": "Pacts to be verified" } }
}
FieldWhat it is
shortDescriptionWhy the pact was chosen, in a few words. Pact Go names its test after it.
verificationProperties.pendingWith includePendingStatus, and always for a WIP pact. true when a failure of this pact does not fail the build.
verificationProperties.wiptrue for a work-in-progress pact; left out otherwise.
verificationProperties.noticesWhat the verifier prints, and when (before_verification, after_verification:…).
_links.self.hrefThe pact to fetch. The last segment records which selectors chose it, so the verification result can be traced back to the consumer version.

Pending pacts​

A pact is pending until the provider has verified it successfully. A failed verification of a pending pact is reported, but does not fail the provider build, so a consumer can publish a new expectation without breaking the provider's pipeline. A successful verification result from the provider branch takes the pact out of the pending state.

Leave pending off (includePendingStatus not sent) if you want every failure to fail the build. Pending and work-in-progress pacts has the exact rules, two worked examples and the work-in-progress pacts.

Latest pacts without selectors​

To readRequest
The latest pact of a consumer tagged prodGET …/pact-broker/pacts/provider/ledger-api/consumer/billing-service/latest/prod
The latest pact of a consumer from a branchGET …/pact-broker/pacts/provider/ledger-api/consumer/billing-service/branch/main/latest
The latest pact of every consumer of a providerGET …/pact-broker/pacts/provider/ledger-api/latest
The same, from versions tagged prodGET …/pact-broker/pacts/provider/ledger-api/latest/prod
  • The first two answer with the pact itself, like the other pact reads. A branch name with a slash works as it is (branch/feat/new-invoice/latest) or encoded (feat%2Fnew-invoice).
  • The provider-wide reads answer with one pb:pacts link per consumer.
  • No matching version is 404 pact-not-found; an unknown application is 404 pacticipant-not-found.

The index (GET …/pact-broker) links to all of these: pb:provider-pacts-for-verification, pb:latest-provider-pacts and pb:latest-provider-pacts-with-tag. Each pact also carries pb:latest-tagged-pact-version.

Who can do what​

ActionNeedsViewerEditorAdminOwner
Fetch pacts for verification and the latest readspacts:view✓✓✓✓