https://pact.io logo
#pact-net
Title
# pact-net
d

David Hvilava

05/25/2022, 9:05 AM
Hi guys! I'm adopting Pact on my project. Maybe I misunderstood it. Considering Pact.Net v4, shouldn't
IPactUriOptions
provide an ability to publish verification results similar to
IPactBrokerOptions
? Example: a contract is changed and published to PactFlow, then a webhook triggers a provider CI to check the contract, then we need to publish verification results back to PactFlow
a

Akke Luukkonen

05/25/2022, 10:42 AM
Since the recommended way is to use the CLI tools (based on this doc) I would expect that publishing contracts would eventually get removed from the libraries, but that's literally just my own guess. I haven't seen anything mentioned about it here in Slack.
d

David Hvilava

05/25/2022, 10:46 AM
You're right regarding publish a contract itself. But I'm concerned more about publishing a contract verification result by provider. Not sure if it's possible to do via CLI
a

Akke Luukkonen

05/25/2022, 10:49 AM
Ahh, sorry I misread a bit. Technically, it is possible depending on how you do the verifications. I personally run the verification of contracts using the Rust based
pact_verifier_cli
tool in my pipelines to verify the contracts for a provider. But that's a bit different case. But indeed I'm not aware if you could just publish some verification results from a verification run made with the libraries. I doubt that since it probably doesn't produce any files?
d

David Hvilava

05/25/2022, 10:57 AM
Here is an excerpt of my code for provider
The 'else' part works fine. A pact is fetched from PactFlow, verified and the result is sent back. But for case when "PactUrl" is provided the verification result is not sent to PactFlow
m

Matt (pactflow.io / pact-js / pact-go)

05/25/2022, 11:38 AM
That’s a good question. I think it is supported, I’ll search back up the slack threads, I’m sure this has been asked before but I can’t recall the answer
👍 1
a

Adam Rodger (pact-net)

05/25/2022, 5:40 PM
The URI option doesn't support publishing results, no. A pact can come from any URI, so it doesn't make sense to publish verification results. It could be a random repo on GitHub, or a CI artefact from TeamCity or Jenkins. Publishing results might make no sense at all. Results are something you publish to a broker, so you'd use the broker source for that. It would be weird to get the pact from a broker via URI instead of the broker source, but then to also want to publish results back to the broker. It's also weird to grab pacts from somewhere other than the broker but then publish the results of that to a broker.
@David Hvilava take your example above - the URI source is used when you don't have a broker URL. That means you couldn't publish results back anywhere anyway, because you don't have the broker URL for publishing. If you do have the broker URL, then you use the broker source to both get the pact and publish the results, so there's no problem.
d

David Hvilava

05/25/2022, 6:58 PM
Adam, thank you very much for detailed answer! I asked about that following this documentation. "When a pact has changed, a webhook in the Pact Broker will kick off a build of the provider, passing through the URL of the pact that has changed". I understood it in a way that we can provide a link to a changed pact (from some feature branch) in Pact broker to a provider CI that will build 'main' branch and then return verification result back to the Broker. Or if it's not correct then I believe we can pass a branch name via webhook request to a provider CI to use
ConsumerVersionSelector
as for regular pact verification
a

Adam Rodger (pact-net)

05/25/2022, 7:01 PM
Interesting! Yeah I'm not sure I agree with that documentation. It's certainly not how I've ever used it in practice. I just kick off the entire provider run again and verify everything. I'm not sure if the FFI supports publishing verification results with URI sources either. I'll check.
I can't even tell from the FFI code if it's supported or not. You set the publish options but you never pass a broker URL, so how would it know where to publish the results to? In theory you could use that with any source, even a file or directory, if you could pass the broker details through. Since you can't, I can only assume it only works with the broker source so that it has the correct details on where to publish. https://github.com/pact-foundation/pact-reference/blob/e32caf8defd399029dcdf09c5d9298a1fe71d75a/rust/pact_ffi/src/verifier/mod.rs#L260
So yeah, I'd recommend just redoing the entire provider run. Publishing duplicate verification options isn't a problem.
d

David Hvilava

05/25/2022, 7:19 PM
Thanks!
m

Matt (pactflow.io / pact-js / pact-go)

05/26/2022, 1:55 AM
So yeah, I’d recommend just redoing the entire provider run. Publishing duplicate verification options isn’t a problem.
No, that’s not the recommended flow. In step 6 of the CI/CD setup guide, you can verify a specific pact version with the webhook: https://docs.pact.io/pact_nirvana/step_6#add-can-i-deploy-to-consumer-pr-pipeline. This is how you ensure there are no “gaps” in coverage, meaning no surprises for use of
can-i-deploy
I believe this is what David is talking about. You can re-run the verification, but it does mean that the verification options are broad enough to verify the specific pact that was changed which is not always the case.
It’s also weird to grab pacts from somewhere other than the broker but then publish the results of that to a broker.
In this case, the URI is a broker URL. It’s just a path to the contract, not a hypermedia relation to discover the pacts to verify.
I can’t even tell from the FFI code if it’s supported or not. You set the publish options but you never pass a broker URL, so how would it know where to publish the results to?
It should be possible, but I can see why you can’t infer that from the APIs. If the URI is a pact broker URL, it should have the correct relations in it to publish a result In this case, I believe you can set the values of
pactffi_verifier_set_publish_options
. @uglyog is my understanding correct?
d

David Hvilava

05/26/2022, 8:46 AM
Matt, you got me right 👍 More over I have a feeling that this code path (with PactUrl) worked fine in Pact.Net v3. Meaning it sent verification results back to Pact Broker. While exploring Pact framework a year ago in my team we created a POC based on V3. And as I remember it worked back then. So maybe current implementation (v4) works differently
m

Matt (pactflow.io / pact-js / pact-go)

05/26/2022, 8:48 AM
Yeah. Adam has re-written the guts of it to use a new core module written in Rust (much faster, new features, fixes Ruby long path issue etc. etc.). But it’s still new-ish and is not well documented for how to sequence the calls for all of the use cases. So based on the FFI interfaces it’s not obvious this is a thing that can be done
a

Adam Rodger (pact-net)

05/26/2022, 3:54 PM
I'm still not sure from the API that it can be done? The function for setting publish options doesn't have an argument for passing a broker URL. Do the FFI internals magically extract the host if you use the URI source and use it as a broker source? That sounds dangerous to me. There's nothing to validate that the host of a URI source even is a broker, or that it's the correct broker. And what happens if you set the publish options but use a file source? Where would it get the broker URL from? That either doesn't work or at best it's all very opaque, and not something I really want to try and build a sensible API around as it stands today.
@David Hvilava I've raised an enhancement ticket for this, but unfortunately it won't be q quick turnaround because it requires FFI changes: https://github.com/pact-foundation/pact-net/issues/392 I was right that the FFI doesn't support this, for the reasons I said above. You don't know the broker URL, and it's not safe/robust to just assume it's the same as the host from the URI source. @Matt (pactflow.io / pact-js / pact-go) I've started a discussion thread for it on the FFI channel
🙏 1
d

David Hvilava

05/27/2022, 8:22 AM
Thank you, Adam 👍
e

Eugene Baranovsky

07/13/2022, 9:50 AM
d

David Hvilava

07/13/2022, 12:15 PM
Awesome) Thanks!
2 Views