From d01ba59b06c4d866a1ab9d2e87fb6c3a6fd72492 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 13:29:56 +1100 Subject: [PATCH 01/15] chore: pin Rust 1.99.1 and declare CI tools in mise Rust 1.99.0 miscompiled C `bool` returns from the FFI library; 1.99.1 carries the fix. A root toolchain file makes the test, FFI and release jobs build with the same compiler as each other and as local builds. mise pins the dev tooling CI installs, so local runs can use the same versions. It reads Rust itself from rust-toolchain.toml, so the version lives in one file. The nextest `ci` profile reports every failure and kills hung tests. Assisted-by: Claude Code:claude-opus-5-5 --- mise.toml | 12 ++++++++++++ rust-toolchain.toml | 2 ++ rust/.config/nextest.toml | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 mise.toml create mode 100644 rust-toolchain.toml create mode 100644 rust/.config/nextest.toml diff --git a/mise.toml b/mise.toml new file mode 100644 index 000000000..1628faa22 --- /dev/null +++ b/mise.toml @@ -0,0 +1,12 @@ +#:schema https://mise.jdx.dev/schema/mise.json + +# Development tooling. Rust itself is read from `rust-toolchain.toml`. +[tools] +"aqua:cargo-bins/cargo-binstall" = "1.23.0" +"aqua:nextest-rs/nextest/cargo-nextest" = "0.9.148" +"cargo:cbindgen" = "0.29.4" +"github:taiki-e/cargo-hack" = "0.6.45" +just = "1.59.0" + +[settings] +idiomatic_version_file_enable_tools = ["rust"] diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..246cb22c3 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.99.1" diff --git a/rust/.config/nextest.toml b/rust/.config/nextest.toml new file mode 100644 index 000000000..ca823884a --- /dev/null +++ b/rust/.config/nextest.toml @@ -0,0 +1,6 @@ +[profile.ci] +# Report every failure in one run. +fail-fast = false + +# Flag tests slower than 60 s; kill them after 5 periods. +slow-timeout = { period = "60s", terminate-after = 5 } From edc8212708ffc22d5ec5ae1b10e2c0a5403926a8 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 13:31:36 +1100 Subject: [PATCH 02/15] test: install the rustls crypto provider in tests that build HTTP clients reqwest is built with `rustls-no-provider`, so building a client panics unless a rustls crypto provider has been installed for the process. Library entry points install the ring provider before building their own clients. Several tests build their own client to call a mock server or to feed a request into the code under test. Those tests passed only when an earlier test in the same binary had already installed the provider. Under nextest, which runs each test in its own process, and under `cargo test `, those tests panic with "No rustls crypto provider is configured". A small helper in each test module now installs the provider before building the client. Assisted-by: Claude Code:claude-opus-5-5 --- rust/pact_consumer/tests/tests.rs | 7 ++++ rust/pact_ffi/tests/tests.rs | 51 ++++++++++++----------- rust/pact_verifier/src/provider_client.rs | 14 +++---- rust/pact_verifier/src/tests.rs | 7 ++++ rust/pact_verifier/src/utils.rs | 8 ++-- 5 files changed, 52 insertions(+), 35 deletions(-) diff --git a/rust/pact_consumer/tests/tests.rs b/rust/pact_consumer/tests/tests.rs index 322a65f6c..6bbf56471 100644 --- a/rust/pact_consumer/tests/tests.rs +++ b/rust/pact_consumer/tests/tests.rs @@ -28,6 +28,11 @@ use pact_models::sync_pact::RequestResponsePact; use pact_models::v4::http_parts::{HttpRequest, HttpResponse}; use pact_models::v4::synch_http::SynchronousHttp; +/// Installs the rustls crypto provider that a test's own HTTP clients need. +fn install_crypto_provider() { + let _ = rustls::crypto::ring::default_provider().install_default(); +} + /// This is supposed to be a doctest in mod, but it's breaking there, so /// we have an executable copy here. #[test_log::test(tokio::test)] @@ -107,6 +112,7 @@ async fn mock_server_passing_validation() -> anyhow::Result<()> { #[test_log::test] fn mock_server_passing_validation_blocking() -> anyhow::Result<()> { + install_crypto_provider(); let alice_service = PactBuilder::new_v4("BlockingConsumer", "Alice Service") .interaction("a retrieve Mallory request", "", |mut i| { i.given("there is some good mallory"); @@ -331,6 +337,7 @@ async fn post_json_with_incorrect_content_type() { // Issue #300 #[test_log::test(tokio::test)] async fn multi_value_headers() { + install_crypto_provider(); let alice_service = PactBuilder::new_v4("Consumer", "Alice Service") .interaction("a retrieve Mallory request", "", |mut i| { i.given("there is some good mallory"); diff --git a/rust/pact_ffi/tests/tests.rs b/rust/pact_ffi/tests/tests.rs index d3e9e55fa..c01bbe9b9 100644 --- a/rust/pact_ffi/tests/tests.rs +++ b/rust/pact_ffi/tests/tests.rs @@ -89,6 +89,13 @@ use pact_models::matchingrules::{MatchingRule, RuleLogic}; use pact_models::matchingrules::matchers_to_json; use pact_models::path_exp::DocPath; +/// HTTP client for calling mock servers. +/// It installs the rustls crypto provider, which the library installs only on its own code paths. +fn http_client() -> Client { + init_crypto(); + Client::default() +} + #[test] fn post_to_mock_server_with_mismatches() { // Refactored to use pactffi_create_mock_server_for_transport and pact handle API @@ -112,7 +119,7 @@ fn post_to_mock_server_with_mismatches() { let port = pactffi_create_mock_server_for_transport(pact_handle, address.as_ptr(), 0, null(), null()); expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); client.post(format!("http://127.0.0.1:{}/path", port).as_str()) .header(CONTENT_TYPE, "application/json") .body(r#"{"foo":"no-very-bar"}"#) @@ -527,7 +534,7 @@ fn http_consumer_feature_test() { // Mock server has started, we can't now modify the pact expect!(pactffi_upon_receiving(interaction.clone(), description.as_ptr())).to(be_false()); - let client = Client::default(); + let client = http_client(); let result = client.post(format!("http://127.0.0.1:{}/request/9999?foo=baz", port).as_str()) .header("Content-Type", "application/json") .header("Authorization", "Bearer 9999") @@ -596,7 +603,7 @@ fn http_xml_consumer_feature_test() { // Mock server has started, we can't now modify the pact expect!(pactffi_upon_receiving(interaction.clone(), description.as_ptr())).to(be_false()); - let client = Client::default(); + let client = http_client(); let result = client.get(format!("http://127.0.0.1:{}/xml", port).as_str()) .header("Accept", "application/xml") .send(); @@ -716,7 +723,7 @@ fn http_xml_consumer_with_examples_and_content_test() { expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let result = client.get(format!("http://127.0.0.1:{}/items", port).as_str()) .header("Accept", "application/xml") .send(); @@ -827,7 +834,7 @@ fn pactffi_with_binary_file_feature_test(specification: PactSpecification, expec let port = pactffi_create_mock_server_for_transport(pact_handle.clone(), address.as_ptr(), 0, null(), null()); expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let result = client.post(format!("http://127.0.0.1:{}/upload", port).as_str()) .header("Content-Type", "image/gif") .body(buffer) @@ -951,7 +958,7 @@ fn each_value_matcher() { expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let result = client.put(format!("http://127.0.0.1:{}/book", port).as_str()) .header("Content-Type", "application/json") .body(r#"{"id1": "book100", "id2": "book2"}"#) @@ -1019,7 +1026,7 @@ fn each_key_matcher() { expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let result = client.put(format!("http://127.0.0.1:{}/book", port).as_str()) .header("Content-Type", "application/json") .body(r#"{"1": "foo","not valid": 1,"key": "value","key2": "value"}"#) @@ -1103,7 +1110,7 @@ fn array_contains_matcher() { expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let result = client.get(format!("http://127.0.0.1:{}/book", port).as_str()) .header("Content-Type", "application/json") .send(); @@ -1167,7 +1174,7 @@ fn multiple_query_values_with_regex_matcher() { let port = pactffi_create_mock_server_for_transport(pact_handle.clone(), address.as_ptr(), 0, null(), null()); expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let result = client.get(format!("http://127.0.0.1:{}/request?foo=1&foo=443&foo=112", port).as_str()) .send(); @@ -1869,7 +1876,7 @@ fn combined_each_key_and_each_value_matcher() { expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let json_body = json!({ "results": { "KGK-9954356": { @@ -1936,7 +1943,7 @@ fn matching_definition_expressions_matcher() { expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let json_body = json!({ "results": { "KGK-9954356": { @@ -1995,11 +2002,7 @@ fn returns_mock_server_logs() { let port = pactffi_create_mock_server_for_transport(pact_handle, address.as_ptr(), 0, null(), null()); expect!(port).to(be_greater_than(0)); - if rustls::crypto::CryptoProvider::get_default().is_none() { - let _ = rustls::crypto::ring::default_provider().install_default(); - } - - let client = Client::default(); + let client = http_client(); client.post(format!("http://127.0.0.1:{}/path", port).as_str()) .header(CONTENT_TYPE, "application/json") .body(r#"{"foo":"no-very-bar"}"#) @@ -2095,7 +2098,7 @@ fn http_form_urlencoded_consumer_feature_test() { // Mock server has started, we can't now modify the pact expect!(pactffi_upon_receiving(interaction.clone(), description.as_ptr())).to(be_false()); - let client = Client::default(); + let client = http_client(); let result = client.post(format!("http://127.0.0.1:{}/form-urlencoded", port).as_str()) .header("Accept", "application/x-www-form-urlencoded") .header("Content-Type", "application/x-www-form-urlencoded") @@ -2144,7 +2147,7 @@ fn time_matcher_in_query_parameters() { let port = pactffi_create_mock_server_for_transport(pact_handle.clone(), address.as_ptr(), 0, null(), null()); expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let result = client.get(format!("http://127.0.0.1:{}/request?item=12:13", port).as_str()) .send(); @@ -2193,7 +2196,7 @@ fn numeric_matcher_passing_test_sending_string_value() { let port = pactffi_create_mock_server_for_transport(pact_handle.clone(), address.as_ptr(), 0, null(), null()); expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let _result = client.post(format!("http://127.0.0.1:{}/request", port).as_str()) .header("Content-Type", "application/json") .body(r#"{"key2":"456","key1":"321.1"}"#) @@ -2245,7 +2248,7 @@ fn include_matcher_in_query_parameters() { let port = pactffi_create_mock_server_for_transport(pact_handle.clone(), address.as_ptr(), 0, null(), null()); expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let result = client.get(format!("http://127.0.0.1:{}/request?item=subway", port).as_str()) .send(); @@ -2304,7 +2307,7 @@ fn mime_multipart() { let port = pactffi_create_mock_server_for_transport(pact_handle.clone(), address.as_ptr(), 0, null(), null()); expect!(port).to(be_greater_than(0)); - let client = Client::default(); + let client = http_client(); let form = reqwest::blocking::multipart::Form::new().text("baz", "bat"); let result = client.post(format!("http://127.0.0.1:{}/formpost", port).as_str()) .multipart(form) @@ -2378,7 +2381,7 @@ fn date_matcher_in_response_body_with_generator_type() { )) .to(be_false()); - let client = Client::default(); + let client = http_client(); let result = client .get(format!("http://127.0.0.1:{}/request", port).as_str()) .send(); @@ -2455,7 +2458,7 @@ fn date_matcher_in_response_body_without_generator_type() { )) .to(be_false()); - let client = Client::default(); + let client = http_client(); let result = client .get(format!("http://127.0.0.1:{}/request", port).as_str()) .send(); @@ -2558,7 +2561,7 @@ fn mime_multipart_with_json_and_image() { expect!(port).to(be_greater_than(0)); // Make actual request with different JSON values and the same JPEG structure - let client = Client::default(); + let client = http_client(); let form = reqwest::blocking::multipart::Form::new() .text("metadata", r#"{"name":"different","size":200}"#) .part( diff --git a/rust/pact_verifier/src/provider_client.rs b/rust/pact_verifier/src/provider_client.rs index 9b0d56c67..fff0e45cf 100644 --- a/rust/pact_verifier/src/provider_client.rs +++ b/rust/pact_verifier/src/provider_client.rs @@ -353,7 +353,7 @@ mod tests { #[test] fn convert_request_to_native_request_test() { - let client = reqwest::Client::new(); + let client = crate::tests::http_client(); let base_url = "http://example.test:8080".to_string(); let request = HttpRequest::default(); let request_builder = create_native_request(&client, &base_url, &request, &hashmap!{}).unwrap().build().unwrap(); @@ -365,7 +365,7 @@ mod tests { #[test] fn convert_request_to_native_request_with_query_parameters() { - let client = reqwest::Client::new(); + let client = crate::tests::http_client(); let base_url = "http://example.test:8080".to_string(); let request = HttpRequest { query: Some(hashmap!{ @@ -382,7 +382,7 @@ mod tests { #[test] fn convert_request_to_native_request_with_headers() { - let client = reqwest::Client::new(); + let client = crate::tests::http_client(); let base_url = "http://example.test:8080".to_string(); let request = HttpRequest { headers: Some(hashmap! { @@ -406,7 +406,7 @@ mod tests { #[test] fn convert_request_to_native_request_with_body() { - let client = reqwest::Client::new(); + let client = crate::tests::http_client(); let base_url = "http://example.test:8080".to_string(); let request = HttpRequest { body: OptionalBody::from("body"), @@ -421,7 +421,7 @@ mod tests { #[test] fn convert_request_to_native_request_with_null_body() { - let client = reqwest::Client::new(); + let client = crate::tests::http_client(); let base_url = "http://example.test:8080".to_string(); let request = HttpRequest { body: OptionalBody::Null, @@ -436,7 +436,7 @@ mod tests { #[test] fn convert_request_to_native_request_with_json_null_body() { - let client = reqwest::Client::new(); + let client = crate::tests::http_client(); let base_url = "http://example.test:8080".to_string(); let request = HttpRequest { headers: Some(hashmap! { @@ -493,7 +493,7 @@ mod tests { #[test] fn convert_request_to_native_request_with_custom_headers() { - let client = reqwest::Client::new(); + let client = crate::tests::http_client(); let base_url = "http://example.test:8080".to_string(); let request = HttpRequest { headers: Some(hashmap! { diff --git a/rust/pact_verifier/src/tests.rs b/rust/pact_verifier/src/tests.rs index f0f61f9e4..f520190df 100644 --- a/rust/pact_verifier/src/tests.rs +++ b/rust/pact_verifier/src/tests.rs @@ -41,6 +41,13 @@ use crate::VERIFIER_VERSION; use super::{execute_state_change, filter_consumers, filter_interaction, FilterInfo}; +/// HTTP client for tests that call servers directly. +/// It installs the rustls crypto provider, which production code installs before building its own clients. +pub(crate) fn http_client() -> Client { + let _ = rustls::crypto::ring::default_provider().install_default(); + Client::new() +} + #[test] fn if_no_interaction_filter_is_defined_returns_true() { let interaction = RequestResponseInteraction::default(); diff --git a/rust/pact_verifier/src/utils.rs b/rust/pact_verifier/src/utils.rs index 4738136b2..4df6c4e30 100644 --- a/rust/pact_verifier/src/utils.rs +++ b/rust/pact_verifier/src/utils.rs @@ -268,7 +268,7 @@ mod tests { }) .await; - let client = reqwest::Client::new(); + let client = crate::tests::http_client(); let request = client.get(&url); // retries=3: attempt 1 → 429, attempt 2 → 429, attempt 3 → 200 let result = with_retries(3, request).await; @@ -281,7 +281,7 @@ mod tests { async fn with_retries_does_not_retry_404_responses() { let (url, call_count) = spawn_server(|_| axum::http::StatusCode::NOT_FOUND.into_response()).await; - let client = reqwest::Client::new(); + let client = crate::tests::http_client(); let request = client.get(&url); let result = with_retries(3, request).await; // 404 is not retryable — should get a response after exactly 1 call @@ -295,7 +295,7 @@ mod tests { let (url, call_count) = spawn_server(|_| axum::http::StatusCode::TOO_MANY_REQUESTS.into_response()).await; - let client = reqwest::Client::new(); + let client = crate::tests::http_client(); let request = client.get(&url); // retries=0 must not panic and must send the request exactly once let result = with_retries(0, request).await; @@ -321,7 +321,7 @@ mod tests { }) .await; - let client = reqwest::Client::new(); + let client = crate::tests::http_client(); let request = client.get(&url); let result = with_retries(3, request).await; assert!(result.is_ok()); From 8afe2f13606f35204c6e81988006ea98cde3eb5a Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 13:36:03 +1100 Subject: [PATCH 03/15] build(ffi): build with the pinned toolchain, keep nightly for cbindgen The CMake project refused to configure unless `cargo +nightly` existed, and FindCargo reported nightly's version even though the library builds with whichever toolchain `cargo` resolves to. With `rust-toolchain.toml` pinning stable, FindCargo now reports the cargo that actually builds the library, and the nightly gate is gone. Header generation still needs nightly. cbindgen's macro expansion passes `-Zunpretty=expanded`, which stable rejects, so the `rustup run nightly` call sites stay. Assisted-by: Claude Code:claude-opus-5-5 --- rust/pact_ffi/CMakeLists.txt | 4 ---- rust/pact_ffi/README.md | 2 +- rust/pact_ffi/cmake/FindCargo.cmake | 10 +--------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/rust/pact_ffi/CMakeLists.txt b/rust/pact_ffi/CMakeLists.txt index bc751ce04..1b47d4bfd 100644 --- a/rust/pact_ffi/CMakeLists.txt +++ b/rust/pact_ffi/CMakeLists.txt @@ -146,10 +146,6 @@ endif() # Uses the finder specified in `cmake/FindCargo.cmake` find_package(Cargo) -if(NOT CARGO_CHANNEL STREQUAL "nightly") - message(FATAL_ERROR "${NAME_STRING} requires a nightly Cargo version to build.") -endif() - # Uses the finder specified in `cmake/FindCbindgen.cmake` find_package(Cbindgen) diff --git a/rust/pact_ffi/README.md b/rust/pact_ffi/README.md index ebb1fafc9..6ab2147dc 100644 --- a/rust/pact_ffi/README.md +++ b/rust/pact_ffi/README.md @@ -14,7 +14,7 @@ documentation on the integration JSON format is [IntegrationJson.md](https://git This crates requires: - `cbindgen`, a tool for automatically generating the header file needed for C users of the crate. -- A nightly-channel version of Cargo (needed for an unstable flag used by `cbindgen` to get the macro-expanded contents of the crate source). +- A nightly Rust toolchain, used only by `cbindgen` for an unstable flag that gets the macro-expanded contents of the crate source. The library itself builds with the toolchain pinned in `rust-toolchain.toml`. It will additionally attempt to find and use `Doxygen` to generate C-friendly documentation (you can of course alternatively use `cargo doc` to get Rustdoc documentation). diff --git a/rust/pact_ffi/cmake/FindCargo.cmake b/rust/pact_ffi/cmake/FindCargo.cmake index 23eb54762..28ce53dd2 100644 --- a/rust/pact_ffi/cmake/FindCargo.cmake +++ b/rust/pact_ffi/cmake/FindCargo.cmake @@ -4,21 +4,14 @@ find_program(CARGO_EXECUTABLE cargo PATHS "$ENV{HOME}/.cargo" PATH_SUFFIXES bin) set(CARGO_VERSION "") -set(CARGO_CHANNEL "stable") # If we found it, see if we can get its version. if(CARGO_EXECUTABLE) - execute_process(COMMAND ${CARGO_EXECUTABLE} +nightly -V OUTPUT_VARIABLE CARGO_VERSION_OUTPUT OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${CARGO_EXECUTABLE} -V OUTPUT_VARIABLE CARGO_VERSION_OUTPUT OUTPUT_STRIP_TRAILING_WHITESPACE) if(CARGO_VERSION_OUTPUT MATCHES "cargo ([0-9]+\\.[0-9]+\\.[0-9]+).*") set(CARGO_VERSION ${CMAKE_MATCH_1}) endif() - - execute_process(COMMAND ${CARGO_EXECUTABLE} +nightly -V OUTPUT_VARIABLE CARGO_CHANNEL_OUTPUT OUTPUT_STRIP_TRAILING_WHITESPACE) - - if(CARGO_CHANNEL_OUTPUT MATCHES "cargo [0-9]+\\.[0-9]+\\.[0-9]+-([a-zA-Z]*).*") - set(CARGO_CHANNEL ${CMAKE_MATCH_1}) - endif() endif() # Hides the CARGO_EXECUTABLE variable unless advanced variables are requested @@ -30,7 +23,6 @@ find_package_handle_standard_args( Cargo REQUIRED_VARS CARGO_VERSION - CARGO_CHANNEL CARGO_EXECUTABLE VERSION_VAR CARGO_VERSION From 5a18ad1d83f083e6ba67c9b52fc15f64da8ab31f Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 13:38:19 +1100 Subject: [PATCH 04/15] test(ffi): build and run the C examples against one release build The examples under rust/pact_ffi/examples had no CI coverage. .github/scripts/ffi-examples.sh builds pact_ffi once in release, the profile that ships, and installs it under rust/pact_ffi/build/install. Each example then runs against that install, and the C projects under c/ reuse the same install. The script replaces rust/pact_ffi/ci-build.sh. Only CI runs it, so it sits with the workflows, not in the crate. Assisted-by: Claude Code:claude-opus-5-5 --- .github/scripts/ffi-examples.sh | 37 +++++++++++++++++++ rust/pact_ffi/ci-build.sh | 63 --------------------------------- 2 files changed, 37 insertions(+), 63 deletions(-) create mode 100755 .github/scripts/ffi-examples.sh delete mode 100755 rust/pact_ffi/ci-build.sh diff --git a/.github/scripts/ffi-examples.sh b/.github/scripts/ffi-examples.sh new file mode 100755 index 000000000..c288530a4 --- /dev/null +++ b/.github/scripts/ffi-examples.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# Builds pact_ffi in release through its CMake project, installs it under +# rust/pact_ffi/build/install (lib/ + include/pact.h), then builds and runs +# every example in rust/pact_ffi/examples/ against that install. +set -euo pipefail + +cd "$(dirname "$0")/../../rust/pact_ffi" +install_dir="$PWD/build/install" + +# MARK: Library + +cmake -S . -B build -DCMAKE_BUILD_TYPE=Release +cmake --build build --config Release +cmake --build build --config Release --target generate_header +cmake --install build --config Release --prefix "$install_dir" + +# MARK: Examples + +for example in examples/*/; do + name=$(basename "$example") + build_dir="build/examples/$name" + echo "::group::Example $name" + cmake -S "$example" -B "$build_dir" -DCMAKE_BUILD_TYPE=Release + cmake --build "$build_dir" --config Release + case "$(uname -s)" in + MINGW* | MSYS* | CYGWIN*) + PATH="$install_dir/lib:$PATH" "$build_dir/Release/example.exe" + ;; + Darwin) + DYLD_LIBRARY_PATH="$install_dir/lib" "$build_dir/example" + ;; + *) + LD_LIBRARY_PATH="$install_dir/lib" "$build_dir/example" + ;; + esac + echo "::endgroup::" +done diff --git a/rust/pact_ffi/ci-build.sh b/rust/pact_ffi/ci-build.sh deleted file mode 100755 index 209e0b674..000000000 --- a/rust/pact_ffi/ci-build.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash - -set -e -set -x - -rustc --version - -cargo install --force cbindgen -rm -rf ./include - -rustup toolchain install nightly - -echo ------------------------------------- -echo - Build library with CMake -echo ------------------------------------- -mkdir -p build -cd build -cmake -DCMAKE_BUILD_TYPE=Debug .. -cmake --build . -v -cd .. - -echo ------------------------------------- -echo - Generate header with cbindgen -echo ------------------------------------- -rustup run nightly cbindgen \ - --config cbindgen.toml \ - --crate pact_ffi \ - --output include/pact.h -rustup run nightly cbindgen \ - --config cbindgen-c++.toml \ - --crate pact_ffi \ - --output include/pact-c++.h - -echo ------------------------------------- -echo - Make library available for examples -echo ------------------------------------- -cd build -cmake --install . --prefix ./install - -echo ------------------------------------- -echo - Running examples -echo ------------------------------------- -cd .. -for i in examples/*; do - pushd $i - mkdir -p build - cd build - cmake .. - cmake --build . - - echo "Running example $i" - if [[ "$OSTYPE" == "msys"* ]]; then - cp ../../../build/install/lib/*.dll Debug/ - ./Debug/example.exe - elif [[ "$OSTYPE" == "darwin"* ]]; then - cp ../../../build/install/lib/*.dylib . - ./example - else - ./example - fi - - popd -done From b90dc72f4b45eab07a82ebb33f2cb4e07b9fb669 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 14:03:09 +1100 Subject: [PATCH 05/15] build(c): accept a prebuilt pact_ffi through PACT_FFI_PREBUILT_DIR Corrosion builds pact_ffi in release inside each project's own build directory, so CI compiled the library twice per OS. With the variable set, both projects link the install produced by rust/pact_ffi/ci-build.sh and copy the library beside the executable, where the run recipe expects it. Without it, local builds keep using Corrosion. The new root rust-toolchain.toml pins stable, which would otherwise apply to the local Corrosion build. Corrosion runs cbindgen with no toolchain override, and cbindgen's macro expansion needs nightly. The justfiles therefore default RUSTUP_TOOLCHAIN to nightly, as the READMEs already required; a caller's own RUSTUP_TOOLCHAIN still wins. Assisted-by: Claude Code:claude-opus-5-5 --- c/consumer/CMakeLists.txt | 64 ++++++++++++++++++++++++++++----------- c/consumer/README.md | 2 +- c/consumer/justfile | 4 +++ c/provider/CMakeLists.txt | 64 ++++++++++++++++++++++++++++----------- c/provider/README.md | 2 +- c/provider/justfile | 4 +++ 6 files changed, 102 insertions(+), 38 deletions(-) diff --git a/c/consumer/CMakeLists.txt b/c/consumer/CMakeLists.txt index d1b75a4c0..01f678cd8 100644 --- a/c/consumer/CMakeLists.txt +++ b/c/consumer/CMakeLists.txt @@ -11,16 +11,6 @@ if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conan_toolchain.cmake") include("${CMAKE_CURRENT_BINARY_DIR}/conan_toolchain.cmake") endif() -# We use [corrosion](https://github.com/corrosion-rs/corrosion) to integrate -# Rust into our C project. -include(FetchContent) -FetchContent_Declare( - Corrosion - GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git - GIT_TAG v0.5 -) -FetchContent_MakeAvailable(Corrosion) - get_filename_component(PACT_FFI_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../rust/pact_ffi" ABSOLUTE) ################################################################################ @@ -56,14 +46,44 @@ find_package(ZLIB REQUIRED) # dependencies' build scripts (e.g. mlua's vendored Lua), which cargo bakes # into the cdylib at link time but does not surface to corrosion for the # staticlib, causing missing symbol errors when linking against libpact_ffi.a. -corrosion_import_crate( - MANIFEST_PATH "${PACT_FFI_ROOT}/Cargo.toml" - CRATE_TYPES cdylib -) -corrosion_experimental_cbindgen( - TARGET pact_ffi - HEADER_NAME pact.h -) +# PACT_FFI_PREBUILT_DIR names an install prefix holding lib/ and +# include/pact.h. CI sets it to reuse one release build across projects; +# without it, Corrosion builds pact_ffi from source. +if(DEFINED ENV{PACT_FFI_PREBUILT_DIR}) + file(TO_CMAKE_PATH "$ENV{PACT_FFI_PREBUILT_DIR}" PACT_FFI_PREBUILT_DIR) + add_library(pact_ffi SHARED IMPORTED) + if(WIN32) + set_target_properties(pact_ffi PROPERTIES + IMPORTED_LOCATION "${PACT_FFI_PREBUILT_DIR}/lib/pact_ffi.dll" + IMPORTED_IMPLIB "${PACT_FFI_PREBUILT_DIR}/lib/pact_ffi.dll.lib") + elseif(APPLE) + set_target_properties(pact_ffi PROPERTIES + IMPORTED_LOCATION "${PACT_FFI_PREBUILT_DIR}/lib/libpact_ffi.dylib") + else() + set_target_properties(pact_ffi PROPERTIES + IMPORTED_LOCATION "${PACT_FFI_PREBUILT_DIR}/lib/libpact_ffi.so") + endif() + target_include_directories(pact_ffi INTERFACE "${PACT_FFI_PREBUILT_DIR}/include") +else() + # We use [corrosion](https://github.com/corrosion-rs/corrosion) to + # integrate Rust into our C project. + include(FetchContent) + FetchContent_Declare( + Corrosion + GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git + GIT_TAG v0.5 + ) + FetchContent_MakeAvailable(Corrosion) + + corrosion_import_crate( + MANIFEST_PATH "${PACT_FFI_ROOT}/Cargo.toml" + CRATE_TYPES cdylib + ) + corrosion_experimental_cbindgen( + TARGET pact_ffi + HEADER_NAME pact.h + ) +endif() target_link_libraries( pact_ffi @@ -106,6 +126,14 @@ if(WIN32) ) endif() +# The run recipe loads the library from beside the executable, where +# Corrosion would have built it, so copy the prebuilt one there. +if(DEFINED ENV{PACT_FFI_PREBUILT_DIR}) + add_custom_command(TARGET pact-consumer POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ $) +endif() + # Link macOS system frameworks if building on Apple platforms if(APPLE) target_link_libraries( diff --git a/c/consumer/README.md b/c/consumer/README.md index a1328ceb7..b2ec0d136 100644 --- a/c/consumer/README.md +++ b/c/consumer/README.md @@ -33,7 +33,7 @@ The results of the tests are printed to stdout and will exit with a non-zero sta The tests require: -- A C and Rust compiler (Rust compiler requires nightly toolchain) +- A C compiler and a nightly Rust toolchain (the justfile selects nightly, which `cbindgen` needs to generate the header) - CMake (version 3.24 or higher) - Conan (version 2.0 or higher) diff --git a/c/consumer/justfile b/c/consumer/justfile index cec30e3d1..88c8e961d 100644 --- a/c/consumer/justfile +++ b/c/consumer/justfile @@ -1,3 +1,7 @@ +# Without PACT_FFI_PREBUILT_DIR, Corrosion builds pact_ffi, and cbindgen's +# macro expansion needs a nightly toolchain. +export RUSTUP_TOOLCHAIN := env("RUSTUP_TOOLCHAIN", "nightly") + [unix] build: conan install . --output-folder=build --build=missing diff --git a/c/provider/CMakeLists.txt b/c/provider/CMakeLists.txt index 0245644e8..dc5ba3e30 100644 --- a/c/provider/CMakeLists.txt +++ b/c/provider/CMakeLists.txt @@ -11,16 +11,6 @@ if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conan_toolchain.cmake") include("${CMAKE_CURRENT_BINARY_DIR}/conan_toolchain.cmake") endif() -# We use [corrosion](https://github.com/corrosion-rs/corrosion) to integrate -# Rust into our C project. -include(FetchContent) -FetchContent_Declare( - Corrosion - GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git - GIT_TAG v0.5 -) -FetchContent_MakeAvailable(Corrosion) - get_filename_component(PACT_FFI_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../rust/pact_ffi" ABSOLUTE) ################################################################################ @@ -55,14 +45,44 @@ find_package(ZLIB REQUIRED) # dependencies' build scripts (e.g. mlua's vendored Lua), which cargo bakes # into the cdylib at link time but does not surface to corrosion for the # staticlib, causing missing symbol errors when linking against libpact_ffi.a. -corrosion_import_crate( - MANIFEST_PATH "${PACT_FFI_ROOT}/Cargo.toml" - CRATE_TYPES cdylib -) -corrosion_experimental_cbindgen( - TARGET pact_ffi - HEADER_NAME pact.h -) +# PACT_FFI_PREBUILT_DIR names an install prefix holding lib/ and +# include/pact.h. CI sets it to reuse one release build across projects; +# without it, Corrosion builds pact_ffi from source. +if(DEFINED ENV{PACT_FFI_PREBUILT_DIR}) + file(TO_CMAKE_PATH "$ENV{PACT_FFI_PREBUILT_DIR}" PACT_FFI_PREBUILT_DIR) + add_library(pact_ffi SHARED IMPORTED) + if(WIN32) + set_target_properties(pact_ffi PROPERTIES + IMPORTED_LOCATION "${PACT_FFI_PREBUILT_DIR}/lib/pact_ffi.dll" + IMPORTED_IMPLIB "${PACT_FFI_PREBUILT_DIR}/lib/pact_ffi.dll.lib") + elseif(APPLE) + set_target_properties(pact_ffi PROPERTIES + IMPORTED_LOCATION "${PACT_FFI_PREBUILT_DIR}/lib/libpact_ffi.dylib") + else() + set_target_properties(pact_ffi PROPERTIES + IMPORTED_LOCATION "${PACT_FFI_PREBUILT_DIR}/lib/libpact_ffi.so") + endif() + target_include_directories(pact_ffi INTERFACE "${PACT_FFI_PREBUILT_DIR}/include") +else() + # We use [corrosion](https://github.com/corrosion-rs/corrosion) to + # integrate Rust into our C project. + include(FetchContent) + FetchContent_Declare( + Corrosion + GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git + GIT_TAG v0.5 + ) + FetchContent_MakeAvailable(Corrosion) + + corrosion_import_crate( + MANIFEST_PATH "${PACT_FFI_ROOT}/Cargo.toml" + CRATE_TYPES cdylib + ) + corrosion_experimental_cbindgen( + TARGET pact_ffi + HEADER_NAME pact.h + ) +endif() target_link_libraries( pact_ffi @@ -121,6 +141,14 @@ if(WIN32) ) endif() +# The run recipe loads the library from beside the executable, where +# Corrosion would have built it, so copy the prebuilt one there. +if(DEFINED ENV{PACT_FFI_PREBUILT_DIR}) + add_custom_command(TARGET pact-provider POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ $) +endif() + # Link macOS system frameworks if building on Apple platforms if(APPLE) target_link_libraries( diff --git a/c/provider/README.md b/c/provider/README.md index 8afebdb38..a702c6337 100644 --- a/c/provider/README.md +++ b/c/provider/README.md @@ -34,7 +34,7 @@ It assumes that the consumer contracts have already been generated by running th The verification tests require: -- A C and Rust compiler (Rust compiler requires nightly toolchain) +- A C compiler and a nightly Rust toolchain (the justfile selects nightly, which `cbindgen` needs to generate the header) - CMake (version 3.24 or higher) - Conan (version 2.0 or higher) diff --git a/c/provider/justfile b/c/provider/justfile index 0ae8e1568..599281de7 100644 --- a/c/provider/justfile +++ b/c/provider/justfile @@ -1,3 +1,7 @@ +# Without PACT_FFI_PREBUILT_DIR, Corrosion builds pact_ffi, and cbindgen's +# macro expansion needs a nightly toolchain. +export RUSTUP_TOOLCHAIN := env("RUSTUP_TOOLCHAIN", "nightly") + [unix] build: conan install . --output-folder=build --build=missing From 9c7077512857b628b04c996071541beae291f039 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 14:08:43 +1100 Subject: [PATCH 06/15] ci: consolidate testing into one draft-aware workflow Build, FFI and compatibility runs move into test.yml, gated by a single `CI complete` check: - Pull requests run once per commit, on Linux, macOS and Windows. - Draft PRs run nothing heavy until marked ready. - Caches save only from master, so PR runs restore master's entries without filling the repository's 10 GB budget. - nextest runs the suite, with doctests run separately. - The V2 matching engine and the ignored mock-server-log test reuse the same build. - Compatibility v1-v4 share one compile per OS. - pact_ffi builds once per OS, in release with the pinned toolchain, for every C example. Nightly is installed only for cbindgen. - Windows legs build on a Dev Drive. - A per-feature check replaces the single --no-default-features check. It skips pact_matching with `plugins` alone, which pact-plugin-driver currently breaks by using chrono's clock without enabling it. Assisted-by: Claude Code:claude-opus-5-5 --- .github/workflows/test.yml | 362 +++++++++++++++++++++++++++++++++++++ 1 file changed, 362 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..e3164501c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,362 @@ +--- +name: Test + +on: + push: + branches: + - master + pull_request: + branches: + - master + types: + - opened + - synchronize + - reopened + - ready_for_review + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +env: + FORCE_COLOR: '1' + NEXTEST_PROFILE: ci + PACT_DO_NOT_TRACK: 'true' + +jobs: + # MARK: Sentinel + + complete: + name: CI complete + if: always() + needs: + - test + - compat + - ffi + - musl + - features + - wasm + - clippy + runs-on: ubuntu-latest + steps: + - name: Fail if any job failed + if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') + run: exit 1 + + # MARK: Cross-platform + + test: + name: Test (${{ matrix.os }}) + if: github.event_name != 'pull_request' || !github.event.pull_request.draft + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + # Windows builds are dominated by filesystem overhead; ReFS Dev Drives + # avoid most of it. + - name: Set up Dev Drive + if: runner.os == 'Windows' + uses: samypr100/setup-dev-drive@562171fe8df7401fdf582d766cd3b6ab80d5b1a0 # v4.1.0 + with: + drive-size: 12GB + workspace-copy: true + env-mapping: | + CARGO_HOME,{{ DEV_DRIVE }}/.cargo + RUSTUP_HOME,{{ DEV_DRIVE }}/.rustup + + - name: Resolve workspace root + shell: bash + run: echo "WORKSPACE_ROOT=${DEV_DRIVE_WORKSPACE:-$GITHUB_WORKSPACE}" >> "$GITHUB_ENV" + + - name: Install macOS dependencies + if: runner.os == 'macOS' + run: brew install shared-mime-info + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0 + with: + build-warnings: warn + cache-workspaces: ${{ env.WORKSPACE_ROOT }}/rust -> target + cache-save-if: ${{ github.ref == 'refs/heads/master' }} + + - name: Install tools + uses: jdx/mise-action@08ae2a091c038e1e05ec6f5115dc5c69d5a2a6b8 # v5.1.2 + with: + working_directory: ${{ env.WORKSPACE_ROOT }} + install_args: aqua:nextest-rs/nextest/cargo-nextest + cache_save: ${{ github.ref == 'refs/heads/master' }} + + - name: Run tests + working-directory: ${{ env.WORKSPACE_ROOT }}/rust + env: + RUST_LOG: debug + run: cargo nextest run --workspace + + # nextest does not run doctests. + - name: Run doctests + working-directory: ${{ env.WORKSPACE_ROOT }}/rust + run: cargo test --workspace --doc + + - name: Run mock server log test + working-directory: ${{ env.WORKSPACE_ROOT }}/rust + run: cargo nextest run -p pact_ffi --run-ignored only -E 'test(=returns_mock_server_logs)' + + - name: Run tests with the V2 matching engine + if: runner.os == 'Linux' + continue-on-error: true + working-directory: ${{ env.WORKSPACE_ROOT }}/rust + env: + RUST_LOG: debug + PACT_MATCHING_ENGINE: v2 + PACT_V2_MATCHING_LOG_EXECUTED_PLAN: '1' + run: cargo nextest run --workspace + + compat: + name: Compatibility suite (${{ matrix.os }}) + if: github.event_name != 'pull_request' || !github.event.pull_request.draft + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Set up Dev Drive + if: runner.os == 'Windows' + uses: samypr100/setup-dev-drive@562171fe8df7401fdf582d766cd3b6ab80d5b1a0 # v4.1.0 + with: + drive-size: 12GB + workspace-copy: true + env-mapping: | + CARGO_HOME,{{ DEV_DRIVE }}/.cargo + RUSTUP_HOME,{{ DEV_DRIVE }}/.rustup + + - name: Resolve workspace root + shell: bash + run: echo "WORKSPACE_ROOT=${DEV_DRIVE_WORKSPACE:-$GITHUB_WORKSPACE}" >> "$GITHUB_ENV" + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0 + with: + build-warnings: warn + cache-workspaces: ${{ env.WORKSPACE_ROOT }}/compatibility-suite -> target + cache-save-if: ${{ github.ref == 'refs/heads/master' }} + + # The cucumber binaries use `harness = false`, which nextest cannot drive. + - name: Run cucumber suites + working-directory: ${{ env.WORKSPACE_ROOT }}/compatibility-suite + run: cargo test + + ffi: + name: FFI (${{ matrix.os }}) + if: github.event_name != 'pull_request' || !github.event.pull_request.draft + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Set up Dev Drive + if: runner.os == 'Windows' + uses: samypr100/setup-dev-drive@562171fe8df7401fdf582d766cd3b6ab80d5b1a0 # v4.1.0 + with: + drive-size: 12GB + workspace-copy: true + env-mapping: | + CARGO_HOME,{{ DEV_DRIVE }}/.cargo + RUSTUP_HOME,{{ DEV_DRIVE }}/.rustup + + - name: Resolve workspace root + run: echo "WORKSPACE_ROOT=${DEV_DRIVE_WORKSPACE:-$GITHUB_WORKSPACE}" >> "$GITHUB_ENV" + + - name: Install macOS dependencies + if: runner.os == 'macOS' + run: brew install shared-mime-info gettext + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0 + with: + build-warnings: warn + cache-workspaces: ${{ env.WORKSPACE_ROOT }}/rust -> target + cache-save-if: ${{ github.ref == 'refs/heads/master' }} + + # cbindgen's macro expansion passes `-Zunpretty=expanded`, which only + # nightly accepts. The library itself builds with the pinned toolchain. + - name: Install nightly for cbindgen + run: rustup toolchain install nightly --profile minimal + + - name: Install tools + uses: jdx/mise-action@08ae2a091c038e1e05ec6f5115dc5c69d5a2a6b8 # v5.1.2 + with: + working_directory: ${{ env.WORKSPACE_ROOT }} + install_args: cargo:cbindgen just + cache_save: ${{ github.ref == 'refs/heads/master' }} + + - name: Install Conan + uses: conan-io/setup-conan@ed3942a6883243f4af84e13e49c972f9440fa1c2 # v1.4.0 + + - name: Restore Conan packages + id: conan-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.conan2/p + key: conan-${{ runner.os }}-${{ hashFiles('c/*/conanfile.txt') }} + restore-keys: conan-${{ runner.os }}- + + - name: Check plugin log callback headers + if: runner.os == 'Linux' + working-directory: ${{ env.WORKSPACE_ROOT }}/rust/pact_ffi + run: bash tests/check-plugin-log-callback.sh + + - name: Build pact_ffi and run its examples + working-directory: ${{ env.WORKSPACE_ROOT }} + run: .github/scripts/ffi-examples.sh + + - name: Run C consumer example + working-directory: ${{ env.WORKSPACE_ROOT }}/c/consumer + run: PACT_FFI_PREBUILT_DIR="$WORKSPACE_ROOT/rust/pact_ffi/build/install" just run + + - name: Run C provider example + working-directory: ${{ env.WORKSPACE_ROOT }}/c/provider + run: PACT_FFI_PREBUILT_DIR="$WORKSPACE_ROOT/rust/pact_ffi/build/install" just run + + - name: Save Conan packages + if: github.ref == 'refs/heads/master' && steps.conan-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.conan2/p + key: conan-${{ runner.os }}-${{ hashFiles('c/*/conanfile.txt') }} + + # MARK: Linux-only + + musl: + name: Test (musl) + if: github.event_name != 'pull_request' || !github.event.pull_request.draft + runs-on: ubuntu-latest + # The image's own toolchain is unused; rustup installs the pinned one + # from rust-toolchain.toml on first use. + container: rust:alpine + steps: + - name: Install build dependencies + run: >- + apk add --no-cache bash git musl-dev openssl-dev shared-mime-info + protobuf protobuf-dev tzdata zlib-dev + + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0 + with: + build-warnings: warn + components: rustfmt + cache-workspaces: rust -> target + cache-save-if: ${{ github.ref == 'refs/heads/master' }} + + - name: Build and test + working-directory: rust + env: + TZ: UTC + run: | + cargo build + cargo test + + features: + name: Feature combinations + if: github.event_name != 'pull_request' || !github.event.pull_request.draft + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0 + with: + build-warnings: warn + cache-workspaces: rust -> target + cache-save-if: ${{ github.ref == 'refs/heads/master' }} + + - name: Install tools + uses: jdx/mise-action@08ae2a091c038e1e05ec6f5115dc5c69d5a2a6b8 # v5.1.2 + with: + install_args: github:taiki-e/cargo-hack + cache_save: ${{ github.ref == 'refs/heads/master' }} + + # pact-plugin-driver calls `Utc::now()` without enabling chrono's `clock` + # feature, so pact_matching fails to build with `plugins` alone. Check + # that combination again once the driver enables `clock`. + - name: Check each feature + working-directory: rust + run: | + cargo hack check --workspace --exclude pact_matching --each-feature --no-dev-deps + cargo hack check -p pact_matching --each-feature --no-dev-deps --exclude-features plugins + + wasm: + name: WASM + if: github.event_name != 'pull_request' || !github.event.pull_request.draft + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0 + with: + build-warnings: warn + target: wasm32-wasip2 + cache-workspaces: rust -> target + cache-save-if: ${{ github.ref == 'refs/heads/master' }} + + - name: Build pact_models + working-directory: rust/pact_models + run: cargo build --target wasm32-wasip2 + + - name: Build pact_matching + working-directory: rust/pact_matching + run: cargo build --target wasm32-wasip2 + + clippy: + name: Clippy + if: github.event_name != 'pull_request' || !github.event.pull_request.draft + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0 + with: + build-warnings: warn + components: clippy + cache-workspaces: rust -> target + cache-save-if: ${{ github.ref == 'refs/heads/master' }} + + # No `-D warnings`: only deny-by-default lints fail the job. + - name: Run clippy + working-directory: rust + run: cargo clippy From 9e3d8aae1c29d582a6e4d29cb8dba321f6d2cac6 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 14:09:06 +1100 Subject: [PATCH 07/15] fix(ci): keep issue text out of shell commands in the Jira workflow The issue title was interpolated straight into a `run:` script. The job runs for anyone who comments `/jira ticket`, so anyone could open an issue with a crafted title and execute commands on the runner, which holds the Jira credentials. The title and the comment body now reach the shell through environment variables. Assisted-by: Claude Code:claude-opus-5-5 --- .github/workflows/issue-comment-created.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/issue-comment-created.yml b/.github/workflows/issue-comment-created.yml index 8d83e08a3..604c2a584 100644 --- a/.github/workflows/issue-comment-created.yml +++ b/.github/workflows/issue-comment-created.yml @@ -10,7 +10,9 @@ jobs: runs-on: ubuntu-latest if: ${{ github.event.comment.body == '/jira ticket' }} steps: - - run: echo ${{ github.event.comment.body }} + - env: + COMMENT_BODY: ${{ github.event.comment.body }} + run: echo "$COMMENT_BODY" - name: Login uses: atlassian/gajira-login@v3 @@ -20,7 +22,10 @@ jobs: JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} - name: SearchParam - run: echo 'summary ~ ${{ toJSON(github.event.issue.title)}} AND project=${{ secrets.JIRA_PROJECT }}' + env: + ISSUE_TITLE: ${{ toJSON(github.event.issue.title) }} + JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }} + run: echo "summary ~ ${ISSUE_TITLE} AND project=${JIRA_PROJECT}" - name: Search id: search From 8dc87014a9c525f0bae1b4884482f6dea1a29408 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 14:09:30 +1100 Subject: [PATCH 08/15] ci: retire superseded workflows and pin remaining actions test.yml replaces the build, FFI and compatibility workflows. The release build no longer runs on pull requests. Release PRs will trigger it once the release process moves to PRs. The remaining workflows pin actions by commit SHA and declare the token permissions they use. Assisted-by: Claude Code:claude-opus-5-5 --- .github/workflows/build-ffi.yml | 79 -------------- .github/workflows/build.yml | 100 ------------------ .github/workflows/compatability-suite.yml | 78 -------------- .github/workflows/issue-comment-created.yml | 11 +- .github/workflows/release.yml | 4 - .../workflows/trigger_pact_docs_update.yml | 2 + README.md | 3 +- 7 files changed, 10 insertions(+), 267 deletions(-) delete mode 100644 .github/workflows/build-ffi.yml delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/compatability-suite.yml diff --git a/.github/workflows/build-ffi.yml b/.github/workflows/build-ffi.yml deleted file mode 100644 index e31fc0d5d..000000000 --- a/.github/workflows/build-ffi.yml +++ /dev/null @@ -1,79 +0,0 @@ -name: Pact-Rust FFI Build - -on: - push: - branches: - - master - pull_request: - branches: - - master - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -env: - # Generic - FORCE_COLOR: '1' - CLICOLOR: '1' - # Rust - CARGO_TERM_COLOR: always - RUST_BACKTRACE: '1' - -jobs: - build: - runs-on: ${{ matrix.operating-system }} - strategy: - fail-fast: false - matrix: - operating-system: ${{ fromJSON(github.event_name == 'pull_request' && '["ubuntu-latest"]' || '["ubuntu-latest","windows-latest","macos-15"]') }} - rust: [ nightly ] - env: - pact_do_not_track: true - steps: - - name: Checkout code - uses: actions/checkout@v5 - - - name: Install Conan - uses: conan-io/setup-conan@09566912d661de90608308897a4d513e850c04e8 # v1.2.0 - with: - cache_packages: true - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: ${{ matrix.rust }} - - - name: Cache Rust build artifacts - uses: Swatinem/rust-cache@v2 - with: - workspaces: rust -> target - - - name: Install cbindgen and just - uses: taiki-e/install-action@main - with: - tool: cbindgen,just - - - name: Install macOS dependencies - if: runner.os == 'macOS' - run: | - brew install \ - shared-mime-info \ - gettext - - - name: Check plugin log callback headers - if: runner.os == 'Linux' - working-directory: rust/pact_ffi - run: bash tests/check-plugin-log-callback.sh - - - name: Run C consumer examples - working-directory: c/consumer - run: just run - - - name: Run C provider verification - working-directory: c/provider - run: just run - - - name: Run mock_server_logs test - run: cargo test -p pact_ffi returns_mock_server_logs -- --nocapture --include-ignored - working-directory: rust diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 9ac77f3c3..000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,100 +0,0 @@ -name: Pact-Rust Build - -on: - push: - branches: - - '**' - pull_request: - branches: - - master - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ${{ matrix.operating-system }} - strategy: - fail-fast: false - matrix: - operating-system: ${{ fromJSON(github.event_name == 'pull_request' && '["ubuntu-latest"]' || '["ubuntu-latest","windows-latest","macos-15"]') }} - env: - pact_do_not_track: true - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - components: clippy - - uses: Swatinem/rust-cache@v2 - with: - workspaces: rust -> target - - name: Install shared mime info DB - if: runner.os == 'macOS' - run: brew install shared-mime-info - - name: Tests - run: cargo test - working-directory: rust - env: - RUST_LOG: debug - RUST_BACKTRACE: 1 - - name: Build Components - run: cargo build - working-directory: rust - - name: Clippy - if: runner.os == 'Linux' - run: cargo clippy - working-directory: rust - - v2-engine: - runs-on: ubuntu-latest - continue-on-error: true - env: - pact_do_not_track: true - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - with: - workspaces: rust -> target - - name: Tests - run: cargo test - working-directory: rust - env: - RUST_LOG: debug - RUST_BACKTRACE: 1 - PACT_MATCHING_ENGINE: v2 - PACT_V2_MATCHING_LOG_EXECUTED_PLAN: 1 - - musl-build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: | - docker 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.sh - - check-features: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: Swatinem/rust-cache@v2 - with: - workspaces: rust -> target - - run: cargo check --no-default-features - working-directory: rust - - check-wasm: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable - with: - targets: wasm32-wasip2 - - uses: Swatinem/rust-cache@v2 - with: - workspaces: rust -> target - - run: cargo build --target wasm32-wasip2 - working-directory: rust/pact_models - - run: cargo build --target wasm32-wasip2 - working-directory: rust/pact_matching diff --git a/.github/workflows/compatability-suite.yml b/.github/workflows/compatability-suite.yml deleted file mode 100644 index 00fbef144..000000000 --- a/.github/workflows/compatability-suite.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: Pact-Rust Compatibility Suite - -on: - push: - branches: - - master - pull_request: - branches: - - master - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -env: - pact_do_not_track: true - -jobs: - v1: - runs-on: ${{ matrix.operating-system }} - strategy: - fail-fast: false - matrix: - operating-system: ${{ fromJSON(github.event_name == 'pull_request' && '["ubuntu-latest"]' || '["ubuntu-latest","windows-latest","macos-15"]') }} - steps: - - uses: actions/checkout@v2 - - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - with: - workspaces: compatibility-suite -> target - - name: Run Cucumber - run: cargo test --test v1* - working-directory: compatibility-suite - v2: - runs-on: ${{ matrix.operating-system }} - strategy: - fail-fast: false - matrix: - operating-system: ${{ fromJSON(github.event_name == 'pull_request' && '["ubuntu-latest"]' || '["ubuntu-latest","windows-latest","macos-15"]') }} - steps: - - uses: actions/checkout@v2 - - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - with: - workspaces: compatibility-suite -> target - - name: Run Cucumber - run: cargo test --test v2* - working-directory: compatibility-suite - v3: - runs-on: ${{ matrix.operating-system }} - strategy: - fail-fast: false - matrix: - operating-system: ${{ fromJSON(github.event_name == 'pull_request' && '["ubuntu-latest"]' || '["ubuntu-latest","windows-latest","macos-15"]') }} - steps: - - uses: actions/checkout@v2 - - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - with: - workspaces: compatibility-suite -> target - - name: Run Cucumber - run: cargo test --test v3* - working-directory: compatibility-suite - v4: - runs-on: ${{ matrix.operating-system }} - strategy: - fail-fast: false - matrix: - operating-system: ${{ fromJSON(github.event_name == 'pull_request' && '["ubuntu-latest"]' || '["ubuntu-latest","windows-latest","macos-15"]') }} - steps: - - uses: actions/checkout@v2 - - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - with: - workspaces: compatibility-suite -> target - - name: Run Cucumber - run: cargo test --test v4* - working-directory: compatibility-suite diff --git a/.github/workflows/issue-comment-created.yml b/.github/workflows/issue-comment-created.yml index 604c2a584..69639a685 100644 --- a/.github/workflows/issue-comment-created.yml +++ b/.github/workflows/issue-comment-created.yml @@ -5,6 +5,9 @@ on: types: - created +permissions: + issues: write + jobs: jira: runs-on: ubuntu-latest @@ -15,7 +18,7 @@ jobs: run: echo "$COMMENT_BODY" - name: Login - uses: atlassian/gajira-login@v3 + uses: atlassian/gajira-login@ca13f8850ea309cf44a6e4e0c49d9aa48ac3ca4c # v3 env: JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} @@ -29,7 +32,7 @@ jobs: - name: Search id: search - uses: tomhjp/gh-action-jira-search@v0.1.0 + uses: tomhjp/gh-action-jira-search@e099f122d99bf8f12707c157a98166b16498466c # v0.1.0 with: jql: 'summary ~ ${{ toJSON(github.event.issue.title)}} AND project=${{ secrets.JIRA_PROJECT }}' @@ -39,7 +42,7 @@ jobs: - name: Create id: create if: steps.search.outputs.issue == '' - uses: atlassian/gajira-create@v3 + uses: atlassian/gajira-create@1ff0b6bd115a780592b47bfbb63fc4629132e6ec # v3 with: project: ${{ secrets.JIRA_PROJECT }} issuetype: Task @@ -52,7 +55,7 @@ jobs: - name: Add Comment if: steps.search.outputs.issue == '' && steps.create.outputs.issue != '' - uses: actions/github-script@v5 + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f171ae1cd..e05cfc53d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,10 +5,6 @@ on: types: - published - pull_request: - branches: - - master - workflow_dispatch: jobs: diff --git a/.github/workflows/trigger_pact_docs_update.yml b/.github/workflows/trigger_pact_docs_update.yml index 8129910ae..60fe20020 100644 --- a/.github/workflows/trigger_pact_docs_update.yml +++ b/.github/workflows/trigger_pact_docs_update.yml @@ -7,6 +7,8 @@ on: paths: - '**.md' +permissions: {} + jobs: run: runs-on: ubuntu-latest diff --git a/README.md b/README.md index 377d18dfb..440ef1593 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ ![Logo of the project](https://raw.githubusercontent.com/pact-foundation/pact-reference/master/images/logo.svg) -[![Pact-Rust Build](https://github.com/pact-foundation/pact-reference/workflows/Pact-Rust%20Build/badge.svg)](https://github.com/pact-foundation/pact-reference/actions?query=workflow%3A%22Pact-Rust+Build%22) -[![Pact-Rust FFI Build](https://github.com/pact-foundation/pact-reference/actions/workflows/build-ffi.yml/badge.svg)](https://github.com/pact-foundation/pact-reference/actions/workflows/build-ffi.yml) +[![Test](https://github.com/pact-foundation/pact-reference/actions/workflows/test.yml/badge.svg)](https://github.com/pact-foundation/pact-reference/actions/workflows/test.yml) # Pact Reference Implementation From e86b0e02f884cc7373c71855125c2218c558b24b Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 14:09:55 +1100 Subject: [PATCH 09/15] docs: describe the consolidated CI and nextest workflow The README badge points at test.yml, and the AppVeyor badge for a service the repository no longer uses is gone. CLAUDE.md and the Copilot instructions describe the pinned toolchain, the mise-managed tools, nextest, and what test.yml covers. Assisted-by: Claude Code:claude-opus-5-5 --- .github/copilot-instructions.md | 2 +- CLAUDE.md | 5 +++++ CONTRIBUTING.md | 14 ++++++++++++++ rust/README.md | 3 +-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 1c8d4d228..3cd73a469 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -97,5 +97,5 @@ Key architectural boundaries: - `pact_models` is patched in `rust/Cargo.toml` via `[patch.crates-io]` to the local path. Changes there automatically affect workspace crates without publishing. - Logging and test output are centered on `tracing`/`tracing-subscriber`; tests commonly use `test-log` so `RUST_LOG=debug` is useful when debugging failures. - Common test helpers across crates are `rstest`, `expectest`, `hamcrest2`, and `pretty_assertions`. Follow those existing choices before introducing new test utilities. -- CI exercises more than the default happy path: full workspace build/test, Linux `cargo clippy`, `cargo check --no-default-features`, WASM builds for `pact_models` and `pact_matching`, and a separate run with `PACT_MATCHING_ENGINE=v2`. +- CI (`.github/workflows/test.yml`) runs on Linux, macOS and Windows: nextest plus doctests, the compatibility suite, the FFI C examples, a musl build, `cargo hack check --each-feature`, WASM builds for `pact_models` and `pact_matching`, Linux `cargo clippy`, and an advisory run with `PACT_MATCHING_ENGINE=v2`. - Commit messages follow Conventional Changelog style (`feat:`, `fix:`, `chore:`, `refactor:`). diff --git a/CLAUDE.md b/CLAUDE.md index 42e8e1979..ae8f5c476 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -24,6 +24,10 @@ cargo test # Run tests for a specific crate cargo test --package pact_models +# Run tests with nextest, as CI does (install tools with `mise install`) +cargo nextest run --workspace +cargo test --workspace --doc # nextest skips doctests + # Run a single test by name (exact match) cargo test --package pact_models -- my_test_name --exact @@ -90,6 +94,7 @@ pact_verifier_cli pact_ffi ← Standalone CLI / C FFI bindings - **Rust edition**: 2024 for all crates except `pact_ffi` (2021). - **Minimum Rust version**: 1.88.0 (required for edition 2024). +- **Toolchain**: pinned in the root `rust-toolchain.toml`. mise manages the dev tooling. cbindgen alone needs a nightly toolchain, for macro expansion. - **Async runtime**: `tokio` throughout (except WASM builds). - **Logging**: `tracing` / `tracing-subscriber` (not `log`). - **Test helpers**: `rstest`, `hamcrest2`, `expectest`, `pretty_assertions` are common dev-dependencies. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8707b6e3b..8c3c4e9ca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,6 +48,20 @@ cargo build This will compile all the libraries and put the generated files in `rust/target/debug`. +The root `rust-toolchain.toml` pins the Rust version. [mise](https://mise.jdx.dev) manages the rest of the dev tooling; run `mise install` from the repository root to install it. + +### Testing + +CI runs the tests with [nextest](https://nexte.st). nextest skips doctests, so run those separately: + +```shell +cd rust +cargo nextest run --workspace +cargo test --workspace --doc +``` + +Plain `cargo test` also runs the whole suite, doctests included. + ### Releasing The released libraries for each module are built by a GH action that attaches the libraries to the GH release for each diff --git a/rust/README.md b/rust/README.md index f12da1511..3d75becf9 100644 --- a/rust/README.md +++ b/rust/README.md @@ -1,7 +1,6 @@ ![Logo of the project](https://raw.githubusercontent.com/pact-foundation/pact-reference/master/images/logo.svg) -[![Pact-Rust Build](https://github.com/pact-foundation/pact-reference/workflows/Pact-Rust%20Build/badge.svg)](https://github.com/pact-foundation/pact-reference/actions?query=workflow%3A%22Pact-Rust+Build%22) -[![Windows Build status](https://ci.appveyor.com/api/projects/status/bqlb7ny924lsu6yi?svg=true)](https://ci.appveyor.com/project/pact-foundation/pact-reference) +[![Test](https://github.com/pact-foundation/pact-reference/actions/workflows/test.yml/badge.svg)](https://github.com/pact-foundation/pact-reference/actions/workflows/test.yml) # Pact-Rust > Pact implementation written in Rust. From 4bf3238d862b8241f279e3c5751f3d2962f59207 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 14:23:55 +1100 Subject: [PATCH 10/15] ci: build releases with the toolchain from rust-toolchain.toml The release workflow named its own compiler, so it could drift from the pin in rust-toolchain.toml. dtolnay/rust-toolchain also adds the matrix `targets` only to the toolchain named in the action. The aarch64-pc-windows-msvc leg cross-compiles on an x64 runner, so a mismatch would leave the toolchain that builds without its standard library. actions-rust-lang/setup-rust-toolchain, given no `toolchain`, installs the one rust-toolchain.toml names and adds `target` to it. The pin now lives in one file. The action's caching stays off because the workflow already runs Swatinem/rust-cache. The pact_ffi README's "Release compiler" section went with the separate pin. Its Dependencies section already says the library builds with the pinned toolchain. Assisted-by: Claude Code:claude-opus-5-5 --- .github/workflows/release.yml | 10 ++++++---- rust/pact_ffi/README.md | 17 ----------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e05cfc53d..608cbf78f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,12 +38,14 @@ jobs: steps: - uses: actions/checkout@v4 + # With no `toolchain` input, the action installs the one pinned in + # rust-toolchain.toml and adds the matrix target to it. - name: Install release Rust toolchain - uses: dtolnay/rust-toolchain@stable + uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0 with: - # Rust 1.99 miscompiles C bool returns on Linux x86_64 (rust-lang/rust#163911). - toolchain: 1.98.1 - targets: ${{ matrix.targets }} + target: ${{ matrix.targets }} + build-warnings: warn + cache: false - name: Rust caching uses: Swatinem/rust-cache@v2 diff --git a/rust/pact_ffi/README.md b/rust/pact_ffi/README.md index 6ab2147dc..6547b7ac2 100644 --- a/rust/pact_ffi/README.md +++ b/rust/pact_ffi/README.md @@ -20,23 +20,6 @@ It will additionally attempt to find and use `Doxygen` to generate C-friendly do **Note:** Linking to the generated static library on Linux requires you to also link to `pthread`, `dl` and `m`. -## Release compiler - -The [release workflow](../../.github/workflows/release.yml) pins Rust to **1.98.1** -to avoid the Linux x86_64 C boolean return regression in Rust 1.99, tracked in -[rust-lang/rust#163911](https://github.com/rust-lang/rust/issues/163911). -Optimized code can return the `Option::None` encoding (`2`) instead of -the required false byte (`0`), causing foreign-language callers to interpret -false results as true. The 0.5.10 Linux x86_64 release artifacts exhibited this -issue; the same reduced example returns `0` with Rust 1.98.1. - -Keep the release compiler pinned until a corrected compiler is verified through -a foreign-language caller. Rust-only tests can miss this regression because -the lowest bit of the invalid return byte is still zero. This pin applies to -native release builds, not the nightly toolchain used to generate C headers. -Already-published artifacts are not repaired by this change; corrected artifacts -require rebuilding and a separate release. - ## Building with CMake For convenience, this tool integrates with CMake, which is setup to: From 5e95ddae50f1ee44f6d035ed69ba5d3129bd5eb9 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 14:23:56 +1100 Subject: [PATCH 11/15] ci: report every failure and cache the musl job The steps after nextest now run even when nextest fails. The compatibility suite, the musl job and the doctests pass `--no-fail-fast`, so one failing test binary no longer hides the results of later ones. @actions/cache passes GNU tar options such as `--posix`, which Alpine's busybox tar rejects. rust-cache reports the failure as a warning, so the musl job always built cold. The job now installs GNU tar. Assisted-by: Claude Code:claude-opus-5-5 --- .github/workflows/test.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e3164501c..1f5aa81a9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -103,17 +103,20 @@ jobs: RUST_LOG: debug run: cargo nextest run --workspace - # nextest does not run doctests. + # nextest does not run doctests. This step and the ones below run even + # when nextest fails, so one failure does not hide the rest. - name: Run doctests + if: ${{ !cancelled() }} working-directory: ${{ env.WORKSPACE_ROOT }}/rust - run: cargo test --workspace --doc + run: cargo test --workspace --doc --no-fail-fast - name: Run mock server log test + if: ${{ !cancelled() }} working-directory: ${{ env.WORKSPACE_ROOT }}/rust run: cargo nextest run -p pact_ffi --run-ignored only -E 'test(=returns_mock_server_logs)' - name: Run tests with the V2 matching engine - if: runner.os == 'Linux' + if: ${{ !cancelled() && runner.os == 'Linux' }} continue-on-error: true working-directory: ${{ env.WORKSPACE_ROOT }}/rust env: @@ -161,7 +164,7 @@ jobs: # The cucumber binaries use `harness = false`, which nextest cannot drive. - name: Run cucumber suites working-directory: ${{ env.WORKSPACE_ROOT }}/compatibility-suite - run: cargo test + run: cargo test --no-fail-fast ffi: name: FFI (${{ matrix.os }}) @@ -265,7 +268,7 @@ jobs: - name: Install build dependencies run: >- apk add --no-cache bash git musl-dev openssl-dev shared-mime-info - protobuf protobuf-dev tzdata zlib-dev + protobuf protobuf-dev tar tzdata zlib-dev - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -284,7 +287,7 @@ jobs: TZ: UTC run: | cargo build - cargo test + cargo test --no-fail-fast features: name: Feature combinations From be9ffa87512ebcd326b947fce0511d94a9473918 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 16 Oct 2026 14:52:21 +1100 Subject: [PATCH 12/15] ci: install cbindgen from prebuilt binaries only mise pinned cargo-binstall, but the FFI job never installed it, so the `cargo:` backend fell back to compiling cbindgen from source on every cold run. The job now installs cargo-binstall alongside cbindgen. mise.toml enables cargo-quickinstall as a binary source and sets `binstall_only`, so a missing prebuilt binary fails the install instead of silently compiling. Assisted-by: Claude Code:claude-opus-5-5 --- .github/workflows/test.yml | 4 +++- mise.toml | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f5aa81a9..8ae8dc4d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -213,11 +213,13 @@ jobs: - name: Install nightly for cbindgen run: rustup toolchain install nightly --profile minimal + # mise's `cargo:` backend requires mise's own `rust` tool, which resolves + # to the toolchain already installed from rust-toolchain.toml. - name: Install tools uses: jdx/mise-action@08ae2a091c038e1e05ec6f5115dc5c69d5a2a6b8 # v5.1.2 with: working_directory: ${{ env.WORKSPACE_ROOT }} - install_args: cargo:cbindgen just + install_args: rust aqua:cargo-bins/cargo-binstall cargo:cbindgen just cache_save: ${{ github.ref == 'refs/heads/master' }} - name: Install Conan diff --git a/mise.toml b/mise.toml index 1628faa22..40eab52a4 100644 --- a/mise.toml +++ b/mise.toml @@ -10,3 +10,9 @@ just = "1.59.0" [settings] idiomatic_version_file_enable_tools = ["rust"] + +# Install cargo tools from prebuilt binaries only, falling back to +# cargo-quickinstall's builds; never compile them from source. +[settings.cargo] +binstall_only = true +binstall_quickinstall = true From 1ea86ddc9d009a3a925422c1b5f1548d16eda234 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Sat, 17 Oct 2026 09:30:27 +1100 Subject: [PATCH 13/15] build(c): generate pact.h on nightly, build pact_ffi with the pinned toolchain Without PACT_FFI_PREBUILT_DIR, the C projects build pact_ffi through Corrosion. Corrosion's cbindgen helper runs cbindgen with whatever toolchain the environment selects, and cbindgen's macro expansion needs nightly. The justfiles worked around this by defaulting RUSTUP_TOOLCHAIN to nightly. Corrosion then built the whole library on nightly too, unlike every other build in the repository. mise now exports RUSTUP_TOOLCHAIN from rust-toolchain.toml, so the justfile default no longer applied inside a mise environment, and the header step would have run on the pinned toolchain and failed. Each CMakeLists.txt now generates the header with its own `rustup run nightly cbindgen` command, the same way rust/pact_ffi's CMake project does. Corrosion builds the library with whichever toolchain rust-toolchain.toml selects. The justfiles no longer set RUSTUP_TOOLCHAIN. Assisted-by: Claude Code:claude-opus-5-5 --- c/consumer/CMakeLists.txt | 20 +++++++++++++++++--- c/consumer/README.md | 3 ++- c/consumer/justfile | 4 ---- c/provider/CMakeLists.txt | 20 +++++++++++++++++--- c/provider/README.md | 3 ++- c/provider/justfile | 4 ---- 6 files changed, 38 insertions(+), 16 deletions(-) diff --git a/c/consumer/CMakeLists.txt b/c/consumer/CMakeLists.txt index 01f678cd8..969b6da96 100644 --- a/c/consumer/CMakeLists.txt +++ b/c/consumer/CMakeLists.txt @@ -79,10 +79,24 @@ else() MANIFEST_PATH "${PACT_FFI_ROOT}/Cargo.toml" CRATE_TYPES cdylib ) - corrosion_experimental_cbindgen( - TARGET pact_ffi - HEADER_NAME pact.h + + # cbindgen's macro expansion needs nightly; the library itself builds + # with the toolchain pinned in rust-toolchain.toml. + find_program(CBINDGEN_EXECUTABLE cbindgen REQUIRED) + set(PACT_FFI_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/pact_ffi/include") + file(MAKE_DIRECTORY "${PACT_FFI_INCLUDE_DIR}") + add_custom_command( + OUTPUT "${PACT_FFI_INCLUDE_DIR}/pact.h" + COMMAND rustup run nightly "${CBINDGEN_EXECUTABLE}" + --config "${PACT_FFI_ROOT}/cbindgen.toml" + --crate pact_ffi + --output "${PACT_FFI_INCLUDE_DIR}/pact.h" + WORKING_DIRECTORY "${PACT_FFI_ROOT}" + COMMENT "Generating pact.h with cbindgen" ) + add_custom_target(pact_ffi_header DEPENDS "${PACT_FFI_INCLUDE_DIR}/pact.h") + add_dependencies(pact_ffi pact_ffi_header) + target_include_directories(pact_ffi INTERFACE "${PACT_FFI_INCLUDE_DIR}") endif() target_link_libraries( diff --git a/c/consumer/README.md b/c/consumer/README.md index b2ec0d136..75713a71b 100644 --- a/c/consumer/README.md +++ b/c/consumer/README.md @@ -33,7 +33,8 @@ The results of the tests are printed to stdout and will exit with a non-zero sta The tests require: -- A C compiler and a nightly Rust toolchain (the justfile selects nightly, which `cbindgen` needs to generate the header) +- A C compiler and the Rust toolchain pinned in `rust-toolchain.toml` +- `cbindgen` and a nightly Rust toolchain, which `cbindgen` needs to generate the header - CMake (version 3.24 or higher) - Conan (version 2.0 or higher) diff --git a/c/consumer/justfile b/c/consumer/justfile index 88c8e961d..cec30e3d1 100644 --- a/c/consumer/justfile +++ b/c/consumer/justfile @@ -1,7 +1,3 @@ -# Without PACT_FFI_PREBUILT_DIR, Corrosion builds pact_ffi, and cbindgen's -# macro expansion needs a nightly toolchain. -export RUSTUP_TOOLCHAIN := env("RUSTUP_TOOLCHAIN", "nightly") - [unix] build: conan install . --output-folder=build --build=missing diff --git a/c/provider/CMakeLists.txt b/c/provider/CMakeLists.txt index dc5ba3e30..8101433a5 100644 --- a/c/provider/CMakeLists.txt +++ b/c/provider/CMakeLists.txt @@ -78,10 +78,24 @@ else() MANIFEST_PATH "${PACT_FFI_ROOT}/Cargo.toml" CRATE_TYPES cdylib ) - corrosion_experimental_cbindgen( - TARGET pact_ffi - HEADER_NAME pact.h + + # cbindgen's macro expansion needs nightly; the library itself builds + # with the toolchain pinned in rust-toolchain.toml. + find_program(CBINDGEN_EXECUTABLE cbindgen REQUIRED) + set(PACT_FFI_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/pact_ffi/include") + file(MAKE_DIRECTORY "${PACT_FFI_INCLUDE_DIR}") + add_custom_command( + OUTPUT "${PACT_FFI_INCLUDE_DIR}/pact.h" + COMMAND rustup run nightly "${CBINDGEN_EXECUTABLE}" + --config "${PACT_FFI_ROOT}/cbindgen.toml" + --crate pact_ffi + --output "${PACT_FFI_INCLUDE_DIR}/pact.h" + WORKING_DIRECTORY "${PACT_FFI_ROOT}" + COMMENT "Generating pact.h with cbindgen" ) + add_custom_target(pact_ffi_header DEPENDS "${PACT_FFI_INCLUDE_DIR}/pact.h") + add_dependencies(pact_ffi pact_ffi_header) + target_include_directories(pact_ffi INTERFACE "${PACT_FFI_INCLUDE_DIR}") endif() target_link_libraries( diff --git a/c/provider/README.md b/c/provider/README.md index a702c6337..5600547a6 100644 --- a/c/provider/README.md +++ b/c/provider/README.md @@ -34,7 +34,8 @@ It assumes that the consumer contracts have already been generated by running th The verification tests require: -- A C compiler and a nightly Rust toolchain (the justfile selects nightly, which `cbindgen` needs to generate the header) +- A C compiler and the Rust toolchain pinned in `rust-toolchain.toml` +- `cbindgen` and a nightly Rust toolchain, which `cbindgen` needs to generate the header - CMake (version 3.24 or higher) - Conan (version 2.0 or higher) diff --git a/c/provider/justfile b/c/provider/justfile index 599281de7..0ae8e1568 100644 --- a/c/provider/justfile +++ b/c/provider/justfile @@ -1,7 +1,3 @@ -# Without PACT_FFI_PREBUILT_DIR, Corrosion builds pact_ffi, and cbindgen's -# macro expansion needs a nightly toolchain. -export RUSTUP_TOOLCHAIN := env("RUSTUP_TOOLCHAIN", "nightly") - [unix] build: conan install . --output-folder=build --build=missing From f765d828b1099e5963af4a362b8257fd0f5fcfe9 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Sat, 17 Oct 2026 09:39:35 +1100 Subject: [PATCH 14/15] build: update pact-plugin-driver and check `plugins` alone again pact-plugin-driver called `Utc::now()` without enabling chrono's `clock` feature, so pact_matching failed to build with `plugins` as its only feature. The features job skipped that combination. pact-plugins 801c1433 enables `clock`, and the lock now resolves the driver to 7a290b6b, which carries that fix and moves to zip 9. Every zip 8 release is yanked. The features job now runs one `cargo hack check --each-feature` over the whole workspace. Assisted-by: Claude Code:claude-opus-5-5 --- .github/workflows/test.yml | 7 +--- rust/Cargo.lock | 65 ++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ae8dc4d1..7a1cca3f9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -312,14 +312,9 @@ jobs: install_args: github:taiki-e/cargo-hack cache_save: ${{ github.ref == 'refs/heads/master' }} - # pact-plugin-driver calls `Utc::now()` without enabling chrono's `clock` - # feature, so pact_matching fails to build with `plugins` alone. Check - # that combination again once the driver enables `clock`. - name: Check each feature working-directory: rust - run: | - cargo hack check --workspace --exclude pact_matching --each-feature --no-dev-deps - cargo hack check -p pact_matching --each-feature --no-dev-deps --exclude-features plugins + run: cargo hack check --workspace --each-feature --no-dev-deps wasm: name: WASM diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 794119122..fd80a28dd 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -130,7 +130,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -141,7 +141,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -661,9 +661,12 @@ checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" [[package]] name = "constant_time_eq" -version = "0.4.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" +checksum = "9eb6feb175df65d0a3ccd3e73484e940d0ac664e8034f0519fd49a93db3071d9" +dependencies = [ + "rustversion", +] [[package]] name = "content_inspector" @@ -1103,7 +1106,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -1892,15 +1895,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.15.0" @@ -2204,9 +2198,9 @@ dependencies = [ [[package]] name = "lzma-rust2" -version = "0.16.5" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca93e534d1142d1d0dcca6d25fe302508a5dfb40b302802904577725ea0b695b" +checksum = "7277c9742229dc25243236d578b6471a798c554512c6f6a04365ec2e87c2a3bb" dependencies = [ "sha2 0.11.0", ] @@ -2458,7 +2452,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -2833,13 +2827,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] name = "pact-plugin-driver" version = "1.2.7" -source = "git+https://github.com/pact-foundation/pact-plugins.git#d7882b0273cffa0b963e07cd9be2fccd1dce90b1" +source = "git+https://github.com/pact-foundation/pact-plugins.git#7a290b6b165b839abf897f77fad9cce31db728c0" dependencies = [ "anyhow", "async-trait", @@ -3538,7 +3532,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03da047801ff44bb6a4d407d4860c05fd70bb81714e6b2f3812603d5b145b042" dependencies = [ "heck", - "itertools 0.14.0", + "itertools 0.13.0", "log", "multimap", "petgraph", @@ -3559,7 +3553,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b570b25f7617e43d59005d0990ccb79e950a423952cea19671b7a876da390adf" dependencies = [ "anyhow", - "itertools 0.14.0", + "itertools 0.13.0", "proc-macro2 1.0.107", "quote 1.0.47", "syn 2.0.119", @@ -4056,7 +4050,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -4122,7 +4116,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -4516,7 +4510,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -4563,7 +4557,7 @@ dependencies = [ "cfg-if", "libc", "psm", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -4750,7 +4744,7 @@ dependencies = [ "getrandom 0.4.3", "once_cell", "rustix", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -5556,7 +5550,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -6011,9 +6005,9 @@ dependencies = [ [[package]] name = "zip" -version = "8.6.0" +version = "9.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d04a6b5381502aa6087c94c669499eb1602eb9c5e8198e534de571f7154809b" +checksum = "a954114b47a54df49f83d2722814e86b23d4bb1b54a1b90fb7d92b41619ddc22" dependencies = [ "aes", "bzip2", @@ -6026,6 +6020,7 @@ dependencies = [ "indexmap 2.14.2", "lzma-rust2", "memchr", + "nix", "pbkdf2", "ppmd-rust", "sha1", @@ -6062,27 +6057,27 @@ dependencies = [ [[package]] name = "zstd" -version = "0.13.3" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +checksum = "db3ae9bf90af6e40197bef767eeefc46ad6397420fe873830bd85e5fbbfb3c70" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "7.3.0" +version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d80649ab6db9d9f6f9c80a40becd948eda4714a0a5ac8c4d157a32231c7882" +checksum = "ded520f16b29e1a9b771c722221b2b0a0398c2316d9bb3c42b458a5414d7434b" dependencies = [ "zstd-sys", ] [[package]] name = "zstd-sys" -version = "2.1.1+zstd.1.5.7" +version = "2.1.2+zstd.1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeec9eaf2dffbbd09201e23bd0ffcbaa33bb8e9266a10734fd7ed90a85eca078" +checksum = "481ada9c543b2323cbb7bbdbb5249177fbf0188ed959ed2c15e4b22421c84ed3" dependencies = [ "cc", "pkg-config", From b962629278137eadea21fb68c05031a5b951f04d Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Sat, 17 Oct 2026 10:30:13 +1100 Subject: [PATCH 15/15] test: run pact_verifier's pact-writing tests one at a time under nextest pact_verifier's unit tests start mock servers that merge their interactions into shared pact files, such as RustPactVerifier-PactBrokerStub.json. `write_pact` serialises writers with an in-process mutex only. Its new-file branch also truncates the file before taking the file lock. `cargo test` runs these tests as threads of one process, so the mutex was enough. nextest runs each test in its own process, and on macOS CI eleven pact_broker tests failed with "Failed to parse Pact JSON" after reading a file another process had just truncated. A nextest test group with one thread covers the `tests` and `pact_broker::tests` modules of the pact_verifier library. That is about 150 tests, and serialised they still take about 15 s. The race in `write_pact` itself is left for a library change. Assisted-by: Claude Code:claude-opus-5-5 --- rust/.config/nextest.toml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rust/.config/nextest.toml b/rust/.config/nextest.toml index ca823884a..64f5ad2c3 100644 --- a/rust/.config/nextest.toml +++ b/rust/.config/nextest.toml @@ -4,3 +4,13 @@ fail-fast = false # Flag tests slower than 60 s; kill them after 5 periods. slow-timeout = { period = "60s", terminate-after = 5 } + +# pact_verifier's unit tests merge their mock servers' interactions into +# shared pact files. Pact writes lock only within a process, and nextest runs +# each test in its own, so concurrent runs read each other's truncated files. +[test-groups] +pact-verifier-pact-files = { max-threads = 1 } + +[[profile.default.overrides]] +filter = 'package(pact_verifier) & kind(lib) & test(/^(pact_broker::)?tests::/)' +test-group = 'pact-verifier-pact-files'