This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the reference implementation of Pact contract testing written in Rust. It provides shared libraries for consumer and provider testing, with FFI bindings for use in other languages. The project supports Pact specification V1–V4.
Note: The mock server crates (
pact_mock_server,pact_mock_server_cli) have moved to https://github.com/pact-foundation/pact-core-mock-server and are excluded from this workspace.
All Cargo commands must be run from the rust/ subdirectory (the workspace root):
cd rust
# Build all crates
cargo build
# Run all tests
cargo test
# Run tests for a specific crate
cargo test --package pact_models
# Run a single test by name (exact match)
cargo test --package pact_models -- my_test_name --exact
# Run tests in a specific module
cargo test --package pact_matching headers::tests
# Run tests with log output
RUST_LOG=debug cargo test -- --nocapture
# Lint
cargo clippy
# Check without building (faster)
cargo check
# Release build (strip=true, opt-level="z")
cargo build --releasecargo build --target wasm32-wasip2docker run --rm --user "$(id -u)":"$(id -g)" \
-v $(pwd):/workspace -w /workspace/rust \
-t -e TZ=UTC pactfoundation/rust-musl-build \
./scripts/ci-musl-build.shThe dependency graph flows upward — each layer depends on those below it:
pact_models ← Pact data structures, reading/writing pact files
↑
pact_matching ← Request/response matching logic
↑ ↖
pact_verifier pact_consumer ← Verification library / Consumer DSL
↑ ↑
pact_verifier_cli pact_ffi ← Standalone CLI / C FFI bindings
-
pact_models: Core data structures for Pact contracts. Handles JSON serialization of pact files. WASM-compatible (no
tokio/reqweston WASM). Features:datetime,xml,form_urlencoded. -
pact_matching: Implements all matching rules and interaction matching. Supports plugin-based extensibility via
pact-plugin-driver. Features:datetime,xml,plugins,multipart,form_urlencoded. -
pact_consumer: DSL for writing consumer tests in Rust. Integrates with
pact_mock_server(external repo). Features:datetime,xml,plugins,multipart,tls,colour. -
pact_verifier: Core provider verification logic (library). Compiled as
cdylib+rlib. Features:datetime,xml,plugins,multipart. -
pact_ffi: C-compatible FFI layer exposing consumer and verifier APIs. Compiled as
cdylib,staticlib, andrlib. Uses Rust edition 2021 (differs from other crates, which use 2024). -
pact_verifier_cli: Command-line tool wrapping
pact_verifier. Features includejunitoutput format.
- Rust edition: 2024 for all crates except
pact_ffi(2021). - Minimum Rust version: 1.88.0 (required for edition 2024).
- Async runtime:
tokiothroughout (except WASM builds). - Logging:
tracing/tracing-subscriber(notlog). - Test helpers:
rstest,hamcrest2,expectest,pretty_assertionsare common dev-dependencies. - Workspace patch:
pact_modelsis patched inrust/Cargo.tomlto always use the local path (./pact_models), so changes propagate across all crates without a publish.
Follow Conventional Changelog format:
feat: ...for new featuresfix: ...for bug fixeschore: ...for maintenancerefactor: ...for refactoring
BDD-style integration tests covering V1–V4 spec compliance live in /compatibility-suite/. These use the cucumber framework and run separately from the main workspace tests.
Each crate has a release.groovy script that guides the release process and updates changelogs. Releases are published to crates.io and tagged on GitHub. CI builds attach platform binaries to each GH release.