Hey, I’ve trying to setup the provider verificatio...
# pact-js
j
Hey, I’ve trying to setup the provider verification flow using Pact JS. I’m passing
PACT_URL
through to
pactUrls
e.g.
Copy code
const getWebhookConfig: () => Partial<VerifierOptions> = () => ({
      ...(process.env.PACT_URL ? { pactUrls: [process.env.PACT_URL] } : {}),
    });
I’m not passing any
consumerVersionSelectors
through to the verifier, but I’m still seeing additional pacts being verified e.g.
Copy code
The pact at /pacts/provider/OrderApi/consumer/OrderWeb/pact-version/a35bc17d448c90799f325b3f25bf79ab5e52a1b7 is being verified because the pact content belongs to the consumer version matching the following criterion:
    * consumer version(s) currently deployed to test (73f8b19456b2deb6d041c4363f583c03156dd469)
and
Copy code
The pact at /pacts/provider/OrderApi/consumer/OrderWeb/pact-version/5acaf2b2f1201889a93d933f4782de68a571533f is being verified because the pact content belongs to the consumer version matching the following criterion:
    * latest version of OrderWeb from the main branch 'main' (18a22a96bed11ce6a612b1f02eb702649de95036)
Is this expected behaviour to still verify pacts from main when I’m only passing
pactUrls
through?
m
What options have you passed in?
I'd you set log level to debug, you should be able to see the request to the
/for-verification
endpoint
j
There are the full options @Matt (pactflow.io / pact-js / pact-go):
Copy code
Pact Verification Options {
      provider: 'OrderApi',
      publishVerificationResult: false,
      providerVersion: 'dev',
      providerVersionBranch: 'main',
      logLevel: 'error',
      providerBaseUrl: '<http://localhost:60905>',
      pactUrls: [
        '<https://contentful.pactflow.io/pacts/provider/OrderApi/consumer/OrderWeb/pact-version/07fac56c66697041bf18268587336c6cdf4ea418/metadata/Y3ZuPWY0NDkyNjgyZWY1NDQ0YWVmYTZmOGY3YmNlOWI0Y2IwZWFiNzBiNDkmdz10cnVl>'
      ]
    }
I see in the logs:
Copy code
[13:02:12.291] DEBUG (24492): pact-core@14.3.3: checking source type of given pactUrl: <https://contentful.pactflow.io/pacts/provider/OrderApi/consumer/OrderWeb/pact-version/07fac56c66697041bf18268587336c6cdf4ea418/metadata/Y3ZuPWY0NDkyNjgyZWY1NDQ0YWVmYTZmOGY3YmNlOWI0Y2IwZWFiNzBiNDkmdz10cnVl>
[13:02:12.292] DEBUG (24492): pact-core@14.3.3: adding <https://contentful.pactflow.io/pacts/provider/OrderApi/consumer/OrderWeb/pact-version/07fac56c66697041bf18268587336c6cdf4ea418/metadata/Y3ZuPWY0NDkyNjgyZWY1NDQ0YWVmYTZmOGY3YmNlOWI0Y2IwZWFiNzBiNDkmdz10cnVl> as a Url source
And also:
Copy code
2024-04-26T11:02:15.632168Z DEBUG ThreadId(02) pact_verifier::pact_broker: final URL = <https://contentful.pactflow.io/pacts/provider/OrderApi/for-verification>
2024-04-26T11:02:15.632233Z DEBUG ThreadId(02) pact_verifier::pact_broker: Sending JSON to <https://contentful.pactflow.io/pacts/provider/OrderApi/for-verification> using POST: {"includePendingStatus":false,"consumerVersionSelectors":[],"providerVersionBranch":"main"}
I ran:
Copy code
$ http '<https://contentful.pactflow.io/pacts/provider/OrderApi/for-verification>' "Authorization: Bearer $PACT_BROKER_TOKEN" includePendingStatus:=false consumerVersionSelectors:=[] providerVersionBranch=main
and this is the response I get back:
Interestingly if I specify
consumerVersionSelectors:='[{"mainBranch": true}]'
, I get back only a single verification
latest from main branch
So it seems like
consumerVersionSelectors
is defaulting to something like
[{"mainBranch": true}, {"deployedOrReleased": true}]
if I pass it as
[]
y
Hmm can you try not passing in the
provider
It seems to the only difference I can gather between my setup here, for splitting our consumer changes (by pact url) and provider changes (by consumer version selectors) • https://github.com/pactflow/example-provider/blob/master/src/product/product.consumerChange.pact.test.jshttps://github.com/pactflow/example-provider/blob/master/src/product/product.providerChange.pact.test.jshttps://github.com/pactflow/example-provider/blob/master/src/product/pact.setup.js
I think the name comes from the pact file, and if the
provider
is set, it is using that, without any consumer version selectors, to grab the pacts for verification by name without any selectors bar the providerVersionBranch (which would be relevant if you had say matchingBranch as a consumer version selector)
j
Yeah that seems to be exactly it, nice one @Yousaf Nabi (pactflow.io)! 🙌
y
nice! i’m sure we could make it easier for users by maybe exposing a consumer change or provider change verification wrapper of sorts that can validate the params and tell you if you are passing in things that you shouldn’t. currently the verifier will let you load it up with multiple sources, and its a bit opaque to the end user. whether this should be in js land or rust land. probably rust so all other languages could leverage
j
Yeah, some sensible defaults (also pulling env vars for branch, tag for common CI systems) would be great, feels like a lot of what we’re writing is boilerplate to implement the recommended verification flows
m
That's a good idea Yousaf. Another idea we've considered is having the broker set the defaults and drive client behaviour. In this case we need to know it's a webhook flow but that's all we need the user to specify. Ideally the rest we can infer