pact-foundation / pact-reference

Reference implementations for the pact specifications
https://pact.io
MIT License
91 stars 46 forks source link

Consumer Version Selector `fallbackBranch` Is Ignored #195

Closed adamrodger closed 3 months ago

adamrodger commented 2 years ago

The fallbackBranch option on consumer version selectors is ignored, even though it's a valid property.

If you run:

pact_verifier_cli \
    -b "https://pactbroker.example.org" \
    --consumer-version-selectors '{"branch":"feat/foo","fallbackBranch":"main"}' \
    -n "My API" \
    -l debug

then the verifier submits the following:

[DEBUG] (1) pact_verifier::pact_broker: Sending JSON to https://pactbroker.example.org/pacts/provider/My%20API/for-verification
using POST: {"providerVersionTags":[],"includePendingStatus":false,"consumerVersionSelectors":[{"branch":"feat/foo"}]}

This then retrieves no pacts if the consumers aren't using the same branch name, and so the provider test fails:

Failures:

1) Failed to load pact - Could not load pacts from the pact broker 'https://pactbroker.example.org'
- NotFound("No pacts were found for this provider")
bethesque commented 2 years ago

This does need to be fixed, but I recommend not using the fallback branch option, and I regret creating it. The reason is that it allows you to make backwards incompatible changes with the master branch. If you use two selectors, branch=master and branch={feature_branch}, the feature branch selector will just select nothing if there is no matching branch, and you'll still get master. If you're on master, then the pacts are deduplicated anyway, so there's no negative side effect.

If you use the fallback option, then you're either verifying the feature pact OR the master pact, and this can allow you to introduce changes that are not backwards compatible with master.