Hi - I'm reading the material on <consumer version...
# pact-broker
a
Hi - I'm reading the material on consumer version selectors (henceforth cvs) and just wanted to check some basic points of understanding that I couldn't glean from the docs... First really basic thing; if I pass an array of cvs via the rawjson property when running verification tests which looks like this:
[ selector_1, selector_2, ..., selector_n ]
where each
selector_i
represents an individual cvs (e.g.
{ "tag": "develop", "latest": true }
) then are these selectors logically OR'd together or AND'd together or is it not as simple as that? My assumption is that its a disjunction (logical OR) but the first example on this page confused me:
Copy code
consumerVersionSelectors: [
    {
      mainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
    },
    {
      deployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
    },
    {
      environment: 'test', // Normally, this would not be needed, as it is recommended to verify the pacts for all currently deployed/currently supported released versions.
    },
    {
      environment: 'production', // Normally, this would not be needed, as it is recommended to verify the pacts for all currently deployed/currently supported released versions.
    },
  ]
where the explanation is that this will target: > • any pacts for the consumer associated with their configured
mainBranch
property > • any pacts for the consumers, deployed to
any
environment > ◦ This if (sic) filtered by only pacts
deployed
or
released
to the
test
/
production
environments. > ◦ If this consumer/provider pair, has an additional environment
staging
, it would not be picked up, due to the named
test
/
production
environments. Removing these conditions, will return any pacts, deployed or released to any environment, which is the recommended setup for the majority of cases. (coupled with enabling pending pacts.) It looks like cvs #1 and #2 are expressing a disjunction (either the pact is associated with the main branch of the consumer or the pact is deployed or support-released) However cvs #3 and #4 then appear to be used as additional mandatory subcriteria on #2 (i.e. not only does the pact have to be deployed, the deployment has to be to either
test
or
production
). This has confused me; if the cvs's are logically OR'd together then the above example seems to be saying return all pacts that are either on main branch, or deployed and released, or deployed to
test
, or deployed to
production
. Under those criteria we would get pacts deployed to
staging
because they would satisfy the 2nd cvs. I was expecting the desired filter to be expressed in pure disjunctive form
Copy code
consumerVersionSelectors: [
    {
      // pacts for consumers configured mainBranch property
      mainBranch: true, 
    },
    {
      // pacts currently released and supported
      released: true
    },
    {
      // pacts currently deployed to test
      deployed: true,
      environment: 'test'
    },
    {
      // pacts currently deployed to production
      deployed: true,
      environment: 'production'
    },
  ]
where the cvs's are logically OR'd together (disjunction) and with each csv, its predicates are logically AND'd together (conjunction).
y
Hey hey, Sorry that example is pretty poor, most would probably have the following, you are correct that
deployedOrReleased
would also include for example staging.
Copy code
consumerVersionSelectors: [
    {
      mainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
    },
    {
      deployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
    }
  ]
if I wanted to qualify just deployedOrReleased to test/prod (excluding any other envs that may exist) I believe I can do
Copy code
consumerVersionSelectors: [
    {
      // pacts for consumers configured mainBranch property
      mainBranch: true, 
    },
    {
      // pacts currently deployedOrReleased to test
      deployedOrReleased: true,
      environment: 'test'
    },
    {
      // pacts currently deployedOrReleased to production
      deployedOrReleased: true,
      environment: 'production'
    },
  ]
from the docs they are deduped, so on the first example you got from the page. the latter two are superfluous, as they would also be picked up by deployedOrReleased which isn’t scoped to any particular env (and therefore would get them all). Happy to remove those from the examples, if they are just confusing and mean you can’t just copy pasta from the page
Copy code
{
      deployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
    },
    {
      environment: 'test', // Normally, this would not be needed, as it is recommended to verify the pacts for all currently deployed/currently supported released versions.
    },
    {
      environment: 'production', // Normally, this would not be needed, as it is recommended to verify the pacts for all currently deployed/currently supported released versions.
    },
a
Thanks @Yousaf Nabi (pactflow.io) - I think TBH that example is currently doing more harm than good there 🙂 as it completely confused me. I think an equivalent example like the one you described above would be useful, and if my assumptions are correct (cvs elements are OR'd together, but attribute value predicates within a cvs are AND'ed together) then it would be super useful to state that uprfront, as I think once that's understood everything else slots nicely into place.
y
I have to check the code in the pact_broker to be able to answer that with certainty. Especially as I assumed it would be AND'd I believe when I wrote this.
- any pacts for the consumers, deployed to
any
environment
- This if filtered by only pacts
deployed
or
released
to the
test
/
production
environments.
- If this consumer/provider pair, has an additional environment
staging
, it would not be picked up, due to the named
test
/
production
environments. Removing these conditions, will return any pacts, deployed or released to any environment, which is the recommended setup for the majority of cases. (coupled with enabling pending pacts.)
Will give it a test and will update the docs. Do you think it is also worth removing the comments from the code snippets? there is an explainer at the top.
// (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
a
Thanks - yes if there's any doubt about what rules the broker is following best to check first, but I think it would be of huge help in the docs to state whatever those rules are clearly in general form before getting to any examples. (and yes I think the comments are best removed if they just repeat what the explainer has already covered, on the DRY principle)
y
okay here is a first pass at pulling out the comments and cleaning up the code examples and the confusing statement/sample https://github.com/pact-foundation/docs.pact.io/pull/333/files
🙌 1
a
Looks good so far!
m
Thanks for raising Alan!