Skip to content

spike: pact-matchers, matcher templates from msw resolvers - #469

Draft
YOU54F wants to merge 4 commits into
mainfrom
spike/pact-body
Draft

YOU54F wants to merge 4 commits into
mainfrom
spike/pact-body

Conversation

@YOU54F

@YOU54F YOU54F commented Nov 27, 2026

Copy link
Copy Markdown
Member

Spike, not for merging yet.

  • spike: pactJson/withPact builds matcher templates from msw resolvers
  • packages/pact-matchers is a zero-dep matcher DSL. It extracts rules the same way pact_ffi does, and golden tests compare its output with what pact-js / pact_ffi write for V2/V3/V4
  • the golden pacts are also validated against pact-schemas (below)

Schema validation

Wired pact-schemas into the
golden tests, so every pact the FFI writes for us is also validated
against the spec.

schemas v2 v3 v4
pact-schemas main ✅ ✅ ❌ 17 failing
pactflow/pact-schemas#174 ✅ ✅ ✅ 86/86 overall

The v4 failures on main are schema bugs (eachKey/eachValue rules,
arrayContains variants, statusCode classes, generator expressions,
optional contentTypeHint, plugin matchers). They're fixed in the PR above.

v2/v3 also turned up the FFI writing rules a spec version doesn't define
(v4 matchers in v3 pacts, integer in v2). Those cases are listed in
ffiSpecLeaks for now. pact-foundation/pact-reference#613 warns on these,
or errors with PACT_STRICT_SPEC_VERSION=true. I've checked it against
this harness by swapping the built libpact_ffi into pact-js-core's
prebuilds: no change by default, and exactly those 5 cases fail in strict
mode.

To run with the schemas:

PACT_SCHEMAS_DIR=~/path/to/pact-schemas/dist npm test -w packages/pact-matchers

Spiking #435. A resolver can hand a matcher template to the adapter, the
app gets the reified example body, and the pact gets v2 matchingRules.

msw doesn't keep Response identity between the resolver and
response:mocked (node or browser), and in the browser the Request is
re-deserialised too, so templates are keyed on requestId instead.

The registry lives on globalThis under a Symbol.for key. In Cypress the
handler runs in the app window and the adapter in the spec window, so
there you pass templateRegistry: getPactTemplateRegistry(win).

Only like/eachLike for now, probe files are throwaway.
…ction

Adds packages/pact-matchers, a TS port of the pact-js MatchersV3 DSL and the
pact_ffi bodies.rs/pact_models logic that turns a matcher template into a
plain body, matching rules (v2 + v3) and generators.

Golden tests run every template through the real FFI via pact-js and assert
body/rules/generators line up, plus DSL parity with MatchersV3. We follow
libpact_ffi 0.5.13 for rules nested under eachValue (pact-reference 1f1c2e61),
which the FFI bundled with pact-js 17.1.4 predates.

The pactBody spike now sources its DSL and rule generation from the package.
Every golden case is now also run through pact-schemas (v2/v3/v4) with
ajv. pact-schemas isn't on npm yet, so point PACT_SCHEMAS_DIR at a
checkout's dist/ (or install it from git). The schema checks are skipped
without it.

Cases where the FFI writes rules its spec version doesn't define are
tracked in ffiSpecLeaks. If one of them starts producing a valid pact, the
test fails and tells you to drop it from the list.

Adds a v4 pass through PactV4.
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant