From 71ddf7989edd70226f35008179f3f5dcb86a14d9 Mon Sep 17 00:00:00 2001
From: Andrew Dunstan <andrew@dunslane.net>
Date: Thu, 11 Jun 2026 08:38:00 -0400
Subject: [PATCH v15 4/5] ci: make the TAP test jobs work with
 PostgreSQL::Test::Session

PostgreSQL::Test::Session loads libpq in-process via FFI::Platypus,
which the CI environments do not yet provide, and the switch exposed
several other gaps in the CI setups:

* Install FFI::Platypus at job setup time: from the Debian package on
  the Linux containers, via MacPorts on macOS, and from CPAN on MinGW
  (MSYS2 does not package it).  The Windows VS job needs nothing, as
  Strawberry Perl already bundles FFI::Platypus.

* Linux - Meson (64-bit) builds with -fsanitize=address.  Loading the
  ASan-instrumented libpq into the uninstrumented perl aborts every
  TAP test with "ASan runtime does not come first in initial library
  list" (reported as exit status 250 via testwrap).  Preload the ASan
  runtime for that job's "Test world" step, scoped to the step so the
  build and ccache are unaffected.

* Linux - Meson (32-bit) runs its TAP tests with the image's i386
  perl, so it needs the i386 build of libffi-platypus-perl.  That
  package cannot be installed alongside the amd64 one (it depends on
  perl:i386, which conflicts with the installed amd64 perl), so
  download it and extract it into place with dpkg -x, the same way
  the image provides the i386 perl itself.  Verified against the
  linux_debian_trixie_ci container image.

* Adding p5.34-ffi-platypus to the macOS package list changed the
  MacPorts cache key, and the resulting fresh MacPorts installation
  revealed that curl and libuuid were never in the package list even
  though the job configures with -Dlibcurl=enabled and -Duuid=e2fs;
  both had been supplied by stale cached installations.  Add curl and
  libuuid (MacPorts' build of util-linux's libuuid, which installs
  uuid/uuid.h and uuid.pc).

Eventually the Linux requirements should instead be handled in the
pg-vm-images container builds.
---
 .github/workflows/pg-ci.yml | 39 +++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/.github/workflows/pg-ci.yml b/.github/workflows/pg-ci.yml
index 5bc5292d2a5..5992e588432 100644
--- a/.github/workflows/pg-ci.yml
+++ b/.github/workflows/pg-ci.yml
@@ -336,6 +336,22 @@ jobs:
             127.0.0.3 pg-loadbalancetest
           EOF
 
+          # The CI container images don't yet include FFI::Platypus,
+          # which PostgreSQL::Test::Session needs. Install it from the
+          # Debian package until the images provide it. The 32-bit job
+          # runs its TAP tests with the image's i386 perl, which needs
+          # the i386 build of the module; that package cannot be
+          # installed alongside the amd64 one (it depends on perl:i386,
+          # which conflicts with the installed perl), so extract it into
+          # place the same way the image provides the i386 perl itself.
+          echo ::group::apt_ffi_platypus
+          apt-get -y -q update
+          apt-get -y -q install libffi-platypus-perl
+          (cd /tmp &&
+            apt-get -y -q download libffi-platypus-perl:i386 &&
+            dpkg -x libffi-platypus-perl_*_i386.deb /)
+          echo ::endgroup::
+
       # By using a shell that includes su, the run commands themselves get
       # simpler. As there are quite a few commands that need to use su...
       - name: Configure
@@ -668,6 +684,16 @@ jobs:
 
       - name: Test world
         shell: *su_postgres_shell
+        # PostgreSQL::Test::Session loads the ASan-instrumented libpq
+        # in-process via FFI::Platypus.  ASan must come first in the link
+        # order; dlopening it into an otherwise uninstrumented perl aborts
+        # with "ASan runtime does not come first".  Preload the ASan
+        # runtime for the test run to satisfy that (a no-op for the
+        # already-instrumented server/client binaries).  Scoped to this
+        # step so the build is unaffected; detect_leaks is already
+        # disabled via ASAN_OPTIONS.
+        env:
+          ADDITIONAL_SETUP: export LD_PRELOAD="$(gcc -print-file-name=libasan.so)"
         run: *meson_test_world_cmd
 
       - *linux_collect_cores_step
@@ -702,12 +728,15 @@ jobs:
 
       MACOS_PACKAGE_LIST: >-
         ccache
+        curl
         icu
         kerberos5
+        libuuid
         lz4
         meson
         openldap
         openssl
+        p5.34-ffi-platypus
         p5.34-io-tty
         p5.34-ipc-run
         python312
@@ -1089,6 +1118,7 @@ jobs:
             ${MINGW_PACKAGE_PREFIX}-gcc \
             ${MINGW_PACKAGE_PREFIX}-icu \
             ${MINGW_PACKAGE_PREFIX}-libbacktrace \
+            ${MINGW_PACKAGE_PREFIX}-libffi \
             ${MINGW_PACKAGE_PREFIX}-libxml2 \
             ${MINGW_PACKAGE_PREFIX}-libxslt \
             ${MINGW_PACKAGE_PREFIX}-lz4 \
@@ -1112,6 +1142,15 @@ jobs:
           perl -mIPC::Run -e 1
           echo ::endgroup::
 
+          # FFI::Platypus, needed by PostgreSQL::Test::Session, is not
+          # packaged for MSYS2, so install it from CPAN. The mingw libffi
+          # installed above lets Alien::FFI use the system library rather
+          # than building its own.
+          echo ::group::cpan_ffi_platypus
+          (echo; echo o conf recommends_policy 0; echo notest install FFI::Platypus) | cpan
+          perl -mFFI::Platypus -e 1
+          echo ::endgroup::
+
       - name: Setup socket directory
         shell: cmd
         run: mkdir ${{env.PG_REGRESS_SOCK_DIR}}
-- 
2.43.0

