Skip to content

feat(ffi): add pactffi_sync_message_match_response_contents - #557

Merged
rholshausen merged 2 commits into
pact-foundation:masterfrom
fabio-andre-rodrigues:feat/sync-message-match-response
Oct 8, 2026
Merged

rholshausen merged 2 commits into
pact-foundation:masterfrom
fabio-andre-rodrigues:feat/sync-message-match-response

Conversation

@fabio-andre-rodrigues

Copy link
Copy Markdown
Contributor

Summary

Adds pactffi_sync_message_match_response_contents, so a consumer test for a synchronous message can check the response its handler produces against the expected response's matching rules.

pactffi_sync_message_generate_contents (#555) gives the consumer the generated request, but there was no way to check the handler's response with the matchers applied. PactNet (pact-foundation/pact-net#562) fell back to exact equality with the generated example, so Match.Type("shipped") still required "shipped".

const char *pactffi_sync_message_match_response_contents(
    InteractionHandle interaction,
    size_t index,               // expected response, 0 for the first
    const char *content_type,   // NULL = content type of the expected response
    const char *contents);      // actual contents
  • Returns a JSON array of mismatches; [] when the contents match.
  • Returns NULL if the handle isn't a sync message interaction, the index is out of range, or an argument is NULL or not UTF-8.
  • Uses the same matching context as match_sync_message_response in the verifier: content rules, V4, unexpected keys allowed.
  • Only the contents are compared. Metadata is not, since a handler returns a body.
  • Free the result with pactffi_string_delete.

Tests

cargo test -p pact_ffi --lib sync_message_match_response, 11 cases:

  • type matcher accepts another value of the same type, rejects a different type
  • integer rejects a decimal, decimal rejects an integer
  • regex accepts a datetime in the expected format, rejects another format
  • unexpected keys allowed, missing key reported
  • no matchers falls back to equality
  • invalid index and non-sync interaction return NULL

Also checked from PactNet against a local build of this branch: 180 tests pass on net8.0 and net462.

Consumer tests for synchronous messages can generate the request with
pactffi_sync_message_generate_contents, but had no way to check the
response the handler under test produces against the expected response's
matching rules. Hosts fell back to exact equality with the generated
example, so a type matcher still required the example value.

The new function matches given contents against an expected response of
a sync message interaction, with the same matching context the verifier
uses in match_sync_message_response (content rules, unexpected keys
allowed). It returns a JSON array of mismatches, empty when the contents
match, or NULL for an invalid handle, index or input.
The V2 matching engine reports a missing key as both a type mismatch and
a missing entry, where V1 reports one mismatch, so the exact count check
failed in the v2-engine job. Check that the contents matched, or that a
mismatch was reported for the expected field, which holds for both.

@YOU54F YOU54F left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested against pact-foundation/pact-net#562 and works nicely

I'll wait for a review from Josh and Ron and then I'd be happy to get this merged and released if they have no issue

@rholshausen

Copy link
Copy Markdown
Contributor

Nice one!

@rholshausen
rholshausen merged commit cb9c197 into pact-foundation:master Oct 8, 2026
18 checks passed
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.

3 participants