From 54c93a1372ed273511908ddc3c3eeacfb9ecdde1 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Fri, 21 Nov 2025 19:01:43 -0600 Subject: [PATCH] Export `SYNAPSE_SUPPORTED_COMPLEMENT_TEST_PACKAGES` from `scripts-dev/complement.sh` (#19208) This is useful as someone downstream can source the `scripts-dev/complement.sh` script and run the same set of tests as Synapse: ```bash # Grab the test packages supported by Synapse. # # --fast: Skip rebuilding the docker images, # --build-only: Will only build Docker images but because we also used `--fast`, it won't do anything. # `>/dev/null` to redirect stdout to `/dev/null` to get rid of the `echo` logs from the script. test_packages=$(source ${SYNAPSE_DIR}/scripts-dev/complement.sh --fast --build-only >/dev/null && echo "$SYNAPSE_SUPPORTED_COMPLEMENT_TEST_PACKAGES") echo $test_packages ``` This is spawning from wanting to run the same set of Complement tests in the https://github.com/element-hq/synapse-rust-apps project. --- changelog.d/19208.misc | 1 + scripts-dev/complement.sh | 55 +++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 changelog.d/19208.misc diff --git a/changelog.d/19208.misc b/changelog.d/19208.misc new file mode 100644 index 000000000..1948be309 --- /dev/null +++ b/changelog.d/19208.misc @@ -0,0 +1 @@ +Export `SYNAPSE_SUPPORTED_COMPLEMENT_TEST_PACKAGES` environment variable from `scripts-dev/complement.sh`. diff --git a/scripts-dev/complement.sh b/scripts-dev/complement.sh index adb580732..2447e0dc7 100755 --- a/scripts-dev/complement.sh +++ b/scripts-dev/complement.sh @@ -72,6 +72,12 @@ For help on arguments to 'go test', run 'go help testflag'. EOF } +# We use a function to wrap the script logic so that we can use `return` to exit early +# if needed. This is particularly useful so that this script can be sourced by other +# scripts without exiting the calling subshell (composable). This allows us to share +# variables like `SYNAPSE_SUPPORTED_COMPLEMENT_TEST_PACKAGES` with other scripts. +# +# Returns an exit code of 0 on success, or 1 on failure. main() { # parse our arguments skip_docker_build="" @@ -204,21 +210,12 @@ main() { echo_if_github "::endgroup::" fi + + echo "Docker images built." + else + echo "Skipping Docker image build as requested." fi - if [ -n "$skip_complement_run" ]; then - echo "Skipping Complement run as requested." - return 0 - fi - - export COMPLEMENT_BASE_IMAGE=complement-synapse - if [ -n "$use_editable_synapse" ]; then - export COMPLEMENT_BASE_IMAGE=complement-synapse-editable - export COMPLEMENT_HOST_MOUNTS="$editable_mount" - fi - - extra_test_args=() - test_packages=( ./tests/csapi ./tests @@ -234,6 +231,16 @@ main() { ./tests/msc4306 ) + # Export the list of test packages as a space-separated environment variable, so other + # scripts can use it. + export SYNAPSE_SUPPORTED_COMPLEMENT_TEST_PACKAGES="${test_packages[@]}" + + export COMPLEMENT_BASE_IMAGE=complement-synapse + if [ -n "$use_editable_synapse" ]; then + export COMPLEMENT_BASE_IMAGE=complement-synapse-editable + export COMPLEMENT_HOST_MOUNTS="$editable_mount" + fi + # Enable dirty runs, so tests will reuse the same container where possible. # This significantly speeds up tests, but increases the possibility of test pollution. export COMPLEMENT_ENABLE_DIRTY_RUNS=1 @@ -242,8 +249,18 @@ main() { # (The prefix is stripped off before reaching the container.) export COMPLEMENT_SHARE_ENV_PREFIX=PASS_ + # * -count=1: Only run tests once, and disable caching for tests. + # * -v: Output test logs, even if those tests pass. + # * -tags=synapse_blacklist: Enable the `synapse_blacklist` build tag, which is + # necessary for `runtime.Synapse` checks/skips to work in the tests + test_args=( + -v + -tags="synapse_blacklist" + -count=1 + ) + # It takes longer than 10m to run the whole suite. - extra_test_args+=("-timeout=60m") + test_args+=("-timeout=60m") if [[ -n "$WORKERS" ]]; then # Use workers. @@ -295,11 +312,15 @@ main() { # particularly tricky. export PASS_SYNAPSE_LOG_TESTING=1 + if [ -n "$skip_complement_run" ]; then + echo "Skipping Complement run as requested." + return 0 + fi + # Run the tests! - echo "Images built; running complement with ${extra_test_args[@]} $@ ${test_packages[@]}" + echo "Running Complement with ${test_args[@]} $@ ${test_packages[@]}" cd "$COMPLEMENT_DIR" - - go test -v -tags "synapse_blacklist" -count=1 "${extra_test_args[@]}" "$@" "${test_packages[@]}" + go test "${test_args[@]}" "$@" "${test_packages[@]}" } main "$@"