Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/compat-ffi-plugins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
name: FFI compatibility suite (V4 plugins)

# The V4 plugin features are not in the pinned suite submodule yet, so this
# checks out the suite branch that adds them and runs `tests/plugins.rs` in
# compatibility-suite-ffi against it. It runs on draft PRs and on PRs to any
# base, unlike test.yml.
on:
push:
branches:
- master
pull_request:
workflow_dispatch:
inputs:
suite-repository:
description: pact-compatibility-suite repository with features/V4/plugins
default: YOU54F/pact-compatibility-suite
suite-ref:
description: Ref of that repository to run
default: feat/plugin-features

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
FORCE_COLOR: '1'
PACT_DO_NOT_TRACK: 'true'
SUITE_REPOSITORY: ${{ inputs.suite-repository || 'YOU54F/pact-compatibility-suite' }}
SUITE_REF: ${{ inputs.suite-ref || 'feat/plugin-features' }}

jobs:
plugins:
name: FFI plugins (ubuntu-latest)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Checkout plugin suite
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ env.SUITE_REPOSITORY }}
ref: ${{ env.SUITE_REF }}
path: pact-compatibility-suite-plugins

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0
with:
build-warnings: warn
cache-workspaces: |
rust -> target
compatibility-suite-ffi -> 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
timeout-minutes: 3
with:
cache_save: ${{ github.ref == 'refs/heads/master' }}

# The library and header steps of .github/scripts/ffi-examples.sh, without the examples.
- name: Build and install pact_ffi
working-directory: rust/pact_ffi
run: |
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 "$PWD/build/install"

- name: Install the Pact CLI
uses: pact-foundation/pact-cli@ce8e65692ad3ea9d11244749ae24c8c49225d95f # main

- name: Install plugins
run: |
# matt is not in the plugin repository index, so it is installed from its release.
pact plugin install https://github.com/mefellows/pact-matt-plugin/releases/tag/v0.1.1 -y
pact plugin install csv --version 0.0.6 -y
pact plugin install avro --version 0.1.3 -y
pact plugin install protobuf --version 0.8.0 -y

- name: Run plugin features
working-directory: compatibility-suite-ffi
run: cargo test --test plugins
env:
PACT_COMPAT_SUITE: ${{ github.workspace }}/pact-compatibility-suite-plugins
9 changes: 8 additions & 1 deletion compatibility-suite-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ description = "Pact compatibility suite driven only through the pact_ffi C ABI,
[dependencies]
anyhow = "1"
base64 = "0.22"
bytes = "1"
cucumber = "0.23"
h2 = "0.4"
http = "1"
libloading = "0.8"
regex = "1"
reqwest = { version = "0.12", default-features = false }
roxmltree = "0.20"
serde_json = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread", "net", "io-util"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "net", "io-util", "time"] }
url = "2"

[build-dependencies]
Expand All @@ -39,3 +42,7 @@ harness = false
[[test]]
name = "message"
harness = false

[[test]]
name = "plugins"
harness = false
2 changes: 2 additions & 0 deletions compatibility-suite-ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cargo test --no-fail-fast
| `PACT_FFI_HEADER` | `../rust/pact_ffi/build/install/include/pact.h` (read at build time) |
| `PACT_FFI_LIB` | `../rust/pact_ffi/build/install/lib/<libpact_ffi.so, .dylib or pact_ffi.dll>` |
| `FFI_TRACE_DIR` | `target/ffi-trace`: each scenario's FFI calls, one file per scenario |
| `PACT_COMPAT_SUITE` | `../compatibility-suite/pact-compatibility-suite`: the suite checkout `plugins` reads features and fixtures from |

## Tests

Expand All @@ -36,6 +37,7 @@ cargo test --no-fail-fast
| `matching` | V3 `http_matching` and `matching_rules`, V4 `matching_rules` |
| `generators` | V3 `generators` and `http_generators`, V4 `generators` |
| `message` | V3 `message_consumer`, V4 `message_consumer`, `synchronous_message_consumer`, `v4` |
| `plugins` | V4 `plugins/*`: lifecycle, HTTP, message, synchronous message and transports (needs the matt, csv, avro and protobuf plugins installed) |

Scenarios tagged `wip` are skipped. `tests/matching.rs` also skips one known failure: the mock server reads a
0-byte body as no body, so the V4 "not empty matcher with binary data (negative case)" scenario can't get its
Expand Down
32 changes: 32 additions & 0 deletions compatibility-suite-ffi/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,35 @@ pub fn async_body_generators_with_context(pact: PactHandle, context: &str) -> Ve
trace::call("pactffi_pact_async_message_iter_delete(iter)".into(), "void");
out
}

// ---- Plugins ----

/// The FFI's last error on this thread (`LAST_ERROR`), which `pactffi_using_plugin` sets when it fails.
pub fn last_error() -> Option<String> {
let mut buf = vec![0u8; 4096];
let n = unsafe { lib().pactffi_get_error_message(buf.as_mut_ptr() as *mut c_char, buf.len() as i32) };
let r = (n > 0).then(|| CStr::from_bytes_until_nul(&buf).map(|s| s.to_string_lossy().into_owned()).unwrap_or_default());
trace::call(format!("pactffi_get_error_message(buffer, {})", buf.len()), r.as_deref().map(lit).unwrap_or(n.to_string()));
r
}

/// 0 is success; 2 means the plugin could not be loaded, with the reason in `last_error`.
pub fn using_plugin(pact: PactHandle, name: &str, version: Option<&str>) -> u32 {
let (version_c, version_lit) = opt(version);
let r = unsafe { lib().pactffi_using_plugin(pact, c(name).as_ptr(), opt_ptr(&version_c)) };
trace::call(format!("pactffi_using_plugin({pact}, {}, {version_lit})", lit(name)), r);
r
}

/// `contents` is the plugin's JSON configuration for the part. 0 is success; 6 is an error from the plugin.
pub fn interaction_contents(i: InteractionHandle, p: InteractionPart, content_type: &str, contents: &str) -> u32 {
let r = unsafe { lib().pactffi_interaction_contents(i, p, c(content_type).as_ptr(), c(contents).as_ptr()) };
trace::call(format!("pactffi_interaction_contents({i}, {}, {}, {})", part(p), lit(content_type), lit(contents)), r);
r
}

/// Releases the pact's hold on its plugins; a plugin no other pact uses is shut down.
pub fn cleanup_plugins(pact: PactHandle) {
unsafe { lib().pactffi_cleanup_plugins(pact) };
trace::call(format!("pactffi_cleanup_plugins({pact})"), "void");
}
Loading
Loading