add e2e testing (#167)

Reviewed-on: #167
This commit is contained in:
Henry Hiles 2026-11-10 18:29:02 -05:00 • committed by Henry Hiles
commit af99de75da
4 changed files with 1346 additions and 41 deletions

30
linux/nix/build_env.nix Normal file
View file

@ -0,0 +1,30 @@
{ pkgs, lib }:
# What building Nexus needs, shared by the dev shell and the e2e tests
{
packages =
with pkgs;
[
stdenv.cc
go
git
libGL
(flutter.override {
extraPkgConfigPackages = [
mpv-unwrapped
libass
];
})
]
++ lib.optionals pkgs.stdenv.isLinux [
wayland
# nativeapi includes XInput2.h, which needs these, but xi.pc only lists them privately
libxext
libxfixes
(callPackage ./pkg/hook_pkg_config.nix { })
];
env = lib.optionalAttrs pkgs.stdenv.isLinux {
LD_LIBRARY_PATH = "./build/native_assets/linux:${lib.makeLibraryPath [ pkgs.zlib ]}";
};
}

View file

@ -54,6 +54,52 @@
};
devShells.default = pkgs.callPackage ./devshell.nix { };
apps =
let
buildEnv = import ./build_env.nix { inherit pkgs lib; };
e2e = pkgs.writeShellApplication {
name = "nexus-e2e";
runtimeInputs =
buildEnv.packages
++ (with pkgs; [
# TEMPORARY: matrix-continuwuity, once the local fixes are released
inputs.continuwuity.packages.${system}.default
curl
dbus
]);
runtimeEnv = buildEnv.env;
text = builtins.readFile ./e2e.sh;
};
in
{
e2e = {
type = "app";
program = lib.getExe e2e;
};
e2e-headless = {
type = "app";
program = lib.getExe (
pkgs.writeShellApplication {
name = "nexus-e2e-headless";
runtimeInputs = [ pkgs.cage ];
runtimeEnv = {
WLR_BACKENDS = "headless";
__EGL_VENDOR_LIBRARY_FILENAMES = "${pkgs.mesa}/share/glvnd/egl_vendor.d/50_mesa.json";
};
text = ''
unset DISPLAY WAYLAND_DISPLAY
# Wayland needs one, which CI may not have
XDG_RUNTIME_DIR="''${XDG_RUNTIME_DIR:-$(mktemp -d)}"
export XDG_RUNTIME_DIR
exec cage -- ${lib.getExe e2e} "$@"
'';
}
);
};
};
};
flake.nixosModules.default = import ./module.nix self;

View file

@ -20,41 +20,20 @@ let
includeNDK = true;
ndkVersions = [ "28.2.13676358" ];
};
buildEnv = import ./build_env.nix { inherit pkgs lib; };
in
pkgs.mkShell {
packages =
with pkgs;
[
go
git
packages = buildEnv.packages ++ [ android.platform-tools ];
libGL
(flutter.override {
extraPkgConfigPackages = [
mpv-unwrapped
libass
];
})
android.platform-tools
]
++ lib.optionals pkgs.stdenv.isLinux [
wayland
# nativeapi includes XInput2.h, which needs these, but xi.pc only lists them privately
libxext
libxfixes
(callPackage ./pkg/hook_pkg_config.nix { })
];
env =
rec {
LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.libclang ];
env = rec {
LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.libclang ];
ANDROID_HOME = "${android.androidsdk}/libexec/android-sdk";
ANDROID_SDK_ROOT = ANDROID_HOME;
JAVA_HOME = pkgs.jdk21;
ANDROID_HOME = "${android.androidsdk}/libexec/android-sdk";
ANDROID_SDK_ROOT = ANDROID_HOME;
JAVA_HOME = pkgs.jdk21;
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_HOME}/build-tools/36.0.0/aapt2";
}
// lib.optionalAttrs pkgs.stdenv.isLinux {
LD_LIBRARY_PATH = "./build/native_assets/linux:${lib.makeLibraryPath [ pkgs.zlib ]}";
};
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_HOME}/build-tools/36.0.0/aapt2";
}
// buildEnv.env;
}

77
linux/nix/e2e.sh Executable file
View file

@ -0,0 +1,77 @@
# shellcheck shell=bash
files=()
flutter_args=()
for arg in "$@"; do
if [[ "$arg" == *.dart ]]; then files+=("$arg"); else flutter_args+=("$arg"); fi
done
if [[ ${#files[@]} -eq 0 ]]; then files=(integration_test/*_test.dart); fi
homeserver="http://localhost:8448"
if curl -s -o /dev/null "$homeserver"; then
echo "Something is already using port 8448, like another e2e run." >&2
exit 1
fi
work="$(mktemp -d)"
# shellcheck disable=SC2329 # Run by the trap
cleanup() {
[[ -n "${server_pid:-}" ]] && kill "$server_pid" 2>/dev/null && wait "$server_pid" 2>/dev/null
rm -rf "$work"
}
trap cleanup EXIT
mkdir -p "$work/db"
cat > "$work/continuwuity.toml" <<EOF
[global]
server_name = "localhost"
database_path = "$work/db"
address = ["127.0.0.1", "::1"]
port = 8448
[global.well_known]
client = "$homeserver"
EOF
users=(alice bob carol dave)
create_users=()
for user in "${users[@]}"; do
create_users+=(--execute "users create-user $user ${user}pass")
done
echo "Starting Continuwuity (log: $work/continuwuity.log)..."
conduwuit -c "$work/continuwuity.toml" "${create_users[@]}" \
> "$work/continuwuity.log" 2>&1 &
server_pid=$!
all_can_log_in() {
for user in "${users[@]}"; do
curl -sf -XPOST "$homeserver/_matrix/client/v3/login" \
-d "{\"type\":\"m.login.password\",\"identifier\":{\"type\":\"m.id.user\",\"user\":\"$user\"},\"password\":\"${user}pass\"}" \
> /dev/null || return 1
done
}
# Wait until login succeeds, otherwise you might try to log in before the account is created
attempts=60
until all_can_log_in; do
kill -0 "$server_pid" 2>/dev/null || { cat "$work/continuwuity.log"; exit 1; }
(( --attempts )) || { echo "Test users weren't created" >&2; exit 1; }
sleep 0.5
done
GOCACHE="$(go env GOCACHE)"
export GOCACHE
status=0
for file in "${files[@]}"; do
name="$(basename "$file" .dart)"
mkdir -p "$work/$name/data" "$work/$name/cache"
XDG_DATA_HOME="$work/$name/data" XDG_CACHE_HOME="$work/$name/cache" \
dbus-run-session -- \
flutter test "$file" -d linux \
--dart-define="NEXUS_E2E_HOMESERVER=$homeserver" "${flutter_args[@]}" ||
status=$?
done
exit "$status"