liveBook · Manning

Consumer version selector

As explained in Contract Testing in Action

A consumer version selector is a Pact configuration that chooses consumer contract versions according to branch, deployment, release, or other version metadata.

When a provider verifies contracts in CI/CD, it may need the consumer’s main contract, the contract from a matching feature branch, or both. A consumer version selector chooses those contracts using version metadata such as branches, deployments, or releases. section 10.2.2 section 10.3

Common selector properties include:

  • mainBranch: verify the consumer contract published from its main branch. section 10.2.2
  • matchingBranch: verify a consumer contract from the branch matching the provider branch. section 10.2.2
  • deployedOrReleased: select consumer versions associated with deployment or release status. section 10.3

Provider verification configuration

A provider can publish its version and branch, then ask Pact to verify both the consumer’s main branch and the matching branch: providerVersion: process.env.GITHUB_SHA, providerVersionBranch: process.env.GITHUB_BRANCH, consumerVersionSelectors: [{ mainBranch: true }, { matchingBranch: true }]. If both teams work on a feature, they use the same branch name, such as test-pact-features. section 10.2.2

const options = {
  …
  providerVersion: process.env.GITHUB_SHA,
  providerVersionBranch: process.env.GITHUB_BRANCH,
  consumerVersionSelectors: [
    { mainBranch: true },
    { matchingBranch: true },
  ]
  …
}

Inspect the complete provider options snippet showing automated versioning, branch identification, and selector configuration. section 10.2.2

How Contract Testing in Action covers it

How deep it goes
Explains main-branch and matching-branch selection with configuration, while deferring the complete property list to Pact documentation.
Examples
Uses main and matching branches, GitHub commit and branch variables, and the WebConsumer–MoviesAPI verification workflow.
What it assumes
Assumes contract testing and GitHub workflow familiarity while practicing versioning, branching, deployment, release, and deployment-safety configuration.
What you can do after
Operate/configure Pact provider verification to select main, matching, deployed, or released consumer contract versions.
How it connects
Connects consumer version selectors with contract testing, CI/CD pipelines, provider versions, branches, deployments, releases, and can-i-deploy.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Contract Testing in Action. The section links point to the parts of the book it draws on.