Repository navigation
Conversation
The model is version agnostic, so it is easy to build an interaction with V4-only matchers (eachKey, arrayContains, statusCode, plugins...) and write it as a V3 pact, or V3 matchers into a V2 one. Older verifiers ignore the rules they don't know, and anything validating against the spec rejects the file. Downgrade where nothing is lost (V2): - equality rules are dropped, unless they sit under a parent rule where dropping them would change what is matched - include becomes an escaped regex - generators are no longer written (was "generators": null) Everything else is checked in write_pact against the JSON that is about to land on disk. By default it logs a warning per violation, naming the rule, its JSON pointer and the spec version it needs. Set PACT_STRICT_SPEC_VERSION=true to fail the write instead. Warn-by-default because pact-js users write fromProviderState generators into V3 pacts today. Plan is to make strict the default in the next major.
This was referenced Nov 27, 2026
YOU54F
added a commit
to pactflow/pact-msw-adapter
that referenced
this pull request
Nov 27, 2026
The FFI writes equality and include into v2 pacts as-is today, so both cases are tracked in ffiSpecLeaks. With the v2 downgrade in pact-foundation/pact-reference#613: - equalityInclude flips: top-level equality is dropped and include becomes a regex. The test will then ask for it to come out of ffiSpecLeaks, and toV2MatchingRules needs to do the same downgrade - equalityUnderParent stays a leak: equality under eachLike has no lossless v2 form, so the FFI keeps it and warns
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pact_modelswill happily write rules a spec version doesn't define:eachKey/eachValue/arrayContains/statusCode/notEmpty/semver/ plugin matchers andMockServerURL/ProviderStategenerators into V3 pacts, and
integeretc. into V2 ones. V2 pacts alsogot
"generators": null. Verifiers on the older spec silently skip therules, so the contract is weaker than the consumer thinks it is, and
schema validation (pactflow/pact-schemas) rejects the files.
Change
matches by equality), unless they sit under a parent rule.
includeiswritten as an escaped regex (
(?s).*<escaped>.*). Generators aren'twritten at all.
spec_version_check::spec_violationswalks theserialised JSON.
write_pactreports each rule or generator the targetversion doesn't define, e.g.
matcher 'eachKey' at /interactions/0/response/matchingRules/body/$.k/matchers/0 requires a V4 pactPACT_STRICT_SPEC_VERSION=truethe write fails and lists everyviolation. Unknown match/generator types are treated as plugins, so they
need V4.
I went with warn-by-default because pact-js users write
fromProviderStateinto V3 pacts today, and failing those writes in aminor would break people. I'd like strict to be the default in the next
major.
Testing
suite passes (641 + doc tests).
libpact_ffi(release) and swapped it intopact-js-core 20.2.0's prebuild folder, then ran the pact-msw-adapter
golden harness (86 cases across V2/V3/V4, validated against
pact-schemas):
downgrades, and the warnings are logged.
PACT_STRICT_SPEC_VERSION=true: exactly the 5 known leak cases fail,each with the violations listed (eachKey, eachValue, arrayContains,
notEmpty, semver, statusCode, a plugin matcher, MockServerURL and
ProviderState into V3; integer into V2).
Follow ups
pactffi_with_strict_spec_version) so pact-js etc.can opt in without an env var.
up in the test rather than at write time. I kept it at write because
FFI interactions keep changing until then.
Related: pactflow/pact-schemas#174 fixes the v4 schema gaps the same harness turned up.