Replies: 1 comment
-
|
NOTE: these responses were taken from the above conversation, and copied here by Matt Fellows so as to retain history. The names of the participants have been kept inline Matt Fellows
if you were to remove this constraint, you could create a more “provider driven” workflow. What you could do is:
Joshua Ellis Daniel Willian But this doesn’t fail the test if something is missing, and usually requires extra setup code that's unrelated to the business test itself.
This would keep the test code clean and expressive, while still enforcing strict validation — and would make this workflow feel native to Pact, not bolted on externally Joshua Ellis (haha, messages have crossed) Taking that existing mechanism to its extreme, you could read the pact.json to set up all the interactions, and then run the test suite against the Pact server to ensure all interactions succeed. This may in fact achieve what you want. Daniel Willian Absolutely, I completely agree that the strength of Pact is its consumer-driven model, and I’m not proposing flipping it to be provider-driven.
The reason I’m asking for consumer-side interaction verification is not to force consumers to match the provider’s full API (which would break everything), but to ensure that when both sides have agreed to a set of interactions, the consumer actually exercises all of them — and nothing silently gets left behind. Matt Fellows In practice, having all consumers adhere exactly to the same contract is usually very difficult - it requires all of them to synchronise changes.
Personally, I think the idea of a provider contract (that is shared/authored) and a consumer contract (that tracks the specific differences) might be another approach. The provider contract says “here is all of the APIs and scenarios I support” and the consumers each use a subset of them. This way, the verification is much faster (it just happens once and they get to control that process). The consumer contract is effectively “did you use test scenarios from this contract?“. Daniel Willian I agree. I also think your idea of a provider-authored superset + consumer overlays is compelling — but that would be a much bigger shift, requiring changes to the Pact file format, how verification works, and how can-i-deploy interprets compatibility.
This isn’t about enforcing a provider-driven model — far from it. It’s about giving consumer teams more tooling to enforce the contracts they authored, and keep them clean, the same tools that exist on the provider side. Matt Fellows
This is a very helpful (and pragmatic) clarification, thanks.
Yes, as you say, that’s a problem today anyway. It’s hard to automate your way around it (maybe the consumer is just really stable and doesn’t change?). PactFlow AI aims to help with this because it will (soon) review code and compare against tests to generate recommended fixes (i.e. gaps that need filling, or over specifying). Daniel Willian Yeah, I’m definitely up for giving it a crack, though I’m not sure exactly when 😅 Matt Fellows
totally agree.
I believe this capability might already exist. This function accepts a fully formed Pact JSON and would behave as per the usual mock server rules - any interactions not exercise will fail the test. Also, I propose moving this conversation to a github discussion. I’ll do that today (the reason being is that this slack workspace has a free tier conversation limit, and I don’t want to lose the great work here to the trash can) Daniel Willian Oh, interesting, I wasn’t aware the mock server already fails when interactions aren’t exercised. That’s really helpful to know! From what we observed, the tests would still pass even if we only exercised a subset of the interactions, which led us to believe that unused interactions weren’t being validated. Knowing now that this behavior is enforced by the stub server makes me think we may have missed something in the way we were using it. Matt Fellows I can't speak for JVM I'm afraid. might be able to provide some pointers, but perhaps the distinction between stubs and mocks might help Daniel Willian Hey folks! “Participant A produced a pact, and participant B verified it.” Instead, these contracts would be:
Just to clarify: even though both sides are binding to the same contract, they would continue to publish verification results as usual, reporting that they fulfill a pact file.
Whereas some directions for bi-directional testing are leaning toward OpenAPI-based schema validation, I believe this approach retains the behavioral confidence Pact is known for while enabling better collaboration across teams. "Would this be considered too broad of a change to be supported in the Broker and Pact ecosystem, or is it something that could be explored formally?" Really appreciate all the feedback and openness so far, and I'm happy to contribute more structured thoughts if there's interest in taking this further. Thanks again 🙏 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
NOTE: this proposal was taken from the #feature-requests channel from the Slack workspace to improve visibility.
Author: @DanielWillian
TL;DR:
I’m proposing a way for consumers to verify they exercised all interactions in a shared pact.json, even if they didn’t generate it.
Pact already supports provider verification from a pact file; this would add optional support for consumer-side verification by failing tests if any interactions weren’t used.
It’s a small step toward bi-directional confidence, without compromising the consumer-driven philosophy.
Proposal
Hey all 👋, I have a proposal that I think could complement Pact’s philosophy while supporting teams working in highly collaborative environments.
In some cases, teams may want to mutually agree on a shared pact.json file, hand-written, but collaboratively authored and version-controlled, and use it as a behavioral contract.
This allows both sides to contribute: the consumer knows what it wants, but the provider knows what it can do.
It would be really helpful if Pact supported workflows for teams that want to validate both sides of such a contract, even when the consumer isn’t generating the pact file through tests.
Right now, Pact already fully supports the provider side of this setup, but not the consumer side.
In this verification approach, the consumer would:
The goal is to ensure the consumer really uses what the pact says it does, just like it does with the provider.
I know Pact is consumer-driven and discourages hand-written contracts, mainly because people might rely on the contract instead of verifying their usage through real tests, and I fully agree with that philosophy.
This proposal isn’t about skipping tests, it's about adding strictness to ensure the consumer truly adheres to the shared contract. It's a small step toward bi-directional testing without compromising the core consumer-driven model.
I’m asking because Pact provides the strongest confidence in contract testing available today — thanks to its precise request/response mapping (not just schema validation) and the compatibility matrix enabled by can-i-deploy.
Creating a new tool just to support this small bi-directional need feels like a waste when Pact is already so close to solving it.
Would this be a welcome addition to the tooling, for example, a flag in the mock server or test library that serves only one interaction at a time, to force full coverage?
Or is this too far outside Pact’s intended model?
Beta Was this translation helpful? Give feedback.
All reactions