2024-04-21 15:28:35 -07:00
#!/usr/bin/env bash
set -euo pipefail
2026-08-20 22:38:41 +02:00
toplevel = " $( git rev-parse --show-toplevel) "
DEFAULT_COMPLEMENT_SRC = " $toplevel /target/complement"
DEFAULT_COMPLEMENT_REVISION = "6d2fdc286c2b44faaddd1037205869b2242a4005"
2024-04-21 15:28:35 -07:00
2026-08-20 22:38:41 +02:00
MSC = " ${ COMPLEMENT_MSC :- } "
2026-08-20 22:44:03 +02:00
IMAGE_ARCHIVE = ""
while [ " $# " -gt 0 ] ; do
case " $1 " in
--msc)
if [ " $# " -lt 2 ] ; then
echo "--msc requires an MSC number"
exit 2
fi
MSC = " $2 "
shift 2
;;
--image)
if [ " $# " -lt 2 ] ; then
echo "--image requires a path to a Docker image archive"
exit 2
fi
IMAGE_ARCHIVE = " $2 "
shift 2
;;
*)
break
;;
esac
done
2024-04-21 15:28:35 -07:00
2026-08-20 22:38:41 +02:00
if [ -n " $MSC " ] ; then
MSC = " ${ MSC #MSC } "
MSC = " ${ MSC #msc } "
if ! [[ " $MSC " = ~ ^[ 0-9] +$ ]] ; then
echo "--msc must be an MSC number, for example: --msc 3391"
exit 2
fi
fi
# The root path where Complement is available.
if [ -n " ${ COMPLEMENT_SRC :- } " ] ; then
LOG_FILE = " ${ 1 :- tests /test_results/complement/test_logs.jsonl } "
RESULTS_FILE = " ${ 2 :- tests /test_results/complement/test_results.jsonl } "
else
COMPLEMENT_SRC = " ${ 1 :- $DEFAULT_COMPLEMENT_SRC } "
LOG_FILE = " ${ 2 :- tests /test_results/complement/test_logs.jsonl } "
RESULTS_FILE = " ${ 3 :- tests /test_results/complement/test_results.jsonl } "
fi
2024-04-21 15:28:35 -07:00
2025-12-22 22:31:06 +00:00
# The base docker image to use for complement tests
2026-11-18 12:37:15 +00:00
# On Linux, you can build the default with `docker build -t continuwuity:complement -f ./docker/complement.Dockerfile .`
# after running `cargo build -p conduwuit --features openreg`.
# On non-Linux platforms (or to use a container build), build `docker/Dockerfile` with debuginfo and openreg `--build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg`
# and then run `docker build -t continuwuity:complement --target container -f ./docker/complement.Dockerfile .`.
2025-12-22 22:31:06 +00:00
COMPLEMENT_BASE_IMAGE = " ${ COMPLEMENT_BASE_IMAGE :- continuwuity : complement } "
2024-04-21 15:28:35 -07:00
2025-03-08 00:15:13 -05:00
# Complement tests that are skipped due to flakiness/reliability issues or we don't implement such features and won't for a long time
2025-03-14 15:57:18 -04:00
SKIPPED_COMPLEMENT_TESTS = 'TestPartialStateJoin.*|TestRoomDeleteAlias/Parallel/Regular_users_can_add_and_delete_aliases_when_m.*|TestRoomDeleteAlias/Parallel/Can_delete_canonical_alias|TestUnbanViaInvite.*|TestRoomState/Parallel/GET_/publicRooms_lists.*"|TestRoomDeleteAlias/Parallel/Users_with_sufficient_power-level_can_delete_other.*'
2024-05-21 20:59:45 -04:00
2026-08-20 22:38:41 +02:00
# Download the pinned upstream Complement checkout on first use. A local
# checkout can be supplied as the first argument or with COMPLEMENT_SRC.
if [ ! -e " $COMPLEMENT_SRC " ] ; then
mkdir -p " $( dirname " $COMPLEMENT_SRC " ) "
git init --quiet " $COMPLEMENT_SRC "
git -C " $COMPLEMENT_SRC " remote add origin https://github.com/matrix-org/complement.git
git -C " $COMPLEMENT_SRC " fetch --depth 1 origin " $DEFAULT_COMPLEMENT_REVISION "
git -C " $COMPLEMENT_SRC " checkout --quiet --detach FETCH_HEAD
fi
if [ ! -d " $COMPLEMENT_SRC " ] || [ ! -f " $COMPLEMENT_SRC /go.mod" ] ; then
echo "\$COMPLEMENT_SRC must be a directory containing Complement source code"
2024-07-06 21:15:44 -04:00
exit 1
fi
2024-05-01 23:30:49 -04:00
pushd " $toplevel " > /dev/null
2024-05-06 01:09:51 -04:00
2026-08-20 22:38:41 +02:00
for command in docker go jq; do
if ! command -v " $command " > /dev/null; then
echo "missing required command: $command "
exit 1
fi
done
2026-11-18 12:37:15 +00:00
if [ -z " ${ DOCKER_HOST :- } " ] ; then
DOCKER_HOST = " $( docker context inspect --format '{{.Endpoints.docker.Host}}' 2>/dev/null || true ) "
if [ -n " $DOCKER_HOST " ] ; then
export DOCKER_HOST
fi
fi
2026-08-20 22:44:03 +02:00
if [ -n " $IMAGE_ARCHIVE " ] ; then
if [ ! -f " $IMAGE_ARCHIVE " ] ; then
echo "Docker image archive not found: $IMAGE_ARCHIVE "
exit 1
fi
load_output = " $( docker load --input " $IMAGE_ARCHIVE " 2>& 1) "
printf '%s\n' " $load_output "
COMPLEMENT_BASE_IMAGE = " $( printf '%s\n' " $load_output " | sed -n 's/^Loaded image: //p; s/^Loaded image ID: //p' | tail -n1) "
if [ -z " $COMPLEMENT_BASE_IMAGE " ] ; then
echo "could not determine the image loaded from: $IMAGE_ARCHIVE "
exit 1
fi
fi
2026-08-20 22:38:41 +02:00
if ! docker image inspect " $COMPLEMENT_BASE_IMAGE " > /dev/null 2>& 1; then
echo "Complement base image not found: $COMPLEMENT_BASE_IMAGE "
2026-11-18 12:37:15 +00:00
if [ " $( uname -s) " != "Linux" ] ; then
echo "Build it with: docker buildx build --load -t continuwuity:latest-openreg --build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg -f docker/Dockerfile . && docker build -t $COMPLEMENT_BASE_IMAGE --target container -f docker/complement.Dockerfile ."
else
echo "Build it with: cargo build -p conduwuit --features openreg && docker build -t $COMPLEMENT_BASE_IMAGE -f docker/complement.Dockerfile ."
echo "Or from a container build: docker buildx build --load -t continuwuity:latest-openreg --build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg -f docker/Dockerfile . && docker build -t $COMPLEMENT_BASE_IMAGE --target container -f docker/complement.Dockerfile ."
fi
2026-08-20 22:38:41 +02:00
exit 1
fi
mkdir -p " $( dirname " $LOG_FILE " ) " " $( dirname " $RESULTS_FILE " ) "
LOG_TMP = " $( mktemp " ${ LOG_FILE } .XXXXXX" ) "
RESULTS_TMP = " $( mktemp " ${ RESULTS_FILE } .XXXXXX" ) "
trap 'rm -f "$LOG_TMP" "$RESULTS_TMP"' EXIT
2025-03-08 01:35:26 -05:00
echo ""
echo "running go test with:"
echo "\$COMPLEMENT_SRC: $COMPLEMENT_SRC "
2026-08-20 22:38:41 +02:00
COMPLEMENT_REVISION = " $( git -C " $COMPLEMENT_SRC " rev-parse HEAD 2>/dev/null || echo unknown) "
echo "\$COMPLEMENT_REVISION: $COMPLEMENT_REVISION "
echo "\$COMPLEMENT_MSC: ${ MSC :- all } "
2025-03-08 01:35:26 -05:00
echo "\$COMPLEMENT_BASE_IMAGE: $COMPLEMENT_BASE_IMAGE "
echo "\$RESULTS_FILE: $RESULTS_FILE "
echo "\$LOG_FILE: $LOG_FILE "
echo ""
2024-04-21 15:28:35 -07:00
2026-08-20 22:38:41 +02:00
TEST_PACKAGES =( ./tests/...)
if [ -n " $MSC " ] ; then
test_files = " $( {
grep -rilE --include= '*.go' "msc $MSC ([^0-9]| $)" " $COMPLEMENT_SRC /tests" || true
find " $COMPLEMENT_SRC /tests" -type f -name '*.go' -print | while IFS = read -r file; do
if [[ " $( basename " $file " ) " = ~ [ Mm][ Ss][ Cc] $MSC ([ ^0-9] | $) ]]; then
printf '%s\n' " $file "
fi
done
} | sort -u)"
if [ -z " $test_files " ] ; then
echo "no Complement tests mention MSC $MSC "
exit 1
fi
TEST_PACKAGES =()
while IFS = read -r test_file; do
test_dir = " $( dirname " $test_file " ) "
TEST_PACKAGES +=( ". ${ test_dir # " $COMPLEMENT_SRC " } " )
done <<< " $test_files "
fi
2025-03-08 15:48:23 -05:00
# `COMPLEMENT_ENABLE_DIRTY_RUNS=1` reuses the same complement container for faster complement, at the possible expense of test environment pollution
2026-08-20 22:38:41 +02:00
set +e
( cd " $COMPLEMENT_SRC " && \
2025-03-08 15:48:23 -05:00
COMPLEMENT_BASE_IMAGE = " $COMPLEMENT_BASE_IMAGE " \
2026-08-20 22:38:41 +02:00
go test -tags= "conduwuit_blacklist" -skip= " $SKIPPED_COMPLEMENT_TESTS " -v -timeout 1h -json " ${ TEST_PACKAGES [@] } "
) | tee " $LOG_TMP "
test_status = ${ PIPESTATUS [0] }
set -e
2024-04-21 15:28:35 -07:00
2024-05-02 10:32:30 -04:00
# Post-process the results into an easy-to-compare format, sorted by Test name for reproducible results
2026-08-20 22:38:41 +02:00
jq -s -c 'sort_by(.Test)[]' < " $LOG_TMP " | jq -c '
2024-04-21 15:28:35 -07:00
select(
(.Action == "pass" or .Action == "fail" or .Action == "skip")
and .Test != null
) | {Action: .Action, Test: .Test}
2026-08-20 22:38:41 +02:00
' > " $RESULTS_TMP "
mv " $LOG_TMP " " $LOG_FILE "
mv " $RESULTS_TMP " " $RESULTS_FILE "
trap - EXIT
2025-03-08 00:15:13 -05:00
echo ""
echo ""
echo "complement logs saved at $LOG_FILE "
echo "complement results saved at $RESULTS_FILE "
echo ""
echo ""
2026-08-20 22:38:41 +02:00
exit " $test_status "